From: Cecil Westerhof <Cecil@decebal.nl>
To: help-gnu-emacs@gnu.org
Subject: Re: How to copy current buffer to a temporary buffer
Date: Fri, 16 May 2014 13:49:00 +0200 [thread overview]
Message-ID: <87ppjec5ar.fsf@Equus.Decebal.nl> (raw)
In-Reply-To: mailman.1456.1400235243.1147.help-gnu-emacs@gnu.org
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
next prev parent reply other threads:[~2014-05-16 11:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 7:59 How to copy current buffer to a temporary buffer Cecil Westerhof
2014-05-16 9:31 ` Pascal J. Bourguignon
2014-05-16 10:13 ` Eli Zaretskii
[not found] ` <mailman.1456.1400235243.1147.help-gnu-emacs@gnu.org>
2014-05-16 11:49 ` Cecil Westerhof [this message]
2014-05-16 18:22 ` Pascal J. Bourguignon
2014-05-16 19:05 ` Thien-Thi Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ppjec5ar.fsf@Equus.Decebal.nl \
--to=cecil@decebal.nl \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.