RectangleAdd

I sometimes have a chart of some kind, a row of prices or anything like this in my emacs. And then I want to add that. If there is nothing besides the numbers on the line, you can just prepend (+ and append ), and C-x C-e will do the adding. But IF there is stuff on the line… I use rectangle-add. It shows the result in the minibuffer, and puts it in the kill ring. Have fun.

     (defun rectangle-add (start end)
       "Add all the lines in the region-rectangle and put the result in the 
        kill ring."
       (interactive "r")
       (let ((sum 0))
         (mapc (lambda (line)
                 (setq sum (+ sum (rectangle-add-make-number line))))
               (extract-rectangle start end))
         (kill-new (number-to-string sum))
         (message "%s" sum)))
    (defun rectangle-add-make-number (n)
      "Turn a string into a number, being tolerant of commas and even other 
       'junk'.
    When I started programming, my numeric input routines translated l 
    (lowercase ell) into 'one', as many users had learnt their
      keyboarding on manual typewriters which typically lacked 
      a separate key for the digit 1. Am I old, or what?"
    (while (string-match "[^0-9.]" n)
      (setq n (replace-match "" nil nil n)))
      (string-to-number n))

Nice. But have you tried Org-mode’s table editor?

See also AddNumbers.

See also ‘M-x calc-grab-sum-down’, which is available once the AdvancedDeskCalculator has been loaded. – JohnWiegley


CategoryCalculators CategoryRegion