Merge module list into doom/help-search

This commit is contained in:
Henrik Lissner 2019-10-26 01:48:36 -04:00
parent 592c548b24
commit d0ae6c9bda
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -158,17 +158,19 @@ selection of all minor-modes, active or not."
(defvar ivy-sort-functions-alist) (defvar ivy-sort-functions-alist)
;;;###autoload ;;;###autoload
(defun doom-completing-read-org-headings (prompt files &optional depth include-files initial-input) (defun doom-completing-read-org-headings (prompt files &optional depth include-files initial-input extra-candidates)
"TODO" "TODO"
(let (ivy-sort-functions-alist) (let (ivy-sort-functions-alist)
(if-let* ((result (completing-read (if-let* ((result (completing-read
prompt prompt
(doom--org-headings files depth include-files) (append (doom--org-headings files depth include-files)
extra-candidates)
nil nil initial-input))) nil nil initial-input)))
(cl-destructuring-bind (file . location) (cl-destructuring-bind (file . location)
(get-text-property 0 'location result) (get-text-property 0 'location result)
(find-file file) (find-file file)
(goto-char location)) (when location
(goto-char location)))
(user-error "Aborted")))) (user-error "Aborted"))))
;;;###autoload ;;;###autoload
@ -193,9 +195,13 @@ selection of all minor-modes, active or not."
"contributing.org" "contributing.org"
"troubleshooting.org" "troubleshooting.org"
"tutorials.org" "tutorials.org"
"faq.org" "faq.org")
"../modules/README.org") 2 t initial-input
2 t initial-input)) (mapcar (lambda (x)
(propertize (concat "Doom Modules > " x)
'location
(get-text-property (1- (length x)) 'location x)))
(doom--help-modules-list))))
;;;###autoload ;;;###autoload
(defun doom/help-news-search (&optional initial-input) (defun doom/help-news-search (&optional initial-input)
@ -288,18 +294,24 @@ without needing to check if they are available."
(helpful-callable fn) (helpful-callable fn)
(describe-function fn)))) (describe-function fn))))
;;;###autoload (defun doom--help-modules-list ()
(defun doom/help-modules (category module) (cl-loop for path in (doom-module-load-path 'all)
"Open the documentation for a Doom module. for (cat . mod) = (doom-module-from-path path)
for location = (cons (or (doom-module-locate-path cat mod "README.org")
(doom-module-locate-path cat mod))
nil)
for format = (propertize (format "%s %s" cat mod)
'location location)
if (doom-module-p cat mod)
collect format
else if (and cat mod)
collect
(propertize
format
'face 'font-lock-comment-face
'location location)))
CATEGORY is a keyword and MODULE is a symbol. e.g. :editor and 'evil. (defun doom--help-current-module-str ()
Automatically selects a) the module at point (in private init files), b) the
module derived from a `featurep!' or `require!' call, c) the module that the
current file is in, or d) the module associated with the current major mode (see
`doom--help-major-mode-module-alist')."
(interactive
(let* ((module
(cond ((and buffer-file-name (cond ((and buffer-file-name
(eq major-mode 'emacs-lisp-mode) (eq major-mode 'emacs-lisp-mode)
(file-in-directory-p buffer-file-name doom-private-dir) (file-in-directory-p buffer-file-name doom-private-dir)
@ -322,20 +334,27 @@ current file is in, or d) the module associated with the current major mode (see
(format "%s %s" (format "%s %s"
(symbol-name (car mod)) (symbol-name (car mod))
(symbol-name (cadr mod))))))) (symbol-name (cadr mod)))))))
(module-string
(completing-read ;;;###autoload
"Describe module: " (defun doom/help-modules (category module)
(cl-loop for path in (doom-module-load-path 'all) "Open the documentation for a Doom module.
for (cat . mod) = (doom-module-from-path path)
for format = (format "%s %s" cat mod) CATEGORY is a keyword and MODULE is a symbol. e.g. :editor and 'evil.
if (doom-module-p cat mod)
collect format Automatically selects a) the module at point (in private init files), b) the
else if (and cat mod) module derived from a `featurep!' or `require!' call, c) the module that the
collect (propertize format 'face 'font-lock-comment-face)) current file is in, or d) the module associated with the current major mode (see
nil t nil nil module)) `doom--help-major-mode-module-alist')."
(key (split-string module-string " "))) (interactive
(list (intern (car key)) (let* ((module-string
(intern (cadr key))))) (completing-read "Describe module: "
(doom--help-modules-list)
nil t nil nil
(doom--help-current-module-str)))
(key (doom-module-from-path
(car (get-text-property 0 'location module-string)))))
(list (car key)
(cdr key))))
(cl-check-type category symbol) (cl-check-type category symbol)
(cl-check-type module symbol) (cl-check-type module symbol)
(let ((path (doom-module-locate-path category module))) (let ((path (doom-module-locate-path category module)))
@ -579,7 +598,7 @@ Uses the symbol at point or the current selection, if available."
(interactive (interactive
(let ((query (let ((query
;; TODO Generalize this later; into something the lookup module and ;; TODO Generalize this later; into something the lookup module and
;; project search commands could as well. ;; project search commands could as well
(if (use-region-p) (if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end)) (buffer-substring-no-properties (region-beginning) (region-end))
(or (symbol-name (symbol-at-point)) "")))) (or (symbol-name (symbol-at-point)) ""))))