zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _postfix (postconf): Complete only applicable parameters for -X and -#.
@ 2016-09-14  5:14 Daniel Shahaf
  2016-09-14 16:46 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2016-09-14  5:14 UTC (permalink / raw)
  To: zsh-workers

---
One question about this patch:

    % /usr/sbin/postconf -X <TAB>
    zsh: do you wish to see all 112 possibilities (28 lines)? 

I don't understand why it says "112".  I expected it to say "32" since
my `postconf -n` output has 32 lines.  Without this patch, it says
"928 possibilities", as expected, since my `postconf -d` output [what
the before-the-patch code uses] has 928 lines.

Why does it say 112 rather than 32?

Thanks,

Daniel


 Completion/Unix/Command/_postfix | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/Completion/Unix/Command/_postfix b/Completion/Unix/Command/_postfix
index 528034e..afd56b7 100644
--- a/Completion/Unix/Command/_postfix
+++ b/Completion/Unix/Command/_postfix
@@ -16,11 +16,31 @@ _postfix_queue_id() {
   compadd "$@" -- ${${${(M)lines:#(#s)[0-9bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ](#c10)z*}%% *}%[*!]}
 }
 
+# The first argument must be either 'd' or 'n', to complete parameters in
+# `postconf -d -H` or `postconf -n -H` output, respectively.
 _postfix_main_cf_parameter() {
-  local expl
-  # Note for the future: if $mail_version >= 3.1, we can pass -H instead of
-  # stripping the = signs by hand.
-  _wanted parameters expl 'main.cf parameter' compadd "$@" -- ${${(f)"$(_call_program postconf-defaults "${(q)words[1]} -d")"}%% =*}
+  local -a expl
+  local kind
+
+  kind=$1; shift
+  case $kind in
+    (d)
+      # Note for the future: if $mail_version >= 3.1, we can pass -H instead of
+      # stripping the = signs by hand.
+      #
+      # don't bother to add -c in this case: the defaults don't depend on the config dir.
+      _wanted parameters expl 'main.cf parameter' compadd "$@" -- \
+        ${${(f)"$(_call_program postconf_-d "${(q)words[1]} -$kind")"}%% =*}
+      ;;
+    (n)
+      # Show the values too.
+      local -a kv=( ${${(f)"$(_call_program postconf_-n "${(q)words[1]} ${opt_args[-c]+"-c ${(q)opt_args[-c]}"} -$kind")"}/ = /:} )
+      _describe parameters kv
+      ;;
+    (*)
+      return 1 # can't happen due to the guard above
+      ;;
+  esac
 }
 
 _postfix_main_cf_parameter_and_value() {
@@ -33,7 +53,7 @@ _postfix_main_cf_parameter_and_value() {
     local value="`_call_program postconf-get-value-at-dir "${(q)words[1]} ${opt_args[-c]+"-c ${(q)opt_args[-c]}"} -h -- ${(q)IPREFIX%=}"`"
     [[ -n $value ]] && compadd "$@" -- $value
   else
-    _postfix_main_cf_parameter -S=
+    _postfix_main_cf_parameter d -S=
   fi
 }
 
@@ -130,8 +150,10 @@ case $service in
               elif (( $+opt_args[-p] )); then
                 if (( $+opt_args[-e] )); then
                   _postfix_main_cf_parameter_and_value
+                elif [[ -n $opt_args[(i)(-X|-[#])] ]]; then
+                  _postfix_main_cf_parameter n
                 else
-                  _postfix_main_cf_parameter
+                  _postfix_main_cf_parameter d
                 fi
               else # one of the master.cf modes: -M -F -P
                 _message "arguments for $opt_args[(i)${(j.|.)modes}] mode"


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

* Re: [PATCH] _postfix (postconf): Complete only applicable parameters for -X and -#.
  2016-09-14  5:14 [PATCH] _postfix (postconf): Complete only applicable parameters for -X and -# Daniel Shahaf
@ 2016-09-14 16:46 ` Bart Schaefer
  2016-09-15  2:15   ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2016-09-14 16:46 UTC (permalink / raw)
  To: zsh-workers

On Sep 14,  5:14am, Daniel Shahaf wrote:
} Subject: [PATCH] _postfix (postconf): Complete only applicable parameters 
}
} ---
} One question about this patch:
} 
}     % /usr/sbin/postconf -X <TAB>
}     zsh: do you wish to see all 112 possibilities (28 lines)? 
} 
} I don't understand why it says "112".

It's probably the case that each of the matches has been added to
more than one tag group.  What's output of ^Xh in place of TAB there?
What do you get if you agree to see all the possibilities?


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

* Re: [PATCH] _postfix (postconf): Complete only applicable parameters for -X and -#.
  2016-09-14 16:46 ` Bart Schaefer
@ 2016-09-15  2:15   ` Daniel Shahaf
  2016-09-15  3:35     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2016-09-15  2:15 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Wed, Sep 14, 2016 at 09:46:58 -0700:
> On Sep 14,  5:14am, Daniel Shahaf wrote:
> } Subject: [PATCH] _postfix (postconf): Complete only applicable parameters
> }
> } ---
> } One question about this patch:
> }
> }     % /usr/sbin/postconf -X <TAB>
> }     zsh: do you wish to see all 112 possibilities (28 lines)?
> }
> } I don't understand why it says "112".
>
> It's probably the case that each of the matches has been added to
> more than one tag group.  What's output of ^Xh in place of TAB there?

% /usr/sbin/postconf -X <_complete_help>
tags in context :completion::complete:postconf::
    argument-rest options  (_arguments _postfix)
tags in context :completion::complete:postconf:argument-rest:
    values  (_postfix_main_cf_parameter _postfix)

> What do you get if you agree to see all the possibilities?

The prompt says:

    zsh: do you wish to see all 112 possibilities (28 lines)?

If I answer "yes" then I get 28 lines, that show everything in my
`postconf -n` output and nothing else:

    alias_database                           alias_maps                            -- hash:/etc/aliases
    append_dot_mydomain                      biff                                  -- no
    config_directory                                                               -- /etc/postfix
    ⋮
    smtp_sasl_auth_enable                    enable_long_queue_ids  smtpd_use_tls  -- yes
    ⋮
    smtpd_tls_session_cache_database                                               -- btree:${data_directory}/smtpd_scache

This is in 'zsh -f'.

Thanks,

Daniel


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

* Re: [PATCH] _postfix (postconf): Complete only applicable parameters for -X and -#.
  2016-09-15  2:15   ` Daniel Shahaf
@ 2016-09-15  3:35     ` Bart Schaefer
  2016-09-15  4:48       ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2016-09-15  3:35 UTC (permalink / raw)
  To: zsh-workers

On Sep 15,  2:15am, Daniel Shahaf wrote:
} Subject: Re: [PATCH] _postfix (postconf): Complete only applicable paramet
}
} The prompt says:
} 
}     zsh: do you wish to see all 112 possibilities (28 lines)?
} 
} If I answer "yes" then I get 28 lines, that show everything in my
} `postconf -n` output and nothing else:

And how many words is that, all together?  I think it must be counting
the words in the descriptions as "possibilities" which probably has
something to do with the way the column positions are abused to get
the description to line up nicely alongside the thing described.

(Not the groups thing I first suspected after all, obviously.)


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

* Re: [PATCH] _postfix (postconf): Complete only applicable parameters for -X and -#.
  2016-09-15  3:35     ` Bart Schaefer
@ 2016-09-15  4:48       ` Daniel Shahaf
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2016-09-15  4:48 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Wed, Sep 14, 2016 at 20:35:06 -0700:
> On Sep 15,  2:15am, Daniel Shahaf wrote:
> } Subject: Re: [PATCH] _postfix (postconf): Complete only applicable paramet
> }
> } The prompt says:
> } 
> }     zsh: do you wish to see all 112 possibilities (28 lines)?
> } 
> } If I answer "yes" then I get 28 lines, that show everything in my
> } `postconf -n` output and nothing else:
> 
> And how many words is that, all together?  I think it must be counting
> the words in the descriptions as "possibilities" which probably has
> something to do with the way the column positions are abused to get
> the description to line up nicely alongside the thing described.

Bingo.  I see it now.  My 'postconf -n' has:

- 1 value that repeats 3 times
- 2 values that repeat twice, each
- 25 values that appear once each

So _describe puts that into a table as follows:

a1  a2  a3  -- va
b1  b2      -- vb
c1  c2      -- vc
k1          -- v1
k2          -- v2
⋮
k25         -- v25

The table has 4 columns — headed by "a1", "a2", "a3", and "-- v1" where
the double-hyphen is the list-separator style — and 28 rows, so it
counts as 28×4 = 112 matches.

Here's a reproducer:

_f () {
	a=( )
	i=25
	while (( i-- )
	do
		a+=( k${i}:v$i )
	done
	a+=( a{1..3}:va b{1..2}:vb c{1..2}:vc )
	a=( ${a/:/_______________________:} )
	_describe d a
}


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

end of thread, other threads:[~2016-09-15  4:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14  5:14 [PATCH] _postfix (postconf): Complete only applicable parameters for -X and -# Daniel Shahaf
2016-09-14 16:46 ` Bart Schaefer
2016-09-15  2:15   ` Daniel Shahaf
2016-09-15  3:35     ` Bart Schaefer
2016-09-15  4:48       ` Daniel Shahaf

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