From 69d3a6c90f9bafdc4742097d1828ed7204aa12e0 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Tue, 9 Feb 2021 09:41:13 +0000 Subject: [PATCH] Allow exit-minibuffer to be called from Lisp code. Fixes bug #46373 * lisp/minibuffer.el (exit-minibuffer): Throw the error "Not in most nested minibuffer" only when the current buffer is a minibuffer (thus the command came directly from a key binding). * doc/lispref/minibuf.texi (Minibuffer Commands): Change the documentation accordingly. --- doc/lispref/minibuf.texi | 2 +- lisp/minibuffer.el | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 185d355ba70..b60775d4575 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -2393,7 +2393,7 @@ minibuffer. @deffn Command exit-minibuffer This command exits the active minibuffer. It is normally bound to keys in minibuffer local keymaps. The command throws an error if the -current buffer is not the active minibuffer. +current buffer is a minibuffer, but not the active minibuffer. @end deffn @deffn Command self-insert-and-exit diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 03cc70c0d4d..a899a943d4c 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2116,13 +2116,15 @@ variables.") (defun exit-minibuffer () "Terminate this minibuffer argument." (interactive) + (when (or + (innermost-minibuffer-p) + (not (minibufferp))) ;; If the command that uses this has made modifications in the minibuffer, ;; we don't want them to cause deactivation of the mark in the original ;; buffer. ;; A better solution would be to make deactivate-mark buffer-local ;; (or to turn it into a list of buffers, ...), but in the mean time, ;; this should do the trick in most cases. - (when (innermost-minibuffer-p) (setq deactivate-mark nil) (throw 'exit nil)) (error "%s" "Not in most nested minibuffer")) -- 2.39.2