On 17 dec, 14:31, Decebal <CLDWester...@gmail.com> wrote:
A lot of times I need to copy a part of a (log) file for an e-mail. I
like to indent this (default with four spaces). At this moment I do
this by hand. But I would like to do this with a function.
What I would like this function to do is take the part that is
selected, indent this with (default) four spaces, put the indented
region in the kill-ring and undo the indent. Has anyone a pointer
about how to code this?
I found a way. In my .emacs I put:
(defun my-indented-yank(indent)
"Put indented region in the kill-ring"
(interactive "p")
(setq indent (cond ((eq indent 0) 1)
((eq indent 1) 4)
(t indent)
)
)
(indent-rigidly (region-beginning) (region-end) indent)
(copy-region-as-kill (region-beginning) (region-end))
(undo)
)
It looks like this satifies my demands. ;-}
In this way the default indent is 4. If I need an indent of one I can
use 'C-u 0'.
The only thing is that the 'GNU Emacs Lisp Reference Manual' says that
I should not use 'copy-region-as-kill'. I should use 'kill-new' or
'kill-append'. But those do not work with a region. What am I missing?