Simplify set-docset! & add unset capability

Removed :add and :remove capabilities. Now appends the provided docset
to the mode's list of docsets, if one exists.
This commit is contained in:
Henrik Lissner 2018-06-21 13:58:16 +02:00
parent ad2de8e2e5
commit dbc7b667cf
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -12,39 +12,22 @@
"Registers a list of DOCSETS (strings) for MODES (either one major mode
symbol or a list of them).
If MODES is a minor mode, you can use :add or :remove as the first element of
DOCSETS, to instruct it to append (or remove) those from the docsets already set
by a major-mode, if any.
Used by `+lookup/in-docsets' and `+lookup/documentation'."
(dolist (mode (doom-enlist modes))
(let ((hook-sym
(intern (format "+lookup|%s-docsets--%s"
(pcase (car docsets)
(:add 'add)
(:remove 'remove)
(_ 'set))
mode))))
(fset hook-sym
(let ((fn (intern (format "+lookup|init-docsets--%s" mode)))
(hook (intern (format "%s-hook" mode))))
(cond ((null (car-safe docsets))
(remove-hook hook fn)
(unintern fn))
((fset fn
(lambda ()
(let (var-sym)
(cond ((featurep! :completion ivy)
(setq var-sym 'counsel-dash-docsets))
((featurep! :completion helm)
(setq var-sym 'helm-dash-docsets)))
(when var-sym
(let ((val (symbol-value var-sym)))
(pcase (car docsets)
(:add
(set var-sym (append val (cdr docsets))))
(:remove
(let ((var-sym (if (featurep! :completion ivy)
'counsel-dash-docsets
'helm-dash-docsets)))
(set var-sym
(cl-loop with to-delete = (cdr docsets)
for docset in val
unless (member docset to-delete)
collect docset)))
(_ (set var-sym (cdr docsets)))))))))
(add-hook (intern (format "%s-hook" mode)) hook-sym))))
(append (symbol-value var-sym)
docsets)))))
(add-hook hook fn))))))
;;;###autoload
(def-setting! :docset (modes &rest docsets)