From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?=C3=93scar_Fuentes?= Newsgroups: gmane.emacs.help Subject: Re: safe way to add contents to a file ? Date: Mon, 23 Dec 2019 01:08:05 +0100 Message-ID: <87y2v3ewey.fsf@telefonica.net> References: <0FE61EAF-672C-4348-8107-F4C3D176FCF4@traduction-libre.org> <87k16ua2qm.fsf@telefonica.net> <2C8281A0-290F-4505-8495-4992E8E0B82B@traduction-libre.org> <3C9F1A1A-551E-411B-91B2-CB31B51094B4@traduction-libre.org> <55F7CE36-37C4-49BC-95F2-E91DE6C4628F@traduction-libre.org> <877e2ofmtv.fsf@telefonica.net> <4F3F7D8E-870C-4C9B-8B7D-2B05CE1B87A8@traduction-libre.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="156424"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 23 01:08:32 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ijBGy-000eb7-Dc for geh-help-gnu-emacs@m.gmane.org; Mon, 23 Dec 2019 01:08:32 +0100 Original-Received: from localhost ([::1]:51848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ijBGx-0007KM-Ai for geh-help-gnu-emacs@m.gmane.org; Sun, 22 Dec 2019 19:08:31 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47859) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ijBGm-0007K4-9i for help-gnu-emacs@gnu.org; Sun, 22 Dec 2019 19:08:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ijBGk-000803-Ti for help-gnu-emacs@gnu.org; Sun, 22 Dec 2019 19:08:20 -0500 Original-Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:41798 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ijBGk-0007qY-DE for help-gnu-emacs@gnu.org; Sun, 22 Dec 2019 19:08:18 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1ijBGh-000eM3-2C for help-gnu-emacs@gnu.org; Mon, 23 Dec 2019 01:08:15 +0100 X-Injected-Via-Gmane: http://gmane.org/ Cancel-Lock: sha1:jwHAjxy2T8N8s2gm2ciJiNV9zJM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:122086 Archived-At: Jean-Christophe Helary 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.