From: "Óscar Fuentes" <ofv@wanadoo.es>
To: help-gnu-emacs@gnu.org
Subject: Re: safe way to add contents to a file ?
Date: Mon, 23 Dec 2019 01:08:05 +0100 [thread overview]
Message-ID: <87y2v3ewey.fsf@telefonica.net> (raw)
In-Reply-To: 4F3F7D8E-870C-4C9B-8B7D-2B05CE1B87A8@traduction-libre.org
Jean-Christophe Helary <jean.christophe.helary@traduction-libre.org>
writes:
> 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 ?
Yes.
> 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.
next prev parent reply other threads:[~2019-12-23 0:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-18 0:03 safe way to add contents to a file ? Jean-Christophe Helary
2019-12-18 0:36 ` Óscar Fuentes
2019-12-18 3:20 ` Jean-Christophe Helary
2019-12-20 13:50 ` Jean-Christophe Helary
2019-12-20 16:00 ` Stefan Monnier
2019-12-22 3:14 ` Jean-Christophe Helary
2019-12-22 4:42 ` Jean-Christophe Helary
2019-12-22 14:37 ` Óscar Fuentes
2019-12-22 22:18 ` Jean-Christophe Helary
2019-12-23 0:08 ` Óscar Fuentes [this message]
2019-12-22 18:23 ` Stefan Monnier
2019-12-18 3:59 ` Stefan Monnier
2019-12-18 9:41 ` Jean-Christophe Helary
2019-12-18 13:10 ` Óscar Fuentes
2019-12-18 22:33 ` Jean-Christophe Helary
2019-12-18 14:10 ` Stefan Monnier
2019-12-18 22:25 ` Jean-Christophe Helary
2019-12-18 22:27 ` Jean-Christophe Helary
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y2v3ewey.fsf@telefonica.net \
--to=ofv@wanadoo.es \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.