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

PATCH: use new splitting mechanism for _sequence



This changes _sequence to use the new way of splitting strings with
a dynamic separator from 33423.

The patch also adds some quoting to cope with separators that need to be
quoted.

Oliver

diff --git a/Completion/Base/Utility/_sequence b/Completion/Base/Utility/_sequence
index 391e5f7..9167b8f 100644
--- a/Completion/Base/Utility/_sequence
+++ b/Completion/Base/Utility/_sequence
@@ -7,11 +7,11 @@
 # -s sep : specify separator [defaults to comma]
 # -d     : duplicate values allowed
 
-local curcontext="$curcontext" nm="$compstate[nmatches]" pre nosep minus
+local curcontext="$curcontext" nm="$compstate[nmatches]" pre qsep nosep minus
 local -a sep num pref suf end uniq dedup
 
 zparseopts -D -a opts s:=sep n:=num p:=pref i:=pref P:=pref I:=suf S:=suf q=suf r:=suf R:=suf C:=cont d=uniq M: J: X: x:
-(( $#cont )) && curcontext="$curcontext%:*}:$cont[2]"
+(( $#cont )) && curcontext="${curcontext%:*}:$cont[2]"
 (( $#sep )) || sep[2]=,
 
 if (( $+suf[(r)-S] )); then
@@ -19,20 +19,20 @@ if (( $+suf[(r)-S] )); then
   (( $#end )) && compset -S ${end}\* && suf=() && nosep=1
 fi
 
+qsep="${sep[2]}"
+compquote -p qsep
 if (( ! $#uniq )); then
   (( $+pref[(r)-P] )) && pre="${(q)pref[pref[(i)-P]+1]}"
-  typeset -T unique="${PREFIX#$pre}" uniq $sep[2]
-  dedup=( ${(q)uniq[1,-2]} )
-  unique="${SUFFIX}"
-  dedup+=( ${(q)uniq[2,-1]} )
+  dedup=( "${(@)${(@ps.$qsep.)PREFIX#$pre}[1,-2]}" "${(@)${(@ps.$qsep.)SUFFIX}[2,-1]}" )
+  [[ -n $compstate[quoting] ]] || dedup=( ${(Q)dedup} )
 fi
 
-if (( ! $#num )) || (( num[2] > 1 )) && ! compset -P $(( num[2] - 1 )) \*$sep[2]; then
-  (( nosep )) || suf=( -S $sep[2] -r "$end[1]${sep[2][1]} \t\n\-" )
-  compset -S ${sep[2]}\* && suf=()
-  compset -P \*$sep[2] && pref=()
-else
+if (( $#num )) && compset -P $(( num[2] - 1 )) \*${(q)qsep}; then
   pref=()
+else
+  (( ! nosep && (!$#num || num[2] > 1) )) && suf=( -S ${qsep} -r "$end[1]${(q)qsep[1]} \t\n\-" )
+  compset -S ${(q)qsep}\* && suf=()
+  compset -P \*${(q)qsep} && pref=()
 fi
 
 (( minus = argv[(ib:2:)-] ))



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