From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Decebal Newsgroups: gmane.emacs.help Subject: Re: Writing a function for a indented copy of a region Date: Wed, 17 Dec 2008 15:37:37 -0800 (PST) Organization: http://groups.google.com Message-ID: <38ccb458-3f76-4461-bf75-57c674affae9@c36g2000prc.googlegroups.com> References: <1229543337.962004@arno.fh-trier.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1229557371 12115 80.91.229.12 (17 Dec 2008 23:42:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Dec 2008 23:42:51 +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 00:43:54 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 1LD63U-0005Ho-Pn for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Dec 2008 00:43:53 +0100 Original-Received: from localhost ([127.0.0.1]:34378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LD62I-0001ox-MK for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Dec 2008 18:42:38 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!c36g2000prc.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 38 Original-NNTP-Posting-Host: 84.53.123.169 Original-X-Trace: posting.google.com 1229557058 26521 127.0.0.1 (17 Dec 2008 23:37:38 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 17 Dec 2008 23:37:38 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c36g2000prc.googlegroups.com; posting-host=84.53.123.169; posting-account=K-cdeAoAAAD_0d505kUtHXJaT5LFIu-3 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; nl; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:165429 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:60760 Archived-At: On 17 dec, 20:47, Andreas Politz wrote: > Why not work with a string, instead of messing with your buffers undo his= tory. > > (defun kill-save-indent-region (indent start end) > =A0 =A0(interactive "p\nr") > =A0 =A0(kill-new (replace-regexp-in-string > =A0 =A0 =A0 =A0 =A0 =A0 =A0"^" =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0;or "^\\s-*" > =A0 =A0 =A0 =A0 =A0 =A0 =A0(format (format "%%%ds" (case indent > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0(0 1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0(1 4) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0(t indent))) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"") > =A0 =A0 =A0 =A0 =A0 =A0 =A0(buffer-substring start end))) > =A0 =A0(deactivate-mark)) Looking at your code I should replace: (indent-rigidly (region-beginning) (region-end) indent) (if do-kill (kill-region (region-beginning) (region-end)) (copy-region-as-kill (region-beginning) (region-end)) (undo) ) with: (kill-new (replace-regexp-in-string "^" (format (format "%%%ds" indent) "") (filter-buffer-substring (region-beginning) (region- end) do-kill) ) ) but then I get that filter-buffer-substring is void. What am I doing wrong?