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

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

Re: doc string of with-temp-file


From: Stefan Monnier
Subject: Re: doc string of with-temp-file
Date: Tue, 27 Dec 2005 12:30:05 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> My point is that the doc string of `with-temp-file' says that a new buffer
> is _created_, used to evaluate stuff, and then written to its file.
> It says nothing about the buffer being _temporary_ (i.e., being deleted
> after being saved).

Indeed it doesn't ay so.  I don't find it indispensable to mention it since
it seems that the behavior is the expected one: after all, it doesn't even
tell you which name this buffer is going to have, so if you have to kill it
yourself afterwards you're going to always have to do something like

  (let (buf)
    (unwind-protect
        (with-temp-file "foo"
          (setq buf (current-buffer))
          ...)
      (kill-buffer buf)))

which is really cumbersome.

> My second point is that the name of the function `with-temp-file' suggests
> that the _file_ is temporary, not the buffer.

100% agreement here.  Actually, when I created make-temp-file I thought it
would be quite natural to define a macro

  (defmacro with-temp-file (x &rest body)
    (let ((file-name (make-symbol "file-name")))
      `(let ((,file-name (make-temp-file ,@(or (cdr x) '("etemp")))))
         (unwind-protect
             (let ((,(car x) ,file-name))
               ,@body)
           (if (file-exists-p ,file-name)
               (delete-file ,file-name))))))

and only later on noticed that the name was already taken by something which
I found wasn't doing what its name implied.

> A better name would be something like `with-temp-buffer-write' or
> `with-temp-buffer-saved'. I don't suggest that those are great names
> either, but they make it clear that 1) the buffer is temporary, 2) the
> file is not temporary, and 3) the buffer is written (to its file). With
> such a name, even the current, bad doc string would be less of a problem.

Agreed.  It should be made clear that the point of this form is to be able
to build a file's content bit-by-bit in elisp (by working in a temp buffer
which is then written to the file when the work is finished).

I can't think of a good name either:

  with-temp-buffer-for-file
  build-file-in-temp-buffer


        Stefan




reply via email to

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