Optimize texdoc discovery in latex-help.el

This commit is contained in:
Alexander Rosenberg 2024-10-14 14:27:31 -07:00
parent cc91d6b7b7
commit 7cd012f02b
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -264,10 +264,10 @@ A marker file is a file that signifies that its parent is a texdoc entry."
(regexp-quote dirname))
name)))))
(defun latex-help--search-texdoc-root (root)
"Search the texdoc root directory ROOT and discover package names."
(cl-loop with found = nil
with to-search = nil
(defun latex-help--search-texdoc-root (root found)
"Search the texdoc root directory ROOT and discover package names.
FOUND is the hash table in which to put the entries."
(cl-loop with to-search = nil
for dir = root then (pop to-search)
while dir
when (file-directory-p dir) do
@ -276,7 +276,7 @@ A marker file is a file that signifies that its parent is a texdoc entry."
(latex-help--is-marker-file file root))
files)
;; dir is an entry
(push (file-name-nondirectory dir) found)
(puthash (file-name-nondirectory dir) nil found)
;; search all subdirs
(setq to-search
(nconc to-search
@ -299,39 +299,38 @@ A marker file is a file that signifies that its parent is a texdoc entry."
(group (+ any)) eol) nil t)
collect (match-string 1))))
(defun latex-help--texdoc-config-file-entries (file)
(defun latex-help--texdoc-config-file-entries (file found)
"Parse the texdoc config file FILE to find entries.
This attempts to find entries that might have been missed during the initial
scan. The return value is a list of cahce entries with the second element being
nil (signifying that we don't know the directory they below to)."
scan. The entries will be `puthash'ed into FOUND as keys."
(with-temp-buffer
(insert-file-contents file)
(goto-char (point-min))
(let ((found))
(while (re-search-forward (rx bol "adjscore("
(group (+ (not ")"))) ")")
nil t)
(push (match-string 1) found))
(while (re-search-forward
(rx bol "alias" (? "(" (+ (any (?0 . ?9) ".")) ")")
" " (group (+ (not " ")))
" = " (group (* (not (any "#" "\n" " ")))))
nil t)
(push (match-string 1) found)
(let ((m2 (match-string 2)))
(unless (or (zerop (length m2))
(seq-contains-p m2 ?/))
(push m2 found))))
found)))
(while (re-search-forward (rx bol "adjscore("
(group (+ (not ")"))) ")")
nil t)
(puthash (match-string 1) nil found))
(goto-char (point-min))
(while (re-search-forward
(rx bol "alias" (? "(" (+ (any (?0 . ?9) ".")) ")")
" " (group (+ (not " ")))
" = " (group (* (not (any "#" "\n" " ")))))
nil t)
(puthash (match-string 1) nil found)
(let ((m2 (match-string 2)))
(unless (or (zerop (length m2))
(seq-contains-p m2 ?/))
(puthash m2 nil found))))))
(defun latex-help--discover-texdoc-entries ()
"Discover texdoc entries in each of `latex-help-documentation-roots'."
(let ((output))
(let ((found (make-hash-table :test 'equal)))
(dolist (root latex-help-documentation-roots)
(setq output (nconc output (latex-help--search-texdoc-root root))))
(latex-help--search-texdoc-root root found))
(dolist (file (latex-help--texdoc-config-files))
(setq output (nconc output (latex-help--texdoc-config-file-entries file))))
(seq-uniq output)))
(latex-help--texdoc-config-file-entries file found))
(cl-loop for entry being the hash-keys of found
collect entry)))
(defun latex-help--texdoc-files-for-entry (entry)
"List the texdoc files for ENTRY.