Commit 99f053cf authored by Jari Aalto's avatar Jari Aalto Committed by Chong Yidong
Browse files

New command rectangle-number-lines (Bug#4382).

* rect.el (rectange--default-line-number-format)
(rectangle-number-line-callback): New functions.
(rectangle-number-lines): New command, bound to C-x r N.
parent 5614fd56
......@@ -303,6 +303,10 @@ set `x-select-enable-clipboard' to nil.
*** Support for X cut buffers has been removed.
** New command `rectangle-number-lines', bound to `C-x r N', numbers
the lines in the current rectangle. With an prefix argument, this
prompts for a number to count from and for a format string.
* Changes in Specialized Modes and Packages in Emacs 24.1
2010-12-15 Jari Aalto <>
Scott Evans <>
* rect.el (rectange--default-line-number-format)
(rectangle-number-line-callback): New functions.
(rectangle-number-lines): New command, bound to C-x r N (Bug#4382).
2010-12-15 Chong Yidong <>
* rect.el (operate-on-rectangle-lines, string-rectangle-string):
......@@ -38,6 +38,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" 'rectangle-number-lines)
;;; Code:
......@@ -370,6 +371,45 @@ rectangle which were empty."
(delete-region pt (point))
(indent-to endcol)))))
;; Line numbers for `rectangle-number-line-callback'.
(defvar rectangle-number-line-counter)
(defun rectangle-number-line-callback (start end format-string)
(move-to-column start t)
(insert (format format-string rectangle-number-line-counter))
(setq rectangle-number-line-counter
(1+ rectangle-number-line-counter)))
(defun rectange--default-line-number-format (start end start-at)
(concat "%"
(int-to-string (length (int-to-string (+ (count-lines start end)
"d "))
(defun rectangle-number-lines (start end start-at &optional format)
"Insert numbers in front of the region-rectangle.
START-AT, if non-nil, should be a number from which to begin
counting. FORMAT, if non-nil, should be a format string to pass
to `format' along with the line count. When called interactively
with a prefix argument, prompt for START-AT and FORMAT."
(if current-prefix-arg
(let* ((start (region-beginning))
(end (region-end))
(start-at (read-number "Number to count from: " 1)))
(list start end start-at
(read-string "Format string: "
start end start-at))))
(list (region-beginning) (region-end) 1 nil)))
(unless format
(setq format (rectange--default-line-number-format start end start-at)))
(let ((rectangle-number-line-counter start-at))
(apply-on-rectangle 'rectangle-number-line-callback
start end format)))
(provide 'rect)
;; arch-tag: 178847b3-1f50-4b03-83de-a6e911cc1d16
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment