Skip to content

Instantly share code, notes, and snippets.

@mrBliss
Created January 19, 2011 17:28
Show Gist options
  • Save mrBliss/786493 to your computer and use it in GitHub Desktop.
Save mrBliss/786493 to your computer and use it in GitHub Desktop.
sum-column
(defun sum-column ()
"Sums a column of numbers starting at point"
(interactive)
(save-excursion
(if (and (not (= (current-column) 0))
(re-search-backward "[ \t]" 0 t ))
(forward-char))
(let ((retn 0)
(old-column (current-column))
(old-next-line-add-newlines))
(setq next-line-add-newlines nil)
(while (not
(looking-at "^[ \t]*$"))
(move-to-column old-column t)
(if (and (looking-at "-?[0123456789]+")
(eq (current-column) old-column))
(setq retn (+ retn (string-to-number (current-word)))))
(next-line)
(beginning-of-line))
(next-line)
(next-line)
(move-end-of-line 0)
(insert (make-string (- old-column (current-column)) 32))
(insert (number-to-string retn))
(setq next-line-add-newlines old-next-line-add-newlines)
retn)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment