;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 ;; David J. Biesack ;; This file is not part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; sum up the values in a column of integers ;; Author: David Biesack (David.Biesack@sas.com or biesack@mindspring.com) ;; Last Modified By: biesack@mindspring.com ;; Last Modified: Thu Mar 15 17:42:16 2001 (defvar *column-sum* 0 "Result of last \\[column-sum]") (defun column-sum (start end arg) "Compute and print in minibuffer the sum of the numbers in the column delimited by START and END. Result is stored in the elisp variable *column-sum*. With an ARG, the result is inserted into the buffer." (interactive "r\nP") (copy-rectangle-to-register ?S start end) (let ((sum (get-buffer-create " *Column-Sum*"))) (save-excursion (set-buffer sum) (erase-buffer) (insert "(setq *column-sum* \(+ \n") (insert-register ?S) (end-of-buffer) (insert "\)\)") (eval-last-sexp 1)) (and arg (insert " (" (int-to-string *column-sum*) ") ")) (message "Sum: %d" *column-sum*))) ; 1 ; 2 ; 23 ; 3 ; 23 ; 43 ; -43 ; 43