Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marking candidates #467

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions embark.el
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ There are three kinds:
- :live, which does
- :completions, which also auto-updates, but is ephemeral.")

;; TODO Do we need this variable?
;; Also add a list of marked candidates, or a list of overlays?
;; When switching the display modes we have to move the overlays too.
;; We could also turn this variable into an alist, with value=marked.
(defvar-local embark-collect-candidates nil
"List of candidates in current collect buffer.")

Expand Down Expand Up @@ -2576,7 +2580,17 @@ all buffers."
"Return candidates in Embark Collect buffer.
This makes `embark-export' work in Embark Collect buffers."
(when (derived-mode-p 'embark-collect-mode)
(cons embark--type embark-collect-candidates)))
(cons embark--type
(or (save-excursion
(mapcar
(lambda (ov)
(goto-char (overlay-start ov))
(cadr (embark-target-collect-candidate)))
(nreverse
(seq-filter
(lambda (ov) (overlay-get ov 'embark--collect-mark))
(overlays-in (point-min) (point-max))))))
embark-collect-candidates))))

(defun embark-completions-buffer-candidates ()
"Return all candidates in a completions buffer."
Expand Down Expand Up @@ -2714,6 +2728,8 @@ For other Embark Collect buffers, run the default action on ENTRY."
("M-q" embark-collect-toggle-view)
("v" embark-collect-toggle-view)
("e" embark-export)
("m" embark-collect-mark)
("u" embark-collect-unmark)
("s" isearch-forward)
("f" forward-button)
("b" backward-button)
Expand Down Expand Up @@ -3052,6 +3068,30 @@ the minibuffer is exited."

window)))

(defun embark-collect-mark (&optional unmark)
"Mark the candidate at point in a collect buffer.
If UNMARK is non-nil, unmark the candidate instead."
(interactive)
(unless (derived-mode-p #'embark-collect-mode)
(error "Not in an Embark collect buffer"))
(when-let (target (embark-target-collect-candidate))
(pcase-let* ((`(,_type ,_cand ,beg . ,end) target)
(ov (seq-find (lambda (ov) (overlay-get ov 'embark--collect-mark)) (overlays-at beg))))
(unless (eq (not ov) unmark)
(if ov
(delete-overlay ov)
;; TODO: Define our own face here?
(unless (facep 'dired-marked) (require 'dired))
(setq ov (make-overlay beg end))
(overlay-put ov 'embark--collect-mark t)
(overlay-put ov 'face 'dired-marked)))))
(forward-button 1))

(defun embark-collect-unmark ()
"Unmark the candidate at point in a collect buffer."
(interactive)
(embark-collect-mark t))

;;;###autoload
(defun embark-collect-live (&optional initial-view)
"Create a live-updating Embark Collect buffer.
Expand Down Expand Up @@ -3321,7 +3361,7 @@ Return the category metadatum as the type of the target."
(unless selectrum--previous-input-string
(selectrum-exhibit))
(cons (selectrum--get-meta 'category)
(selectrum-get-current-candidate))))
(selectrum-get-current-candidate))))

(defun embark--selectrum-candidates ()
"Collect the current Selectrum candidates.
Expand All @@ -3331,9 +3371,9 @@ Return the category metadatum as the type of the candidates."
(unless selectrum--previous-input-string
(selectrum-exhibit))
(cons (selectrum--get-meta 'category)
(selectrum-get-current-candidates
;; Pass relative file names for dired.
minibuffer-completing-file-name))))
(selectrum-get-current-candidates
;; Pass relative file names for dired.
minibuffer-completing-file-name))))

(defun embark--selectrum-indicator ()
"Embark indicator highlighting the current Selectrum candidate."
Expand Down