Any objections to this proposed change? (BTW, what's the rationale of stripping the filename extension here?)
2005-12-02 Matthias Koeppe mkoeppe@mail.math.uni-magdeburg.de
* slime.el (slime-load-file): Strip the extension from the file name of the current buffer only if it is ".lisp". Much more convenient when you try to load the .asd file in the current buffer.
--- slime.el.~1.566.~ 2005-12-01 13:32:54.000000000 +0100 +++ slime.el 2005-12-02 16:37:38.678149000 +0100 @@ -6520,9 +6520,13 @@ (interactive (list (read-file-name "Load file: " nil nil nil (if (buffer-file-name) - (file-name-sans-extension - (file-name-nondirectory - (buffer-file-name))))))) + (let ((file-name + (file-name-nondirectory + (buffer-file-name)))) + (if (string= (file-name-extension file-name) + "lisp") + (file-name-sans-extension file-name) + file-name)))))) (let ((lisp-filename (slime-to-lisp-filename (expand-file-name filename)))) (slime-eval-with-transcript `(swank:load-file ,lisp-filename))))
* Matthias Koeppe [2005-12-02 16:42+0100] writes:
Any objections to this proposed change?
I would very much appreciate if you could rewrite so that it needs less than 80 columns.
(BTW, what's the rationale of stripping the filename extension here?)
Without the extension it's possible to load fasl files with the same command, just as you can load fasl files with CL:LOAD.
Helmut Eller heller@common-lisp.net writes:
- Matthias Koeppe [2005-12-02 16:42+0100] writes:
Any objections to this proposed change? (BTW, what's the rationale of stripping the filename extension here?)
Without the extension it's possible to load fasl files with the same command, just as you can load fasl files with CL:LOAD.
I see, this is what I suspected. As Edi Weitz pointed out, the various Lisp implementations use several default source extensions, so it is not easy to decide which source file can be loaded without specifying the extension. Therefore, I have revised my approach to improve slime-load-file. What do you think of this change?
2005-12-03 Matthias Koeppe mkoeppe@mail.math.uni-magdeburg.de
* slime.el (slime-load-file): Load the FASL file if it exists. Offer to recompile it if FASL file exists but is not current. Don't try to use or update FASL files of .asd files (using slime-load-file-no-compile-regexps), since .asd files are never compiled and often there exists a .lisp file with the same name. (slime-load-file-no-compile-regexps): New variable.
--- slime.el.~1.566.~ 2005-12-01 13:32:54.000000000 +0100 +++ slime.el 2005-12-03 20:06:52.667146000 +0100 @@ -6515,18 +6515,47 @@ (slime-eval-async `(swank:undefine-function ,symbol-name) (lambda (result) (message "%s" result))))
+(defvar slime-load-file-no-compile-regexps + '(".asd$") + "If a source file matches a regexp in this list, +`slime-load-file' will not offer to compile this file.") + (defun slime-load-file (filename) "Load the Lisp file FILENAME." (interactive (list (read-file-name "Load file: " nil nil - nil (if (buffer-file-name) - (file-name-sans-extension - (file-name-nondirectory - (buffer-file-name))))))) - (let ((lisp-filename (slime-to-lisp-filename (expand-file-name filename)))) - (slime-eval-with-transcript `(swank:load-file ,lisp-filename)))) - - + nil + (if (buffer-file-name) + (file-name-nondirectory + (buffer-file-name)))))) + (let ((lisp-filename + (slime-to-lisp-filename (expand-file-name filename)))) + (flet ((load-it (filename) + (slime-eval-with-transcript + `(swank:load-file ,filename)))) + (if (some #'(lambda (regexp) + (string-match regexp filename)) + slime-load-file-no-compile-regexps) + (load-it filename) + (let ((fasl-filename + (slime-eval + `(cl:namestring (cl:compile-file-pathname ,lisp-filename)))) + (fasl-file-exists + (slime-eval + `(cl:not + (cl:not (cl:probe-file + (cl:compile-file-pathname ,lisp-filename))))))) + (cond + ((not fasl-file-exists) + (load-it lisp-filename)) + ((not (slime-eval `(swank:requires-compile-p ,lisp-filename))) + (load-it fasl-filename)) + ((y-or-n-p "An old FASL file exists. Compile first and \ +load FASL file instead of source file? ") + (slime-eval-async + `(swank:compile-file-for-emacs ,lisp-filename t))) + (t + (load-it lisp-filename))))))))
;;;; Profiling --- swank.lisp.~1.353.~ 2005-12-01 13:32:55.000000000 +0100 +++ swank.lisp 2005-12-03 19:15:26.677303000 +0100 @@ -2382,7 +2382,7 @@ "Returns true if NEW-FILE is newer than OLD-FILE." (> (file-write-date new-file) (file-write-date old-file)))
-(defun requires-compile-p (source-file) +(defslimefun requires-compile-p (source-file) (let ((fasl-file (probe-file (compile-file-pathname source-file)))) (or (not fasl-file) (file-newer-p source-file fasl-file))))
* Matthias Koeppe [2005-12-03 20:43+0100] writes:
I see, this is what I suspected. As Edi Weitz pointed out, the various Lisp implementations use several default source extensions, so it is not easy to decide which source file can be loaded without specifying the extension. Therefore, I have revised my approach to improve slime-load-file. What do you think of this change?
Hmm, that's now rather complicated. I think it would be simpler and better to always keep the file extension. Those people who know that the command just boils down to CL:LOAD can still delete the extension manually, beginners aren't confused, and we don't have to document this minor feature.
Helmut.
Helmut Eller heller@common-lisp.net writes:
- Matthias Koeppe [2005-12-03 20:43+0100] writes:
[slime-load-file]
I think it would be simpler and better to always keep the file extension.
OK, I have commited a simple change in this direction.
On Fri, 02 Dec 2005 16:42:16 +0100, Matthias Koeppe mkoeppe+slime@mail.math.uni-magdeburg.de wrote:
(if (string= (file-name-extension file-name)
"lisp")
Lisp source files sometimes also have the extension "cl" or "lsp".
Cheers, Edi.