branch: externals/embark
commit 79ac772a21513681572ff5b334fc39dc2c99e409
Author: Omar Antolín <[email protected]>
Commit: Omar Antolín <[email protected]>
Fix #806
Make `embark-insert' use `minibuffer-selected-window' in a very narrow
set of cirumstances, namely, when used as a (1) quitting action (2) from the
minibuffer (3) when not in a completion session.
---
embark.el | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/embark.el b/embark.el
index 7ec8220c86..16240e5ef7 100644
--- a/embark.el
+++ b/embark.el
@@ -507,7 +507,10 @@ arguments and more details."
(insert-pair embark--mark-target)
(org-emphasize embark--mark-target)
;; do the actual work of selecting & deselecting targets
- (embark-select embark--select))
+ (embark-select embark--select)
+ ;; fix behavior of embark-insert when called as a quitting action
+ ;; from a minibuffer without a completion session (see issue #806)
+ (embark-insert embark--insert-in-minibuffer-selected-window-if-quitting))
"Alist associating commands with post-action hooks.
The hooks are run instead of the embarked upon action. The hook
can decide whether or not to run the action or it can run it
@@ -4247,7 +4250,21 @@ This simply calls RUN with the REST of its arguments
inside
"Run action with a universal prefix argument."
(setq prefix-arg '(4)))
-;;; keymaps
+(cl-defun embark--insert-in-minibuffer-selected-window-if-quitting
+ (&rest args &key quit run &allow-other-keys)
+ "Insert in `minibuffer-selected-window' if called quittingly from minibuffer.
+For use as an around action hook on `embark-insert'. When called as an
+action from the minibuffer, `embark-insert' will insert into the window
+returned by `minibuffer-selected-window' if the minibuffer is in a
+completion session, and into the minibuffer itself- if not. This is not
+useful behavior if the action will also quit the minibuffer, so this
+hook makes the minibuffer read-only in the quitting case, which causes
+`embark-insert' to insert into the window returned by
+`other-window-for-scrolling' instead."
+ (let ((buffer-read-only (or (and quit (minibufferp)) buffer-read-only)))
+ (apply run args)))
+
+;;; Keymaps
(defvar-keymap embark-meta-map
:doc "Keymap for non-action Embark functions."