help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to copy current buffer to a temporary buffer


From: Cecil Westerhof
Subject: Re: How to copy current buffer to a temporary buffer
Date: Fri, 16 May 2014 13:49:00 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Op Friday 16 May 2014 12:13 CEST schreef Eli Zaretskii:

>> From: "Pascal J. Bourguignon" <pjb@informatimago.com>
>> Date: Fri, 16 May 2014 11:31:28 +0200
>>
>> Cecil Westerhof <Cecil@decebal.nl> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]