branch: externals/embark commit e476ca781a7782540c076262d64ea435728af78e Author: Omar Antolín <omar.anto...@gmail.com> Commit: Omar Antolín <omar.anto...@gmail.com>
Add "obey/disobey embark-quit-after-action" message Whether or not an action will quit the minibuffer is the xor of three boolean values: - Whether there was a prefix argument. - Whether the user pressed q an odd number of times. - What (alist-get action embark-quit-after-action) says. We cannot know the last one until the user selects the action, of course, but the other two are known before then. So after the prefix argument and after each press of q we can tell the user whether we will obey or disobey embark-quit-after-action. --- embark.el | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/embark.el b/embark.el index ee61b9937e..695e5ada95 100644 --- a/embark.el +++ b/embark.el @@ -1990,15 +1990,13 @@ keymap for the given type." :target (plist-get target :orig-target)) :type (plist-get target :orig-type))) -(defun embark--quit-p (action &optional negate) +(defun embark--quit-p (action) "Determine whether to quit the minibuffer after ACTION. This function consults `embark-quit-after-action' to decide whether or not the user wishes to quit the minibuffer after -performing the ACTION, assuming this is done from a minibuffer. -If NEGATE is non-nil, return the opposite value." +performing the ACTION, assuming this is done from a minibuffer." (let* ((cfg embark-quit-after-action) (quit (if (consp cfg) (alist-get action cfg (alist-get t cfg)) cfg))) - (when negate (setq quit (not quit))) ; Emacs 27.1 has an xor function... (when embark--toggle-quit (setq quit (not quit))) (setq embark--toggle-quit nil) quit)) @@ -2031,8 +2029,10 @@ target." (let* ((targets (or (embark--targets) (user-error "No target found"))) (indicators (mapcar #'funcall embark-indicators)) (default-done nil)) - (when (and arg (not (minibufferp))) - (setq targets (embark--rotate targets (prefix-numeric-value arg)))) + (when arg + (if (minibufferp) + (embark-toggle-quit) + (setq targets (embark--rotate targets (prefix-numeric-value arg))))) (unwind-protect (while (let* ((target (car targets)) @@ -2070,7 +2070,7 @@ target." (eq action embark--command)) (embark--orig-target target) target) - (embark--quit-p action arg)) + (embark--quit-p action)) (user-error (funcall (if repeat #'message #'user-error) "%s" (cadr err)))) @@ -2154,6 +2154,7 @@ ARG is the prefix argument." (plist-get transformed :orig-candidates)) (user-error "No candidates to act on"))) (indicators (mapcar #'funcall embark-indicators))) + (when arg (embark-toggle-quit)) (unwind-protect (let* ((action (or (embark--prompt @@ -2166,7 +2167,7 @@ ARG is the prefix argument." ((symbol-function 'embark--confirm) #'ignore)) (let ((prefix-arg prefix)) (embark--act action candidate))))) - (quit (embark--quit-p action arg))) + (quit (embark--quit-p action))) (when (and (eq action (embark--default-action type)) (eq action embark--command)) (setq candidates (mapcar #'embark--orig-target candidates))) @@ -2258,11 +2259,12 @@ See `embark-act' for the meaning of the prefix ARG." targets))) (default-action (embark--default-action (plist-get target :type))) (action (or (command-remapping default-action) default-action))) + (when (and arg (minibufferp)) (setq embark--toggle-quit t)) (embark--act action (if (eq default-action embark--command) (embark--orig-target target) target) - (embark--quit-p action arg))) + (embark--quit-p action))) (user-error "No target found"))) (defun embark--become-keymap () @@ -3256,7 +3258,8 @@ Return the category metadatum as the type of the target." (interactive) (when (minibufferp) (setq embark--toggle-quit (not embark--toggle-quit)) - (message "Quitting toggled."))) + (message "Will %sobey embark-quit-after-action." + (if embark--toggle-quit "dis" "")))) (defun embark-insert (string &optional multiline) "Insert STRING at point.