* Re: _expand_word
@ 2000-04-25 10:26 Sven Wischnowsky
0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 2000-04-25 10:26 UTC (permalink / raw)
To: zsh-workers
Peter Stephenson wrote:
> ...
>
> Another problem is one we've met before, that things like $PATH have the
> `$' stripped before the ever get here and can't be expanded. This is highly
> counterintuitive in this case.
I'm not exactly sure anymore when I changed that so that the parameter
expansion prefix/suffix wasn't reported in IPREFIX/ISUFFIX anymore.
I've spent most of last Thursday trying to find it out, but still...
Anyway, let's try it. This makes it be stuffed into IPREFIX/ISUFFIX
again and changes _expand to allow expansion of `$foo'. It seems to
work, i.e. I couldn't find a case where it fails, maybe someone else
remembers something about this? It might have had to do with
completion in quotes-in-expansions (`${"foo<TAB>') which may then have
been changed by the last completion-in-nested-quotes patch.
Bye
Sven
Index: Completion/Core/_expand
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_expand,v
retrieving revision 1.3
diff -u -r1.3 _expand
--- Completion/Core/_expand 2000/04/20 08:04:56 1.3
+++ Completion/Core/_expand 2000/04/25 10:24:30
@@ -11,8 +11,14 @@
[[ _matcher_num -gt 1 ]] && return 1
-local exp word="$PREFIX$SUFFIX" sort expr expl subd suf=" "
+local exp word sort expr expl subd suf=" "
+if [[ "$funcstack[2]" = _prefix ]]; then
+ word="$IPREFIX$PREFIX$SUFFIX"
+else
+ word="$IPREFIX$PREFIX$SUFFIX$ISUFFIX"
+fi
+
# First, see if we should insert all *completions*.
if zstyle -s ":completion:${curcontext}:" completions expr &&
@@ -29,7 +35,7 @@
# changes quoted spaces, tabs, and newlines into spaces.
{ zstyle -s ":completion:${curcontext}:" substitute expr ||
- [[ "$curcontext" = expand-word:* ]] && expr=1 } &&
+ { [[ "$curcontext" = expand-word:* ]] && expr=1 } } &&
[[ "${(e):-\$[$expr]}" -eq 1 ]] &&
exp=( "${(e)exp//\\[
]/ }" )
@@ -43,7 +49,7 @@
# Now try globbing.
{ zstyle -s ":completion:${curcontext}:" glob expr ||
- [[ "$curcontext" = expand-word:* ]] && expr=1 } &&
+ { [[ "$curcontext" = expand-word:* ]] && expr=1 } } &&
[[ "${(e):-\$[$expr]}" -eq 1 ]] &&
exp=( ${~exp} )
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.9
diff -u -r1.9 compcore.c
--- Src/Zle/compcore.c 2000/04/17 11:17:10 1.9
+++ Src/Zle/compcore.c 2000/04/25 10:24:31
@@ -492,6 +492,8 @@
/* This calls the given completion widget function. */
+static int parwb, parwe, paroffs;
+
/**/
static void
callcompfunc(char *s, char *fn)
@@ -637,9 +639,24 @@
compsuffix = ztrdup(ss);
}
zsfree(compiprefix);
- compiprefix = ztrdup("");
zsfree(compisuffix);
- compisuffix = ztrdup("");
+ if (parwb < 0) {
+ compiprefix = ztrdup("");
+ compisuffix = ztrdup("");
+ } else {
+ int l;
+
+ compiprefix = (char *) zalloc((l = wb - parwb) + 1);
+ memcpy(compiprefix, line + parwb, l);
+ compiprefix[l] = '\0';
+ compisuffix = (char *) zalloc((l = parwe - we) + 1);
+ memcpy(compisuffix, line + we, l);
+ compisuffix[l] = '\0';
+
+ wb = parwb;
+ we = parwe;
+ offs = paroffs;
+ }
zsfree(compqiprefix);
compqiprefix = ztrdup(qipre ? qipre : "");
zsfree(compqisuffix);
@@ -829,10 +846,16 @@
makecomplist(char *s, int incmd, int lst)
{
char *p;
+ int owb = wb, owe = we, ooffs = offs;
/* Inside $... ? */
- if (compfunc && (p = check_param(s, 0, 0)))
+ if (compfunc && (p = check_param(s, 0, 0))) {
s = p;
+ parwb = owb;
+ parwe = owe;
+ paroffs = ooffs;
+ } else
+ parwb = -1;
linwhat = inwhat;
@@ -1073,7 +1096,7 @@
}
/* Save the prefix. */
if (compfunc) {
- parflags = (br >= 2 ? CMF_PARBR : 0);
+ parflags = (br >= 2 ? CMF_PARBR | (nest ? CMF_PARNEST : 0) : 0);
sav = *b;
*b = '\0';
untokenize(parpre = ztrdup(s));
Index: Src/Zle/compresult.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v
retrieving revision 1.8
diff -u -r1.8 compresult.c
--- Src/Zle/compresult.c 2000/04/17 11:17:10 1.8
+++ Src/Zle/compresult.c 2000/04/25 10:24:32
@@ -1030,8 +1030,6 @@
else if (cs > ll)
cs = ll;
inststrlen(" ", 1, 1);
- if (parpre)
- inststr(parpre);
minfo.insc = minfo.len = 0;
minfo.pos = cs;
minfo.we = 1;
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 2+ messages in thread
* _expand_word
@ 2000-04-19 13:55 Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2000-04-19 13:55 UTC (permalink / raw)
To: Zsh hackers list
I was hoping to be able to use _expand_word, bound to ^Xe, as more or less
a drop-in replacement for ^X* --- which is presumably what it should be.
However, you need to set some styles for this to work. I set
zstyle ':completion:expand-word:*' glob 1
zstyle ':completion:expand-word:*' substitute 1
zstyle ':completion:expand-word:*' original false
zstyle ':completion:expand-word:*' tag-order '!original'
(maybe I don't need substitute) and it now does pretty much what I expect;
one slight exception is that it leaves the cursor right after the expansion
with no space if there's just the one expansion. It would probably be good
if there was some way to have these set by default for expand-word without
stamping on anything supplied by the user, and without affecting the use
of _expand from the completer list.
Another problem is one we've met before, that things like $PATH have the
`$' stripped before the ever get here and can't be expanded. This is highly
counterintuitive in this case.
A more minor issue is that it would be good to have a way of listing
expansions as a replacment for ^Xg. This could easily be done with a
compdef -K at the top of _expand_word with a binding to e.g. ^Xd. I could
even do that myself.
--
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-04-25 10:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-25 10:26 _expand_word Sven Wischnowsky
-- strict thread matches above, loose matches on Subject: below --
2000-04-19 13:55 _expand_word Peter Stephenson
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).