Subject: bug#53367: 29.0.50; tramp-debug-buffer-command-completion-p fails in empty buffers

From: Koen van Greevenbroek <[email-masked]>
Date: Wed, 19 Jan 2022 11:27:41 +0000

Starting from `emacs -Q`:
1. Evaluate the following:
(require 'tramp)
(setq read-extended-command-predicate
      #'command-completion-default-include-p)
2. Open any empty buffer.
3. Press 'M-x TAB' to trigger a completion.

We get the following message: "read-extended-command-predicate:
tramp-setup-debug-buffer: Args out of range: #<buffer *scratch*>, 1,
10".

This is due to the following code in tramp.el:

;; This function takes action since Emacs 28.1, when
;; `read-extended-command-predicate' is set to
;; `command-completion-default-include-p'.
(defun tramp-debug-buffer-command-completion-p (_symbol buffer)
  "A predicate for Tramp interactive commands.
They are completed by \"M-x TAB\" only in Tramp debug buffers."
  (with-current-buffer buffer
    (string-equal (buffer-substring 1 10) ";; Emacs:")))

In particular, the above function assumes that the current buffer
contains 10 or more characters, which might not always be the case.

In emacs -Q, the error message is "silent" (only shown in the
*Messages*), but the message is somewhat annoyingly shown in the
completion prompt when using e.g. vertico.

Cheers,

Koen