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