From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.help Subject: Re: Writing a function for a indented copy of a region Date: Thu, 18 Dec 2008 16:05:17 +0100 Organization: FH-Trier Message-ID: <1229612783.940597@arno.fh-trier.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1229614905 6958 80.91.229.12 (18 Dec 2008 15:41:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 18 Dec 2008 15:41:45 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 18 16:42:50 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LDL1Q-0001uZ-Ns for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Dec 2008 16:42:44 +0100 Original-Received: from localhost ([127.0.0.1]:43995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LDL0E-0007MS-DG for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Dec 2008 10:41:30 -0500 Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!t-online.de!inka.de!peernews!news.belwue.de!news.uni-kl.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 75 Original-NNTP-Posting-Host: 143-93-54-11.arno.fh-trier.de Original-X-Trace: news.uni-kl.de 1229612833 11493 143.93.54.11 (18 Dec 2008 15:07:13 GMT) Original-X-Complaints-To: usenet@news.uni-kl.de Original-NNTP-Posting-Date: Thu, 18 Dec 2008 15:07:13 +0000 (UTC) User-Agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018) In-Reply-To: Cache-Post-Path: arno.fh-trier.de!unknown@dslb-088-069-051-076.pools.arcor-ip.net X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) Original-Xref: news.stanford.edu gnu.emacs.help:165470 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:60796 Archived-At: Decebal wrote: > On 17 dec, 14:31, Decebal 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? > It is mentioned somewhere in the info files, that C-c is/should be reserved for the user. C-c C- is often used by major-modes, whose keymap will potentially shadow your global-map . > 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) > ) Have a look at `delete-region'. -ap > (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)