[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: TAB completions in *shell*: why need one character hint?
From: |
Colin Walters |
Subject: |
Re: TAB completions in *shell*: why need one character hint? |
Date: |
23 Feb 2001 11:26:32 -0500 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.96 |
jidanni@kimo.FiXcomTHiS.tw (Dan Jacobson) writes:
> Do:
> ESC x s h e l l RET c a t SPC TAB TAB TAB
> Why can't it show me filename choices at this point? Why does it
> insist that I give it at least one character to start with? Bash
> wouldn't treat me this way.
That's because the function `shell-dynamic-complete-command' declines
to expand on the empty string, to give the other completion functions
a chance. See below for more information.
> If it's so smart that it knows the first item is a command, and the
> second is a filename, one would think that it could expand with no
> need for me to give it a one letter hint. I mean the directory I
> was in only had a few files in it.
>
> By the way, doing C-h k TAB shows
>
> TAB runs the command comint-dynamic-complete
> which is an interactive compiled Lisp function in `comint'.
> (comint-dynamic-complete)
>
> Dynamically perform completion at point.
> Calls the functions in `comint-dynamic-complete-functions' to perform
> completion until a function returns non-nil, at which point completion is
> assumed to have occurred.
>
> That's no way to talk to a user. You want to at least mention
> things like "if used at the first item after the [shell] prompt,
> expands command names, otherwise expands filenames. Just like bash."
That's because this function simply runs other functions, as its
docstring says. If you type
'C-h v comint-dynamic-complete-functions RET', you will see a list of
these functions.
The machinery behind this is a lot more powerful than Bash could be,
and it's designed to be customizable. For example, let's write a
simple function which will attempt to complete recently used command
line arguments.
(defun cw/comint-dynamic-complete-argument ()
(interactive)
(let* ((origpoint (point))
(newpoint (progn
(skip-syntax-backward "w")
(skip-chars-backward "-")
(point)))
(maybe-arg (buffer-substring origpoint newpoint)))
(if (and (<= (length maybe-arg) 10)
(eql (char-after (point))
?-)
(search-backward maybe-arg 500 t))
(let ((argument (buffer-substring (point)
(progn (skip-chars-forward "-")
(skip-syntax-forward "w")
(point)))))
(goto-char newpoint)
(delete-region newpoint origpoint)
(insert argument)
t)
(progn
(goto-char origpoint)
nil))))
It doesn't offer choices between completions or anything, which I
might add later, but I hope you see why the docstring for
`comint-dynamic-complete' is written the way it is.
Note I don't speak for the Emacs maintainers, I just think that a lot
of your bug reports are actually questions, and I like to help out.
(Of course, questions would be better posted to gnu.emacs.help...)