From cf52ad5812bb3c5796ee75f388e099151af27d04 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Thu, 5 May 1994 05:27:59 +0000 Subject: [PATCH] (choose-completion-string): Barf if completing into a minibuffer but it's not now active. --- lisp/simple.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 69df7fa5eeb..7ebdbf033eb 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2461,14 +2461,22 @@ it were the arg to `interactive' (which see) to interactively read the value." (defun choose-completion-string (choice &optional buffer) (let ((buffer (or buffer completion-reference-buffer))) - (set-buffer buffer) - (choose-completion-delete-max-match choice) - (insert choice) - ;; Update point in the window that BUFFER is showing in. - (let ((window (get-buffer-window buffer t))) - (set-window-point window (point))) - (and (equal buffer (window-buffer (minibuffer-window))) - (minibuffer-complete-and-exit)))) + ;; If BUFFER is a minibuffer, barf unless it's the currently + ;; active minibuffer. + (if (and (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer)) + (or (not (minibuffer-window-active-p (minibuffer-window))) + (not (equal buffer (window-buffer (minibuffer-window)))))) + (error "Minibuffer is not active for completion") + ;; Insert the completion into the buffer where completion was requested. + (set-buffer buffer) + (choose-completion-delete-max-match choice) + (insert choice) + ;; Update point in the window that BUFFER is showing in. + (let ((window (get-buffer-window buffer t))) + (set-window-point window (point))) + ;; If completing for the minibuffer, exit it with this choice. + (and (equal buffer (window-buffer (minibuffer-window))) + (minibuffer-complete-and-exit))))) (defun completion-list-mode () "Major mode for buffers showing lists of possible completions. -- 2.39.5