[Top][All Lists]

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

Re: with-temp-buffer, insert-file-content and errors

From: Michael Olson
Subject: Re: with-temp-buffer, insert-file-content and errors
Date: Mon, 18 Jul 2005 18:11:30 -0500
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

"Richard M. Stallman" <address@hidden> writes:

> I think it is incorrect to use insert-file-contents with VISIT
> non-nil on a temp buffer, so I think we don't need to try to fix
> this.  (It would not be easy, since the unwind-protect cleanup has
> to execute before the error message gets displayed.)

drkm was using code from my emacs-wiki program as an example for this.
You're right in that using a non-nil VISIT argument was a bad idea.
I've also worked around the "prompted to save a temp buffer" problem
by making a macro called `emacs-wiki-with-temp-buffer' as follows.
The condition-case call is mainly used for displaying diagnostic
information, so it might not be generally useful.  A part of the
cleanup code,

         (when (buffer-live-p ,temp-buffer)
           (with-current-buffer ,temp-buffer
             (set-buffer-modified-p nil))
           (... (kill-buffer ,temp-buffer)))

might perhaps be generally useful, but this is mostly an FYI rather
than a feature request.

(defmacro emacs-wiki-with-temp-buffer (&rest body)
  "Create a temporary buffer, and evaluate BODY there like `progn'.
See also `with-temp-file' and `with-output-to-string'.
Unlike `with-temp-buffer', this will never attempt to save the temp buffer."
  (let ((temp-buffer (make-symbol "temp-buffer")))
    `(let ((,temp-buffer (generate-new-buffer " *emacs-wiki-temp*")))
           (condition-case err
               (with-current-buffer ,temp-buffer
              (if (fboundp 'display-warning)
                  (display-warning 'emacs-wiki
                                   (format "%s: Error occurred: %s"
                (message "%s: Error occurred: %s"
         (when (buffer-live-p ,temp-buffer)
           (with-current-buffer ,temp-buffer
             (set-buffer-modified-p nil))
           (unless debug-on-error (kill-buffer ,temp-buffer)))))))
(put 'emacs-wiki-with-temp-buffer 'lisp-indent-function 0)
(put 'emacs-wiki-with-temp-buffer 'edebug-form-spec '(body))

Michael Olson -- FSF Associate Member #652 -- http://www.mwolson.org/
Interests: anime, Debian, XHTML, wiki, Emacs Lisp
  /` |\ | | | IRC: mwolson on freenode.net: #hcoop, #muse, #pulug
 |_] | \| |_| Jabber: mwolson_at_hcoop.net

Attachment: pgpwfVZMTsCq_.pgp
Description: PGP signature

reply via email to

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