zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: new-style completion for parameters and options
Date: Tue, 23 Mar 1999 16:13:34 +0100 (MET)	[thread overview]
Message-ID: <199903231513.QAA19509@beta.informatik.hu-berlin.de> (raw)


As Andrej mentioned, this had some problems.

Making typeset print `local' for local parameters was simple. I've
made it be printed after the type since there may uses relying on
things like `array' to be the first on the line. Thank god I don't
have to decide if this is important/careful enough to be included in
an official version. If not, most the rest of this patch is pretty
useless.

This adds the files `Core/_{{set_,unset_}options,parameters}' to be
able to easily complete them. The ones for the options also use a `-M' 
option for this ignore-underscore-and-map-upper-to-lower-case thing.

Btw, why is `_vars' in `Base' and `_vars_eq' in `Builtins'?

Bye
 Sven

--- os/params.c	Mon Mar 22 13:44:37 1999
+++ Src/params.c	Tue Mar 23 15:31:05 1999
@@ -2709,6 +2709,8 @@
 	    printf("array ");
 	else if (p->flags & PM_HASHED)
 	    printf("association ");
+	if (p->level)
+	    printf("local ");
 	if (p->flags & PM_LEFT)
 	    printf("left justified %d ", p->ct);
 	if (p->flags & PM_RIGHT_B)
diff -u -r oc/Base/_brace_parameter Completion/Base/_brace_parameter
--- oc/Base/_brace_parameter	Tue Mar 23 11:56:54 1999
+++ Completion/Base/_brace_parameter	Tue Mar 23 15:52:08 1999
@@ -1,11 +1,9 @@
 #defcomp -brace-parameter-
 
-# Simple but without spiffy suffix handling: compgen -v -S '} '
-
 if [[ "$SUFFIX" = *\}* ]]; then
   ISUFFIX="${SUFFIX#*\}}$ISUFFIX"
   SUFFIX="${SUFFIX%%\}*}"
-  compadd -S '} ' -r '-:?#%+=[/' - "${(@)${(@)${(@f)$(set)}%%\=*}:gs/'//}"
+  _parameters -S '} ' -r '-:?#%+=[/'
 else
-  compadd -S '} ' -r '-:?#%+=[/' - "${(@)${(@)${(@f)$(set)}%%\=*}:gs/'//}"
+  _parameters -S '} ' -r '-:?#%+=[/'
 fi
diff -u -r oc/Base/_condition Completion/Base/_condition
--- oc/Base/_condition	Tue Mar 23 11:56:54 1999
+++ Completion/Base/_condition	Tue Mar 23 15:59:32 1999
@@ -3,14 +3,14 @@
 local prev="$words[CURRENT-1]"
 
 if [[ "$prev" = -o ]]; then
-  compgen -o -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}'
+  _options
 elif [[ "$prev" = -([no]t|ef) ]]; then
   _files
 else
   local ret=1
 
   _files && ret=0
-  compgen -v && ret=0
+  _parameters && ret=0
 
   return ret
 fi
diff -u -r oc/Base/_math Completion/Base/_math
--- oc/Base/_math	Tue Mar 23 11:56:55 1999
+++ Completion/Base/_math	Tue Mar 23 15:51:04 1999
@@ -9,4 +9,4 @@
   SUFFIX="${SUFFIX%%[^a-zA-Z0-9_]*}"
 fi
 
-compgen -v
+_parameters
diff -u -r oc/Base/_parameter Completion/Base/_parameter
--- oc/Base/_parameter	Tue Mar 23 11:56:54 1999
+++ Completion/Base/_parameter	Tue Mar 23 15:50:44 1999
@@ -1,3 +1,3 @@
 #defcomp -parameter-
 
-compgen -v
+_parameters
diff -u -r oc/Base/_vars Completion/Base/_vars
--- oc/Base/_vars	Tue Mar 23 11:56:54 1999
+++ Completion/Base/_vars	Tue Mar 23 15:49:30 1999
@@ -1,3 +1,3 @@
 #defcomp getopts read unset vared
 
-compgen -v
+_parameters
diff -u -r oc/Builtins/_setopt Completion/Builtins/_setopt
--- oc/Builtins/_setopt	Tue Mar 23 11:56:56 1999
+++ Completion/Builtins/_setopt	Tue Mar 23 16:01:14 1999
@@ -1,11 +1,3 @@
 #defcomp setopt
 
-local nm=$compstate[nmatches] ret=1
-
-compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \
-         -s '$({ unsetopt kshoptionprint; unsetopt } 2>/dev/null)' && ret=0
-
-[[ compstate[nmatches] -eq nm ]] &&
-    compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o && ret=0
-
-return ret
+_unset_options || _options
diff -u -r oc/Builtins/_unsetopt Completion/Builtins/_unsetopt
--- oc/Builtins/_unsetopt	Tue Mar 23 11:56:56 1999
+++ Completion/Builtins/_unsetopt	Tue Mar 23 16:02:02 1999
@@ -1,11 +1,3 @@
 #defcomp unsetopt
 
-local nm=$compstate[nmatches] ret=1
-
-compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \
-         -s '$({ unsetopt kshoptionprint; setopt } 2>/dev/null)' && ret=0
-
-[[ compstate[nmatches] -eq nm ]] &&
-    compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o && ret=0
-
-return ret
+_set_options || _options
diff -u -r oc/Builtins/_vars_eq Completion/Builtins/_vars_eq
--- oc/Builtins/_vars_eq	Tue Mar 23 11:56:56 1999
+++ Completion/Builtins/_vars_eq	Tue Mar 23 15:50:04 1999
@@ -1,3 +1,3 @@
 #defcomp declare export integer local readonly typeset
 
-compgen -v -q -S '='
+_parameters -q -S '='
diff -u -r oc/Core/_main_complete Completion/Core/_main_complete
--- oc/Core/_main_complete	Tue Mar 23 11:56:57 1999
+++ Completion/Core/_main_complete	Tue Mar 23 15:55:59 1999
@@ -15,7 +15,10 @@
 #    any matches, correction is tried and if that doesn't yield
 #    anything either, correcting completion is attempted.
 
-local comp
+local comp _set_options _unset_options
+
+_set_options=("${(@f)$({ unsetopt kshoptionprint; setopt } 2>/dev/null)}")
+_unset_options=("${(@f)$({ unsetopt kshoptionprint; setopt } 2>/dev/null)}")
 
 setopt localoptions nullglob rcexpandparam
 unsetopt markdirs globsubst shwordsplit nounset ksharrays
diff -u -r Completion/Core/_options Completion/Core/_options
--- Completion/Core/_options	Tue Mar 23 16:04:24 1999
+++ Completion/Core/_options	Tue Mar 23 15:57:49 1999
@@ -0,0 +1,5 @@
+#autoload
+
+# This should be used to complete all option names.
+
+compgen "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o
diff -u -r Completion/Core/_parameters Completion/Core/_parameters
--- Completion/Core/_parameters	Tue Mar 23 16:04:24 1999
+++ Completion/Core/_parameters	Tue Mar 23 15:49:26 1999
@@ -0,0 +1,7 @@
+#autoload
+
+# This should be used to complete parameter names, it first tries to
+# complete only non-local parameters. All arguments are given to compadd.
+
+compadd "$@" - "${(@)${(@)${(@)${(@f)$(typeset)}:#*local *\=*}%%\=*}##* }" ||
+    compadd "$@" - "${(@)${(@)${(@f)$(typeset)}%%\=*}##* }"
diff -u -r Completion/Core/_set_options Completion/Core/_set_options
--- Completion/Core/_set_options	Tue Mar 23 16:04:25 1999
+++ Completion/Core/_set_options	Tue Mar 23 16:01:24 1999
@@ -0,0 +1,7 @@
+#autoload
+
+# Complete all set options. This relies on `_main_complete' to store the
+# names of the options that were set when it was called in the array
+# `_set_options'.
+
+compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - $=_set_options
diff -u -r Completion/Core/_unset_options Completion/Core/_unset_options
--- Completion/Core/_unset_options	Tue Mar 23 16:04:25 1999
+++ Completion/Core/_unset_options	Tue Mar 23 16:01:31 1999
@@ -0,0 +1,7 @@
+#autoload
+
+# Complete all unset options. This relies on `_main_complete' to store the
+# names of the options that were set when it was called in the array
+# `_set_options'.
+
+compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - $=_unset_options

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


             reply	other threads:[~1999-03-23 15:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-23 15:13 Sven Wischnowsky [this message]
1999-03-24 11:15 ` Andrej Borsenkow
1999-03-25  8:35 Sven Wischnowsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199903231513.QAA19509@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).