Completiong for first word invoked even when cursor is before the first word

2011-05-01 Thread Ville Skyttä
Hello,

Completion functions seem to be invoked for the first word even when the
cursor is before that word.  For example:

$ foo() { echo ; echo completing; }
$ foo # hit Ctrl-A to go to beginning of line (before foo), then Tab
completing

Same thing if there's whitespace before the first word and cursor is
somewhere there in the whitespace.  Is this on purpose?

I find that behavior unexpected and I suppose this is a case that is
awkward to handle in completion functions and I'm not aware of any
functions "out there" that would handle it.  I'd expect either the empty
completion or no completions at all in that case.



Re: bug on [A-Z] and [a-z]

2011-05-01 Thread Jonathan Nieder
Hi,

ri...@inf.ufpr.br wrote:

>   When  running "echo [A-Z]*" , it shows all files/dirs of current
> directory, not only those starting with capital letters. I tried
> different locales such as: POSIX, C, en_US, pt_BR
>
> Repeat-By:
> $ mkdir a && cd a
> $ touch a b c; mkdir D E F
> $ echo [A-Z]*
> b c D E F
> $ echo [a-z]*
> a b c D E F

See http://bugs.debian.org/301717 (“fnmatch("[a-z]", ...) matches
capital letters in most locales”) for some details.

I'm puzzled by your comment on trying different locales, though:
I tried

mkdir a && cd a
touch a b c; mkdir D E F
echo [A-Z]*

and got output

b c D E F

as expected.  Then I tried

LANG=C
export LANG
echo [A-Z]*

and got output

D E F

Does your experience differ?  I'm using 4.1.5(1)-release fwiw.

> No Fix yet, looking on the source code.

In the long run, a good fix might be to teach fnmatch a new
FNM_STRICTCASE flag and optionally use it.  The hardest part would
seem to be making tables so the system can know what "this range,
using the same case" means.  If you'd like to work on this, please
feel free to coordinate using the aforementioned libc bug report (and
cc-ing me).

A separate aspect is documentation.  I imagine Chet wouldn't mind
a patch to bash.1 and bash.info to explain this pitfall under
"Pattern Matching" or even under "BUGS" (aka LIMITATIONS).

Hope that helps,
Jonathan