doom/describe-module: detect module associated with major-mode
This commit is contained in:
parent
6f4ca15445
commit
95009c08f8
1 changed files with 64 additions and 46 deletions
|
@ -1,14 +1,5 @@
|
|||
;;; 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!').
|
||||
|
@ -24,53 +15,80 @@ Defaults to the "
|
|||
(error "'%s' is not a valid DOOM setting" setting))
|
||||
(describe-function fn)))
|
||||
|
||||
|
||||
;;
|
||||
(defvar doom--module-mode-alist
|
||||
'((c-mode :lang cc)
|
||||
(c++-mode :lang cc)
|
||||
(objc++-mode :lang cc)
|
||||
(java-mode :lang java)
|
||||
(csharp-mode :lang csharp)
|
||||
(clojure-mode :lang clojure)
|
||||
(emacs-lisp-mode :lang emacs-lisp)
|
||||
(go-mode :lang go)
|
||||
(haskell-mode :lang haskell)
|
||||
(js2-mode :lang javascript)
|
||||
(julia-mode :lang julia)
|
||||
(latex-mode :lang latex)
|
||||
(LaTeX-mode :lang latex)
|
||||
(ledger-mode :lang ledger)
|
||||
(lua-mode :lang lua)
|
||||
(markdown-mode :lang markdown)
|
||||
(gfm-mode :lang markdown)
|
||||
(ocaml-mode :lang ocaml)
|
||||
(org-mode :lang org)
|
||||
(perl-mode :lang perl)
|
||||
(php-mode :lang php)
|
||||
(hack-mode :lang php)
|
||||
(plantuml-mode :lang plantuml)
|
||||
(purescript-mode :lang purescript)
|
||||
(python-mode :lang python)
|
||||
(restclient-mode :lang rest)
|
||||
(ruby-mode :lang ruby)
|
||||
(rust-mode :lang rust)
|
||||
(scala-mode :lang scala)
|
||||
(sh-mode :lang sh)
|
||||
(swift-mode :lang swift)
|
||||
(typescript-mode :lang typescript)
|
||||
(web-mode :lang web)
|
||||
(css-mode :lang web)
|
||||
(scss-mode :lang web)
|
||||
(sass-mode :lang web)
|
||||
(less-css-mode :lang web)
|
||||
(stylus-mode :lang web))
|
||||
"TODO")
|
||||
|
||||
;;;###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').
|
||||
|
||||
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."
|
||||
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--module-mode-alist')."
|
||||
(interactive
|
||||
(let ((module
|
||||
(cond ((and buffer-file-name
|
||||
(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))))
|
||||
(eq major-mode 'emacs-lisp-mode)
|
||||
(string= (file-name-nondirectory buffer-file-name)
|
||||
"init.el")
|
||||
(thing-at-point 'sexp t)))
|
||||
((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))))))
|
||||
(buffer-file-name
|
||||
(when-let* ((module (doom-module-from-path buffer-file-name)))
|
||||
(format "%s %s" (car module) (cdr module)))))))
|
||||
(ignore-errors
|
||||
(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)))))))
|
||||
((and buffer-file-name
|
||||
(when-let* ((mod (doom-module-from-path buffer-file-name)))
|
||||
(format "%s %s" (car mod) (cdr mod)))))
|
||||
((when-let* ((mod (cdr (assq major-mode doom--module-mode-alist))))
|
||||
(format "%s %s"
|
||||
(symbol-name (car mod))
|
||||
(symbol-name (cadr mod))))))))
|
||||
(list (completing-read "Describe module: "
|
||||
(cl-loop for (module . sub) in (reverse (hash-table-keys doom-modules))
|
||||
collect (format "%s %s" module sub))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue