;; -*- coding: utf-8; lexical-binding: t; -*- ;; file name: elisp_count_func_frequency.el ;; run it by ;; emacs --script elisp_count_func_frequency.el ;; ;; created: 2022-05-28 ;; version: 2023-08-23 (setq xOutputFileName "xfuncfreq.txt") (set-default-coding-systems 'utf-8-unix) (defun xah-hash-to-list (HashTable) "Return a list that represent the HASHTABLE Each element is a list: '(key value). URL `http://xahlee.info/emacs/emacs/elisp_hash_table.html' Version 2019-06-11 2022-05-28" (let ((xresult nil)) (maphash (lambda (k v) (push (list k v) xresult)) HashTable) xresult)) (defun xah-report-func-freq () "go thru emacs lisp source code dir, computer function usage frequency. version 2022-05-28" (interactive) (let ((xDir (expand-file-name (concat invocation-directory "../" "share/emacs/28.1/lisp/"))) xFuncName (xHash (make-hash-table :test 'equal)) xKeyExistVal xFnSortedList ) ;; walk the directory. for each file, open it. find text like 「(some-thing」 put it in a hashtable (mapc (lambda (fPath) (with-temp-buffer (insert-file-contents fPath) (goto-char (point-min)) (while (re-search-forward "(+\\([^ )\n]+\\)" nil t) (setq xFuncName (match-string 1)) (setq xKeyExistVal (gethash xFuncName xHash)) (if xKeyExistVal (puthash xFuncName (1+ xKeyExistVal) xHash) (puthash xFuncName 1 xHash))))) (directory-files xDir t "\\.el$")) (setq xFnSortedList (sort (xah-hash-to-list xHash) (lambda (a b) (< (cadr a) (cadr b))))) (setq xFnSortedList (nreverse xFnSortedList)) (with-temp-file xOutputFileName (mapc (lambda (x) (insert (format "「%s」 %s\n" (car x) (cadr x)))) xFnSortedList)))) (xah-report-func-freq)