From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.help Subject: Re: Adding `#' at each new line with text until the end of the file Date: Thu, 20 May 2010 21:05:06 +0200 Organization: FH-Trier Message-ID: <87k4qyiecd.fsf@fh-trier.de> 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> <87mxvx2m2w.fsf@merciadriluca-station.MERCIADRILUCA> <87pr0tlzuz.fsf@kuiper.lan.informatimago.com> <87sk5neuwz.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 1291833231 18942 80.91.229.12 (8 Dec 2010 18:33:51 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2010 18:33:51 +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:33:47 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 1PQOpm-0006CN-Mk for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 19:33:46 +0100 Original-Received: from localhost ([127.0.0.1]:39942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQOpl-0004Xn-Qo for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 13:33:45 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!kanaga.switch.ch!switch.ch!news.belwue.de!news.uni-kl.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 39 Original-NNTP-Posting-Host: 143-93-54-11.arno.fh-trier.de Original-X-Trace: news.uni-kl.de 1274382307 1469 143.93.54.11 (20 May 2010 19:05:07 GMT) Original-X-Complaints-To: usenet@news.uni-kl.de Original-NNTP-Posting-Date: Thu, 20 May 2010 19:05:07 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:W+TzUH8UuIOLO/wsI0GqY/Lr78w= Cache-Post-Path: arno.fh-trier.de!unknown@dslb-088-068-217-079.pools.arcor-ip.net X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) Original-Xref: usenet.stanford.edu gnu.emacs.help:178309 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:75799 Archived-At: Merciadri Luca writes: >> Here with find-file-noselect as it has been advised (not tested): >> >> (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 >> (find-file-noselect ,path t ,literal) >> (prog1 (save-excursion ,@body) >> ,(when save `(save-buffer 1)))) >> ,(when kill >> `(kill-buffer (current-buffer))))))) >> This macro may kill buffers at random, because `find-file-noselect' does not make the files buffer current. But even with `find-file', this may go wrong, in case the function does not succeed or body changes the current buffer. -ap