[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
mm-survey.el
From: |
thi |
Subject: |
mm-survey.el |
Date: |
Fri, 9 Mar 2001 03:45:57 -0800 |
greetings emacs sourcerers and apprenti,
about a month back, i posted some code to do a minor mode survey on
gnu-emacs-help. the data is back in, so here's some more code to
analyze it. i added each respondant's email to an RMAIL file and
cleaned out the identifying bits (sigs). then i found some free time
and wrote this (the original two gatherer functions are also included).
see gnu-emacs-help for output of running this code on the RMAIL file, or
mail me privately if you would like a copy (of the output -- i will not
honor requests for the RMAIL file).
data mining? data minor-moding? tada minusing?
thi
______________________________________________
;;; mm-survey.el
;;; author: address@hidden
;;; created: 2001/03/09 03:28:44
;;; public domain
;; these were mailed to address@hidden
(defun buffer-modes-usage (buffer)
(with-current-buffer buffer
(cons major-mode
(let ((acc nil) (mma minor-mode-alist))
(while mma ; avoid cl :-P
(let ((minor-mode (caar mma)))
;; use `describe-mode' inclusion method -- see help.el
(when (and (symbol-value minor-mode)
(fboundp minor-mode))
(setq acc (cons minor-mode acc))))
(setq mma (cdr mma)))
acc))))
(defun compose-mode-usage-mail ()
(interactive)
(let ((forms (mapcar 'buffer-modes-usage (buffer-list)))
(mail-self-blind nil))
(compose-mail "address@hidden" "minor mode survey response")
(goto-char (point-max))
(let ((standard-output (current-buffer)))
(mapcar '(lambda (form)
(unless (= 1 (length form)) ; ignorance is bliss
(print form)))
forms)))
(setq fill-prefix ";;; ")
(insert "\n;;; additional comments (fill-prefix set to \""
fill-prefix
"\")\n;;; "))
;; new stuff
(require 'cl) ; use the source luke!
(defun sort-freq-hash (hash)
(let (unsorted)
(maphash (lambda (x count) (push (cons count x) unsorted)) hash)
(sort unsorted (lambda (a b) (> (car a) (car b))))))
(defun insert-compressed-freq-list (ls)
(let ((last-seen 0))
(dolist (x ls)
(insert (if (= (car x) last-seen)
(format " %s" (cdr x))
(setq last-seen (car x))
(format "\n- %d %s" (car x) (cdr x))))))
(insert "\n\n"))
(defun analyze-mode-usage-response (data)
(insert (format "%d buffers scanned" (length data)))
(dolist (x data) (setcdr x (remove-duplicates (sort (cdr x) 'string<))))
(setq data (delete-duplicates data :test 'equal))
(insert (format " (%d w/ unique mode signatures)\n" (length data)))
(dolist (x data) (insert (format "- %s\n" x)))
(insert "\n")
;; major mode summary
(let ((majs (make-hash-table)))
(dolist (x data) (incf (gethash (car x) majs 0)))
(insert (format "%d unique major modes, sorted by instances in unique sig"
(hash-table-count majs)))
(insert-compressed-freq-list (sort-freq-hash majs)))
;; minor mode
(let ((mins (make-hash-table)) sorted)
;; summary
(dolist (x (apply 'append (mapcar 'cdr data))) (incf (gethash x mins 0)))
(insert (format "%d unique minor modes, sorted by instances in unique sig"
(hash-table-count mins)))
(setq sorted (sort-freq-hash mins))
(insert-compressed-freq-list sorted)
;; details: clumps and bros
(insert "FOO-MINOR-MODE: CONCURRENT:COUNT CONCURRENT:COUNT ...\n"
"- MOST CONCURRENT MINOR MODE\n"
"- NEXT MOST CONCURRENT MINOR MODE\n"
"- ...\n\n")
(dolist (m (mapcar 'cdr sorted))
(insert (format "%s:" m))
(let* ((mdata (mapcar 'cdr data))
(hood (remove-if-not (lambda (sig) (memq m (cdr sig))) mdata))
(clumps (make-hash-table))
(bros (make-hash-table)))
(dolist (h hood) (incf (gethash (1- (length h)) clumps 0)))
(dolist (b (remove m (apply 'append hood))) (incf (gethash b bros 0)))
(dolist (x (sort (sort-freq-hash clumps)
(lambda (a b) (< (cdr a) (cdr b)))))
(insert (format " %d:%d" (cdr x) (car x))))
(insert-compressed-freq-list (sort-freq-hash bros))))))
(defun summarize-mode-usage-responses (file)
(interactive "fMail file: ")
(find-file file)
(unless (eq 'rmail-mode major-mode)
(error "wrong file, dude"))
(let (data comments)
(do ((i 1 (1+ i)))
((> i rmail-total-messages))
(rmail-show-message i)
(goto-char (point-min))
(search-forward "\n\n")
;; pass twice to handle interspersed comments
(let ((beg (point)))
(goto-char beg)
(ignore-errors (while t (push (read (current-buffer)) data)))
(goto-char beg)
(while (re-search-forward "^;;;\\(.+\n\\)" (point-max) t)
(push (match-string 1) comments)))
(push "----------------------------\n" comments))
(kill-buffer (current-buffer))
(switch-to-buffer "*Mode Usage Response Summary*")
(erase-buffer)
(analyze-mode-usage-response data)
(insert "\n")
(dolist (comment (reverse comments)) (insert comment))
;; gratuitous prettiness
(while (re-search-backward "^---+\n\\s-*\n" (point-min) t)
(replace-match ""))
(re-search-backward "^---+\n" (point-min) t)
(while (search-backward "-mode" (point-min) 1)
(replace-match ""))))
;;; mm-survey.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |