diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index 6caffddaa01..c4840059f64 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -974,18 +974,20 @@ Typing SPC flushes the help buffer." (while (with-current-buffer (get-buffer "*Completions*") (setq event (pcomplete-read-event))) (cond - ((event-matches-key-specifier-p event ? ) + ((event-matches-key-specifier-p event ?\s) (set-window-configuration pcomplete-last-window-config) (setq pcomplete-last-window-config nil) (throw 'done nil)) ((or (event-matches-key-specifier-p event 'tab) ;; Needed on a terminal (event-matches-key-specifier-p event 9)) - (save-selected-window - (select-window (get-buffer-window "*Completions*" t)) - (if (pos-visible-in-window-p (point-max)) - (goto-char (point-min)) - (scroll-up))) + (let ((win (or (get-buffer-window "*Completions*" 0) + (display-buffer "*Completions*" + 'not-this-window)))) + (with-selected-window win + (if (pos-visible-in-window-p (point-max)) + (goto-char (point-min)) + (scroll-up)))) (message "")) (t (setq unread-command-events (list event))