From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Peter Lee Newsgroups: gmane.emacs.help Subject: Re: Column replace Date: Wed, 13 Jun 2007 16:01:59 -0500 Organization: x Message-ID: References: <1181638134.131187.199190@i13g2000prf.googlegroups.com> <1181669823.283617.131480@n15g2000prd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1181770868 24831 80.91.229.12 (13 Jun 2007 21:41:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 13 Jun 2007 21:41:08 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jun 13 23:41:06 2007 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 1HyaaP-0004Pb-RA for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Jun 2007 23:41:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HyaaP-0003R8-AY for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Jun 2007 17:41:05 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!newscon04.news.prodigy.net!prodigy.net!newsdst01.news.prodigy.net!prodigy.com!postmaster.news.prodigy.com!newssvr19.news.prodigy.net.POSTED!404941e6!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (windows-nt) Cancel-Lock: sha1:ZML80gnNHimoDtzY670Oe8nP37Y= Original-Lines: 28 Original-NNTP-Posting-Host: 66.194.80.196 Original-X-Complaints-To: abuse@prodigy.net Original-X-Trace: newssvr19.news.prodigy.net 1181768518 ST000 66.194.80.196 (Wed, 13 Jun 2007 17:01:58 EDT) Original-NNTP-Posting-Date: Wed, 13 Jun 2007 17:01:58 EDT X-UserInfo1: OH]YBTSEJCUYRTH]]ZN@_TDAYZOZ@GXOXZ^L\UQHWIWDUWYADNVOPCKZBL\NX_KHV^GY[KVMG^ZPNHSCZNS[^UXFJVWYXVXKBH[XRWWBBDTN@AX\JSBVH]_@T\EKJHBMZ\_WZJFNRY]YWKSPED_U^NC\HSZ\WS[KEAYI@DO@\K@BP\LD[\GTMPLDFVU]ASJM Original-Xref: shelby.stanford.edu gnu.emacs.help:149438 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:45027 Archived-At: >>>> deprecated writes: > Just in case anyone was worried that emacs has only two solutions to > this problem, there is a third way ..... :) Don't know where I got this, but this is what I use: (defun another-line (num-lines) "Copies line, preserving cursor column, and increments any numbers found. Copies a block of optional NUM-LINES lines. If no optional argument is given, then only one line is copied." (interactive "p") (if (not num-lines) (setq num-lines 0) (setq num-lines (1- num-lines))) (let* ((col (current-column)) (bol (save-excursion (forward-line (- num-lines)) (beginning-of-line) (point))) (eol (progn (end-of-line) (point))) (line (buffer-substring bol eol))) (goto-char bol) (while (re-search-forward "[0-9]+" eol 1) (let ((num (string-to-number (buffer-substring (match-beginning 0) (match-end 0))))) (replace-match (int-to-string (1+ num)))) (setq eol (save-excursion (goto-char eol) (end-of-line) (point)))) (goto-char bol) (insert line "\n") (move-to-column col))) (global-set-key (kbd "M-O") 'another-line)