embark
embark copied to clipboard
embark-collect-live: Remember candidate collector
Instead of registering the collectors in the embark-candidate-collectors list one may want to override them locally. This allows us to write top-level commands for the live updating TOC. Unfortunately this does not work with embark-collect-live when updating.
;; does not work when updating, since embark-candidate-collectors override is forgotten
(defun embark-consult-outline-live ()
(interactive)
(let ((embark-candidate-collectors (list #'embark-consult-outline-candidates)))
(embark-collect-live)))
;; does not work when updating, since embark-candidate-collectors override is forgotten
(defun embark-consult-imenu-live ()
(interactive)
(let ((embark-candidate-collectors (list #'embark-consult-imenu-candidates)))
(embark-collect-live)))
;; works
(defun embark-consult-outline-snapshot ()
(interactive)
(let ((embark-candidate-collectors (list #'embark-consult-outline-candidates)))
(embark-collect-snapshot)))
;; works
(defun embark-consult-imenu-snapshot ()
(interactive)
(let ((embark-candidate-collectors (list #'embark-consult-imenu-candidates)))
(embark-collect-snapshot)))
Furthermore it would be neat to have an API like this:
(defun embark-consult-outline-live ()
(interactive)
(embark-collect-live :collector #'embark-consult-outline-candidates))
(defun embark-consult-imenu-live ()
(interactive)
(embark-collect-live :collector #'embark-consult-imenu-candidates))
(defun embark-consult-outline-snapshot ()
(interactive)
(embark-collect-snapshot :collector #'embark-consult-outline-candidates))
(defun embark-consult-imenu-snapshot ()
(interactive)
(embark-collect-snapshot :collector #'embark-consult-imenu-candidates))
cc @hmelman - this is another idea to run the toc collectors from the toplevel. It may give the feature more visibility.
Related #405
(defcustom embark-consult-live-update-delay ...)
(defun embark-consult-imenu-snapshot ()
(interactive)
(let ((embark-collect-live-update-delay embark-consult-live-update-delay)
(embark-candidate-collectors (list #'embark-consult-imenu-candidates)))
(embark-collect-snapshot)))
This is a good idea! The collector should definitely be remembered.
Oh, I think this is still a problem! I guess embark-live could handle this on its own: just capture the value of embark-candidate-collectors when embark-live is called and then let-bind the variable to that same value whenever updating the candidate list.