From: Decebal <CLDWesterhof@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Writing a function for a indented copy of a region
Date: Thu, 18 Dec 2008 05:11:38 -0800 (PST) [thread overview]
Message-ID: <ab6711ce-cf53-492d-a735-0c34eeabb2a4@b41g2000pra.googlegroups.com> (raw)
In-Reply-To: fc025faf-0456-4713-a829-963b5c81e6c8@l33g2000pri.googlegroups.com
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)
next prev parent reply other threads:[~2008-12-18 13:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-17 13:31 Writing a function for a indented copy of a region Decebal
2008-12-17 15:59 ` Drew Adams
2008-12-17 16:26 ` Matthias
[not found] ` <mailman.2956.1229529567.26697.help-gnu-emacs@gnu.org>
2008-12-17 17:09 ` Decebal
2008-12-17 18:49 ` Drew Adams
2008-12-17 19:18 ` Decebal
2008-12-17 19:47 ` Andreas Politz
2008-12-17 23:04 ` Decebal
2008-12-17 23:37 ` Decebal
2008-12-18 0:27 ` Andreas Politz
2008-12-18 0:49 ` Decebal
2008-12-17 22:58 ` Decebal
2008-12-18 13:11 ` Decebal [this message]
2008-12-18 15:05 ` Andreas Politz
2008-12-18 15:48 ` Decebal
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ab6711ce-cf53-492d-a735-0c34eeabb2a4@b41g2000pra.googlegroups.com \
--to=cldwesterhof@gmail.com \
--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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).