[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Enhancement patch: sum-rectangle and numerate-rectangle
From: |
W Snyder |
Subject: |
Enhancement patch: sum-rectangle and numerate-rectangle |
Date: |
Wed, 28 Jun 2006 17:10:57 -0400 (EDT) |
I would like to propose the following additions to rect.el (diffs below
relative to Emacs 22.0.50). I and my coworkers have found these very
useful, and I think they make a good small addition to the current set of
rectangle operations.
A argument could probably be made that there are other mathematical
operations that are useful. I have experimented with several, but I've
found only summing is of general enough use to be worth inclusion in Emacs.
(Example use: with the output of a 'ls' listing, use sum-rectangle to sum
the sizes of all of the files.)
Thanks.
*** lisp/bindings.el 2005-08-30 16:36:34.000000000 -0400
--- lisp/bindings.el 2006-06-28 17:07:49.869246000 -0400
***************
*** 1012,1017 ****
--- 1012,1019 ----
(define-key ctl-x-map "ry" 'yank-rectangle)
(define-key ctl-x-map "ro" 'open-rectangle)
(define-key ctl-x-map "rt" 'string-rectangle)
+ (define-key ctl-x-map "r=" 'sum-rectangle)
+ (define-key ctl-x-map "r#" 'numerate-rectangle)
(define-key ctl-x-map "rw" 'window-configuration-to-register)
(define-key ctl-x-map "rf" 'frame-configuration-to-register)
*** lisp/rect.el 2005-08-30 16:36:34.000000000 -0400
--- lisp/rect.el 2006-06-28 17:08:08.781739000 -0400
***************
*** 385,389 ****
--- 385,427 ----
(provide 'rect)
+ ;;;###autoload
+ (defun numerate-rectangle (start end beginnum &optional increment)
+ "Insert sequential numbers on each line of the region-rectangle,
+ shifting text right.
+ The left edge of the rectangle specifies the column for insertion.
+ Called from a program, takes three args; START, END, BEGINNUM and
+ optional INCREMENT."
+ (interactive "r\nsStart number: ")
+ (setq increment (or increment 1))
+ (let ((num beginnum))
+ (apply-on-rectangle
+ '(lambda (startcol endcol &rest args)
+ (move-to-column-force startcol)
+ (let ((p (point)))
+ (move-to-column-force endcol)
+ (delete-region p (point)))
+ (insert num)
+ (setq num (int-to-string (+ increment (string-to-int num)))))
+ start end)))
+
+ ;;;###autoload
+ (defun sum-rectangle (start end)
+ "Sum the column of numbers with corners at point and mark.
+ Calling from program, supply two args START and END, buffer positions.
+ With a prefix argument, inserts the resulting sum at point."
+ (interactive "r")
+ (let ((sum 0.0))
+ (apply-on-rectangle
+ '(lambda (startcol endcol &rest args)
+ (setq sum (+ sum (string-to-number (buffer-substring
+ (progn (move-to-column startcol)
(point))
+ (progn (move-to-column endcol)
(point)))))))
+ start end)
+ (if current-prefix-arg
+ (insert (number-to-string sum))
+ (message (number-to-string sum)))
+ sum))
+
;;; arch-tag: 178847b3-1f50-4b03-83de-a6e911cc1d16
;;; rect.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Enhancement patch: sum-rectangle and numerate-rectangle,
W Snyder <=