Change add :unset support to set-lookup-handlers!

And update its documentation.
This commit is contained in:
Henrik Lissner 2018-06-20 15:37:49 +02:00
parent d5bb770ea6
commit 6d020a6305
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -5,46 +5,56 @@
(defvar +lookup--last-provider nil)
;;;###autodef
(cl-defun set-lookup-handlers! (modes &key definition references documentation file xref-backend)
"Defines a jump target for major MODES. PLIST accepts the following
(defun set-lookup-handlers! (modes &rest plist)
"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:
:definition FN
Run when jumping to a symbol's definition.
Used by `+lookup/definition'.
:references FN
Run when looking for usage references of a symbol in the current project.
Used by `+lookup/references'.
:documentation FN
Run when looking up documentation for a symbol.
Used by `+lookup/documentation'.
:file FN
Run when looking up the file for a symbol/string. Typically a file path.
Used by `+lookup/file'.
:xref-backend FN
Defines an xref backend for a major-mode. With this, :definition and
:references are unnecessary.
Using this multiple times overwrites previous properties and unsets omitted
ones."
:definition FN
Run when jumping to a symbol's definition.
Used by `+lookup/definition'.
:references FN
Run when looking for usage references of a symbol in the current project.
Used by `+lookup/references'.
:documentation FN
Run when looking up documentation for a symbol.
Used by `+lookup/documentation'.
:file FN
Run when looking up the file for a symbol/string. Typically a file path.
Used by `+lookup/file'.
:xref-backend FN
Defines an xref backend for a major-mode. If you define :definition and
:references along with :xref-backend, those will have higher precedence."
(dolist (mode (doom-enlist modes))
(let ((def-name (intern (format "+lookup|init-%s" mode))))
(fset def-name
(lambda ()
(when (or (eq major-mode mode)
(and (boundp mode)
(symbol-value mode)))
(when definition
(add-hook '+lookup-definition-functions definition nil t))
(when references
(add-hook '+lookup-references-functions references nil t))
(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 (intern (format "%s-hook" mode)) def-name))))
(let ((fn (intern (format "+lookup|init-%s" mode)))
(hook (intern (format "%s-hook" mode))))
(if (eq (car plist) :unset)
(remove-hook hook fn)
(fset fn
(lambda ()
(when (or (eq major-mode mode)
(and (boundp mode)
(symbol-value mode)))
(cl-destructuring-bind
(&key definition references documentation file xref-backend)
plist
(when definition
(add-hook '+lookup-definition-functions definition nil t))
(when references
(add-hook '+lookup-references-functions references nil t))
(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
(def-setting! :lookup (modes &rest plist)