[slime-devel] Patch for slime-load-file
Matthias Koeppe
mkoeppe+slime at mail.math.uni-magdeburg.de
Sat Dec 3 19:43:10 UTC 2005
Helmut Eller <heller at 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 at 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 -- http://www.math.uni-magdeburg.de/~mkoeppe
More information about the slime-devel
mailing list