]> git.eshelyaron.com Git - emacs.git/commitdiff
(lm-with-file): When FILE is nil, run BODY in current buffer.
authorRichard M. Stallman <rms@gnu.org>
Tue, 30 Sep 2003 12:47:04 +0000 (12:47 +0000)
committerRichard M. Stallman <rms@gnu.org>
Tue, 30 Sep 2003 12:47:04 +0000 (12:47 +0000)
lisp/emacs-lisp/lisp-mnt.el

index 893d95db05c2cf6085ce814a90df1459a84d661b..aeb7fb2258d06bc526c581e418b817c2adc8226e 100644 (file)
@@ -297,12 +297,14 @@ The returned value is a list of strings, one per line."
 
 (defmacro lm-with-file (file &rest body)
   "Execute BODY in a buffer containing the contents of FILE.
-If FILE is nil, just return nil."
+If FILE is nil, execute BODY in the current buffer."
   (let ((filesym (make-symbol "file")))
     `(let ((,filesym ,file))
-       (when ,filesym 
-        (with-temp-buffer
-          (insert-file-contents ,filesym)
+       (if ,filesym
+          (with-temp-buffer
+            (insert-file-contents ,filesym)
+            ,@body)
+        (save-excursion 
           ,@body)))))
 (put 'lm-with-file 'lisp-indent-function 1)
 (put 'lm-with-file 'edebug-form-spec t)