Function: keyfreq-table-save
keyfreq-table-save is a natively compiled function defined in
keyfreq.el.
Signature
(keyfreq-table-save TABLE &optional MUSTSAVE)
Documentation
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.
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.
Source Code
;; Defined in /nix/store/vs0cnjcny583s3d1i80ya8g63h6xkwrn-emacs-packages-deps/share/emacs/site-lisp/elpa/keyfreq-20231107.106/keyfreq.el
(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.
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))
))))