;; histogram.el -- simple histogram builder ;; Usage: 1. (histo-print NUMBER-LIST) makes a histogram for NUMBER-LIST, and ;; prints it out in the buffer `*histogram*'. ;; 2. (histo-buffer BUFFERNAME) creates a histogram from a BUFFER that has one number ;; on each line. (defun plusses (n) (cond ((= n 0) "") (t (concat "+" (plusses (- n 1)))))) (defun histo-print (number-list) (pop-to-buffer (generate-new-buffer "*histogram*")) (let ((x 100) (out "")) (while (>= x 0) (setq out (concat out (format "%3s | " x) (plusses (count x number-list)) "\n")) (decf x)) (insert out)) (goto-char (point-min))) (defun histo-buffer-to-list (buffer) "Transform a buffer of integers into a list of integers." (pop-to-buffer buffer) (goto-char (point-min)) (let ((liste '())) (while (search-forward-regexp "[0-9]+" nil t) (setq liste (cons (string-to-number (match-string-no-properties 0)) liste))))) (defun histo-buffer (buffer) (interactive "bMake histogram from buffer: ") (histo-print (histo-buffer-to-list buffer))) ;; end of file histogram.el