GNU bug report logs -
#4382
[PATCH] lisp/rect.el: (rectangle-number-lines): New user key binding C-x r N
Previous Next
Reported by: Jari Aalto <jari.aalto <at> cante.net>
Date: Wed, 9 Sep 2009 10:10:05 UTC
Severity: wishlist
Tags: patch
Merged with 7538
Found in version 23.2+1-5.1
Done: Chong Yidong <cyd <at> stupidchicken.com>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 4382 in the body.
You can then email your comments to 4382 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4382
; Package
emacs
.
(Wed, 09 Sep 2009 10:10:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Jari Aalto <jari.aalto <at> cante.net>
:
New bug report received and forwarded. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Wed, 09 Sep 2009 10:10:05 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):
[Message part 1 (text/plain, inline)]
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 <jari.aalto <at> cante.net>
* 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
<gse <at> antisleep.com>. Used by permission (GPL).
[0001-lisp-rect.el-rectangle-number-lines-New-user-key-bin.patch (text/x-diff, inline)]
From 3ea550b85ded33fae27305bca8710e8f7ce0893b Mon Sep 17 00:00:00 2001
From: Jari Aalto <jari.aalto <at> cante.net>
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 <jari.aalto <at> cante.net>
---
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
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4382
; Package
emacs
.
(Thu, 10 Sep 2009 15:05:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
rms <at> gnu.org
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Thu, 10 Sep 2009 15:05:05 GMT)
Full text and
rfc822 format available.
Message #10 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):
What does this feature do?
Where is the text to describe it?
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4382
; Package
emacs
.
(Thu, 10 Sep 2009 15:05:07 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
rms <at> gnu.org
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Thu, 10 Sep 2009 15:05:07 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4382
; Package
emacs
.
(Thu, 10 Sep 2009 17:05:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Jari Aalto <jari.aalto <at> cante.net>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Thu, 10 Sep 2009 17:05:05 GMT)
Full text and
rfc822 format available.
Message #20 received at 4382 <at> emacsbugs.donarmstrong.com (full text, mbox):
[Message part 1 (text/plain, inline)]
Richard Stallman <rms <at> gnu.org> 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): <RET>
Format: %i <RET>
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 <jari.aalto <at> cante.net>
* 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
<gse <at> antisleep.com>. Used by permission (GPL).
[0001-lisp-rect.el-number-rectangle-New-user-key-binding-C.patch (text/x-diff, inline)]
From cdf6167d8c8975f74a42d943f48b6db99fe9c678 Mon Sep 17 00:00:00 2001
From: Jari Aalto <jari.aalto <at> cante.net>
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 <jari.aalto <at> cante.net>
---
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
Severity set to 'wishlist' from 'normal'
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> emacsbugs.donarmstrong.com
.
(Thu, 10 Sep 2009 17:50:05 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4382
; Package
emacs
.
(Fri, 11 Sep 2009 21:10:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
rms <at> gnu.org
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Fri, 11 Sep 2009 21:10:05 GMT)
Full text and
rfc822 format available.
Message #27 received at 4382 <at> emacsbugs.donarmstrong.com (full text, mbox):
Please include in your patch a change to etc/NEWS.
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4382
; Package
emacs
.
(Sat, 12 Sep 2009 15:55:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Jari Aalto <jari.aalto <at> cante.net>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Sat, 12 Sep 2009 15:55:05 GMT)
Full text and
rfc822 format available.
Message #32 received at 4382 <at> emacsbugs.donarmstrong.com (full text, mbox):
[Message part 1 (text/plain, inline)]
> RMS:
> Please include in your patch a change to etc/NEWS.
** The new command `number-rectangle' bound globally to `C-x r N' can
number selected lines in region. The optional zero padding, if the line
count is bigger than 9, is controlled by a prefix argument.
Patch below is against CVS as of 2009-09-12
[0001-etc-NEWS-The-new-command-number-rectangle.patch (text/x-diff, inline)]
From 8909a2901ed5bc5be1d38590ec7e6795e473f323 Mon Sep 17 00:00:00 2001
From: Jari Aalto <jari.aalto <at> cante.net>
Date: Sat, 12 Sep 2009 18:45:56 +0300
Subject: [PATCH] etc/NEWS: The new command number-rectangle
Signed-off-by: Jari Aalto <jari.aalto <at> cante.net>
---
etc/NEWS | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index c677213..f726c8b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -123,6 +123,10 @@ default-file-name-coding-system on Mac OS X.
* Changes in Specialized Modes and Packages in Emacs 23.2
+** The new command `number-rectangle' bound globally to `C-x r N' can
+number selected lines in region. The optional zero padding, if the line
+count is bigger than 9, is controlled by a prefix argument.
+
** .calc.el and .abbrev_defs obey user-emacs-directory.
** Calc graphing commands (`g f' etc.) now work on MS-Windows,
--
1.6.3.3
Added tag(s) patch.
Request was from
Jari Aalto <jari.aalto <at> cante.net>
to
control <at> emacsbugs.donarmstrong.com
.
(Sun, 13 Sep 2009 14:10:09 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4382
; Package
emacs
.
(Wed, 16 Sep 2009 10:55:18 GMT)
Full text and
rfc822 format available.
Message #37 received at 4382 <at> emacsbugs.donarmstrong.com (full text, mbox):
Jari Aalto <jari.aalto <at> cante.net> writes:
> 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.
FWIW, I have had this code in my .emacs ever since it was posted to
gnu.emacs.sources, and I used it regularly. IMHO it is a nice addition
to the rectangle functions.
Merged 4382 7538.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Fri, 03 Dec 2010 17:18:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#4382
; Package
emacs
.
(Wed, 15 Dec 2010 02:51:02 GMT)
Full text and
rfc822 format available.
Message #42 received at 4382 <at> debbugs.gnu.org (full text, mbox):
> 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.
I have committed this to the trunk, with some tweaks. Thanks.
bug closed, send any further explanations to Jari Aalto <jari.aalto <at> cante.net>
Request was from
Chong Yidong <cyd <at> stupidchicken.com>
to
control <at> debbugs.gnu.org
.
(Wed, 15 Dec 2010 02:52:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 12 Jan 2011 12:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 14 years and 242 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.