From 2a2d4ca9b50fd06ae0f90e401f6d56e73119033a Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sat, 20 Feb 2016 14:24:26 +0100 Subject: [PATCH] update keyfreq. --- elpa/keyfreq-20141124.805/keyfreq-pkg.el | 1 - .../keyfreq-autoloads.el | 7 +- elpa/keyfreq-20150924.2005/keyfreq-pkg.el | 1 + .../keyfreq.el | 155 +++++++++++++----- 4 files changed, 121 insertions(+), 43 deletions(-) delete mode 100644 elpa/keyfreq-20141124.805/keyfreq-pkg.el rename elpa/{keyfreq-20141124.805 => keyfreq-20150924.2005}/keyfreq-autoloads.el (91%) create mode 100644 elpa/keyfreq-20150924.2005/keyfreq-pkg.el rename elpa/{keyfreq-20141124.805 => keyfreq-20150924.2005}/keyfreq.el (79%) diff --git a/elpa/keyfreq-20141124.805/keyfreq-pkg.el b/elpa/keyfreq-20141124.805/keyfreq-pkg.el deleted file mode 100644 index 7dc8d355..00000000 --- a/elpa/keyfreq-20141124.805/keyfreq-pkg.el +++ /dev/null @@ -1 +0,0 @@ -(define-package "keyfreq" "20141124.805" "track command frequencies" 'nil) diff --git a/elpa/keyfreq-20141124.805/keyfreq-autoloads.el b/elpa/keyfreq-20150924.2005/keyfreq-autoloads.el similarity index 91% rename from elpa/keyfreq-20141124.805/keyfreq-autoloads.el rename to elpa/keyfreq-20150924.2005/keyfreq-autoloads.el index bbcc769b..71f160a8 100644 --- a/elpa/keyfreq-20141124.805/keyfreq-autoloads.el +++ b/elpa/keyfreq-20150924.2005/keyfreq-autoloads.el @@ -3,7 +3,7 @@ ;;; Code: (add-to-list 'load-path (or (file-name-directory #$) (car load-path))) -;;;### (autoloads nil "keyfreq" "keyfreq.el" (21908 14229 0 0)) +;;;### (autoloads nil "keyfreq" "keyfreq.el" (22215 7928 0 0)) ;;; Generated autoloads from keyfreq.el (defvar keyfreq-mode nil "\ @@ -38,6 +38,11 @@ and when emacs is killed. \(fn &optional ARG)" t nil) +(autoload 'keyfreq-save-now "keyfreq" "\ +Save keyfreq data now. + +\(fn)" t nil) + ;;;*** ;; Local Variables: diff --git a/elpa/keyfreq-20150924.2005/keyfreq-pkg.el b/elpa/keyfreq-20150924.2005/keyfreq-pkg.el new file mode 100644 index 00000000..9fd306f0 --- /dev/null +++ b/elpa/keyfreq-20150924.2005/keyfreq-pkg.el @@ -0,0 +1 @@ +(define-package "keyfreq" "20150924.2005" "track command frequencies" 'nil) diff --git a/elpa/keyfreq-20141124.805/keyfreq.el b/elpa/keyfreq-20150924.2005/keyfreq.el similarity index 79% rename from elpa/keyfreq-20141124.805/keyfreq.el rename to elpa/keyfreq-20150924.2005/keyfreq.el index 1e2853b3..8078f535 100644 --- a/elpa/keyfreq-20141124.805/keyfreq.el +++ b/elpa/keyfreq-20150924.2005/keyfreq.el @@ -1,8 +1,8 @@ ;;; keyfreq.el --- track command frequencies -;; Package-Version: 20141124.805 +;; Package-Version: 20150924.2005 ;; -*- coding: utf-8 -*- ;; -;; Copyright 2009-2010 by David Capello +;; Copyright 2009-2010, 2015 by David Capello ;; Copyright 2008 by Xah Lee ;; Copyright 2006 by Michal Nazarewicz ;; Copyright 2006 by Ryan Yeske @@ -13,9 +13,16 @@ ;; ;; Keyfreq is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2 of the License, or +;; the Free Software Foundation; either version 3 of the License, or ;; (at your option) any later version. ;; +;; Version 1.7 - 2015-09 - David Capello +;; * Avoid accumulating key frequency if keyfreq-file-release-lock fails +;; +;; Version 1.6 - 2015-09 - David Capello +;; * Added keyfreq-reset thanks to @w-vi +;; * Fixed issue running multiple instances of Emacs 24.5 +;; ;; Version 1.5 - 2014-11 - David Capello ;; * Support cl-lib or cl ;; * Minor doc fixes @@ -76,7 +83,7 @@ "Customization group for Keyfreq mode. This mode stores number of times each command was called and provides it as a statistical data." - :package-version '(keyfreq . "1.5") + :package-version '(keyfreq . "1.7") :group 'local :prefix "keyfreq") @@ -119,14 +126,18 @@ by default." "Hash table storing number of times each command was called in each major mode since the last time the frequencies were saved in `keyfreq-file'.") +(defvar keyfreq-excluded-commands '() + "List of commands excluded by keyfreq.") (defun keyfreq-pre-command-hook () "Record command execution in `keyfreq-table' hash." (let ((command real-last-command) count) (when (and command (symbolp command)) (setq count (gethash (cons major-mode command) keyfreq-table)) - (puthash (cons major-mode command) (if count (1+ count) 1) - keyfreq-table)))) + (unless (memq command keyfreq-excluded-commands) + (puthash (cons major-mode command) (if count (1+ count) 1) + keyfreq-table) + )))) (defun keyfreq-groups-major-modes (table) @@ -384,21 +395,43 @@ is used as MAJOR-MODE-SYMBOL argument." (insert (keyfreq-json-encode table))))) +(defun keyfreq-reset () + "Reset all statistics including those in the file." + (interactive) + (when (yes-or-no-p (concat "Delete keyfreq file? You will lost all your stats. ")) + ;; clear the hash table + (clrhash keyfreq-table) + ;; Deal with the file + (when (keyfreq-file-is-unlocked) + ;; Lock the file + (keyfreq-file-claim-lock) + ;; Check that we have the lock + (if (eq (keyfreq-file-owner) (emacs-pid)) + (unwind-protect + ;; if the file exists just delete it + (if (file-exists-p keyfreq-file) + (delete-file keyfreq-file)) + ;; Release the lock. + (keyfreq-file-release-lock)))))) + + (defun keyfreq-file-owner () "Return the PID of the Emacs process that owns the table file lock file." (let (owner) (and (file-exists-p keyfreq-file-lock) - (with-temp-buffer - (insert-file-contents-literally keyfreq-file-lock) - (goto-char (point-min)) - (setq owner (read (current-buffer))) - (integerp owner)) + (ignore-errors + (with-temp-buffer + (insert-file-contents-literally keyfreq-file-lock) + (goto-char (point-min)) + (setq owner (read (current-buffer))) + (integerp owner))) owner))) (defun keyfreq-file-claim-lock () - (write-region (number-to-string (emacs-pid)) nil - keyfreq-file-lock nil 'nomessage)) + (ignore-errors + (write-region (number-to-string (emacs-pid)) nil + keyfreq-file-lock nil 'nomessage nil 'excl))) (defun keyfreq-file-release-lock () @@ -417,33 +450,58 @@ is used as MAJOR-MODE-SYMBOL argument." (not (file-exists-p keyfreq-file-lock))) -(defun keyfreq-table-save (table) +(defun keyfreq-table-save (table &optional mustsave) "Append all values from the specified TABLE into the `keyfreq-file' as a sexp of an alist. Then resets the TABLE -if it was successfully merged." - - ;; Check that the lock file does not exist - (when (keyfreq-file-is-unlocked) - ;; Lock the file - (keyfreq-file-claim-lock) - - ;; Check that we have the lock - (if (eq (keyfreq-file-owner) (emacs-pid)) - (unwind-protect - (progn - ;; Load values and merge them with the current keyfreq-table - (keyfreq-table-load table) - - ;; Write the new frequencies - (with-temp-file keyfreq-file - (let ((print-level nil) - (print-length nil)) - (prin1 (cdr (keyfreq-list table 'no-sort)) (current-buffer))))) - - ;; Release the lock and reset the hash table. - (keyfreq-file-release-lock) - (clrhash table)) - ))) +if it was successfully merged. + +If MUSTSAVE is t, this function tries to save the table until it +gets the lock and successfully saves it. If MUSTSAVE is nil, it +does nothing if the table cannot be saved." + + ;; Avoid adding nothing to the file + (if (> (hash-table-count table) 0) + (let (done) + ;; Check that the lock file doesn't exist + (while (not done) + (when (keyfreq-file-is-unlocked) + ;; Lock the file + (keyfreq-file-claim-lock) + + ;; Check that we have the lock + (if (eq (keyfreq-file-owner) (emacs-pid)) + (unwind-protect + (progn + ;; Load values and merge them with the current keyfreq-table + (keyfreq-table-load table) + + ;; Write the new frequencies + (with-temp-file keyfreq-file + (let ((l (cdr (keyfreq-list table 'no-sort)))) + (insert "(") + (dolist (item l) + (prin1 item (current-buffer)) + ;; Easy for git to track if every command is + ;; one line + (insert "\n")) + (insert ")")))) + + ;; Reset the hash table, enable the 'done' flag, and + ;; release the lock. + (clrhash table) + (setq done t) + (keyfreq-file-release-lock)))) + + (if (and (not done) mustsave) + ;; If we must save the file right now, we'll just keep + ;; trying until we can get the lock. So we can sleep some + ;; milliseconds for the next while-loop cycle. + (sleep-for 0.1) + ;; If we can wait to the next timer's timeout, just enable + ;; the 'done' flag to break the while-loop. + (setq done t)) + + )))) (defun keyfreq-table-load (table) @@ -461,10 +519,12 @@ The table is not reset, so the values are appended to the table." ;; Add the values in the table (while (and (listp l) l) (if (listp (car l)) - (puthash (caar l) (+ (gethash (caar l) table 0) (cdar l)) table)) + (unless (memq (cdr (caar l)) keyfreq-excluded-commands) + (puthash (caar l) (+ (gethash (caar l) table 0) (cdar l)) table))) (setq l (cdr l))) ))) + ;;;###autoload (define-minor-mode keyfreq-autosave-mode "Keyfreq Autosave mode automatically saves @@ -485,8 +545,9 @@ and when emacs is killed." (setq keyfreq-autosave--timer (run-at-time t keyfreq-autosave-timeout 'keyfreq-autosave--do)) - (add-hook 'kill-emacs-hook 'keyfreq-autosave--do)) - (remove-hook 'kill-emacs-hook 'keyfreq-autosave--do))) + (add-hook 'kill-emacs-hook 'keyfreq-mustsave--do)) + (keyfreq-mustsave--do) + (remove-hook 'kill-emacs-hook 'keyfreq-mustsave--do))) (defcustom keyfreq-autosave-timeout 600 @@ -506,6 +567,18 @@ value will take effect only after (re)enabling (keyfreq-table-save keyfreq-table)) +(defun keyfreq-mustsave--do () + "Function executed when we close Emacs." + (keyfreq-table-save keyfreq-table t)) + + +;;;###autoload +(defun keyfreq-save-now () + "Save keyfreq data now." + (interactive) + (keyfreq-mustsave--do) + (message "keyfreq data saved into %s" keyfreq-file)) + (provide 'keyfreq) ;;; keyfreq.el ends here -- 2.47.3