zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: completion for perl
@ 2000-03-12 13:28 Adam Spiers
  0 siblings, 0 replies; 4+ messages in thread
From: Adam Spiers @ 2000-03-12 13:28 UTC (permalink / raw)
  To: zsh workers mailing list

Here's completion code for perl, and a few clean-ups to _perl_modules.
If anyone would be kind enough to tarball their latest working copy,
I'll be able to submit some more stuff (I guess I should also be
submitting a .yo patch for this new style, for example), but I'm
currently a bit helpless without CVS :-(

Whilst struggling with the mess which is _perl_config_vars below, it
struck me how an equivalent of compset -P which matched the /whole/ of
PREFIX rather than just the beginning would have come in handy.  Is
this worthwhile, Sven, or is my whole approach coming from the wrong
angle?  Also, as you can see from the compstate[quoting] line below, I
tried to get completion working for

  $ perl -V:'<TAB>

and

  $ perl -V:"<TAB>

so that it would insert a single space after each configuration
variable completed while within quotes, rather than a quoted single
space, but I didn't fully understand how compset -q works, and
couldn't stop it from eating up the opening quote.  Help! :-)

Adam


Index: Completion/User/_perl_modules
===================================================================
--- Completion/User/_perl_modules	Tue Nov 16 16:58:15 1999
+++ Completion/User/_perl_modules	Sun Mar 12 11:59:32 2000
@@ -7,16 +7,22 @@
 # Calculate all installed Perl modules.  The result is cached
 # for future use.
 #
+# Available styles:
+#
+# * try-to-use-pminst
+#
+#   Set this if you have pminst and want to use it.  The zsh code
+#   actually produces better results because pminst misses modules of
+#   the form Foo/bar/Baz.pm through its clumsy -d && /^[A-Z]/ && prune
+#   algorithm (the zsh code does almost the same, but only misses
+#   modules which don't begin with an uppercase letter).
 
-# Change this if you have pminst and want to use it.  The zsh code
-# actually produces better results because pminst misses modules of
-# the form Foo/bar/Baz.pm through its clumsy -d && /^[A-Z]/ && prune
-# algorithm (the zsh code does almost the same, but only misses modules
-# which don't begin with an uppercase letter).
-local try_to_use_pminst=0
+local opts
+zparseopts -D -a opts S: q
 
 if [[ ${+_perl_modules} -eq 0 ]]; then
-  if [[ $try_to_use_pminst -ne 0 ]] && which pminst >/dev/null; then
+  if zstyle -t ":completion:${curcontext}:modules" try-to-use-pminst \
+     && which pminst >/dev/null; then
     _perl_modules=( $(pminst) )
   else
     local inc libdir new_pms
@@ -43,4 +49,4 @@
 
 local expl
 
-_wanted modules expl 'Perl modules' && compadd "$expl[@]" - $_perl_modules
+_wanted modules expl 'Perl modules' && compadd "$expl[@]" "$opts[@]" - $_perl_modules
Index: Completion/User/_perl
===================================================================
--- /dev/null	Tue May  5 21:32:27 1998
+++ Completion/User/_perl	Sun Mar 12 13:13:49 2000
@@ -0,0 +1,65 @@
+#compdef perl
+#
+# zsh completion code for the Perl interpreter
+# Adam Spiers <adam@spiers.net>
+#
+
+_perl () {
+  _arguments -s \
+    '-0-:input record separator in octal (\0, if no argument): ' \
+    '-a[autosplit mode with -n or -p (splits $_ into @F)]' \
+    "-c[check syntax only (runs BEGIN and END blocks)]" \
+    '-d[run scripts under debugger]' \
+    '-d\:-[run under control of a debugging/tracing module]:debugging/tracing module:_perl_modules' \
+    '-D-:set debugging flags (argument is a bit mask or flags): ' \
+    "-e+:one line of script. Several -e's allowed. Omit [programfile]." \
+    "-F-:split() pattern for autosplit (-a). The //'s are optional.: " \
+    '-h[list help summary]' \
+    '-i-[edit <> files in place (make backup if extension supplied)]:backup file extension: ' \
+    '-I-[specify @INC/#include directory (may be used more than once)]:include path:_files -/' \
+    '-l-[enable line ending processing, specifies line terminator]:output record separator in octal: ' \
+    {-m,-M}"-[module.. executes \`use/no module...' before executing your script.]:module:_perl_m_opt" \
+    "-n[assume 'while (<>) { ... }' loop around your script]" \
+    "-p[assume loop like -n but print line also like sed]" \
+    "-P[run script through C preprocessor before compilation]" \
+    "-s[enable some switch parsing for switches after script name]" \
+    "-S[look for the script using PATH environment variable]" \
+    "-T[turn on tainting checks]" \
+    "-u[dump core after parsing script]" \
+    "-U[allow unsafe operations]" \
+    "-v[print version number, patchlevel plus VERY IMPORTANT perl info]" \
+    "-V-[print perl configuration information]:configuration keys:_perl_config_vars" \
+    '-w[TURN WARNINGS ON FOR COMPILATION OF YOUR SCRIPT. Recommended.]' \
+    '-x-[strip off text before #!perl line and perhaps cd to directory]:directory to cd to:_files -/' \
+    ':Perl script:_files -g \*.pl'
+}
+
+_perl_m_opt () {
+  compset -P '-'
+
+  if compset -P '*='; then
+    _message 'module arguments, comma separated'
+  else
+    _perl_modules -S= -q
+  fi
+}
+
+_perl_config_vars () {
+  if (( ! $+_perl_config_vars )); then
+    # perl | perl ... nasty, but is there another way?
+    _perl_config_vars=( $(perl -V |
+			    perl -ne 'push @m, (/(\w+)(?==)/g);' \
+			         -e  'END {print join "\n", @m}' ) )
+  fi
+
+  local add_colon='-P:'
+  compset -P '*:' && add_colon=''
+
+  local delimiter='\ '
+  (( compstate[quoting] )) && delimiter=' '
+
+  compset -P '* ' && compset -q
+  compadd "$expl[@]" $add_colon -S$delimiter -q - $_perl_config_vars
+}
+
+_perl "$@"


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: completion for perl
@ 2000-03-14  8:12 Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2000-03-14  8:12 UTC (permalink / raw)
  To: zsh-workers


Adam Spiers wrote:

> Sven Wischnowsky (wischnow@informatik.hu-berlin.de) wrote:
> > 
> > Adam Spiers wrote:
> > 
> > > Whilst struggling with the mess which is _perl_config_vars below, it
> > > struck me how an equivalent of compset -P which matched the /whole/ of
> > > PREFIX rather than just the beginning would have come in handy. 
> > 
> > Err... `compset -P "*"' does that, but it leaves you with an empty
> > $PREFIX, of course, which is probably not what one wants.
> 
> Sorry; I didn't explain myself clearly at all.  I would like to be
> able to do a compset -P type of operation using a pattern which is
> anchored to both the start /and/ end of PREFIX, rather than just the
> start, which is what currently always happens.  Then again, I suppose
> this can be implemented easily manually, e.g.:
> 
>   if [[ "$PREFIX" == *: ]]; then
>     IPREFIX="$IPREFIX$PREFIX"
>     PREFIX=''
>   fi

Yep.

> ...
> > 
> > The problem is that we check the quoting stuff at the very beginning
> > of the completion code -- and detect only quotes at the beginning of
> > the word. So what we could get to work is completion of
> > 
> >   $ perl '-V:<TAB>
> > 
> > but not with the quote after the colon. That's done with first calling 
> > `compset -q', then the `compset -P'. Getting quotes in words to work
> > is to hard to make me try it (all kinds of nasty interactions with the 
> > lexer). But maybe calling first `compset -P' and then `compset -q'
> > should have the same effect as the other way round... I currently
> > don't remember why it behaves the way it does.
> 
> So is there currently no solution?  I tried using things like
> 
>   compset -P '*"'
> 
> but they never matched, presumably because of the lexer interactions
> you mention.

Yes, the completion code doesn't see the in-word quotes (well, only
get_comp_string() sees the tokens for them, but we decided some time
ago that the completion code only keeps quotes at the beginning/end of 
the word, generating some kind of `normalised' quoting).

But at least we should make `compset -q' work on the current value of
$PREFIX/$SUFFIX, keeping $IPREFIX/$ISUFFIX ignored (that's what I
meant in my last mail). The patch below does that.

Bye
 Sven

diff -ru ../z.old/Src/Zle/compcore.c Src/Zle/compcore.c
--- ../z.old/Src/Zle/compcore.c	Tue Mar 14 09:06:21 2000
+++ Src/Zle/compcore.c	Tue Mar 14 09:11:36 2000
@@ -1148,11 +1148,11 @@
     LinkNode n;
     int owe = we, owb = wb, ocs = cs, swb, swe, scs, soffs, ne = noerrs;
     int tl, got = 0, i = 0, cur = -1, oll = ll, sl, remq;
-    int ois = instring, oib = inbackt, noffs = lip + lp;
+    int ois = instring, oib = inbackt, noffs = lp;
     char *tmp, *p, *ns, *ol = (char *) line, sav, *qp, *qs, *ts, qc = '\0';
 
-    if (compisuffix)
-	s = dyncat(s, compisuffix);
+    s += lip;
+    wb += lip;
     untokenize(s);
 
     swb = swe = soffs = 0;
@@ -1343,16 +1343,16 @@
 	    untokenize(ss);
 	    compsuffix = ztrdup(ss);
 	}
-	zsfree(compiprefix);
-	compiprefix = ztrdup("");
-	zsfree(compisuffix);
-	compisuffix = ztrdup("");
-	tmp = tricat(compqiprefix, "", multiquote(qp, 1));
+	tmp = tricat(compqiprefix, compiprefix, multiquote(qp, 1));
 	zsfree(compqiprefix);
 	compqiprefix = tmp;
-	tmp = tricat(multiquote(qs, 1), "", compqisuffix);
+	tmp = tricat(multiquote(qs, 1), compisuffix, compqisuffix);
 	zsfree(compqisuffix);
 	compqisuffix = tmp;
+	zsfree(compiprefix);
+	compiprefix = ztrdup("");
+	zsfree(compisuffix);
+	compisuffix = ztrdup("");
 	freearray(compwords);
 	i = countlinknodes(foo);
 	compwords = (char **) zalloc((i + 1) * sizeof(char *));

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: completion for perl
  2000-03-13 10:57 Sven Wischnowsky
@ 2000-03-13 17:10 ` Adam Spiers
  0 siblings, 0 replies; 4+ messages in thread
From: Adam Spiers @ 2000-03-13 17:10 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky (wischnow@informatik.hu-berlin.de) wrote:
> 
> Adam Spiers wrote:
> 
> > Whilst struggling with the mess which is _perl_config_vars below, it
> > struck me how an equivalent of compset -P which matched the /whole/ of
> > PREFIX rather than just the beginning would have come in handy. 
> 
> Err... `compset -P "*"' does that, but it leaves you with an empty
> $PREFIX, of course, which is probably not what one wants.

Sorry; I didn't explain myself clearly at all.  I would like to be
able to do a compset -P type of operation using a pattern which is
anchored to both the start /and/ end of PREFIX, rather than just the
start, which is what currently always happens.  Then again, I suppose
this can be implemented easily manually, e.g.:

  if [[ "$PREFIX" == *: ]]; then
    IPREFIX="$IPREFIX$PREFIX"
    PREFIX=''
  fi

> > Also, as you can see from the compstate[quoting] line below, I
> > tried to get completion working for
> > 
> >   $ perl -V:'<TAB>
> > 
> > and
> > 
> >   $ perl -V:"<TAB>
> > 
> > so that it would insert a single space after each configuration
> > variable completed while within quotes, rather than a quoted single
> > space, but I didn't fully understand how compset -q works, and
> > couldn't stop it from eating up the opening quote.  Help! :-)
> 
> The problem is that we check the quoting stuff at the very beginning
> of the completion code -- and detect only quotes at the beginning of
> the word. So what we could get to work is completion of
> 
>   $ perl '-V:<TAB>
> 
> but not with the quote after the colon. That's done with first calling 
> `compset -q', then the `compset -P'. Getting quotes in words to work
> is to hard to make me try it (all kinds of nasty interactions with the 
> lexer). But maybe calling first `compset -P' and then `compset -q'
> should have the same effect as the other way round... I currently
> don't remember why it behaves the way it does.

So is there currently no solution?  I tried using things like

  compset -P '*"'

but they never matched, presumably because of the lexer interactions
you mention.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: completion for perl
@ 2000-03-13 10:57 Sven Wischnowsky
  2000-03-13 17:10 ` Adam Spiers
  0 siblings, 1 reply; 4+ messages in thread
From: Sven Wischnowsky @ 2000-03-13 10:57 UTC (permalink / raw)
  To: zsh-workers


Adam Spiers wrote:

> Whilst struggling with the mess which is _perl_config_vars below, it
> struck me how an equivalent of compset -P which matched the /whole/ of
> PREFIX rather than just the beginning would have come in handy. 

Err... `compset -P "*"' does that, but it leaves you with an empty
$PREFIX, of course, which is probably not what one wants.

> Is
> this worthwhile, Sven, or is my whole approach coming from the wrong
> angle?  Also, as you can see from the compstate[quoting] line below, I
> tried to get completion working for
> 
>   $ perl -V:'<TAB>
> 
> and
> 
>   $ perl -V:"<TAB>
> 
> so that it would insert a single space after each configuration
> variable completed while within quotes, rather than a quoted single
> space, but I didn't fully understand how compset -q works, and
> couldn't stop it from eating up the opening quote.  Help! :-)

The problem is that we check the quoting stuff at the very beginning
of the completion code -- and detect only quotes at the beginning of
the word. So what we could get to work is completion of

  $ perl '-V:<TAB>

but not with the quote after the colon. That's done with first calling 
`compset -q', then the `compset -P'. Getting quotes in words to work
is to hard to make me try it (all kinds of nasty interactions with the 
lexer). But maybe calling first `compset -P' and then `compset -q'
should have the same effect as the other way round... I currently
don't remember why it behaves the way it does.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-03-14  8:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-12 13:28 PATCH: completion for perl Adam Spiers
2000-03-13 10:57 Sven Wischnowsky
2000-03-13 17:10 ` Adam Spiers
2000-03-14  8:12 Sven Wischnowsky

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).