[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/embark c5a9167320 01/30: Initial implementation of acti
From: |
ELPA Syncer |
Subject: |
[elpa] externals/embark c5a9167320 01/30: Initial implementation of acting on selections of targets |
Date: |
Thu, 20 Apr 2023 10:58:20 -0400 (EDT) |
branch: externals/embark
commit c5a916732053db0c70a5151e0b5dd03f4b5c4978
Author: Omar Antolín Camarena <omar.antolin@gmail.com>
Commit: Omar Antolín Camarena <omar.antolin@gmail.com>
Initial implementation of acting on selections of targets
---
embark.el | 141 +++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 75 insertions(+), 66 deletions(-)
diff --git a/embark.el b/embark.el
index 1bdbba561e..490346dce6 100644
--- a/embark.el
+++ b/embark.el
@@ -447,7 +447,9 @@ arguments and more details."
:value-type hook))
(defcustom embark-around-action-hooks
- '(;; use directory of target as default-directory
+ '(;; do the actual work of selecting & deselecting targets
+ (embark-toggle-select embark--toggle-select)
+ ;; use directory of target as default-directory
(shell embark--cd)
(eshell embark--cd)
;; narrow to target for duration of action
@@ -2266,6 +2268,7 @@ ARG is the prefix argument."
(or (cl-mapcar
(lambda (cand orig-cand)
(list :type type :target cand
+ :bounds (get-text-property 0 'embark-bounds orig-cand)
:orig-type orig-type :orig-target orig-cand))
(plist-get transformed :candidates)
(plist-get transformed :orig-candidates))
@@ -2464,7 +2467,8 @@ Remember to make `embark-general-map' the parent if
appropriate"))
:group 'embark)
(defcustom embark-candidate-collectors
- '(embark-minibuffer-candidates
+ '(embark-selected-candidates
+ embark-minibuffer-candidates
embark-completions-buffer-candidates
embark-dired-candidates
embark-ibuffer-candidates
@@ -2529,9 +2533,6 @@ default is `embark-collect'"
"Face for annotations in Embark Collect.
This is only used for annotation that are not already fontified.")
-(defface embark-collect-marked '((t (:inherit warning)))
- "Face for marked candidates in an Embark Collect buffer.")
-
(defvar-local embark--rerun-function nil
"Function to rerun the collect or export that made the current buffer.")
@@ -2624,16 +2625,7 @@ all buffers."
This makes `embark-export' work in Embark Collect buffers."
(when (derived-mode-p 'embark-collect-mode)
(cons embark--type
- (or (save-excursion
- (mapcar (lambda (ov)
- (goto-char (overlay-start ov))
- (cadr (embark-target-collect-candidate)))
- (nreverse
- (seq-filter
- (lambda (ov)
- (eq (overlay-get ov 'face) 'embark-collect-marked))
- (overlays-in (point-min) (point-max))))))
- (delq nil (mapcar #'car tabulated-list-entries))))))
+ (delq nil (mapcar #'car tabulated-list-entries)))))
(defun embark-completions-buffer-candidates ()
"Return all candidates in a completions buffer."
@@ -2775,10 +2767,7 @@ If NESTED is non-nil subkeymaps are not flattened."
"A" #'embark-act-all
"M-a" #'embark-collect-direct-action-minor-mode
"E" #'embark-export
- "t" #'embark-collect-toggle-marks
- "m" #'embark-collect-mark
- "u" #'embark-collect-unmark
- "U" #'embark-collect-unmark-all
+ ;; marks t m u U
"s" #'isearch-forward
"n" #'forward-button
"p" #'backward-button
@@ -2833,52 +2822,6 @@ For non-minibuffers, assume candidates are of given
TYPE."
(if-let (a (funcall annotator c)) (list c "" a) c))
candidates)))))
-(defun embark-collect--marked-p (&optional location)
- "Is the candidate at LOCATION marked?
-LOCATION defaults to point."
- (seq-find (lambda (ov) (eq (overlay-get ov 'face) 'embark-collect-marked))
- (overlays-at (or location (point)))))
-
-(defun embark-collect-mark (&optional unmark)
- "Mark the candidate at point in an Embark collect buffer.
-If called from Lisp with a non-nil UNMARK, instead unmark the
-candidate."
- (interactive)
- (unless (derived-mode-p 'embark-collect-mode)
- (user-error "Not in an Embark Collect mode buffer"))
- (pcase (embark-target-collect-candidate)
- (`(,_type ,_cand ,start . ,end)
- (if-let ((ov (embark-collect--marked-p)))
- (when unmark (delete-overlay ov))
- (unless unmark
- (overlay-put (make-overlay start end)
- 'face 'embark-collect-marked)))
- (forward-button 1 nil nil t))
- ('nil (user-error "No candidate at point"))))
-
-(defun embark-collect-unmark ()
- "Unmark the candidate at point in an Embark collect buffer."
- (interactive)
- (embark-collect-mark t))
-
-(defun embark-collect-unmark-all ()
- "Unmark all marked candidates in an Embark Collect buffer."
- (interactive)
- (unless (derived-mode-p 'embark-collect-mode)
- (user-error "Not in an Embark Collect mode buffer"))
- (dolist (ov (overlays-in (point-min) (point-max)))
- (when (eq (overlay-get ov 'face) 'embark-collect-marked)
- (delete-overlay ov))))
-
-(defun embark-collect-toggle-marks ()
- "Toggle each mark: marked candidates become unmarked, and vice versa."
- (interactive)
- (unless (derived-mode-p 'embark-collect-mode)
- (user-error "Not in an Embark Collect mode buffer"))
- (save-excursion
- (goto-char (point-min))
- (while (embark-collect-mark (embark-collect--marked-p)))))
-
(defun embark--for-display (string)
"Return visibly equivalent STRING without display and invisible properties."
(let ((len (length string)) (pos 0) chunks)
@@ -3251,6 +3194,70 @@ PRED is a predicate function used to filter the items."
bookmark-alist)))
(bookmark-bmenu-list))))
+;;; Multiple target selection
+
+(defface embark-selected '((t (:inherit dired-marked)))
+ "Face for selected candidates.")
+
+(defvar-local embark--selection nil)
+
+(defun embark--report-selection ()
+ (message "%d targets selected." (length embark--selection)))
+
+(cl-defun embark--toggle-select (&key target type bounds &allow-other-keys)
+ "Add or remove TARGET of given TYPE to the selection.
+If BOUNDS are given, also highlight the target when selecting it."
+ (if-let ((existing
+ (seq-some
+ (lambda (cand)
+ (and (equal cand target)
+ (eq (car (get-text-property 0 'multi-category cand)) type)
+ (equal (get-text-property 0 'embark-bounds cand) bounds)
+ cand))
+ embark--selection)))
+ (progn
+ (setq embark--selection (delq existing embark--selection))
+ (when-let ((overlay (get-text-property 0 'embark-overlay existing)))
+ (delete-overlay overlay)))
+ (let ((full-target (concat target)) overlay)
+ (when bounds
+ (setq overlay (make-overlay (car bounds) (cdr bounds)))
+ (overlay-put overlay 'face 'embark-selected)
+ (overlay-put overlay 'priority 1001)
+ (add-text-properties 0 (length target)
+ `(embark-bounds ,bounds)
+ full-target))
+ (add-text-properties 0 (length target)
+ `(multi-category ,(cons type target)
+ embark-bounds ,bounds
+ embark-overlay ,overlay)
+ full-target)
+ (push full-target embark--selection)))
+ (embark--report-selection))
+
+(defalias 'embark-toggle-select #'ignore
+ "Add or remove the target from the current buffer's selection.
+You can act on all selected targets at once with `embark-act-all'.")
+
+(defun embark-deselect-all ()
+ "Deselect all selected targets in the buffer."
+ (interactive)
+ (dolist (target embark--selection)
+ (when-let ((overlay (get-text-property 0 'embark-overlay target)))
+ (delete-overlay overlay)))
+ (setq embark--selection nil)
+ (embark--report-selection))
+
+(defun embark-collect-toggle-selection ()
+ "Toggle selection: selected candidates become deselected, and vice versa."
+ (interactive)
+ (error "Not implemented yet"))
+
+(defun embark-selected-candidates ()
+ "Return currently selected candidates in the buffer."
+ (when embark--selection
+ (cons 'multi-category embark--selection)))
+
;;; Integration with external packages, mostly completion UIs
;; marginalia
@@ -3891,7 +3898,9 @@ This simply calls RUN with the REST of its arguments
inside
"A" #'embark-act-all
"C-s" #'embark-isearch
"SPC" #'mark
- "DEL" #'delete-region)
+ "DEL" #'delete-region
+ "y" #'embark-toggle-select
+ "Y" #'embark-deselect-all)
(defvar-keymap embark-encode-map
:doc "Keymap for Embark region encoding actions."
- [elpa] externals/embark 6362c369bf 04/30: Enable multiple selection in Embark Collect buffers, (continued)
- [elpa] externals/embark 6362c369bf 04/30: Enable multiple selection in Embark Collect buffers, ELPA Syncer, 2023/04/20
- [elpa] externals/embark b7550f84d7 09/30: When deciding if a candidate is selected compare original targets, ELPA Syncer, 2023/04/20
- [elpa] externals/embark 2a5edf3cb8 12/30: Document selection, ELPA Syncer, 2023/04/20
- [elpa] externals/embark 729f944a3b 17/30: Avoid long line, ELPA Syncer, 2023/04/20
- [elpa] externals/embark 868d799753 28/30: Change other binding of whitespace-cleanup-region too, ELPA Syncer, 2023/04/20
- [elpa] externals/embark c9954e94f9 16/30: Revert "Do preemptive refinement of selection targets", ELPA Syncer, 2023/04/20
- [elpa] externals/embark edba98ce5c 22/30: Remove C-. C-u SPC in favor of C-. A SPC, ELPA Syncer, 2023/04/20
- [elpa] externals/embark cce4c3b86e 24/30: Allow candidate collectors to include bounds, ELPA Syncer, 2023/04/20
- [elpa] externals/embark ccb8b15edf 25/30: Document new selection functionality for collect buffers, ELPA Syncer, 2023/04/20
- [elpa] externals/embark e7d891a8b2 30/30: Bump version for new selection feature, ELPA Syncer, 2023/04/20
- [elpa] externals/embark c5a9167320 01/30: Initial implementation of acting on selections of targets,
ELPA Syncer <=
- [elpa] externals/embark 2b2e62af00 08/30: Better selection highlight code for Vertico, ELPA Syncer, 2023/04/20
- [elpa] externals/embark 143208cddb 15/30: Make the text property embark-selection private, ELPA Syncer, 2023/04/20
- [elpa] externals/embark 0ad1b4069e 10/30: Fix bug when collecting the selection from the minibuffer, ELPA Syncer, 2023/04/20
- [elpa] externals/embark 55db7435eb 18/30: Fix bug with default action in collected selection, ELPA Syncer, 2023/04/20
- [elpa] externals/embark 83704d8cb9 19/30: A bit of clean up, ELPA Syncer, 2023/04/20
- [elpa] externals/embark aa88649674 20/30: Remove tiny function only used once, ELPA Syncer, 2023/04/20
- [elpa] externals/embark d1f15708c3 27/30: Make embark--toggle-select a pre-action hook, ELPA Syncer, 2023/04/20
- [elpa] externals/embark bbc0f1edc2 13/30: Do preemptive refinement of selection targets, ELPA Syncer, 2023/04/20
- [elpa] externals/embark 85bd2fc7e8 26/30: Document some examples of using selections, ELPA Syncer, 2023/04/20
- [elpa] externals/embark 02b9e3c718 29/30: Start a changelog (finally), ELPA Syncer, 2023/04/20