Improve doom/describe-{setting,module} commands

Now grabs the setting/module at point
This commit is contained in:
Henrik Lissner 2018-01-28 03:00:25 -05:00
parent 2bdd1c98c5
commit 4f983c139e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -1,13 +1,24 @@
;;; core/autoload/help.el -*- lexical-binding: t; -*-
(defun doom--find-next (pred forward-fn end-fn)
(save-excursion
(catch 'found
(ignore-errors
(while (not (funcall end-fn))
(when-let* ((ret (funcall pred)))
(throw 'found ret))
(funcall forward-fn))))))
;;;###autoload
(defun doom/describe-setting (setting)
"Open the documentation of SETTING (a keyword defined with `def-setting!')."
"Open the documentation of SETTING (a keyword defined with `def-setting!').
Defaults to the "
(interactive
;; TODO try to read setting from whole line
(list (completing-read "Describe setting%s: "
(let ((sym (symbol-at-point)))
(list (completing-read "Describe setting: "
(sort (mapcar #'car doom-settings) #'string-lessp)
nil t nil nil)))
nil t (if (keywordp sym) (symbol-name sym))))))
(let ((fn (cdr (assq (intern setting) doom-settings))))
(unless fn
(error "'%s' is not a valid DOOM setting" setting))
@ -16,13 +27,53 @@
;;;###autoload
(defun doom/describe-module (module)
"Open the documentation of MODULE (a string that represents the category and
submodule in the format, e.g. ':feature evil')."
submodule in the format, e.g. ':feature evil').
Defaults to either a) the module at point (in init.el), b) the module derived
from a `featurep!' or `require!' call or c) the module that the current file is
in."
(interactive
;; TODO try to read module from whole line
(let ((module
(cond ((string= (file-truename user-init-file)
(file-truename buffer-file-name))
(let* ((category
(save-excursion
(goto-char (line-end-position))
(doom--find-next
(lambda ()
(and (not (sp-point-in-comment))
(keywordp (symbol-at-point))
(symbol-at-point)))
(lambda () (forward-symbol -1))
#'bobp)))
(module
(save-excursion
(goto-char (line-beginning-position))
(save-restriction
(narrow-to-region (point) (line-end-position))
(doom--find-next
(lambda ()
(and (not (sp-point-in-comment))
(not (keywordp (symbol-at-point)))
(sexp-at-point)))
#'forward-sexp
#'eobp)))))
(when (and category module)
(format "%s %s" category module))))
((save-excursion
(sp-beginning-of-sexp)
(unless (eq (char-after) ?\()
(backward-char))
(let ((sexp (sexp-at-point)))
(when (memq (car-safe sexp) '(featurep! require!))
(format "%s %s" (nth 1 sexp) (nth 2 sexp))))))
((file-in-directory-p buffer-file-name doom-modules-dir)
(let ((module (doom-module-from-path buffer-file-name)))
(format "%s %s" (car module) (cdr module)))))))
(list (completing-read "Describe module: "
(cl-loop for (module . sub) in (reverse (hash-table-keys doom-modules))
collect (format "%s %s" module sub))
nil t)))
nil t module))))
(cl-destructuring-bind (category submodule)
(mapcar #'intern (split-string module " "))
(unless (member (cons category submodule) (doom-module-pairs))