Function: keyfreq-format-list

keyfreq-format-list is a natively compiled function defined in keyfreq.el.

Signature

(keyfreq-format-list LIST &optional FUNC)

Documentation

Return formatted string with command usage statistics.

The LIST is the keyfreq-table converted to a list using the keyfreq-list.

If FUNC is nil each line contains number of times command was called and the command; if it is t percentage usage is added in the middle; if it is 'raw each line will contain number an command separated by single line (with no formatting) otherwise FUNC must be a function returning a string which will be called for each entry with three arguments: number of times command was called, percentage usage and the command.

Source Code

;; Defined in /nix/store/vs0cnjcny583s3d1i80ya8g63h6xkwrn-emacs-packages-deps/share/emacs/site-lisp/elpa/keyfreq-20231107.106/keyfreq.el
(defun keyfreq-format-list (list &optional func)
  "Return formatted string with command usage statistics.

The LIST is the `keyfreq-table' converted to a list using the `keyfreq-list'.

If FUNC is nil each line contains number of times command was
called and the command; if it is t percentage usage is added in
the middle; if it is 'raw each line will contain number an
command separated by single line (with no formatting) otherwise
FUNC must be a function returning a string which will be called
for each entry with three arguments: number of times command was
called, percentage usage and the command."
  (let* ((sum (car list))
         (max-len
          (cl-reduce (lambda (a b) (max a (length (symbol-name (car b)))))
                  (cdr list)
                  :initial-value 0)))
    (mapconcat
     (cond
      ((not func) (lambda (e) (format "%7d  %s\n" (cdr e) (car e))))
      ((equal func t)
       (lambda (e) (format (concat "%7d  %6.2f%%  %- "
                              (format "%d" max-len)
                              "s %s\n")
			   (cdr e) (/ (* 1e2 (cdr e)) sum) (car e)
                           (ignore-errors (keyfreq-where-is (car e))))))
      ((equal func 'raw) (lambda (e) (format "%d %s\n" (cdr e) (car e))))
      (t (lambda (e) (funcall func (cdr e) (/ (* 1e2 (cdr e)) sum) (car e)))))
     (cdr list) "")))