Created
January 19, 2011 17:28
-
-
Save mrBliss/786493 to your computer and use it in GitHub Desktop.
sum-column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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