Guest User

Untitled

a guest
Jan 24th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. (defvar key-stats-commands ())
  2.  
  3. (defun key-stats-record-command ()
  4. (when (and (stringp (this-command-keys))
  5. (not (eql this-command 'self-insert-command)))
  6. (let* ((keys (this-command-keys))
  7. (keys-list (assoc major-mode key-stats-commands))
  8. (command (assoc keys (cdr keys-list))))
  9. (cond (command
  10. (incf (cdr command)))
  11. (keys-list
  12. (push (cons keys 1) (cdr keys-list)))
  13. (t
  14. (push (list major-mode (cons keys 1))
  15. key-stats-commands))))))
  16.  
  17. (defun key-stats-print-keys (keys)
  18. (insert (symbol-name (car keys)))
  19. (newline)
  20. (loop for (key . count) in (sort* (copy-list (cdr keys))
  21. #'> :key #'cdr)
  22. do (insert (format " %-7s %d\n" (key-description key)
  23. count))))
  24.  
  25. (defun key-stats ()
  26. (interactive)
  27. (with-current-buffer (get-buffer-create "*key-stats*")
  28. (erase-buffer)
  29. (mapc 'key-stats-print-keys key-stats-commands)
  30. (goto-char (point-min))
  31. (pop-to-buffer (current-buffer))))
  32.  
  33. (add-hook 'pre-command-hook 'key-stats-record-command)
Add Comment
Please, Sign In to add comment