akhanna@cc5.bbn.com.BBN.COM (Atul Khanna) (10/07/87)
I would like to gather statistics on the frequency with which I use interactive functions (i.e., a function that can be invoked via a M-x command or a keystroke) within emacs. Could someone suggest a way of doing this? Thanks. -- -------------------------------------------------------------------------- Atul C Khanna (akhanna@bbn.com) BBN Communications Corporation 50 Moulton Street Cambridge, MA 02238 ..!{decvax, wjh12, ihnp4, harvard}!bbnccv!akhanna
thomas%spline.uucp@utah-gr.UUCP (Spencer W. Thomas) (10/09/87)
One way is to redefine the function to count its usage. Here is a function that should do that: (defun count-fn (sym) "Cause uses of FUNCTION to be counted in the variable &count-FUNCTION. The function is redefined so that it can be called from C code and its \"commandness\" is preserved." (interactive "aFunction to count: ") (let* ((fun (symbol-function sym)) (doc (or (documentation sym) "")) (counted-doc "<<Counted>> ") (counted-len (min (length counted-doc) (length doc))) (iactive (commandp fun)) (counted-var (intern (concat "&count-" (symbol-name sym))))) (if (and iactive (not (listp iactive)) (not (yes-or-no-p (format "%s will lose command status when counted, ok? " sym)))) (error "%s not counted" sym)) (if (string= (substring doc 0 counted-len) counted-doc) (error "%s is already counted" sym)) (put sym 'count-fun fun) (eval (` (defvar (, counted-var) 0))) (set counted-var 0) (eval (` (defun (, sym) (&rest arglist) (, (concat counted-doc doc)) (, iactive) (setq (, counted-var) (1+ (, counted-var))) (apply '(, fun) arglist))))) ) (defun uncount (sym) "Stop counting FUNCTION." (interactive "aFunction to stop counting: ") (if (not (get sym 'count-fun)) (error "function %s is not counted" sym)) (fset sym (get sym 'count-fun)) (put sym 'count-fun nil) (eval (intern (concat "&count-" (symbol-name sym))))) -- =Spencer ({ihnp4,decvax}!utah-cs!thomas, thomas@cs.utah.edu) =Spencer ({ihnp4,decvax}!utah-cs!thomas, thomas@cs.utah.edu)