From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Cecil Westerhof Newsgroups: gmane.emacs.help Subject: Re: How to copy current buffer to a temporary buffer Date: Fri, 16 May 2014 13:49:00 +0200 Organization: Decebal Computing Message-ID: <87ppjec5ar.fsf@Equus.Decebal.nl> References: <87y4y2cfxr.fsf@Equus.Decebal.nl> <87ha4qjci7.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1400241927 24020 80.91.229.3 (16 May 2014 12:05:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 16 May 2014 12:05:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri May 16 14:05:23 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WlGt6-0004Wp-Qu for geh-help-gnu-emacs@m.gmane.org; Fri, 16 May 2014 14:05:20 +0200 Original-Received: from localhost ([::1]:35198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WlGt6-0002At-9p for geh-help-gnu-emacs@m.gmane.org; Fri, 16 May 2014 08:05:20 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!rt.uk.eu.org!feed.xsnews.nl!border03.ams.xsnews.nl!feeder01.ams.xsnews.nl!frontend-F09-11.ams.news.kpn.nl Original-Newsgroups: gnu.emacs.help X-Face: "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR,v+Pti8=Vi/Z"g^?b"E X-Homepage: http://www.decebal.nl/ User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) Cancel-Lock: sha1:3Msocbe4lDibXhvm+N6Q0+myuGk= Original-Lines: 37 Original-NNTP-Posting-Host: 77.171.42.144 Original-X-Trace: 1400241612 news.kpn.nl 16834 77.171.42.144@kpn/77.171.42.144:53890 Original-Xref: usenet.stanford.edu gnu.emacs.help:205431 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97699 Archived-At: Op Friday 16 May 2014 12:13 CEST schreef Eli Zaretskii: >> From: "Pascal J. Bourguignon" >> Date: Fri, 16 May 2014 11:31:28 +0200 >> >> Cecil Westerhof writes: >> >>> I want to copy the current buffer to a temporary buffer, to do >>> some edits on it. (Converting a text file to a html file.) >> >> >> (let ((contents (buffer-substring (point-min) (point-max)))) >> (with-temp-buffer >> (insert contents) >> (do-something))) > > I think using the insert-buffer function will make this more > efficient (since no string needs to be consed, something that might > not be trivial with large buffers). I used insert-buffer earlier on, but that formatted the lines and that is not acceptable. I now have the following code: (defun make-html-file () (copy-region-as-kill (point-min) (point-max)) (switch-to-buffer (generate-new-buffer-name "tempori.html")) (yank) (pop kill-ring) (html-mode)) No need for a let anymore and I think the code is more clear also. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof