Paste number 26686: command-frequency.el

Index of paste annotations: 1

Paste number 26686: command-frequency.el
Pasted by: rcy
When:2 years, 9 months ago
Share:Tweet this! | http://paste.lisp.org/+KLA
Channel:#emacs
Paste contents:
Raw Source | XML | Display As
;;; command-frequency.el -- track command frequencies
;; Ryan Yeske

(defvar command-frequency-table (make-hash-table :test 'equal))
(defun command-frequency-record ()
  (let* ((command this-command)
	 (count (gethash command command-frequency-table)))
    (puthash command (if count (1+ count) 1)
	     command-frequency-table)))
 
(defun command-frequency-display ()
  (interactive)
  (display-message-or-buffer (command-frequency) "*frequencies*"))

(defun command-frequency ()
  (with-output-to-string
    (let (l)
      (maphash (lambda (k v)
		 (setq l (cons (cons k v) l)))
	       command-frequency-table)
      (mapcar (lambda (e)
		(princ (format "%d\t%s\n" (cdr e) (car e))))
	      (sort l (lambda (a b) (> (cdr a) (cdr b))))))))

(add-hook 'post-command-hook 'command-frequency-record)


(defun command-frequency-write-file (file-name)
  (with-temp-file file-name
    (insert (command-frequencies)))
  (with-temp-message (format "Wrote %s" file-name)))

;; (run-at-time 0 600 'command-frequency-write-file "~/public_html/command-freq.txt")
;; (cancel-function-timers 'command-frequency-write-file)

Annotations for this paste:

Annotation number 1: my result as of 2 days
Pasted by: xahlee
When:2 years, 9 months ago
Share:Tweet this! | http://paste.lisp.org/+KLA#1
Paste contents:
Raw Source | Display As
18052	self-insert-command
4841	next-line
3903	previous-line
2291	backward-word
1727	forward-word
1511	kill-region
1055	isearch-printing-char
936	delete-backward-char
745	mwheel-scroll
635	save-buffer
560	newline
398	forward-char
354	backward-char
346	yank
299	(lambda nil Kill the current buffer silently unless it is modified. (interactive) (kill-buffer nil))
227	isearch-forward
225	delete-char
222	scroll-up
209	scroll-down
208	minibuffer-complete
171	isearch-other-meta-char
170	previous-history-element
166	other-window
147	dired-advertised-find-file
145	undo
124	find-file
120	revert-buffer
119	extend-selection
117	move-beginning-of-line
114	dired-next-line
107	execute-extended-command
104	mouse-drag-region
102	dired
92	kill-ring-save
90	isearch-repeat-forward
88	set-mark-command
85	isearch-other-control-char
81	mouse-set-point
80	sgml-close-tag
73	exit-minibuffer
73	dired-previous-line
69	scroll-bar-toolkit-scroll
68	recenter
66	ibuffer-mark-for-delete
62	shell-command
62	minibuffer-keyboard-quit
58	html-paragraph
57	move-end-of-line
52	keyboard-quit
48	cperl-electric-backspace
47	backward-delete-char-untabify
47	query-replace
43	isearch-repeat-backward
42	delete-other-windows
39	x-htmlize-me
37	isearch-backward
35	split-window-vertically
35	nil
34	dired-mark
34	beginning-of-buffer
33	ignore
33	delete-window
29	sgml-slash
27	wrap-url2
23	mark-whole-buffer
22	describe-function
22	next-buffer
22	dired-do-rename
22	x-htmlize-me-perl
22	end-of-buffer
21	eval-last-sexp
21	insert-p
19	remove-hard-wrap
15	,bbedit
15	bookmark-bmenu-list
14	dired-do-flagged-delete
14	center-line
13	bookmark-bmenu-this-window
13	insert-register
12	fill-paragraph
11	dired-flag-file-deletion
11	replace-quotes
11	isearch-abort
11	upcase-initials-region
11	html-headline-1
9	apropos-command
9	sgml-maybe-name-self
9	switch-to-buffer
8	wrap-url
8	Info-menu
8	tag-image2
8	mode-exited
7	Info-follow-nearest-node
7	(lambda nil (interactive) (let ((orig-function (symbol-function (quote message)))) (unwind-protect (progn (defun message (string &rest arguments) (let* ((s1 (concat prompt (buffer-substring (shell-command/minibuffer-prompt-end) (point-max)))) (s2 (apply (function format) string arguments)) (w (- (window-width) (string-width s1) (string-width s2) 1))) (funcall orig-function (if (>= w 0) (concat s1 (make-string w 32) s2) s2)) (if (sit-for 0.3) (funcall orig-function s1)) s2)) (require (quote shell)) (require (quote comint)) (run-hook-with-args-until-success (quote shell-command-complete-functions))) (fset (quote message) orig-function))))
7	date
7	browse-url-of-buffer
7	backward-sexp
7	just-one-space
6	man
6	previous-buffer
6	dired-create-directory
6	dired-do-copy
6	replace-string
5	handle-switch-frame
5	ispell-word
5	next-history-element
5	python-backspace
5	forward-sexp
4	tt
4	universal-argument-other-key
4	dired-do-query-replace-regexp
4	minibuffer-complete-and-exit
4	command-frequency-display
4	comment-dwim
4	lisp-indent-line
4	htmlize-buffer
3	Info-up
3	other-frame
3	digit-argument
3	bookmark-insert
3	bookmark-set
3	dired-unmark-all-marks
3	ibuffer-forward-line
3	copy-to-register
3	dired-flag-backup-files
3	isearch-toggle-case-fold
3	mouse-set-font
3	(lambda nil (interactive) (progn (split-window-vertically) (find-file ~/web/emacs/unicode.txt)))
3	html-headline-2
3	keystroke-stats
2	push-button
2	string-rectangle
2	isearch-quote-char
2	dired-unmark
2	sgml-tags-invisible
2	dired-do-shell-command
2	skeleton-pair-insert-maybe
2	cperl-electric-rparen
2	cperl-electric-paren
2	bookmark-save
2	info
2	atom-entry
2	ibuffer-do-kill-on-deletion-marks
2	dired-mark-files-regexp
2	exchange-point-and-mark
2	perl-mode
2	replace-list
2	kill-rectangle
2	dired-mouse-find-file-other-window
2	replace-eols
2	eval-region
1	View-quit
1	html-list-item
1	list-colors-display
1	quoted-insert
1	isearch-delete-char
1	universal-argument
1	clone-buffer
1	make-frame-command
1	word-entry
1	dt
1	dired-up-directory
1	abbrev-mode
1	cperl-electric-semi
1	cperl-electric-brace
1	cperl-electric-lbrace
1	Man-goto-section
1	downcase-word
1	ffap
1	describe-mode
1	cssm-insert-curlies
1	ibuffer-backward-line
1	ibuffer-do-save
1	ibuffer-mark-unsaved-buffers
1	ibuffer
1	isearch-exit
1	python-mode
1	replace-html-chars
1	beginning-of-defun

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.