From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: emacs insert icrement numbers Date: Thu, 17 Aug 2006 15:58:26 +0200 Organization: Informatimago Message-ID: <8764grmpkt.fsf@thalassa.informatimago.com> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1155825677 7543 80.91.229.2 (17 Aug 2006 14:41:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 17 Aug 2006 14:41:17 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Aug 17 16:41:12 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GDj3J-0000aV-3Z for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Aug 2006 16:40:57 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GDj3I-0006OD-Kx for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Aug 2006 10:40:56 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 71 Original-X-Trace: individual.net +mzgFzfCnxm6gQ+rX6MYVAk7VkLcuXdC4N8hWijMrFPwAY04zj Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:IuSs8biV6QVfj6W5A6xVrgfeVGQ= Original-Xref: shelby.stanford.edu gnu.emacs.help:141106 Original-To: help-gnu-emacs@gnu.org 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:36731 Archived-At: Step0ut writes: > Hi everyone, > > I am using emacs as an editor for c++ and latex. > I am using the command Ctrl-xrt to insert rectangles (usually numbers) quite > often. > My question is: > Is it possible to insert numbers that increament in each line? > e.g. 0 > 1 > 2 > ... > 99 > Well I don't have gse-number-rect, and I bet it'll be faster to write the following than to use google... (defun insert-numbers (min max) (interactive "nFrom: \nnTo: ") (while (<= min max) (insert (format "\n%d " min)) (setq min (+ 1 min)))) 0 1 2 3 It's also possible to record the left margin, and to copy it on each line: (defun insert-numbers (min max) (interactive "nFrom: \nnTo: ") (let ((margin (buffer-substring (save-excursion (beginning-of-line) (point)) (point)))) (when (<= min max) (insert (format "%d " min)) (setq min (+ 1 min)) (while (<= min max) (insert (format "\n%s%d " margin min)) (setq min (+ 1 min)))))) ==> 0 ==> 1 ==> 2 ==> 3 > Alternatively I was also thinking if it is possible to replace an existing > string (M-x replace-regexp) with an icrement number. It will do the job as > well. With latest versions (>=22), you can use \,form in the the substitutions. For example, select a region and: M-x replace-regexp RET \(.*\) RET \,(progn(defvar n 0)(format "%3d " (incf n)))\1 RET 1 NOTE: The most fundamental particles in this product are held 2 together by a "gluing" force about which little is currently known 3 and whose adhesive power can therefore not be permanently 4 guaranteed. -- __Pascal Bourguignon__ http://www.informatimago.com/ NOTE: The most fundamental particles in this product are held together by a "gluing" force about which little is currently known and whose adhesive power can therefore not be permanently guaranteed.