diff --git a/core/autoload/help.el b/core/autoload/help.el index cb13f1c71..0663fd161 100644 --- a/core/autoload/help.el +++ b/core/autoload/help.el @@ -132,30 +132,30 @@ selection of all minor-modes, active or not." (depth (if (integerp depth) depth))) (message "Loading search results...") (unwind-protect - (delq nil - (org-map-entries - (lambda () - (cl-destructuring-bind (level _reduced-level _todo _priority text tags) - (org-heading-components) - (let ((path (org-get-outline-path))) - (when (and (or (null depth) - (<= level depth)) - (or (null tags) - (not (string-match-p ":TOC" tags)))) - (propertize - (mapconcat - 'identity - (list (mapconcat #'identity - (append (when include-files - (list (or (+org-get-global-property "TITLE") - (file-relative-name buffer-file-name)))) - path - (list (replace-regexp-in-string org-link-any-re "\\4" text))) - " > ") + (delq + nil + (org-map-entries + (lambda () + (cl-destructuring-bind (level _reduced-level _todo _priority text tags) + (org-heading-components) + (when (and (or (null depth) + (<= level depth)) + (or (null tags) + (not (string-match-p ":TOC" tags)))) + (let ((path (org-get-outline-path))) + (list (string-join + (list (string-join + (append (when include-files + (list (or (+org-get-global-property "TITLE") + (file-relative-name (buffer-file-name))))) + path + (list (replace-regexp-in-string org-link-any-re "\\4" text))) + " > ") tags) " ") - 'location (cons buffer-file-name (point))))))) - t 'agenda)) + (buffer-file-name) + (point)))))) + t 'agenda)) (mapc #'kill-buffer org-agenda-new-buffers) (setq org-agenda-new-buffers nil)))) @@ -163,17 +163,18 @@ selection of all minor-modes, active or not." ;;;###autoload (defun doom-completing-read-org-headings (prompt files &optional depth include-files initial-input extra-candidates) "TODO" - (let (ivy-sort-functions-alist) - (if-let* ((result (completing-read - prompt - (append (doom--org-headings files depth include-files) - extra-candidates) - nil nil initial-input))) - (cl-destructuring-bind (file . location) - (get-text-property 0 'location result) + (let ((alist + (append (doom--org-headings files depth include-files) + extra-candidates)) + ivy-sort-functions-alist) + (if-let (result (completing-read prompt alist nil nil initial-input)) + (cl-destructuring-bind (file &optional location) + (cdr (assoc result alist)) (find-file file) - (when location - (goto-char location))) + (cond ((functionp location) + (funcall location)) + (location + (goto-char location)))) (user-error "Aborted")))) ;;;###autoload @@ -201,9 +202,8 @@ selection of all minor-modes, active or not." "faq.org") 2 t initial-input (mapcar (lambda (x) - (propertize (concat "Doom Modules > " x) - 'location - (get-text-property (1- (length x)) 'location x))) + (setcar x (concat "Doom Modules > " (car x))) + x) (doom--help-modules-list)))) ;;;###autoload @@ -300,19 +300,14 @@ without needing to check if they are available." (defun doom--help-modules-list () (cl-loop for path in (cdr (doom-module-load-path 'all)) 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) + for path = (or (doom-module-locate-path cat mod "README.org") + (doom-module-locate-path cat mod)) + for format = (format "%s %s" cat mod) if (doom-module-p cat mod) - collect format + collect (list format path) else if (and cat mod) - collect - (propertize - format - 'face 'font-lock-comment-face - 'location location))) + collect (list (propertize format 'face 'font-lock-comment-face) + path))) (defun doom--help-current-module-str () (cond ((and buffer-file-name @@ -330,10 +325,10 @@ without needing to check if they are available." (let ((sexp (sexp-at-point))) (when (memq (car-safe sexp) '(featurep! require!)) (format "%s %s" (nth 1 sexp) (nth 2 sexp))))))) - ((and buffer-file-name - (when-let (mod (doom-module-from-path buffer-file-name)) - (unless (memq (car mod) '(:core :private)) - (format "%s %s" (car mod) (cdr mod)))))) + ((when buffer-file-name + (when-let (mod (doom-module-from-path buffer-file-name)) + (unless (memq (car mod) '(:core :private)) + (format "%s %s" (car mod) (cdr mod)))))) ((when-let (mod (cdr (assq major-mode doom--help-major-mode-module-alist))) (format "%s %s" (symbol-name (car mod)) @@ -350,25 +345,23 @@ 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-string - (completing-read "Describe module: " - (doom--help-modules-list) - nil t nil nil - (doom--help-current-module-str))) - (key (doom-module-from-path - (or (car (get-text-property 0 'location module-string)) - (user-error "Did not select a valid module"))))) - (list (car key) - (cdr key)))) + (mapcar #'intern + (split-string + (completing-read "Describe module: " + (doom--help-modules-list) nil t nil nil + (doom--help-current-module-str)) + " " t))) (cl-check-type category symbol) (cl-check-type module symbol) - (let ((path (doom-module-locate-path category module))) + (cl-destructuring-bind (module-string path) + (or (assoc (format "%s %s" category module) (doom--help-modules-list)) + (user-error "'%s %s' is not a valid module" category module)) (unless (file-readable-p path) - (error "'%s %s' isn't a valid module; it doesn't exist" category module)) - (if-let (readme-path (doom-module-locate-path category module "README.org")) - (find-file readme-path) - (if (y-or-n-p (format "The '%s %s' module has no README file. Explore its directory?" - category module)) + (error "Can't find or read %S module at %S" module-string path)) + (if (not (file-directory-p path)) + (find-file path) + (if (y-or-n-p (format "The %S module has no README file. Explore its directory?" + module-string)) (doom-project-browse path) (user-error "Aborted module lookup")))))