Fix doom/help-* commands for helm users #2107
This commit is contained in:
parent
d0504e5961
commit
a9f412bf5e
1 changed files with 59 additions and 66 deletions
|
@ -132,30 +132,30 @@ 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
|
||||||
(org-map-entries
|
nil
|
||||||
(lambda ()
|
(org-map-entries
|
||||||
(cl-destructuring-bind (level _reduced-level _todo _priority text tags)
|
(lambda ()
|
||||||
(org-heading-components)
|
(cl-destructuring-bind (level _reduced-level _todo _priority text tags)
|
||||||
(let ((path (org-get-outline-path)))
|
(org-heading-components)
|
||||||
(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)
|
||||||
t 'agenda))
|
(point))))))
|
||||||
|
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
|
(append (doom--org-headings files depth include-files)
|
||||||
prompt
|
extra-candidates))
|
||||||
(append (doom--org-headings files depth include-files)
|
ivy-sort-functions-alist)
|
||||||
extra-candidates)
|
(if-let (result (completing-read prompt alist nil nil initial-input))
|
||||||
nil nil initial-input)))
|
(cl-destructuring-bind (file &optional location)
|
||||||
(cl-destructuring-bind (file . location)
|
(cdr (assoc result alist))
|
||||||
(get-text-property 0 'location result)
|
|
||||||
(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,10 +325,10 @@ 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))))))
|
||||||
((when-let (mod (cdr (assq major-mode doom--help-major-mode-module-alist)))
|
((when-let (mod (cdr (assq major-mode doom--help-major-mode-module-alist)))
|
||||||
(format "%s %s"
|
(format "%s %s"
|
||||||
(symbol-name (car mod))
|
(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
|
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
|
||||||
(completing-read "Describe module: "
|
(split-string
|
||||||
(doom--help-modules-list)
|
(completing-read "Describe module: "
|
||||||
nil t nil nil
|
(doom--help-modules-list) nil t nil nil
|
||||||
(doom--help-current-module-str)))
|
(doom--help-current-module-str))
|
||||||
(key (doom-module-from-path
|
" " t)))
|
||||||
(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")))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue