Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: completion oddity
On May 21, 2:40pm, Danek Duvall wrote:
}
} _k () { _arguments --r1-word --really-r1-word }
}
} then the second tab simply completes --r1-word, which seems wrong to me.
It's the hyphens.
Completion works on words. When you have a compound word joined with
hyphens, it tries to split it up and complete the individual components.
In cases where this is ambiguous, it fills in any word fragments that
are common to all the possible choices and leaves the cursor at the
first ambiguous location. (Most of this can be changed with zstyle,
for the predefined completion set.)
With --r-word on the line, there is only one possible completion that
has exactly one embedded hyphen. This is considered a unique match, so
when you press TAB, it fills in that word and is done. If that isn't
what you want, it's up to you to type (in this example) one of "e" or
"-" at the point where the cursor was left, to disambiguate the choice
before attempting completion again.
Keep in mind that completion is designed to minimize keystrokes, not
to minimize the number of different keys pressed. Thus TAB e TAB is
considered "just as good" as TAB TAB TAB in terms of saving effort.
This isn't directly expressed in the code, but it's the philosophy
behind disambiguating the match as far as possible before stopping,
because if --r1-word is what you wanted then you save one keystroke,
and if it was not there's no extra cost.
If you want to treat the hyphenated strings as single words rather
than as compound words, then you have to do something not entirely
obvious, which is to override the default "matcher" used when creating
the internal representation of the _arguments specifications. You do
this like so:
_k () { _arguments -M '' --r1-word --really-r1-word }
The empty string there turns off matching. You might want something
else, see "Completion Matching Control" in the manual. What I can't
find documented anywhere is the default of "r:|[_-]=* r:|=*" which is
part of the (entirely undocumented) internals of the comparguments
builtin.
--
Barton E. Schaefer
Messages sorted by:
Reverse Date,
Date,
Thread,
Author