[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/embark e23da33f52 2/2: RET=goto when collecting a selec
From: |
ELPA Syncer |
Subject: |
[elpa] externals/embark e23da33f52 2/2: RET=goto when collecting a selection from a normal buffer |
Date: |
Tue, 26 Sep 2023 03:58:08 -0400 (EDT) |
branch: externals/embark
commit e23da33f5283c1f8648ecb9a84dcc266c0d5a964
Author: Omar Antolín <omar.antolin@gmail.com>
Commit: Omar Antolín <omar.antolin@gmail.com>
RET=goto when collecting a selection from a normal buffer
Now pressing RET on a target in an Embark collect buffer made from
a selection of targets from a regular buffer will take you to to the
location that target was collected from. This is helpful for making
ad-hoc bookmark lists.
---
CHANGELOG.org | 3 +++
embark.el | 21 +++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 99afe75792..c3441e198d 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -4,6 +4,9 @@
- =embark-bindings= and similar commands now show definition of keyboard
macros.
- =embark-org= now recognizes Org links in non-org buffers.
+- Now pressing RET in an =embark-collect= on a selection made by
+ using =embark-select= in a normal buffer will take you to the location
+ each target was collected from.
* Version 0.23 (2023-09-19)
- Added a mode line indicator showing the number of selected targets in
the current buffer (contributed by @minad, thanks!)
diff --git a/embark.el b/embark.el
index d911199501..4948b304f0 100644
--- a/embark.el
+++ b/embark.el
@@ -3044,6 +3044,7 @@ example)."
(let* ((transformed (embark--maybe-transform-candidates))
(type (plist-get transformed :orig-type)) ; we need the originals for
(candidates (plist-get transformed :orig-candidates)) ; default action
+ (bounds (plist-get transformed :bounds))
(affixator (embark-collect--affixator type))
(grouper (embark-collect--metadatum type 'group-function)))
(when (eq type 'file)
@@ -3053,12 +3054,32 @@ example)."
(let ((rel (file-relative-name cand dir)))
(if (string-prefix-p "../" rel) cand rel)))
candidates))))
+ (if (seq-some #'identity bounds)
+ (cl-loop for cand in candidates and (start . _end) in bounds
+ when start
+ do (add-text-properties
+ 0 1 `(embark--location ,(copy-marker start)) cand)))
(setq candidates (funcall affixator candidates))
(with-current-buffer buffer
(setq embark--type type)
+ (unless embark--command
+ (setq embark--command #'embark--goto))
(embark-collect--format-entries candidates grouper))
candidates))
+(defun embark--goto (target)
+ "Jump to the original location of TARGET.
+This function is used as a default action in Embark Collect
+buffers when the candidates were a selection from a regular
+buffer."
+ ;; TODO: ensure the location jumped to is visible
+ ;; TODO: remove duplication with embark-org-goto-heading
+ (when-let ((marker (get-text-property 0 'embark--location target)))
+ (pop-to-buffer (marker-buffer marker))
+ (widen)
+ (goto-char marker)
+ (pulse-momentary-highlight-one-line)))
+
(defun embark--collect (buffer-name)
"Create an Embark Collect buffer named BUFFER-NAME.