emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recent change of lm-with-file in emacs-lisp/lisp-mnt.el.


From: Lute Kamstra
Subject: Re: Recent change of lm-with-file in emacs-lisp/lisp-mnt.el.
Date: Fri, 26 Sep 2003 11:38:01 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Richard Stallman <address@hidden> writes:

>     Maybe the change can be fixed so that lm-with-file handles FILE == nil
>     as before?
>
> Does this work right?
>
> (defmacro lm-with-file (file &rest body)
>   "Execute BODY in a buffer containing the contents of FILE.
> If FILE is nil, just return nil."
>   (let ((filesym (make-symbol "file")))
>     `(let ((,filesym ,file))
>        (if ,filesym
>          (with-temp-buffer
>            (insert-file-contents ,filesym)
>            ,@body)
>        ,@body))))

Almost.  BODY used to be wrapped in a save-excursion (docstring
updated too):

(defmacro lm-with-file (file &rest body)
  "Execute BODY in a temporary buffer containing the contents of FILE.
If FILE is nil, execute BODY in the current buffer."
  (let ((filesym (make-symbol "file")))
    `(let ((,filesym ,file))
       (if ,filesym
           (with-temp-buffer
             (insert-file-contents ,filesym)
             ,@body)
         (save-excursion
           ,@body)))))

Isn't it bad to refer to BODY twice?

  Lute.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]