Using the helper command last-message
from another StackExchange question, I wrote and bound an anonymous function to switch to the completion buffer if it exists, and if it doesn't exist but would be created by TAB TAB
, create that buffer. The function works as intended, except for one problem... It's really slow at displaying the new buffer when it's created. I was first running it in a Python inferior shell for testing, but it has the same behavior in M-x shell
.
The function appears to be as fast as you'd expect (basically instant). If I press C-TAB
and hit the down arrow, I immediately see the buffer. However, if I press C-TAB
and do nothing, it takes 2-3 seconds for the window to pop up.
(defun last-message (&optional num)
(or num (setq num 1))
(if (= num 0)
(current-message)
(save-excursion
(set-buffer "*Messages*")
(save-excursion
(forward-line (- 1 num))
(backward-char)
(let ((end (point)))
(forward-line 0)
(buffer-substring-no-properties (point) end))))))
(global-set-key [C-tab]
(lambda ()
(interactive)
(switch-to-completions)
(if (string= "No completions" (last-message))
(progn (completion-help-at-point)
(switch-to-completions)))))
save-excursion
s? (They only became noticeable after fixing your unhelpful indentation, BTW.)switch-to-completions
probably makes no sense and will build completions from the current buffer-string, which may explain the delay.