diff options
| author | Jari Aalto | 2010-12-15 10:56:22 +0800 |
|---|---|---|
| committer | Chong Yidong | 2010-12-15 10:56:22 +0800 |
| commit | 99f053cfb94763b5d31bcf0802e4b9233da2bea4 (patch) | |
| tree | a1edd0b7cae51cc71a25b30157c49f17b2e61a7d | |
| parent | 5614fd56080d50dc3e1b32382a39d2c21fe060eb (diff) | |
| download | emacs-99f053cfb94763b5d31bcf0802e4b9233da2bea4.tar.gz emacs-99f053cfb94763b5d31bcf0802e4b9233da2bea4.zip | |
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.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/rect.el | 40 |
3 files changed, 51 insertions, 0 deletions
| @@ -303,6 +303,10 @@ set `x-select-enable-clipboard' to nil. | |||
| 303 | 303 | ||
| 304 | *** Support for X cut buffers has been removed. | 304 | *** Support for X cut buffers has been removed. |
| 305 | 305 | ||
| 306 | ** New command `rectangle-number-lines', bound to `C-x r N', numbers | ||
| 307 | the lines in the current rectangle. With an prefix argument, this | ||
| 308 | prompts for a number to count from and for a format string. | ||
| 309 | |||
| 306 | 310 | ||
| 307 | * Changes in Specialized Modes and Packages in Emacs 24.1 | 311 | * Changes in Specialized Modes and Packages in Emacs 24.1 |
| 308 | 312 | ||
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9d49d3e0b71..13a5a358546 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2010-12-15 Jari Aalto <jari.aalto@cante.net> | ||
| 2 | Scott Evans <gse@antisleep.com> | ||
| 3 | |||
| 4 | * rect.el (rectange--default-line-number-format) | ||
| 5 | (rectangle-number-line-callback): New functions. | ||
| 6 | (rectangle-number-lines): New command, bound to C-x r N (Bug#4382). | ||
| 7 | |||
| 1 | 2010-12-15 Chong Yidong <cyd@stupidchicken.com> | 8 | 2010-12-15 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 9 | ||
| 3 | * rect.el (operate-on-rectangle-lines, string-rectangle-string): | 10 | * rect.el (operate-on-rectangle-lines, string-rectangle-string): |
diff --git a/lisp/rect.el b/lisp/rect.el index aedddebe4fa..e24331ebbb7 100644 --- a/lisp/rect.el +++ b/lisp/rect.el | |||
| @@ -38,6 +38,7 @@ | |||
| 38 | ;;;###autoload (define-key ctl-x-r-map "y" 'yank-rectangle) | 38 | ;;;###autoload (define-key ctl-x-r-map "y" 'yank-rectangle) |
| 39 | ;;;###autoload (define-key ctl-x-r-map "o" 'open-rectangle) | 39 | ;;;###autoload (define-key ctl-x-r-map "o" 'open-rectangle) |
| 40 | ;;;###autoload (define-key ctl-x-r-map "t" 'string-rectangle) | 40 | ;;;###autoload (define-key ctl-x-r-map "t" 'string-rectangle) |
| 41 | ;;;###autoload (define-key ctl-x-r-map "N" 'rectangle-number-lines) | ||
| 41 | 42 | ||
| 42 | ;;; Code: | 43 | ;;; Code: |
| 43 | 44 | ||
| @@ -370,6 +371,45 @@ rectangle which were empty." | |||
| 370 | (delete-region pt (point)) | 371 | (delete-region pt (point)) |
| 371 | (indent-to endcol))))) | 372 | (indent-to endcol))))) |
| 372 | 373 | ||
| 374 | ;; Line numbers for `rectangle-number-line-callback'. | ||
| 375 | (defvar rectangle-number-line-counter) | ||
| 376 | |||
| 377 | (defun rectangle-number-line-callback (start end format-string) | ||
| 378 | (move-to-column start t) | ||
| 379 | (insert (format format-string rectangle-number-line-counter)) | ||
| 380 | (setq rectangle-number-line-counter | ||
| 381 | (1+ rectangle-number-line-counter))) | ||
| 382 | |||
| 383 | (defun rectange--default-line-number-format (start end start-at) | ||
| 384 | (concat "%" | ||
| 385 | (int-to-string (length (int-to-string (+ (count-lines start end) | ||
| 386 | start-at)))) | ||
| 387 | "d ")) | ||
| 388 | |||
| 389 | ;;;###autoload | ||
| 390 | (defun rectangle-number-lines (start end start-at &optional format) | ||
| 391 | "Insert numbers in front of the region-rectangle. | ||
| 392 | |||
| 393 | START-AT, if non-nil, should be a number from which to begin | ||
| 394 | counting. FORMAT, if non-nil, should be a format string to pass | ||
| 395 | to `format' along with the line count. When called interactively | ||
| 396 | with a prefix argument, prompt for START-AT and FORMAT." | ||
| 397 | (interactive | ||
| 398 | (if current-prefix-arg | ||
| 399 | (let* ((start (region-beginning)) | ||
| 400 | (end (region-end)) | ||
| 401 | (start-at (read-number "Number to count from: " 1))) | ||
| 402 | (list start end start-at | ||
| 403 | (read-string "Format string: " | ||
| 404 | (rectange--default-line-number-format | ||
| 405 | start end start-at)))) | ||
| 406 | (list (region-beginning) (region-end) 1 nil))) | ||
| 407 | (unless format | ||
| 408 | (setq format (rectange--default-line-number-format start end start-at))) | ||
| 409 | (let ((rectangle-number-line-counter start-at)) | ||
| 410 | (apply-on-rectangle 'rectangle-number-line-callback | ||
| 411 | start end format))) | ||
| 412 | |||
| 373 | (provide 'rect) | 413 | (provide 'rect) |
| 374 | 414 | ||
| 375 | ;; arch-tag: 178847b3-1f50-4b03-83de-a6e911cc1d16 | 415 | ;; arch-tag: 178847b3-1f50-4b03-83de-a6e911cc1d16 |