Fix doom/help-* commands for helm users #2107

This commit is contained in:
Henrik Lissner 2019-11-23 20:45:53 -05:00
parent d0504e5961
commit a9f412bf5e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

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