* _history_complete_word and history word begin with quote
@ 2015-04-03 6:16 Han Pingtian
2015-04-03 16:51 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Han Pingtian @ 2015-04-03 6:16 UTC (permalink / raw)
To: zsh-user
Hi,
Looks like if a history word begins with quote, _history_complete_word
cannot complete it?
localhost% autoload -U compinit
localhost% compinit
localhost% print hello world
hello world
localhost% print "foo bar"
foo bar
localhost% echo "foo<\e,>
I pressed <\e,> but cannot get "foo bar". There is nothing being listed
And if I tried to complete after ", then all history word being listed:
localhost% echo "<\e,>
"foo bar" print world hello print compinit -U autoload
if continue press <\e,>, then every history words get inserted there
within double-quotes:
localhost% echo ""foo bar""
"foo bar" print world hello print compinit -U autoload
How should we use _history_complete_word to complete such a word?
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: _history_complete_word and history word begin with quote
2015-04-03 6:16 _history_complete_word and history word begin with quote Han Pingtian
@ 2015-04-03 16:51 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2015-04-03 16:51 UTC (permalink / raw)
To: zsh-user
On Apr 3, 2:16pm, Han Pingtian wrote:
}
} Looks like if a history word begins with quote, _history_complete_word
} cannot complete it?
This is a more generic issue which just happens to be more easily seen
with _history_complete_word. The gist of it is that, if the word has
an quote mark to the left of the cursor, then completion does not treat
the quote as part of the word to be matched, but instead tries to append
new text to the quoted string.
This applies everywhere, not just for history words; e.g. if you type an
open quote and then press TAB to complete file names, those names will
appear after the opening quote and a closing quote will be offered if
the file is not a directory. This is meant to allow the user to choose
how a file name that contains spaces or metacharacters will be quoted in
the final command line, rather than forcing a quoting style. (It would
be a whole lot easier for the internals if we forced the quoting, and
completion did that at first years ago, but too many users griped.)
There is presently no way to turn this off or otherwise force the quote
to become part of the match target. $compstate[quote] is read-only.
The closest we could get is to run "compset -q" when then produces
completions like this:
torch% echo "\"foo bar\"
world hello print \"foo bar\" print
Or without the quote on the command line:
torch% echo
world hello print \"foo\ bar\" print
We could instead peel the quotes off the history words before offering
them as completions (diff below) but this might have unwanted side-
effects elsewhere.
diff --git a/Completion/Base/Completer/_history b/Completion/Base/Completer/_history
index 63878ac..cd69ca1 100644
--- a/Completion/Base/Completer/_history
+++ b/Completion/Base/Completer/_history
@@ -51,9 +51,14 @@ ISUFFIX=
# We skip the first element of historywords so the current word doesn't
# interfere with the completion
+local -a hslice
while [[ $compstate[nmatches] -eq 0 && beg -lt max ]]; do
+ if [[ -n $compstate[quote] ]]
+ then hslice=( ${(Q)historywords[beg,beg+slice]} )
+ else hslice=( ${historywords[beg,beg+slice]} )
+ fi
_wanted "$opt" history-words expl 'history word' \
- compadd -Q -a 'historywords[beg,beg+slice]'
+ compadd -Q -a hslice
(( beg+=slice ))
done
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-04-03 16:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-03 6:16 _history_complete_word and history word begin with quote Han Pingtian
2015-04-03 16:51 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).