- ((event-matches-key-specifier-p event 'tab)
- (save-selected-window
- (select-window (get-buffer-window "*Completions*"))
- (if (pos-visible-in-window-p (point-max))
- (goto-char (point-min))
- (scroll-up)))
+ ((or (pcomplete-event-matches-key-specifier-p event 'tab)
+ ;; Needed on a terminal
+ (pcomplete-event-matches-key-specifier-p event 9))
+ (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))))