[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to copy current buffer to a temporary buffer
From: |
Cecil Westerhof |
Subject: |
How to copy current buffer to a temporary buffer |
Date: |
Fri, 16 May 2014 09:59:12 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
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
- How to copy current buffer to a temporary buffer,
Cecil Westerhof <=