zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Improve extra-verbose completion of array params
@ 2021-04-27 10:28 Marlon Richert
  2021-05-09 17:47 ` Lawrence Velázquez
  2021-05-16 22:09 ` Oliver Kiddle
  0 siblings, 2 replies; 7+ messages in thread
From: Marlon Richert @ 2021-04-27 10:28 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 100 bytes --]

This patch improves the extra-verbose completion display strings for
arrays and associative arrays.

[-- Attachment #2: 0001-Improve-extra-verbose-completion-of-array-params.txt --]
[-- Type: text/plain, Size: 3116 bytes --]

From b2bde2a745693d45036733e8c0169f1c0343200b Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Tue, 27 Apr 2021 13:24:25 +0300
Subject: [PATCH] Improve extra-verbose completion of array params

---
 Completion/Zsh/Type/_parameters |  8 +++-----
 Test/Y01completion.ztst         | 14 +++++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/Completion/Zsh/Type/_parameters b/Completion/Zsh/Type/_parameters
index 00c181e11..2cf8c229a 100644
--- a/Completion/Zsh/Type/_parameters
+++ b/Completion/Zsh/Type/_parameters
@@ -11,8 +11,8 @@ if compset -P '*:'; then
   return
 fi
 
-local MATCH i pfilt
-local -i MBEGIN MEND nm=$compstate[nmatches]
+local i pfilt 
+local -i nm=$compstate[nmatches]
 local -a expl pattern=(-g \*) normal described verbose faked fakes tmp
 
 zstyle -t ":completion:${curcontext}:parameters" prefix-needed &&
@@ -27,8 +27,7 @@ if zstyle -t ":completion:${curcontext}:parameters" extra-verbose; then
   )
   compadd "$@" "$expl[@]" -D described -a - described
   if (( $#described )); then
-    verbose=(
-        ${described[@]:/(#m)*/"${MATCH}:${(@q+)${(Pkv@q+)MATCH}//\\/\\\\}"} )
+    verbose=( ${${${(f@)"$( typeset -m $described )"}/=/:}[@]//'\'/'\\'} )
     _describe -t parameters parameter verbose "$@" "$expl[@]"
   fi
 
@@ -52,4 +51,3 @@ compadd "$@" "$expl[@]" - "$normal[@]" "${(@)fakes:|described}" \
     "${(@)${(@)${(@M)faked:#${~pattern[2]}}%%:*}:|described}"
 
 (( compstate[nmatches] > nm ))
-return 0
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index 2c6d25d9a..882a0adc4 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -255,15 +255,18 @@ F:regression test workers/31611
 >FI:{file1}
 >FI:{file2}
 
-  comptesteval "bar=({$'\\0'..$'\\C-?'}); baz=\$bar"
+  comptesteval "typeset -a bar=({$'\\0'..$'\\C-?'})"
+  comptesteval 'typeset -A bat=( "$bar[@]" )'
+  comptesteval 'typeset bay="$bar"'
   comptesteval 'zstyle ":completion:*:parameters" extra-verbose yes'
-  comptesteval 'zstyle ":completion:*" fake-parameters bar baz:array'
+  comptesteval 'zstyle ":completion:*" fake-parameters bar bat bay'
   comptest $': $ba\t'
 0:extra-verbose shows parameter values
 >line: {: $ba}{}
 >DESCRIPTION:{parameter}
->NO:{bar  -- '^@' '^A' '^B' '^C' '^D' '^E' '^F' '^G' '^H' '\t' '\n' '^K' '^L' '^M}
->NO:{baz  -- '^@ ^A ^B ^C ^D ^E ^F ^G ^H \t \n ^K ^L ^M ^N ^O ^P ^Q ^R ^S ^T ^U ^}
+>NO:{bar  -- ( '^@' '^A' '^B' '^C' '^D' '^E' '^F' '^G' '^H' '\t' '\n' '^K' '^L' '}
+>NO:{bat  -- ( [' ']='!' ['"']='#' ['$']=% ['&']=\' ['(']=')' ['*']=+ [,]=- [.]=/}
+>NO:{bay  -- '^@ ^A ^B ^C ^D ^E ^F ^G ^H \t \n ^K ^L ^M ^N ^O ^P ^Q ^R ^S ^T ^U ^}
 
   comptesteval "path=( $ZTST_srcdir:A )"
   comptesteval 'typeset -H paths=HIDDEN'
@@ -280,7 +283,8 @@ F:regression test workers/31611
 >line: {: $ba}{}
 >DESCRIPTION:{parameter}
 >NO:{bar}
->NO:{baz}
+>NO:{bat}
+>NO:{bay}
 
   comptesteval '_tst() { local disp=( {a..z} ); compadd -ld disp $disp[@]; comppostfuncs=( _pst ) }'
   comptesteval '_pst() { local disp=( "<INSERT>$compstate[insert]</INSERT>" ); compadd -Qld disp $disp }'
-- 
2.31.1


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

* Re: [PATCH] Improve extra-verbose completion of array params
  2021-04-27 10:28 [PATCH] Improve extra-verbose completion of array params Marlon Richert
@ 2021-05-09 17:47 ` Lawrence Velázquez
  2021-05-16 16:12   ` Lawrence Velázquez
  2021-05-16 22:09 ` Oliver Kiddle
  1 sibling, 1 reply; 7+ messages in thread
From: Lawrence Velázquez @ 2021-05-09 17:47 UTC (permalink / raw)
  To: zsh-workers; +Cc: Marlon Richert

On Tue, Apr 27, 2021, at 6:28 AM, Marlon Richert wrote:
> This patch improves the extra-verbose completion display strings for
> arrays and associative arrays.

ping for review

-- 
vq


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

* Re: [PATCH] Improve extra-verbose completion of array params
  2021-05-09 17:47 ` Lawrence Velázquez
@ 2021-05-16 16:12   ` Lawrence Velázquez
  2021-05-16 16:18     ` Mikael Magnusson
  0 siblings, 1 reply; 7+ messages in thread
From: Lawrence Velázquez @ 2021-05-16 16:12 UTC (permalink / raw)
  To: zsh-workers; +Cc: Marlon Richert

On Sun, May 9, 2021, at 1:47 PM, Lawrence Velázquez wrote:
> On Tue, Apr 27, 2021, at 6:28 AM, Marlon Richert wrote:
> > This patch improves the extra-verbose completion display strings for
> > arrays and associative arrays.
> 
> ping for review

Ping II: The Sequel

vq


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

* Re: [PATCH] Improve extra-verbose completion of array params
  2021-05-16 16:12   ` Lawrence Velázquez
@ 2021-05-16 16:18     ` Mikael Magnusson
  2021-05-16 19:40       ` Marlon Richert
  0 siblings, 1 reply; 7+ messages in thread
From: Mikael Magnusson @ 2021-05-16 16:18 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: zsh-workers, Marlon Richert

On 5/16/21, Lawrence Velázquez <larryv@zsh.org> wrote:
> On Sun, May 9, 2021, at 1:47 PM, Lawrence Velázquez wrote:
>> On Tue, Apr 27, 2021, at 6:28 AM, Marlon Richert wrote:
>> > This patch improves the extra-verbose completion display strings for
>> > arrays and associative arrays.
>>
>> ping for review
>
> Ping II: The Sequel

I looked at the patch but there is no description of what the intent
is, so it is impossible for me to say if it achieves it. The code
itself is not exactly self-explanatory...

-- 
Mikael Magnusson


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

* Re: [PATCH] Improve extra-verbose completion of array params
  2021-05-16 16:18     ` Mikael Magnusson
@ 2021-05-16 19:40       ` Marlon Richert
  0 siblings, 0 replies; 7+ messages in thread
From: Marlon Richert @ 2021-05-16 19:40 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Lawrence Velázquez, Zsh hackers list

On Sun, May 16, 2021 at 7:18 PM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> On 5/16/21, Lawrence Velázquez <larryv@zsh.org> wrote:
> > On Sun, May 9, 2021, at 1:47 PM, Lawrence Velázquez wrote:
> >> On Tue, Apr 27, 2021, at 6:28 AM, Marlon Richert wrote:
> >> > This patch improves the extra-verbose completion display strings for
> >> > arrays and associative arrays.
> >>
> >> ping for review
> >
> > Ping II: The Sequel
>
> I looked at the patch but there is no description of what the intent
> is, so it is impossible for me to say if it achieves it. The code
> itself is not exactly self-explanatory...

I thought the test changes included made it rather self-explanatory:

 0:extra-verbose shows parameter values
 >line: {: $ba}{}
 >DESCRIPTION:{parameter}
->NO:{bar  -- '^@' '^A' '^B' '^C' '^D' '^E' '^F' '^G' '^H' '\t' '\n'
'^K' '^L' '^M}
->NO:{baz  -- '^@ ^A ^B ^C ^D ^E ^F ^G ^H \t \n ^K ^L ^M ^N ^O ^P ^Q
^R ^S ^T ^U ^}
+>NO:{bar  -- ( '^@' '^A' '^B' '^C' '^D' '^E' '^F' '^G' '^H' '\t' '\n'
'^K' '^L' '}
+>NO:{bat  -- ( [' ']='!' ['"']='#' ['$']=% ['&']=\' ['(']=')' ['*']=+
[,]=- [.]=/}
+>NO:{bay  -- '^@ ^A ^B ^C ^D ^E ^F ^G ^H \t \n ^K ^L ^M ^N ^O ^P ^Q
^R ^S ^T ^U ^}

When using extra-verbose parameter completion, you can now clearly see
the difference between the values of scalars, arrays and associative
arrays.

How about if I change the commit message? Perhaps something like this:

    Improve formatting of array values in extra-verbose parameter completion

    Make it more visually obvious which values are arrays or
associative arrays."

Would that help? I'm open to suggestions.


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

* Re: [PATCH] Improve extra-verbose completion of array params
  2021-04-27 10:28 [PATCH] Improve extra-verbose completion of array params Marlon Richert
  2021-05-09 17:47 ` Lawrence Velázquez
@ 2021-05-16 22:09 ` Oliver Kiddle
  2021-05-17 11:58   ` Marlon Richert
  1 sibling, 1 reply; 7+ messages in thread
From: Oliver Kiddle @ 2021-05-16 22:09 UTC (permalink / raw)
  To: Marlon Richert; +Cc: Zsh hackers list

On 27 Apr, Marlon Richert wrote:
> This patch improves the extra-verbose completion display strings for
> arrays and associative arrays.
> -    verbose=(
> -        ${described[@]:/(#m)*/"${MATCH}:${(@q+)${(Pkv@q+)MATCH}//\\/\\\\}"} )
> +    verbose=( ${${${(f@)"$( typeset -m $described )"}/=/:}[@]//'\'/'\\'} )

Why the use of -m here? Is that to avoid it creating variables (which
may not matter especially in the subshell). Do we need to be concerned
about the possibility of glob characters appearing there and producing
more output than expected?

Apart from my puzzlement over that the patch essentially looks fine.
I did notice some issues with _describe being messed up with compadd
options in later use of the new feature (without this extra patch) which
I intended to come back and take a look at.

>  (( compstate[nmatches] > nm ))
> -return 0

That's certainly correct and I ought to have caught it before committing.

Oliver


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

* Re: [PATCH] Improve extra-verbose completion of array params
  2021-05-16 22:09 ` Oliver Kiddle
@ 2021-05-17 11:58   ` Marlon Richert
  0 siblings, 0 replies; 7+ messages in thread
From: Marlon Richert @ 2021-05-17 11:58 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh hackers list, Mikael Magnusson

[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

On Mon, May 17, 2021 at 1:09 AM Oliver Kiddle <opk@zsh.org> wrote:
>
> On 27 Apr, Marlon Richert wrote:
> > This patch improves the extra-verbose completion display strings for
> > arrays and associative arrays.
> > -    verbose=(
> > -        ${described[@]:/(#m)*/"${MATCH}:${(@q+)${(Pkv@q+)MATCH}//\\/\\\\}"} )
> > +    verbose=( ${${${(f@)"$( typeset -m $described )"}/=/:}[@]//'\'/'\\'} )
>
> Why the use of -m here? Is that to avoid it creating variables (which
> may not matter especially in the subshell). Do we need to be concerned
> about the possibility of glob characters appearing there and producing
> more output than expected?

Here's a new version of the patch, which hopefully addresses the
concerns above and has a satisfactorily descriptive commit message.

[-- Attachment #2: 0001-Improve-extra-verbose-completion-display-strings-for.txt --]
[-- Type: text/plain, Size: 3559 bytes --]

From e70cf2b4f48fce90f83a89d24e369b9f5eb10fd7 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Mon, 17 May 2021 14:49:02 +0300
Subject: [PATCH] Improve extra-verbose completion display strings for array
 parameter values

---
 Completion/Zsh/Type/_parameters | 16 ++++++++++------
 Test/Y01completion.ztst         | 14 +++++++++-----
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/Completion/Zsh/Type/_parameters b/Completion/Zsh/Type/_parameters
index 00c181e11..549b2157b 100644
--- a/Completion/Zsh/Type/_parameters
+++ b/Completion/Zsh/Type/_parameters
@@ -11,9 +11,9 @@ if compset -P '*:'; then
   return
 fi
 
-local MATCH i pfilt
-local -i MBEGIN MEND nm=$compstate[nmatches]
-local -a expl pattern=(-g \*) normal described verbose faked fakes tmp
+local i pfilt
+local -i nm=$compstate[nmatches]
+local -a expl pattern=( -g \* ) normal described verbose faked fakes tmp
 
 zstyle -t ":completion:${curcontext}:parameters" prefix-needed &&
     [[ $PREFIX != [_.]* ]] &&
@@ -27,8 +27,13 @@ if zstyle -t ":completion:${curcontext}:parameters" extra-verbose; then
   )
   compadd "$@" "$expl[@]" -D described -a - described
   if (( $#described )); then
-    verbose=(
-        ${described[@]:/(#m)*/"${MATCH}:${(@q+)${(Pkv@q+)MATCH}//\\/\\\\}"} )
+    # Normally, calling typeset without flags would print the values of its
+    # arguments. However, inside a function, it instead declare its arguments
+    # as local variables and outputs nothing. Thus, to force it print out
+    # parameter values, we pass it the -m flag.
+    verbose=( 
+        ${${${(f@)"$( typeset -m ${(@b)described} )"}/=/:}[@]//'\'/'\\'} 
+    )
     _describe -t parameters parameter verbose "$@" "$expl[@]"
   fi
 
@@ -52,4 +57,3 @@ compadd "$@" "$expl[@]" - "$normal[@]" "${(@)fakes:|described}" \
     "${(@)${(@)${(@M)faked:#${~pattern[2]}}%%:*}:|described}"
 
 (( compstate[nmatches] > nm ))
-return 0
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index 2c6d25d9a..882a0adc4 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -255,15 +255,18 @@ F:regression test workers/31611
 >FI:{file1}
 >FI:{file2}
 
-  comptesteval "bar=({$'\\0'..$'\\C-?'}); baz=\$bar"
+  comptesteval "typeset -a bar=({$'\\0'..$'\\C-?'})"
+  comptesteval 'typeset -A bat=( "$bar[@]" )'
+  comptesteval 'typeset bay="$bar"'
   comptesteval 'zstyle ":completion:*:parameters" extra-verbose yes'
-  comptesteval 'zstyle ":completion:*" fake-parameters bar baz:array'
+  comptesteval 'zstyle ":completion:*" fake-parameters bar bat bay'
   comptest $': $ba\t'
 0:extra-verbose shows parameter values
 >line: {: $ba}{}
 >DESCRIPTION:{parameter}
->NO:{bar  -- '^@' '^A' '^B' '^C' '^D' '^E' '^F' '^G' '^H' '\t' '\n' '^K' '^L' '^M}
->NO:{baz  -- '^@ ^A ^B ^C ^D ^E ^F ^G ^H \t \n ^K ^L ^M ^N ^O ^P ^Q ^R ^S ^T ^U ^}
+>NO:{bar  -- ( '^@' '^A' '^B' '^C' '^D' '^E' '^F' '^G' '^H' '\t' '\n' '^K' '^L' '}
+>NO:{bat  -- ( [' ']='!' ['"']='#' ['$']=% ['&']=\' ['(']=')' ['*']=+ [,]=- [.]=/}
+>NO:{bay  -- '^@ ^A ^B ^C ^D ^E ^F ^G ^H \t \n ^K ^L ^M ^N ^O ^P ^Q ^R ^S ^T ^U ^}
 
   comptesteval "path=( $ZTST_srcdir:A )"
   comptesteval 'typeset -H paths=HIDDEN'
@@ -280,7 +283,8 @@ F:regression test workers/31611
 >line: {: $ba}{}
 >DESCRIPTION:{parameter}
 >NO:{bar}
->NO:{baz}
+>NO:{bat}
+>NO:{bay}
 
   comptesteval '_tst() { local disp=( {a..z} ); compadd -ld disp $disp[@]; comppostfuncs=( _pst ) }'
   comptesteval '_pst() { local disp=( "<INSERT>$compstate[insert]</INSERT>" ); compadd -Qld disp $disp }'
-- 
2.31.1


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

end of thread, other threads:[~2021-05-17 12:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 10:28 [PATCH] Improve extra-verbose completion of array params Marlon Richert
2021-05-09 17:47 ` Lawrence Velázquez
2021-05-16 16:12   ` Lawrence Velázquez
2021-05-16 16:18     ` Mikael Magnusson
2021-05-16 19:40       ` Marlon Richert
2021-05-16 22:09 ` Oliver Kiddle
2021-05-17 11:58   ` Marlon Richert

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