Change add :unset support to set-lookup-handlers!
And update its documentation.
This commit is contained in:
parent
d5bb770ea6
commit
6d020a6305
1 changed files with 47 additions and 37 deletions
|
@ -5,46 +5,56 @@
|
||||||
(defvar +lookup--last-provider nil)
|
(defvar +lookup--last-provider nil)
|
||||||
|
|
||||||
;;;###autodef
|
;;;###autodef
|
||||||
(cl-defun set-lookup-handlers! (modes &key definition references documentation file xref-backend)
|
(defun set-lookup-handlers! (modes &rest plist)
|
||||||
"Defines a jump target for major MODES. PLIST accepts the following
|
"Defines a jump target for major MODES.
|
||||||
|
|
||||||
|
This overwrites previously defined handlers for MODES. If used on minor modes,
|
||||||
|
they are combined with handlers defined for other minor modes or the major mode
|
||||||
|
it's activated in.
|
||||||
|
|
||||||
|
If the CAR of PLIST is :unset, other properties are ignored and all existing
|
||||||
|
jump handlers for MODES are cleared. Otherwise, PLIST accepts the following
|
||||||
properties:
|
properties:
|
||||||
|
|
||||||
:definition FN
|
:definition FN
|
||||||
Run when jumping to a symbol's definition.
|
Run when jumping to a symbol's definition.
|
||||||
Used by `+lookup/definition'.
|
Used by `+lookup/definition'.
|
||||||
:references FN
|
:references FN
|
||||||
Run when looking for usage references of a symbol in the current project.
|
Run when looking for usage references of a symbol in the current project.
|
||||||
Used by `+lookup/references'.
|
Used by `+lookup/references'.
|
||||||
:documentation FN
|
:documentation FN
|
||||||
Run when looking up documentation for a symbol.
|
Run when looking up documentation for a symbol.
|
||||||
Used by `+lookup/documentation'.
|
Used by `+lookup/documentation'.
|
||||||
:file FN
|
:file FN
|
||||||
Run when looking up the file for a symbol/string. Typically a file path.
|
Run when looking up the file for a symbol/string. Typically a file path.
|
||||||
Used by `+lookup/file'.
|
Used by `+lookup/file'.
|
||||||
:xref-backend FN
|
:xref-backend FN
|
||||||
Defines an xref backend for a major-mode. With this, :definition and
|
Defines an xref backend for a major-mode. If you define :definition and
|
||||||
:references are unnecessary.
|
:references along with :xref-backend, those will have higher precedence."
|
||||||
|
|
||||||
Using this multiple times overwrites previous properties and unsets omitted
|
|
||||||
ones."
|
|
||||||
(dolist (mode (doom-enlist modes))
|
(dolist (mode (doom-enlist modes))
|
||||||
(let ((def-name (intern (format "+lookup|init-%s" mode))))
|
(let ((fn (intern (format "+lookup|init-%s" mode)))
|
||||||
(fset def-name
|
(hook (intern (format "%s-hook" mode))))
|
||||||
(lambda ()
|
(if (eq (car plist) :unset)
|
||||||
(when (or (eq major-mode mode)
|
(remove-hook hook fn)
|
||||||
(and (boundp mode)
|
(fset fn
|
||||||
(symbol-value mode)))
|
(lambda ()
|
||||||
(when definition
|
(when (or (eq major-mode mode)
|
||||||
(add-hook '+lookup-definition-functions definition nil t))
|
(and (boundp mode)
|
||||||
(when references
|
(symbol-value mode)))
|
||||||
(add-hook '+lookup-references-functions references nil t))
|
(cl-destructuring-bind
|
||||||
(when documentation
|
(&key definition references documentation file xref-backend)
|
||||||
(add-hook '+lookup-documentation-functions documentation nil t))
|
plist
|
||||||
(when file
|
(when definition
|
||||||
(add-hook '+lookup-file-functions file nil t))
|
(add-hook '+lookup-definition-functions definition nil t))
|
||||||
(when xref-backend
|
(when references
|
||||||
(add-hook 'xref-backend-functions xref-backend nil t)))))
|
(add-hook '+lookup-references-functions references nil t))
|
||||||
(add-hook (intern (format "%s-hook" mode)) def-name))))
|
(when documentation
|
||||||
|
(add-hook '+lookup-documentation-functions documentation nil t))
|
||||||
|
(when file
|
||||||
|
(add-hook '+lookup-file-functions file nil t))
|
||||||
|
(when xref-backend
|
||||||
|
(add-hook 'xref-backend-functions xref-backend nil t))))))
|
||||||
|
(add-hook hook fn)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(def-setting! :lookup (modes &rest plist)
|
(def-setting! :lookup (modes &rest plist)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue