From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jari Aalto Newsgroups: gmane.emacs.bugs Subject: bug#4382: [PATCH] lisp/rect.el: (rectangle-number-lines): New user key binding C-x r N Date: Thu, 10 Sep 2009 19:59:25 +0300 Organization: Private Message-ID: <87hbvasple.fsf@jondo.cante.net> References: <87pra0v3g6.fsf@jondo.cante.net> Reply-To: Jari Aalto , 4382@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1252602464 15214 80.91.229.12 (10 Sep 2009 17:07:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Sep 2009 17:07:44 +0000 (UTC) Cc: 4382@emacsbugs.donarmstrong.com, gse@antisleep.com To: rms@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Sep 10 19:07:37 2009 Return-path: Envelope-to: geb-bug-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 1Mln7L-00063e-JF for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 Sep 2009 19:07:32 +0200 Original-Received: from localhost ([127.0.0.1]:56624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mln7K-0003oJ-Vr for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 Sep 2009 13:07:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mln6z-0003i4-1U for bug-gnu-emacs@gnu.org; Thu, 10 Sep 2009 13:07:09 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mln6u-0003gC-7t for bug-gnu-emacs@gnu.org; Thu, 10 Sep 2009 13:07:08 -0400 Original-Received: from [199.232.76.173] (port=46372 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mln6u-0003g6-2E for bug-gnu-emacs@gnu.org; Thu, 10 Sep 2009 13:07:04 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:35114) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Mln6t-0004Be-FR for bug-gnu-emacs@gnu.org; Thu, 10 Sep 2009 13:07:03 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n8AH6x2P014370; Thu, 10 Sep 2009 10:06:59 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n8AH553Y013708; Thu, 10 Sep 2009 10:05:05 -0700 Resent-Date: Thu, 10 Sep 2009 10:05:05 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Jari Aalto Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Thu, 10 Sep 2009 17:05:05 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 4382 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 4382-submit@emacsbugs.donarmstrong.com id=B4382.125260197312382 (code B ref 4382); Thu, 10 Sep 2009 17:05:05 +0000 Original-Received: (at 4382) by emacsbugs.donarmstrong.com; 10 Sep 2009 16:59:33 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from emh02.mail.saunalahti.fi (emh02.mail.saunalahti.fi [62.142.5.108]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n8AGxVAh012379 for <4382@emacsbugs.donarmstrong.com>; Thu, 10 Sep 2009 09:59:33 -0700 Original-Received: from saunalahti-vams (vs3-12.mail.saunalahti.fi [62.142.5.96]) by emh02-2.mail.saunalahti.fi (Postfix) with SMTP id 28307EF51A; Thu, 10 Sep 2009 19:59:30 +0300 (EEST) Original-Received: from emh01.mail.saunalahti.fi ([62.142.5.107]) by vs3-12.mail.saunalahti.fi ([62.142.5.96]) with SMTP (gateway) id A02E2F1F059; Thu, 10 Sep 2009 19:59:30 +0300 Original-Received: from jondo.cante.net (a91-155-187-216.elisa-laajakaista.fi [91.155.187.216]) by emh01.mail.saunalahti.fi (Postfix) with ESMTP id 6CCC14050; Thu, 10 Sep 2009 19:59:25 +0300 (EEST) In-Reply-To: (Richard Stallman's message of "Thu, 10 Sep 2009 10:59:37 -0400") User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1 (gnu/linux) X-Antivirus: VAMS X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Thu, 10 Sep 2009 13:07:08 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:30931 Archived-At: --=-=-= Richard Stallman writes: > What does this feature do? > Where is the text to describe it? The code implements: (define-key ctl-x-r-map "N" 'number-rectangle) Where C-h f number-rectangle is described as: Insert numbers in front of lines in rectangle BEG END. START-AT specifices the first number to start at. FORMAT is format string where %i denotes inserted number. If prefix arg NO-ZERO-PADDING is non-nil, do not padd numbers Demonstration, initial data: Item one Item two Item three Put cursor at first line's character, draw region up till last line's first character. Call M-x number-rectangle: First number [1] (default 1): Format: %i Result: 1 Item one 2 Item two 3 Item three It the region would have been longer, say over 10 lines, the padding would have taken in effect: 01 Item one 02 Item two ... Jari Here is slightly updated patch which corrects the name of the function to `number-rectangle'. 2009-03-22 Jari Aalto * rect.el (number-rectangle): New user function. (rectangle-number-line-callback): New function. (rectangle-number-line-format-history): New variable. (rectangle-number-line-counter): New variable. (define-key ctl-x-r-map "N" 'number-rectangle): New user key binding. The basis of the rectangle numbering code was lifted from gse-number-rect.el, orignally developed by Scott Evans . Used by permission (GPL). --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-lisp-rect.el-number-rectangle-New-user-key-binding-C.patch >From cdf6167d8c8975f74a42d943f48b6db99fe9c678 Mon Sep 17 00:00:00 2001 From: Jari Aalto Date: Thu, 10 Sep 2009 19:55:38 +0300 Subject: [PATCH] lisp/rect.el: (number-rectangle): New user key binding C-x r N Signed-off-by: Jari Aalto --- lisp/rect.el | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-) diff --git a/lisp/rect.el b/lisp/rect.el index eb188fc..6b63c81 100644 --- a/lisp/rect.el +++ b/lisp/rect.el @@ -39,6 +39,7 @@ ;;;###autoload (define-key ctl-x-r-map "y" 'yank-rectangle) ;;;###autoload (define-key ctl-x-r-map "o" 'open-rectangle) ;;;###autoload (define-key ctl-x-r-map "t" 'string-rectangle) +;;;###autoload (define-key ctl-x-r-map "N" 'number-rectangle) ;;; Code: @@ -395,6 +396,45 @@ rectangle which were empty." (delete-region pt (point)) (indent-to endcol))))) +(defvar rectangle-number-line-counter nil + "Variable holding line numbering information. +Initial value is set in function `rectangle-number-lines' +and incremented for each line in `rectangle-number-line-callback'.") + +(defvar rectangle-number-line-format-history nil + "History variable that records previous format strings.") + +(defun rectangle-number-line-callback (start end format-string) + (move-to-column start t) + (setq rectangle-number-line-counter (+ rectangle-number-line-counter 1)) + (insert (format format-string rectangle-number-line-counter))) + +(defun rectangle-number-lines (beg end start-at format &optional no-zero-padding) + "Insert numbers in front of lines in rectangle BEG END. + +START-AT specifices the first number to start at. +FORMAT is format string where %i denotes inserted number. + +If prefix arg NO-ZERO-PADDING is non-nil, do not padd numbers +with leading zeroes." + (interactive + (list + (region-beginning) + (region-end) + (if (functionp 'read-number) + (read-number "First number [1]: " 1) + (string-to-int (read-string "First number [1]: " nil nil "1"))) + (read-string "Format: " "%i " 'rectangle-number-line-format-history) + current-prefix-arg)) + (setq start-at (- start-at 1)) + (unless no-zero-padding + (let* ((max (+ (count-lines beg end) start-at)) + (longest (length (int-to-string (+ 1 max)))) + (fmt (concat "%0" (int-to-string longest) "i"))) + (setq format (replace-regexp-in-string "%i" fmt format)))) + (setq rectangle-number-line-counter start-at) + (apply-on-rectangle 'rectangle-number-line-callback beg end format)) + (provide 'rect) ;; arch-tag: 178847b3-1f50-4b03-83de-a6e911cc1d16 -- 1.6.3.3 --=-=-=--