[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC] support 'COMP_WORDBREAKS' value on a per-completion basis
From: |
Raphaël Droz |
Subject: |
[RFC] support 'COMP_WORDBREAKS' value on a per-completion basis |
Date: |
Mon, 30 May 2011 20:05:47 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
It seems like if gnu.bash.bug@googlegroups.com eat the first occurrence
of this email (not in the mailman archives)... second attempt:
=== Rationale:
Let's say you want to complete http URL (which contain ':').
The completion probably contains this kind of statement:
_comp() {
COMPREPLY=( $(compgen -W "http://foo http://bar" -- "$cur") )
}
After the completion function is evaluated, readline will consider
the value of $COMP_WORDBREAKS to split the word to complete...
If the current argument is 'http://', then:
- if $COMP_WORDBREAKS contains ':' , only '//' will be used by the
completion process.
- otherwise (and if ' ' (space) is part of $COMP_WORDBREAKS), the
whole 'http://' string will be used.
The problem is that this evaluation happens after the completion function
has returned (and won't work before $COMP_WORDBREAKS has really been
modified to match our needs):
The FAQ says:
E13) Why does filename completion misbehave if a colon appears in the filename?
and the workaround proposed, ie:
_comp() {
export COMP_WORDBREAKS="${COMP_WORDBREAKS//:/}"
COMPREPLY=( $(compgen -W "http://foo http://bar" -- "$cur") )
}
... has mainly two drawbacks:
1) the completion has to alter the user environment
$ comp http://<TAB>
$ echo $COMP_WORDBREAKS
"'><=;|&( ### ':' has disappeared, other completion functions
### may suffer from this
2) the first time we try a completion, _comp() has not yet been executed
so our modified $COMP_WORDBREAKS isn't yet part of the context.
$ comp http://<TAB>
completes (the first time) to
$ comp http:http://
but after that, $COMP_WORDBREAKS is modified so the next calls will succeed.
=== the proposed patch is in 3 parts (also attached):
https://gitorious.org/drzraf/bash/commit/0994f18671dc9c080b01af9c6005a19c7edac17c
Adds a char *word_breaks to the COMPSPEC struct
https://gitorious.org/drzraf/bash/commit/123ba1c50078c0857c489809132cc39ab59d7636
Support of a -B <COMP_WORDBREAKS> flag to the complete builtin
https://gitorious.org/drzraf/bash/commit/be1ff9edf02d7a28b1a4d18d8e996ef4ba56c490
registers readline 'rl_completion_word_break_hook' and makes the bash
hook returning the value of the complete -B <flag> if it was
specified during the call to the 'complete' builtin.
===
If the rationale of this patch is accepted, I would be happy to discuss
the possibility to implement it at the 'compopt' level (what I was so far
unable to do) in order to change dynamically word bounds *during* the
completion process.
Raph
0001-added-char-word_breaks-to-the-COMPSPEC-struct.patch
Description: Text Data
0002-added-support-of-the-B-COMP_WORDBREAKS-flag-to-the-c.patch
Description: Text Data
0003-Registered-readline-rl_completion_word_break_hook-in.patch
Description: Text Data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [RFC] support 'COMP_WORDBREAKS' value on a per-completion basis,
Raphaël Droz <=