all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to copy current buffer to a temporary buffer
@ 2014-05-16  7:59 Cecil Westerhof
  2014-05-16  9:31 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 6+ messages in thread
From: Cecil Westerhof @ 2014-05-16  7:59 UTC (permalink / raw)
  To: help-gnu-emacs

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

The following works:
    (defun make-html-file ()
      (interactive)
      (let ((buffer-name (generate-new-buffer-name "tempori.html")))
        (copy-region-as-kill (point-min) (point-max))
        (switch-to-buffer buffer-name)
        (html-mode)
        (yank)))

But the ‘problem’ is that this adds your current buffer to the kill
ring. That is a side effect that should be circumvented.

So I tried the following:
    (defun make-html-file ()
      (interactive)
      (let ((buffer-name (generate-new-buffer-name "tempori.html"))
            (old-buffer (current-buffer)))
        (switch-to-buffer buffer-name)
        (auto-fill-mode 0)
        (insert-buffer-substring old-buffer)
        (html-mode)))

The problem is that this formats the lines and because of this the
regular expressions that are used for the converting do not work
anymore. How can I write the function in such a way that it does not
add to the kill ring, without the lines being formatted?

I could of-course use:
    (pop kill-ring)

in the first function, but could the second function made to work?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-05-16 19:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-05-16 18:22       ` Pascal J. Bourguignon
2014-05-16 19:05       ` Thien-Thi Nguyen

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.