From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Merciadri Luca Newsgroups: gmane.emacs.help Subject: Re: Adding `#' at each new line with text until the end of the file Date: Tue, 18 May 2010 18:47:51 +0200 Organization: ULg Message-ID: <87mxvx2m2w.fsf@merciadriluca-station.MERCIADRILUCA> References: <87k4r24iq3.fsf@merciadriluca-station.MERCIADRILUCA> <87bpcel6zj.fsf@kuiper.lan.informatimago.com> <878w7is2yy.fsf@merciadriluca-station.MERCIADRILUCA> <87zkzyjkcb.fsf@kuiper.lan.informatimago.com> <87aarx4j3i.fsf@merciadriluca-station.MERCIADRILUCA> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291833837 22136 80.91.229.12 (8 Dec 2010 18:43:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2010 18:43:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 08 19:43:52 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQOzW-0003Fg-S0 for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 19:43:51 +0100 Original-Received: from localhost ([127.0.0.1]:45559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQOel-0006rS-Uj for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 13:22:23 -0500 Original-Path: usenet.stanford.edu!goblin2!goblin.stu.neva.ru!news.net.uni-c.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:QFbJa0hjaSZvXNuxvUvwsibdWBU= Original-Lines: 60 Original-NNTP-Posting-Host: 62.197.101.67 Original-X-Trace: news.sunsite.dk DXC=]9FT72R94dXPF49IdUYT?QYSB=nbEKnk[2[HYl_M\WJRB`G2cTG; MnQLGVLjEY^2YX[=LHD=0P^YT9g\V1BeNHOY5Z@8`56Df9P; _oYN<1Tn3SKbofEV:W:8[ Original-X-Complaints-To: staff@sunsite.dk Original-Xref: usenet.stanford.edu gnu.emacs.help:178244 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:75814 Archived-At: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 pjb@informatimago.com (Pascal J. Bourguignon) writes: >> Sure, but, as I explained in my previous message, it does not even >> modify the Sayings file. Why? > > Because you didn't instruct the program to modify the file. > Read the documentation of insert, for example. Does it mention files? > What does insert modify? Insert modifies the current buffer, according to the manual. Or find-file loads its arg into a buffer. So, if find-file loads its arg into the *current* buffer, insert should modify the current buffer, that is, `Sayings'. > Here is a macro that could be useful: > > (require 'cl) > (defmacro* with-file (file-and-options &body body) > "Processes BODY with a buffer on the given file. > DO: find-file or find-file-literally, process body, and > optionally save the buffer and kill it. > save is not done if body exits exceptionnaly. > kill is always done as specified. > FILE-AND-OPTION: either an atom evaluated to a path, > or (path &key (save t) (kill t) (literal nil)) > " > (if (atom file-and-options) > `(with-file (,file-and-options) ,@body) > ;; destructuring-bind is broken, we cannot give anything else than nil > ;; as default values: > (destructuring-bind (path &key (save nil savep) (kill nil killp) > (literal nil literalp)) > file-and-options > (unless savep (setf save t)) > (unless killp (setf kill t)) > `(unwind-protect > (progn > (,(if literal 'find-file-literally 'find-file) ,path) > (prog1 (save-excursion ,@body) > ,(when save `(save-buffer 1)))) > ,(when kill > `(kill-buffer (current-buffer))))))) Thanks. I'll keep it. - -- Merciadri Luca See http://www.student.montefiore.ulg.ac.be/~merciadri/ - -- The whole dignity of man lies in the power of thought. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.8 iEYEARECAAYFAkvyxLcACgkQM0LLzLt8MhyKawCfXMN2zho0p+/bBEc1gQAG3YmD MO4AoK6a8STV9snV2hmw0the3TF9GnIy =CMWS -----END PGP SIGNATURE-----