[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Writing a function for a indented copy of a region
From: |
Decebal |
Subject: |
Re: Writing a function for a indented copy of a region |
Date: |
Thu, 18 Dec 2008 05:11:38 -0800 (PST) |
User-agent: |
G2/1.0 |
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 have made a better (and more generally) again.
The function indented-yank is a specialised version of my-headed-yank,
so I wrote that one also. ;-}
I also needed a function to remove a region without putting it in the
kill-ring, so I also made the function my-remove-region.
I made key-combinations for al the three functions.
Are there standards for naming functions and asigning functions to key
combinations?
The code:
(defun my-remove-region(begin end)
"Delete region without putting it in the kill-ring"
(interactive "r")
(kill-region begin end)
(pop kill-ring)
)
(global-set-key (kbd "C-c C-r") 'my-remove-region)
(defun my-headed-yank(head begin end do-kill)
"Put region with 'head' prepended to every line in the kill-
ring"
(interactive "sHead: \nr\nnKill Region? ")
(kill-new (replace-regexp-in-string
"^"
head
(buffer-substring begin end)
)
)
(if do-kill
(my-remove-region begin end)
)
(deactivate-mark)
)
(global-set-key (kbd "C-c C-h") 'my-headed-yank)
(defun my-indented-yank(indent begin end)
"Put indented region in the kill-ring"
(interactive "p\nr")
(setq indent (cond ((eq indent 0) 1)
((eq indent 1) 4)
(t indent)
)
)
(let ((do-kill) (head))
(if (< indent 0)
(setq indent (- 0 indent)
do-kill t
)
)
(setq head
(format (format "%%%ds" indent) "")
)
(my-headed-yank head begin end do-kill)
)
)
(global-set-key (kbd "C-c C-w") 'my-indented-yank)
Re: Writing a function for a indented copy of a region, Decebal, 2008/12/17
Re: Writing a function for a indented copy of a region,
Decebal <=