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: Wed, 09 Sep 2009 13:04:57 +0300 Message-ID: <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 1252492224 2672 80.91.229.12 (9 Sep 2009 10:30:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 9 Sep 2009 10:30:24 +0000 (UTC) Cc: Scott Evans To: submit@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 09 12:30:16 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 1MlKRL-0000sh-1r for geb-bug-gnu-emacs@m.gmane.org; Wed, 09 Sep 2009 12:30:16 +0200 Original-Received: from localhost ([127.0.0.1]:39471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MlKRJ-0007i4-3S for geb-bug-gnu-emacs@m.gmane.org; Wed, 09 Sep 2009 06:30:13 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MlKOM-0007FQ-5i for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2009 06:27:10 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MlKOG-0007E5-5h for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2009 06:27:08 -0400 Original-Received: from [199.232.76.173] (port=48018 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MlKOF-0007Dv-SP for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2009 06:27:03 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:40242) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MlKOE-0001dq-Q3 for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2009 06:27: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 n89AQxxw027768; Wed, 9 Sep 2009 03:26:59 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n89AA5ut024787; Wed, 9 Sep 2009 03:10:05 -0700 Resent-Date: Wed, 9 Sep 2009 03:10: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: Wed, 09 Sep 2009 10:10:05 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: report 4382 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by submit@emacsbugs.donarmstrong.com id=B.125249070423585 (code B ref -1); Wed, 09 Sep 2009 10:10:05 +0000 Original-Received: (at submit) by emacsbugs.donarmstrong.com; 9 Sep 2009 10:05:04 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from emh07.mail.saunalahti.fi (emh07.mail.saunalahti.fi [62.142.5.117]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n89A52ee023318 for ; Wed, 9 Sep 2009 03:05:03 -0700 Original-Received: from saunalahti-vams (vs3-11.mail.saunalahti.fi [62.142.5.95]) by emh07-2.mail.saunalahti.fi (Postfix) with SMTP id 55E1B18D128; Wed, 9 Sep 2009 13:05:01 +0300 (EEST) Original-Received: from emh07.mail.saunalahti.fi ([62.142.5.117]) by vs3-11.mail.saunalahti.fi ([62.142.5.95]) with SMTP (gateway) id A0301151A35; Wed, 09 Sep 2009 13:05:01 +0300 Original-Received: from jondo.cante.net (a91-155-187-216.elisa-laajakaista.fi [91.155.187.216]) by emh07.mail.saunalahti.fi (Postfix) with ESMTP id 7F6B91C6384; Wed, 9 Sep 2009 13:04:57 +0300 (EEST) X-Antivirus: VAMS X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Wed, 09 Sep 2009 06:27: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:30885 Archived-At: --=-=-= Scott has just informaed me that his FSF assignment papers have been processed and cleared. Based on his work at http://www.antisleep.com/elisp/gse-number-rect.el I propose following new feature to be added to the rect.el package. 2009-03-22 Jari Aalto * rect.el (rectangle-number-lines): 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-rectangle-number-lines-New-user-key-bin.patch >From 3ea550b85ded33fae27305bca8710e8f7ce0893b Mon Sep 17 00:00:00 2001 From: Jari Aalto Date: Sun, 22 Mar 2009 17:27:42 +0200 Subject: [PATCH] lisp/rect.el: (rectangle-number-lines): 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 --=-=-=--