Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] completion: improve _message, etc



didn't feel like sending three e-mails but i'll commit separately

- comptest: prefer $TMPDIR for temp files

- _numbers: pass -r and -R to compadd

- _message: use zparseopts for all options, fix broken -JV handling (we
  were only looking for the options themselves, like in _describe etc,
  but we pass them directly to compadd here, so we need their arguments
  too)

dana


diff --git a/Test/comptest b/Test/comptest
index 31de475e5..13bbce3c8 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -149,7 +149,7 @@ comptesteval () {
    {
      # Avoid symlink attacks on the predictable filename
      # TODO: either use =(:) or create this file in the tests' workdir
-     local tmp=/tmp/comptest.$$
+     local tmp=${TMPDIR:-/tmp}/comptest.$$
      () {
        setopt localoptions NO_CLOBBER ERR_EXIT
        print -lr - "$@" > $tmp


diff --git a/Completion/Base/Utility/_numbers b/Completion/Base/Utility/_numbers
index 82edc07bd..8fd2e1d7e 100644
--- a/Completion/Base/Utility/_numbers
+++ b/Completion/Base/Utility/_numbers
@@ -44,7 +44,8 @@ local -a default max min keep tags units
 local -i i
 local -A opts
 
-zparseopts -K -D -A opts M+:=keep q+=keep s+:=keep S+:=keep J+: V+: 1 2 o+: n F: x+: X+: \
+zparseopts -K -D -A opts \
+  {M+:,q+,r+:,R+:,s+:,S+:}=keep J+: V+: 1 2 o+: n F: x+: X+: \
   t:=tags u:=units l:=min m:=max d:=default f=type e=type N=type
 
 desc="${1:-number}" tag="${tags[2]:-numbers}"


diff --git a/Completion/Base/Core/_message b/Completion/Base/Core/_message
index b80aa4237..8c3f351f6 100644
--- a/Completion/Base/Core/_message
+++ b/Completion/Base/Core/_message
@@ -1,19 +1,26 @@
 #autoload
 
-local format raw gopt
+local format raw
+local -a gopt
+local -A opth
 
-if [[ "$1" = -e ]]; then
+zparseopts -A opth -D -F - \
+  {1+,2+,V+:,J+:}=gopt F: M: n o: q s: S: x: X: \
+  e r \
+|| return
+
+if (( $+opth[-e] )); then
   local expl ret=1 tag
 
   _comp_mesg=yes
 
-  if (( $# > 2 )); then
-    tag="$2"
+  if (( $# > 1 )); then
+    tag=$1
     shift
   else
     tag="$curtag"
   fi
-  _tags "$tag" && while _next_label "$tag" expl "$2"; do
+  _tags "$tag" && while _next_label "$tag" expl "$1"; do
     compadd ${expl:/-X/-x}
     ret=0
   done
@@ -24,15 +31,10 @@ if [[ "$1" = -e ]]; then
   return ret
 fi
 
-gopt=()
-zparseopts -D -a gopt 1 2 V J
-
 _tags messages || return 1
 
-if [[ "$1" = -r ]]; then
-  raw=yes
-  shift
-  format="$1"
+if (( $+opth[-r] )); then
+  raw=yes format=$1
 else
   zstyle -s ":completion:${curcontext}:messages" format format ||
       zstyle -s ":completion:${curcontext}:descriptions" format format
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index f6e0d2133..57cac2883 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -424,6 +424,20 @@ F:regression test workers/31611
 >line: {tst }{}
 >MESSAGE:{%foo %BAR}
 
+  comptesteval '_tst() { _message -e abc }'
+  comptest $'tst \t'
+  comptesteval '_tst() { _message -e - abc }'
+  comptest $'tst \t'
+  comptesteval '_tst() { _message -e - tag abc }'
+  comptest $'tst \t'
+0:_message -e
+>line: {tst }{}
+>DESCRIPTION:{abc}
+>line: {tst }{}
+>DESCRIPTION:{abc}
+>line: {tst }{}
+>DESCRIPTION:{abc}
+
 %clean
 
   zmodload -ui zsh/zpty




Messages sorted by: Reverse Date, Date, Thread, Author