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: Pascal J. Bourguignon
Subject: Re: How to copy current buffer to a temporary buffer
Date: Fri, 16 May 2014 20:22:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Cecil Westerhof <Cecil@decebal.nl> writes:

> 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).

Oops, I knew I was missing something.


> I used insert-buffer earlier on, but that formatted the lines and that
> is not acceptable.

You can do this then:

    (let ((source-buffer (current-buffer)))
      (with-temp-buffer
        (insert-buffer source-buffer)
        (set-text-properties (point-min) (point-max) '())
        (do-something)))


-- 
__Pascal Bourguignon__
http://www.informatimago.com/
"Le mercure monte ?  C'est le moment d'acheter !"


reply via email to

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