[Top][All Lists]

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

Re: safe way to add contents to a file ?

From: Óscar Fuentes
Subject: Re: safe way to add contents to a file ?
Date: Mon, 23 Dec 2019 01:08:05 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Jean-Christophe Helary <>

> Oscar, Stephan,
> Thank you *so* much for your comments.
> Regarding `user-error' or `error', neither the doc strings nor the
> reference mention that the execution is stopped, I discovered that
> eventually but that was confusing. Am I missing something ?

Strictly speaking, execution is not stopped but control goes searching
for a matching signal. The net effect on your case is that Emacs comes
back into interactive mode, which implies that the execution of your
command stops.

> Oscar, you say that a `let' would be "nicer" than a `setq', is it
> because `let' is local to the body that follows, so that I don't have
> to "polute" my top level with locally used values ?


> Stephan, regarding `save-current-buffer' vs `with-file-noselect', the

BTW, my example was wrong, I meant to use

(with-current-buffer (find-file-no-select ...

Stefan did it right.

> former saves the buffer that is current so I need to use `set-buffer'
> to set the current buffer, but `with-file-noselect' sets the current
> buffer to the buffer associated with the file, hence `set-buffer' is
> redundant there, right ?

Correct, although you made up the name `with-file-noselect' when you
intended to mention `with-current-buffer' above.

> `unwind-protect' is pretty cool ! I guess it can be used to easily
> handle errors without bothering about error messages. The doc strings
> are very clear, but the reference is totally confusing:
> "The ‘unwind-protect’ construct is essential whenever you temporarily put
> a data structure in an inconsistent state; it permits you to make the
> data consistent again in the event of an error or throw.  (Another more
> specific cleanup construct that is used only for changes in buffer
> contents is the atomic change group; *note Atomic Changes::.)"
> I would never think of using that form for such a trivial issue.

Error handling is always under-appreciated by beginners (and many
veterans, sadly). When creating Emacs commands for your own use,
comprehensive error handling is not crucial, but for important code is
essential and a very difficult topic.

> Why is the writing so obfuscated ?

Actually, the text is trying to be helpful to non-expert readers. That's
always hard to achieve.

reply via email to

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