Skip to content

Commit

Permalink
Pop to target buffer for default action
Browse files Browse the repository at this point in the history
Previously popping to the target buffer was done for all actions if
the originating command was imenu, or if the completion category was
line (this was for consult-line and consult-outline).

But thinking about it some more, I believe it should always be done
for the default action, but never for the other actions (unless they
want do it themselves; embark-insert is almost an example: it inserts
in the target buffer, but doesn't pop there---maybe it should!).

With this change, embark-occur should work better for
consult-{line,outline,mark}, with out any special-casing anymore!

It's also fun now to use embark-occur on M-x, and try out a bunch of
commands in the buffer you started with. :)
  • Loading branch information
oantolin committed Dec 8, 2020
1 parent 5b14e93 commit 2d6fa05
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions embark.el
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,9 @@ If you are using `embark-completing-read' as your
(goto-char entry) ;; pretend RET was pressed even if
(setq last-nonmenu-event 13) ;; mouse was clicked, to fool imenu
(embark--setup-action)
(let ((ecmd embark--command))
(pop-to-buffer embark--target-buffer)
(setq embark--command ecmd))
(run-hooks 'embark-pre-action-hook)
(embark-default-action)
(run-hooks 'embark-post-action-hook)))
Expand Down Expand Up @@ -1349,12 +1352,6 @@ with key \"Embark Live Occur\"."
nil t)
(setq minibuffer-scroll-window occur-window)))))

(defun embark--pop-to-target-buffer ()
"Pop to Embark target buffer."
(let ((ecmd embark--command))
(pop-to-buffer embark--target-buffer)
(setq embark--command ecmd)))

(defun embark-occur (&optional initial-view)
"Create an Embark Occur buffer and exit all minibuffers.
Optionally start in INITIAL-VIEW (either `list' or `grid')
Expand All @@ -1374,11 +1371,7 @@ with key \"Embark Occur\"."
(setq embark-occur-candidates candidates)
(setq embark-occur-annotator annotator)
(when (minibufferp embark-occur-from)
(setq embark-occur-from nil))
(when (or (eq embark--command 'imenu) (eq embark--type 'line))
(add-hook 'embark-pre-action-hook
#'embark--pop-to-target-buffer
nil t)))
(setq embark-occur-from nil)))
(embark-after-exit ()
(select-window
(embark-occur--display occur-buffer))))
Expand Down

0 comments on commit 2d6fa05

Please sign in to comment.