embark icon indicating copy to clipboard operation
embark copied to clipboard

embark-collect-live: Remember candidate collector

Open minad opened this issue 4 years ago • 4 comments

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))

minad avatar Nov 15 '21 02:11 minad

cc @hmelman - this is another idea to run the toc collectors from the toplevel. It may give the feature more visibility.

minad avatar Nov 15 '21 02:11 minad

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)))

minad avatar Nov 15 '21 02:11 minad

This is a good idea! The collector should definitely be remembered.

oantolin avatar Nov 15 '21 13:11 oantolin

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.

oantolin avatar Mar 21 '22 16:03 oantolin