zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Add completion for picocom utility
@ 2016-05-01  1:12 Frank Terbeck
  2016-05-01  3:27 ` Ryan Wilson
  0 siblings, 1 reply; 19+ messages in thread
From: Frank Terbeck @ 2016-05-01  1:12 UTC (permalink / raw)
  To: zsh-workers

---
  We're using picocom quite a lot at work, having to remember options
  and baud-rates by heart is getting tiresome, though. So here's a first
  stab at this. If someone has a portable way to generate a list of
  supported baud-rates for serial devices, I love to hear it.

 Completion/Unix/Command/_picocom | 80 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 Completion/Unix/Command/_picocom

diff --git a/Completion/Unix/Command/_picocom b/Completion/Unix/Command/_picocom
new file mode 100644
index 0000000..6653bc2
--- /dev/null
+++ b/Completion/Unix/Command/_picocom
@@ -0,0 +1,80 @@
+#compdef picocom
+
+# The following function uses a generated list; first find out where the B*
+# macros are defined:
+#
+#   grep -r B115200 /usr/include
+#
+# Then generate the actual list:
+#
+#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
+#           < /usr/include/asm-generic/termbits.h
+#
+# This one was generated on a Debian Stretch system, leaving out the "0" rate,
+# which is synonymous to "hang-up".
+function _picocom_baudrate () {
+    local expl
+    local -a rates
+    rates=( 50 75 110 134 150 200 300 600
+            1200 1800 2400 4800 9600
+            19200 38400 57600
+            115200 230400 460800 500000 576000 921600
+            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
+    # -1V removes dupes (which there shouldn't be) and otherwise leaves the
+    # order in the $rates array intact.
+    _wanted -1V baud-rate expl 'baud rate' compadd -a $expl -- rates
+}
+
+function _picocom_flowcontrol () {
+    local expl
+    local -a modes
+    modes=( x h n )
+    _wanted flow-ctrl-mode expl 'flow control mode' compadd -a $expl -- modes
+}
+
+function _picocom_paritymode () {
+    local expl
+    local -a modes
+    modes=( o e n )
+    _wanted parity-mode expl 'parity mode' compadd -a $expl -- modes
+}
+
+function _picocom_databits () {
+    local expl
+    local -a widths
+    widths=( 5 6 7 8 )
+    _wanted data-bits expl 'data bits' compadd -a $expl -- widths
+}
+
+function _picocom_escape () {
+    setopt localoptions braceccl
+    local expl
+    local -a ctrlchars
+    ctrlchars=( {a-z} _ '?' '[' '\' ']' '@' '^' )
+    _wanted escape-key expl 'escape key' compadd -a $expl -- ctrlchars
+}
+
+function _picocom () {
+    local -a args
+
+    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_picocom_baudrate'
+           '(--flow -f)'{--flow,-f}'[define type of flow control to use]:flow control:_picocom_flowcontrol'
+           '(--parity -p)'{--parity,-p}'[define type of parity to use]:parity mode:_picocom_paritymode'
+           '(--databits -d)'{--databits,-d}'[define the number of databits per word]:data bits:_picocom_databits'
+           '(--escape -e)'{--escape,-e}'[define command mode character]:escape character:_picocom_escape'
+           '(--echo -c)'{--echo,-c}'[enable local echo]'
+           '(--noinit -i)'{--noinit,-i}'[do not initialise serial port]'
+           '(--noreset -r)'{--noreset,-r}'[do not reset serial port]'
+           '(--nolock -l)'{--nolock,-l}'[do not lock serial port]'
+           '(--send-cmd -s)'{--send-cmd,-s}'[define file send command]:file send command:_cmdstring'
+           '(--receive-cmd -v)'{--receive-cmd,-v}'[define file receive command]:file receive command:_cmdstring'
+           '--imap[define input character map]:input character map:'
+           '--omap[define output character map]:output character map:'
+           '--emap[define local echo character map]:local echo character map:'
+           '(--help -h)'{--help,-h}'[display help message]'
+           '*:device:_files -g "*(%c)"' )
+
+    _arguments -C : "${args[@]}"
+}
+
+_picocom "$@"
-- 
2.8.1


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

* Re: [PATCH] Add completion for picocom utility
  2016-05-01  1:12 [PATCH] Add completion for picocom utility Frank Terbeck
@ 2016-05-01  3:27 ` Ryan Wilson
  2016-05-01 10:57   ` Frank Terbeck
  0 siblings, 1 reply; 19+ messages in thread
From: Ryan Wilson @ 2016-05-01  3:27 UTC (permalink / raw)
  To: Frank Terbeck, zsh-workers

On Sun, 2016-05-01 at 03:12 +0200, Frank Terbeck wrote:
> ---
>   We're using picocom quite a lot at work, having to remember options
>   and baud-rates by heart is getting tiresome, though. So here's a first
>   stab at this. If someone has a portable way to generate a list of
>   supported baud-rates for serial devices, I love to hear it.

I was just looking at baud rate completion myself and each command I've
found that does it (namely: _cu, _gdb, _joe, and _screen) uses a
different list. So how about making it a generic _baud_rate helper that
everything can share?


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

* Re: [PATCH] Add completion for picocom utility
  2016-05-01  3:27 ` Ryan Wilson
@ 2016-05-01 10:57   ` Frank Terbeck
  2016-05-01 12:47     ` [PATCH] Refactor baud rate completion Frank Terbeck
                       ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-01 10:57 UTC (permalink / raw)
  To: Ryan Wilson; +Cc: zsh-workers

Hey Ryan,

Ryan Wilson wrote:
> On Sun, 2016-05-01 at 03:12 +0200, Frank Terbeck wrote:
>> ---
>>   We're using picocom quite a lot at work, having to remember options
>>   and baud-rates by heart is getting tiresome, though. So here's a first
>>   stab at this. If someone has a portable way to generate a list of
>>   supported baud-rates for serial devices, I love to hear it.

I took a further look and couldn't find a _portable_ way to generate the
list on the fly. So using some sort of a pre-compiled list seem to be as
good as it gets.

> I was just looking at baud rate completion myself and each command I've
> found that does it (namely: _cu, _gdb, _joe, and _screen) uses a
> different list. So how about making it a generic _baud_rate helper that
> everything can share?

Interesting. Seems like "joe" uses the baud rate for different reasons,
though, and therefore only needs a smaller list.

Actually, scratch that. The option description in _joe misled me into
thinking its -baud option only needed baud rates below 19200.

But since I now already have a working helper with the possibility for
callers to apply filters to the original list, I am not going to throw
it away. Maybe it will come in handy at a later point in time.

Here is a patch that touches the places you mentioned:


>From 093f91482683db03c81ee0dc3fac637a3dcc178e Mon Sep 17 00:00:00 2001
From: Frank Terbeck <ft@bewatermyfriend.org>
Date: Sun, 1 May 2016 12:49:30 +0200
Subject: [PATCH] Refactor baud rate completion

This adds a new helper function _baudrate and uses it in place of
private solutions in various existing completions.
---
 Completion/BSD/Command/_cu       |  2 +-
 Completion/Unix/Command/_gdb     |  4 +--
 Completion/Unix/Command/_joe     |  2 +-
 Completion/Unix/Command/_picocom | 27 +--------------
 Completion/Unix/Command/_screen  |  2 +-
 Completion/Unix/Type/_baudrate   | 73 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 78 insertions(+), 32 deletions(-)
 create mode 100644 Completion/Unix/Type/_baudrate

diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
index bdd5795..4b9f25d 100644
--- a/Completion/BSD/Command/_cu
+++ b/Completion/BSD/Command/_cu
@@ -3,5 +3,5 @@
 _arguments -s -A '-*' \
   '-d[do not block waiting for a carrier to be detected]' \
   '-l[line to use]:line:(/dev/(cuaU#<->|ttyS<->)(N%c))' \
-  '-s[line speed]:line speed:(75 110 300 1200 2400 4800 9600 19200 38400 57600 115200)' \
+  '-s[line speed]:line speed:_baudrate -d "line speed"' \
   '(-*)1:host:'
diff --git a/Completion/Unix/Command/_gdb b/Completion/Unix/Command/_gdb
index e9c3339..d5eed5a 100644
--- a/Completion/Unix/Command/_gdb
+++ b/Completion/Unix/Command/_gdb
@@ -37,9 +37,7 @@ else
   (-[csx]) _files && return 0 ;;
   (-e)     _description files expl executable
            _files "$expl[@]" -g '*(-*)' && return 0 ;;
-  (-b)     _wanted -V values expl 'baud rate' \
-               compadd 0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 \
-		       9600 19200 38400 57600 115200 230400 && return 0 ;;
+  (-b)     _baudrate && return 0 ;;
   esac
 
   w=( "${(@)words[2,-1]}" )
diff --git a/Completion/Unix/Command/_joe b/Completion/Unix/Command/_joe
index 96ad0a4..4e5b43b 100644
--- a/Completion/Unix/Command/_joe
+++ b/Completion/Unix/Command/_joe
@@ -3,7 +3,7 @@
 _arguments \
   '-asis[characters with codes >127 will be displayed non-inverted]' \
   '-backpath[backup file directory]:backup file directory:_files -/' \
-  '-baud[inserts delays for baud rates below 19200]:baud rate:(57600 38400 19200 9600 4800 2400 1200 300)' \
+  '-baud[inserts delays for baud rates below 19200]:baud rate:_baudrate' \
   '-beep[beep on command errors or when cursor goes past extremes]' \
   '-columns[sets the number of screen columns]:num of columns' \
   '-csmode[continued search mode]' \
diff --git a/Completion/Unix/Command/_picocom b/Completion/Unix/Command/_picocom
index 6653bc2..c9d3be0 100644
--- a/Completion/Unix/Command/_picocom
+++ b/Completion/Unix/Command/_picocom
@@ -1,30 +1,5 @@
 #compdef picocom
 
-# The following function uses a generated list; first find out where the B*
-# macros are defined:
-#
-#   grep -r B115200 /usr/include
-#
-# Then generate the actual list:
-#
-#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
-#           < /usr/include/asm-generic/termbits.h
-#
-# This one was generated on a Debian Stretch system, leaving out the "0" rate,
-# which is synonymous to "hang-up".
-function _picocom_baudrate () {
-    local expl
-    local -a rates
-    rates=( 50 75 110 134 150 200 300 600
-            1200 1800 2400 4800 9600
-            19200 38400 57600
-            115200 230400 460800 500000 576000 921600
-            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
-    # -1V removes dupes (which there shouldn't be) and otherwise leaves the
-    # order in the $rates array intact.
-    _wanted -1V baud-rate expl 'baud rate' compadd -a $expl -- rates
-}
-
 function _picocom_flowcontrol () {
     local expl
     local -a modes
@@ -57,7 +32,7 @@ function _picocom_escape () {
 function _picocom () {
     local -a args
 
-    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_picocom_baudrate'
+    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_baudrate'
            '(--flow -f)'{--flow,-f}'[define type of flow control to use]:flow control:_picocom_flowcontrol'
            '(--parity -p)'{--parity,-p}'[define type of parity to use]:parity mode:_picocom_paritymode'
            '(--databits -d)'{--databits,-d}'[define the number of databits per word]:data bits:_picocom_databits'
diff --git a/Completion/Unix/Command/_screen b/Completion/Unix/Command/_screen
index 510fd71..f4d2ef9 100644
--- a/Completion/Unix/Command/_screen
+++ b/Completion/Unix/Command/_screen
@@ -99,7 +99,7 @@ if [[ -n $state ]]; then
       if (( CURRENT == 1 )) && [[ $PREFIX == /dev/* ]]; then
 	  _path_files -g '*(%)'
       elif (( CURRENT == 2 )) && [[ ${words[1]} == /dev/* ]]; then
-	  _message "baud rate"
+	  _baudrate
       elif (( CURRENT > 2 )) && [[ ${words[1]} == /dev/* ]]; then
 	  _message "no more parameters"
       else
diff --git a/Completion/Unix/Type/_baudrate b/Completion/Unix/Type/_baudrate
new file mode 100644
index 0000000..093e42d
--- /dev/null
+++ b/Completion/Unix/Type/_baudrate
@@ -0,0 +1,73 @@
+#autoload
+
+# Offer a list of baud-rates. Usage:
+#
+#   _baudrate [OPTION(s)...]
+#
+# Available options:
+#
+#     -u LIMIT     Upper limit. LIMIT is the maximum value the offered list
+#                  will contain, if the complete list includes LIMIT exactly.
+#
+#     -l LIMIT     Lower limit. Like -u but for the lower boundary.
+#
+#     -f FUNCTION  If given FUNCION is used as a predicate to filter the
+#                  value in the complete list to generate an arbitrary
+#                  sub-set.
+#
+#     -t TAG       Use TAG as the tag value in _wanted call.
+#
+#     -d DESC      Use DESC as the description value in _wanted call.
+#
+# The default complete list of available baud rates is also configurable via
+# the 'baud-rates' style:
+#
+#   zstyle ':completion:*' baud-rates 23 42 666
+
+local -A opts
+local expl tag desc
+local -a rates
+
+zparseopts -E -A opts u: l: f:
+
+# The following uses a generated list; first find out where the B* macros are
+# defined:
+#
+#   grep -r B115200 /usr/include
+#
+# Then generate the actual list:
+#
+#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
+#           < /usr/include/asm-generic/termbits.h
+#
+# This one was generated on a Debian Stretch system, leaving out the "0" rate,
+# which is synonymous to "hang-up".
+
+zstyle -a ":completion:${curcontext}:" baud-rates rates ||
+    rates=( 50 75 110 134 150 200 300 600
+            1200 1800 2400 4800 9600
+            19200 38400 57600
+            115200 230400 460800 500000 576000 921600
+            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
+
+if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then
+    local -i min max
+    min=${opts[-l]:-0}
+    max=${opts[-u]:-${${(On)rates}[1]}}
+    rates=( ${(M)rates:#${~:-<$min-$max>}} )
+fi
+
+if (( ${+opts[-f]} )); then
+    set -- $rates
+    rates=( )
+    for item; do
+        ${opts[-f]} $item && rates+=( $item )
+    done
+fi
+
+tag=${opts[-t]:-baud-rate}
+desc=${opts[-d]:-baud rate}
+
+# -1V removes dupes (which there shouldn't be) and otherwise leaves the
+# order in the $rates array intact.
+_wanted -1V $tag expl $desc compadd -a $expl -- rates
-- 
2.8.1


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

* [PATCH] Refactor baud rate completion
  2016-05-01 10:57   ` Frank Terbeck
@ 2016-05-01 12:47     ` Frank Terbeck
  2016-05-01 13:14     ` [PATCHv2] " Frank Terbeck
  2016-05-01 13:27     ` [PATCHv3] " Frank Terbeck
  2 siblings, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-01 12:47 UTC (permalink / raw)
  To: zsh-workers; +Cc: Ryan Wilson

This adds a new helper function _baudrate and uses it in place of
private solutions in various existing completions.
---
  So I'm embracing my mistake and expose the filtering options
  to the user via styles. That way the user always has the final
  say in which baud rates are available. Now callers of _baudrate
  can define default filters if they want to and the user can
  override those if he/she so desires.

 Completion/BSD/Command/_cu       |  2 +-
 Completion/Unix/Command/_gdb     |  4 +-
 Completion/Unix/Command/_joe     |  2 +-
 Completion/Unix/Command/_picocom | 27 +------------
 Completion/Unix/Command/_screen  |  2 +-
 Completion/Unix/Type/_baudrate   | 84 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 89 insertions(+), 32 deletions(-)
 create mode 100644 Completion/Unix/Type/_baudrate

diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
index bdd5795..4b9f25d 100644
--- a/Completion/BSD/Command/_cu
+++ b/Completion/BSD/Command/_cu
@@ -3,5 +3,5 @@
 _arguments -s -A '-*' \
   '-d[do not block waiting for a carrier to be detected]' \
   '-l[line to use]:line:(/dev/(cuaU#<->|ttyS<->)(N%c))' \
-  '-s[line speed]:line speed:(75 110 300 1200 2400 4800 9600 19200 38400 57600 115200)' \
+  '-s[line speed]:line speed:_baudrate -d "line speed"' \
   '(-*)1:host:'
diff --git a/Completion/Unix/Command/_gdb b/Completion/Unix/Command/_gdb
index e9c3339..d5eed5a 100644
--- a/Completion/Unix/Command/_gdb
+++ b/Completion/Unix/Command/_gdb
@@ -37,9 +37,7 @@ else
   (-[csx]) _files && return 0 ;;
   (-e)     _description files expl executable
            _files "$expl[@]" -g '*(-*)' && return 0 ;;
-  (-b)     _wanted -V values expl 'baud rate' \
-               compadd 0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 \
-		       9600 19200 38400 57600 115200 230400 && return 0 ;;
+  (-b)     _baudrate && return 0 ;;
   esac
 
   w=( "${(@)words[2,-1]}" )
diff --git a/Completion/Unix/Command/_joe b/Completion/Unix/Command/_joe
index 96ad0a4..4e5b43b 100644
--- a/Completion/Unix/Command/_joe
+++ b/Completion/Unix/Command/_joe
@@ -3,7 +3,7 @@
 _arguments \
   '-asis[characters with codes >127 will be displayed non-inverted]' \
   '-backpath[backup file directory]:backup file directory:_files -/' \
-  '-baud[inserts delays for baud rates below 19200]:baud rate:(57600 38400 19200 9600 4800 2400 1200 300)' \
+  '-baud[inserts delays for baud rates below 19200]:baud rate:_baudrate -u 19199' \
   '-beep[beep on command errors or when cursor goes past extremes]' \
   '-columns[sets the number of screen columns]:num of columns' \
   '-csmode[continued search mode]' \
diff --git a/Completion/Unix/Command/_picocom b/Completion/Unix/Command/_picocom
index 6653bc2..c9d3be0 100644
--- a/Completion/Unix/Command/_picocom
+++ b/Completion/Unix/Command/_picocom
@@ -1,30 +1,5 @@
 #compdef picocom
 
-# The following function uses a generated list; first find out where the B*
-# macros are defined:
-#
-#   grep -r B115200 /usr/include
-#
-# Then generate the actual list:
-#
-#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
-#           < /usr/include/asm-generic/termbits.h
-#
-# This one was generated on a Debian Stretch system, leaving out the "0" rate,
-# which is synonymous to "hang-up".
-function _picocom_baudrate () {
-    local expl
-    local -a rates
-    rates=( 50 75 110 134 150 200 300 600
-            1200 1800 2400 4800 9600
-            19200 38400 57600
-            115200 230400 460800 500000 576000 921600
-            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
-    # -1V removes dupes (which there shouldn't be) and otherwise leaves the
-    # order in the $rates array intact.
-    _wanted -1V baud-rate expl 'baud rate' compadd -a $expl -- rates
-}
-
 function _picocom_flowcontrol () {
     local expl
     local -a modes
@@ -57,7 +32,7 @@ function _picocom_escape () {
 function _picocom () {
     local -a args
 
-    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_picocom_baudrate'
+    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_baudrate'
            '(--flow -f)'{--flow,-f}'[define type of flow control to use]:flow control:_picocom_flowcontrol'
            '(--parity -p)'{--parity,-p}'[define type of parity to use]:parity mode:_picocom_paritymode'
            '(--databits -d)'{--databits,-d}'[define the number of databits per word]:data bits:_picocom_databits'
diff --git a/Completion/Unix/Command/_screen b/Completion/Unix/Command/_screen
index 510fd71..f4d2ef9 100644
--- a/Completion/Unix/Command/_screen
+++ b/Completion/Unix/Command/_screen
@@ -99,7 +99,7 @@ if [[ -n $state ]]; then
       if (( CURRENT == 1 )) && [[ $PREFIX == /dev/* ]]; then
 	  _path_files -g '*(%)'
       elif (( CURRENT == 2 )) && [[ ${words[1]} == /dev/* ]]; then
-	  _message "baud rate"
+	  _baudrate
       elif (( CURRENT > 2 )) && [[ ${words[1]} == /dev/* ]]; then
 	  _message "no more parameters"
       else
diff --git a/Completion/Unix/Type/_baudrate b/Completion/Unix/Type/_baudrate
new file mode 100644
index 0000000..3d141dc
--- /dev/null
+++ b/Completion/Unix/Type/_baudrate
@@ -0,0 +1,84 @@
+#autoload
+
+# Offer a list of baud-rates. Usage:
+#
+#   _baudrate [OPTION(s)...]
+#
+# Available options:
+#
+#     -u LIMIT     Upper limit. LIMIT is the maximum value the offered list
+#                  will contain, if the complete list includes LIMIT exactly.
+#
+#     -l LIMIT     Lower limit. Like -u but for the lower boundary.
+#
+#     -f FUNCTION  If given FUNCION is used as a predicate to filter the
+#                  value in the complete list to generate an arbitrary
+#                  sub-set.
+#
+#     -t TAG       Use TAG as the tag value in _wanted call.
+#
+#     -d DESC      Use DESC as the description value in _wanted call.
+#
+# The default complete list of available baud rates is also configurable via
+# the 'baud-rates' style:
+#
+#   zstyle ':completion:*' baud-rates 23 42 666
+#
+# It is also possible to override the arguments to -f, -u and -l via styles in
+# a similar fashion:
+#
+#   zstyle ':completion:*:*:screen:*' max-baud-rate 9600
+#   zstyle ':completion:*:*:screen:*' min-baud-rate 1200
+#   zstyle ':completion:*:*:screen:*' baud-filter some_function_name
+
+local -A opts
+local expl tag desc tmp
+local -a rates
+
+zparseopts -E -A opts u: l: f:
+
+# The following uses a generated list; first find out where the B* macros are
+# defined:
+#
+#   grep -r B115200 /usr/include
+#
+# Then generate the actual list:
+#
+#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
+#           < /usr/include/asm-generic/termbits.h
+#
+# This one was generated on a Debian Stretch system, leaving out the "0" rate,
+# which is synonymous to "hang-up".
+
+zstyle -a ":completion:${curcontext}:" baud-rates rates ||
+    rates=( 50 75 110 134 150 200 300 600
+            1200 1800 2400 4800 9600
+            19200 38400 57600
+            115200 230400 460800 500000 576000 921600
+            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
+
+zstyle -s ":completion:${curcontext}:" max-baud-rate tmp && opts[-u]=$tmp
+zstyle -s ":completion:${curcontext}:" min-baud-rate tmp && opts[-l]=$tmp
+zstyle -s ":completion:${curcontext}:" baud-rate-filter tmp && opts[-f]=$tmp
+
+if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then
+    local -i min max
+    min=${opts[-l]:-0}
+    max=${opts[-u]:-${${(On)rates}[1]}}
+    rates=( ${(M)rates:#${~:-<$min-$max>}} )
+fi
+
+if (( ${+opts[-f]} )); then
+    set -- $rates
+    rates=( )
+    for item; do
+        ${opts[-f]} $item && rates+=( $item )
+    done
+fi
+
+tag=${opts[-t]:-baud-rate}
+desc=${opts[-d]:-baud rate}
+
+# -1V removes dupes (which there shouldn't be) and otherwise leaves the
+# order in the $rates array intact.
+_wanted -1V $tag expl $desc compadd -a $expl -- rates
-- 
2.8.1


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

* [PATCHv2] Refactor baud rate completion
  2016-05-01 10:57   ` Frank Terbeck
  2016-05-01 12:47     ` [PATCH] Refactor baud rate completion Frank Terbeck
@ 2016-05-01 13:14     ` Frank Terbeck
  2016-05-01 13:27     ` [PATCHv3] " Frank Terbeck
  2 siblings, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-01 13:14 UTC (permalink / raw)
  To: zsh-workers; +Cc: Ryan Wilson

This adds a new helper function _baudrate and uses it in place of
private solutions in various existing completions.
---
  This is just the same as my previous patch, except that it
  doesn't have a special treatment in _joe, which I previously
  left in by mistake.

 Completion/BSD/Command/_cu       |  2 +-
 Completion/Unix/Command/_gdb     |  4 +-
 Completion/Unix/Command/_joe     |  2 +-
 Completion/Unix/Command/_picocom | 27 +------------
 Completion/Unix/Command/_screen  |  2 +-
 Completion/Unix/Type/_baudrate   | 84 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 89 insertions(+), 32 deletions(-)
 create mode 100644 Completion/Unix/Type/_baudrate

diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
index bdd5795..4b9f25d 100644
--- a/Completion/BSD/Command/_cu
+++ b/Completion/BSD/Command/_cu
@@ -3,5 +3,5 @@
 _arguments -s -A '-*' \
   '-d[do not block waiting for a carrier to be detected]' \
   '-l[line to use]:line:(/dev/(cuaU#<->|ttyS<->)(N%c))' \
-  '-s[line speed]:line speed:(75 110 300 1200 2400 4800 9600 19200 38400 57600 115200)' \
+  '-s[line speed]:line speed:_baudrate -d "line speed"' \
   '(-*)1:host:'
diff --git a/Completion/Unix/Command/_gdb b/Completion/Unix/Command/_gdb
index e9c3339..d5eed5a 100644
--- a/Completion/Unix/Command/_gdb
+++ b/Completion/Unix/Command/_gdb
@@ -37,9 +37,7 @@ else
   (-[csx]) _files && return 0 ;;
   (-e)     _description files expl executable
            _files "$expl[@]" -g '*(-*)' && return 0 ;;
-  (-b)     _wanted -V values expl 'baud rate' \
-               compadd 0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 \
-		       9600 19200 38400 57600 115200 230400 && return 0 ;;
+  (-b)     _baudrate && return 0 ;;
   esac
 
   w=( "${(@)words[2,-1]}" )
diff --git a/Completion/Unix/Command/_joe b/Completion/Unix/Command/_joe
index 96ad0a4..91c437e 100644
--- a/Completion/Unix/Command/_joe
+++ b/Completion/Unix/Command/_joe
@@ -3,7 +3,7 @@
 _arguments \
   '-asis[characters with codes >127 will be displayed non-inverted]' \
   '-backpath[backup file directory]:backup file directory:_files -/' \
-  '-baud[inserts delays for baud rates below 19200]:baud rate:(57600 38400 19200 9600 4800 2400 1200 300)' \
+  '-baud[inserts delays for baud rates below 19200]:baud rate:_baudrate' \
   '-beep[beep on command errors or when cursor goes past extremes]' \
   '-columns[sets the number of screen columns]:num of columns' \
   '-csmode[continued search mode]' \
diff --git a/Completion/Unix/Command/_picocom b/Completion/Unix/Command/_picocom
index 6653bc2..c9d3be0 100644
--- a/Completion/Unix/Command/_picocom
+++ b/Completion/Unix/Command/_picocom
@@ -1,30 +1,5 @@
 #compdef picocom
 
-# The following function uses a generated list; first find out where the B*
-# macros are defined:
-#
-#   grep -r B115200 /usr/include
-#
-# Then generate the actual list:
-#
-#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
-#           < /usr/include/asm-generic/termbits.h
-#
-# This one was generated on a Debian Stretch system, leaving out the "0" rate,
-# which is synonymous to "hang-up".
-function _picocom_baudrate () {
-    local expl
-    local -a rates
-    rates=( 50 75 110 134 150 200 300 600
-            1200 1800 2400 4800 9600
-            19200 38400 57600
-            115200 230400 460800 500000 576000 921600
-            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
-    # -1V removes dupes (which there shouldn't be) and otherwise leaves the
-    # order in the $rates array intact.
-    _wanted -1V baud-rate expl 'baud rate' compadd -a $expl -- rates
-}
-
 function _picocom_flowcontrol () {
     local expl
     local -a modes
@@ -57,7 +32,7 @@ function _picocom_escape () {
 function _picocom () {
     local -a args
 
-    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_picocom_baudrate'
+    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_baudrate'
            '(--flow -f)'{--flow,-f}'[define type of flow control to use]:flow control:_picocom_flowcontrol'
            '(--parity -p)'{--parity,-p}'[define type of parity to use]:parity mode:_picocom_paritymode'
            '(--databits -d)'{--databits,-d}'[define the number of databits per word]:data bits:_picocom_databits'
diff --git a/Completion/Unix/Command/_screen b/Completion/Unix/Command/_screen
index 510fd71..f4d2ef9 100644
--- a/Completion/Unix/Command/_screen
+++ b/Completion/Unix/Command/_screen
@@ -99,7 +99,7 @@ if [[ -n $state ]]; then
       if (( CURRENT == 1 )) && [[ $PREFIX == /dev/* ]]; then
 	  _path_files -g '*(%)'
       elif (( CURRENT == 2 )) && [[ ${words[1]} == /dev/* ]]; then
-	  _message "baud rate"
+	  _baudrate
       elif (( CURRENT > 2 )) && [[ ${words[1]} == /dev/* ]]; then
 	  _message "no more parameters"
       else
diff --git a/Completion/Unix/Type/_baudrate b/Completion/Unix/Type/_baudrate
new file mode 100644
index 0000000..3d141dc
--- /dev/null
+++ b/Completion/Unix/Type/_baudrate
@@ -0,0 +1,84 @@
+#autoload
+
+# Offer a list of baud-rates. Usage:
+#
+#   _baudrate [OPTION(s)...]
+#
+# Available options:
+#
+#     -u LIMIT     Upper limit. LIMIT is the maximum value the offered list
+#                  will contain, if the complete list includes LIMIT exactly.
+#
+#     -l LIMIT     Lower limit. Like -u but for the lower boundary.
+#
+#     -f FUNCTION  If given FUNCION is used as a predicate to filter the
+#                  value in the complete list to generate an arbitrary
+#                  sub-set.
+#
+#     -t TAG       Use TAG as the tag value in _wanted call.
+#
+#     -d DESC      Use DESC as the description value in _wanted call.
+#
+# The default complete list of available baud rates is also configurable via
+# the 'baud-rates' style:
+#
+#   zstyle ':completion:*' baud-rates 23 42 666
+#
+# It is also possible to override the arguments to -f, -u and -l via styles in
+# a similar fashion:
+#
+#   zstyle ':completion:*:*:screen:*' max-baud-rate 9600
+#   zstyle ':completion:*:*:screen:*' min-baud-rate 1200
+#   zstyle ':completion:*:*:screen:*' baud-filter some_function_name
+
+local -A opts
+local expl tag desc tmp
+local -a rates
+
+zparseopts -E -A opts u: l: f:
+
+# The following uses a generated list; first find out where the B* macros are
+# defined:
+#
+#   grep -r B115200 /usr/include
+#
+# Then generate the actual list:
+#
+#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
+#           < /usr/include/asm-generic/termbits.h
+#
+# This one was generated on a Debian Stretch system, leaving out the "0" rate,
+# which is synonymous to "hang-up".
+
+zstyle -a ":completion:${curcontext}:" baud-rates rates ||
+    rates=( 50 75 110 134 150 200 300 600
+            1200 1800 2400 4800 9600
+            19200 38400 57600
+            115200 230400 460800 500000 576000 921600
+            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
+
+zstyle -s ":completion:${curcontext}:" max-baud-rate tmp && opts[-u]=$tmp
+zstyle -s ":completion:${curcontext}:" min-baud-rate tmp && opts[-l]=$tmp
+zstyle -s ":completion:${curcontext}:" baud-rate-filter tmp && opts[-f]=$tmp
+
+if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then
+    local -i min max
+    min=${opts[-l]:-0}
+    max=${opts[-u]:-${${(On)rates}[1]}}
+    rates=( ${(M)rates:#${~:-<$min-$max>}} )
+fi
+
+if (( ${+opts[-f]} )); then
+    set -- $rates
+    rates=( )
+    for item; do
+        ${opts[-f]} $item && rates+=( $item )
+    done
+fi
+
+tag=${opts[-t]:-baud-rate}
+desc=${opts[-d]:-baud rate}
+
+# -1V removes dupes (which there shouldn't be) and otherwise leaves the
+# order in the $rates array intact.
+_wanted -1V $tag expl $desc compadd -a $expl -- rates
-- 
2.8.1


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

* [PATCHv3] Refactor baud rate completion
  2016-05-01 10:57   ` Frank Terbeck
  2016-05-01 12:47     ` [PATCH] Refactor baud rate completion Frank Terbeck
  2016-05-01 13:14     ` [PATCHv2] " Frank Terbeck
@ 2016-05-01 13:27     ` Frank Terbeck
  2016-05-01 22:21       ` Frank Terbeck
  2016-05-02 12:55       ` Oliver Kiddle
  2 siblings, 2 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-01 13:27 UTC (permalink / raw)
  To: zsh-workers; +Cc: Ryan Wilson

This adds a new helper function _baudrate and uses it in place of
private solutions in various existing completions.
---
  Okay, seems like I am flooding -workers now. I tested the code
  a little more and it seems that in

    _baudrate -d "line speed"

  in _cu, the -s option was not respected. That was because I
  didn't add -t and -d to zparseopts' spec when I added them.

  This revised patch fixes that. I hope this is the last
  iteration and if so I'll push it in a bit.

 Completion/BSD/Command/_cu       |  2 +-
 Completion/Unix/Command/_gdb     |  4 +-
 Completion/Unix/Command/_joe     |  2 +-
 Completion/Unix/Command/_picocom | 27 +------------
 Completion/Unix/Command/_screen  |  2 +-
 Completion/Unix/Type/_baudrate   | 84 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 89 insertions(+), 32 deletions(-)
 create mode 100644 Completion/Unix/Type/_baudrate

diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
index bdd5795..4b9f25d 100644
--- a/Completion/BSD/Command/_cu
+++ b/Completion/BSD/Command/_cu
@@ -3,5 +3,5 @@
 _arguments -s -A '-*' \
   '-d[do not block waiting for a carrier to be detected]' \
   '-l[line to use]:line:(/dev/(cuaU#<->|ttyS<->)(N%c))' \
-  '-s[line speed]:line speed:(75 110 300 1200 2400 4800 9600 19200 38400 57600 115200)' \
+  '-s[line speed]:line speed:_baudrate -d "line speed"' \
   '(-*)1:host:'
diff --git a/Completion/Unix/Command/_gdb b/Completion/Unix/Command/_gdb
index e9c3339..d5eed5a 100644
--- a/Completion/Unix/Command/_gdb
+++ b/Completion/Unix/Command/_gdb
@@ -37,9 +37,7 @@ else
   (-[csx]) _files && return 0 ;;
   (-e)     _description files expl executable
            _files "$expl[@]" -g '*(-*)' && return 0 ;;
-  (-b)     _wanted -V values expl 'baud rate' \
-               compadd 0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 \
-		       9600 19200 38400 57600 115200 230400 && return 0 ;;
+  (-b)     _baudrate && return 0 ;;
   esac
 
   w=( "${(@)words[2,-1]}" )
diff --git a/Completion/Unix/Command/_joe b/Completion/Unix/Command/_joe
index 96ad0a4..91c437e 100644
--- a/Completion/Unix/Command/_joe
+++ b/Completion/Unix/Command/_joe
@@ -3,7 +3,7 @@
 _arguments \
   '-asis[characters with codes >127 will be displayed non-inverted]' \
   '-backpath[backup file directory]:backup file directory:_files -/' \
-  '-baud[inserts delays for baud rates below 19200]:baud rate:(57600 38400 19200 9600 4800 2400 1200 300)' \
+  '-baud[inserts delays for baud rates below 19200]:baud rate:_baudrate' \
   '-beep[beep on command errors or when cursor goes past extremes]' \
   '-columns[sets the number of screen columns]:num of columns' \
   '-csmode[continued search mode]' \
diff --git a/Completion/Unix/Command/_picocom b/Completion/Unix/Command/_picocom
index 6653bc2..c9d3be0 100644
--- a/Completion/Unix/Command/_picocom
+++ b/Completion/Unix/Command/_picocom
@@ -1,30 +1,5 @@
 #compdef picocom
 
-# The following function uses a generated list; first find out where the B*
-# macros are defined:
-#
-#   grep -r B115200 /usr/include
-#
-# Then generate the actual list:
-#
-#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
-#           < /usr/include/asm-generic/termbits.h
-#
-# This one was generated on a Debian Stretch system, leaving out the "0" rate,
-# which is synonymous to "hang-up".
-function _picocom_baudrate () {
-    local expl
-    local -a rates
-    rates=( 50 75 110 134 150 200 300 600
-            1200 1800 2400 4800 9600
-            19200 38400 57600
-            115200 230400 460800 500000 576000 921600
-            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
-    # -1V removes dupes (which there shouldn't be) and otherwise leaves the
-    # order in the $rates array intact.
-    _wanted -1V baud-rate expl 'baud rate' compadd -a $expl -- rates
-}
-
 function _picocom_flowcontrol () {
     local expl
     local -a modes
@@ -57,7 +32,7 @@ function _picocom_escape () {
 function _picocom () {
     local -a args
 
-    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_picocom_baudrate'
+    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_baudrate'
            '(--flow -f)'{--flow,-f}'[define type of flow control to use]:flow control:_picocom_flowcontrol'
            '(--parity -p)'{--parity,-p}'[define type of parity to use]:parity mode:_picocom_paritymode'
            '(--databits -d)'{--databits,-d}'[define the number of databits per word]:data bits:_picocom_databits'
diff --git a/Completion/Unix/Command/_screen b/Completion/Unix/Command/_screen
index 510fd71..f4d2ef9 100644
--- a/Completion/Unix/Command/_screen
+++ b/Completion/Unix/Command/_screen
@@ -99,7 +99,7 @@ if [[ -n $state ]]; then
       if (( CURRENT == 1 )) && [[ $PREFIX == /dev/* ]]; then
 	  _path_files -g '*(%)'
       elif (( CURRENT == 2 )) && [[ ${words[1]} == /dev/* ]]; then
-	  _message "baud rate"
+	  _baudrate
       elif (( CURRENT > 2 )) && [[ ${words[1]} == /dev/* ]]; then
 	  _message "no more parameters"
       else
diff --git a/Completion/Unix/Type/_baudrate b/Completion/Unix/Type/_baudrate
new file mode 100644
index 0000000..df30960
--- /dev/null
+++ b/Completion/Unix/Type/_baudrate
@@ -0,0 +1,84 @@
+#autoload
+
+# Offer a list of baud-rates. Usage:
+#
+#   _baudrate [OPTION(s)...]
+#
+# Available options:
+#
+#     -u LIMIT     Upper limit. LIMIT is the maximum value the offered list
+#                  will contain, if the complete list includes LIMIT exactly.
+#
+#     -l LIMIT     Lower limit. Like -u but for the lower boundary.
+#
+#     -f FUNCTION  If given FUNCION is used as a predicate to filter the
+#                  value in the complete list to generate an arbitrary
+#                  sub-set.
+#
+#     -t TAG       Use TAG as the tag value in _wanted call.
+#
+#     -d DESC      Use DESC as the description value in _wanted call.
+#
+# The default complete list of available baud rates is also configurable via
+# the 'baud-rates' style:
+#
+#   zstyle ':completion:*' baud-rates 23 42 666
+#
+# It is also possible to override the arguments to -f, -u and -l via styles in
+# a similar fashion:
+#
+#   zstyle ':completion:*:*:screen:*' max-baud-rate 9600
+#   zstyle ':completion:*:*:screen:*' min-baud-rate 1200
+#   zstyle ':completion:*:*:screen:*' baud-filter some_function_name
+
+local -A opts
+local expl tag desc tmp
+local -a rates
+
+zparseopts -E -A opts u: l: f: d: t:
+
+# The following uses a generated list; first find out where the B* macros are
+# defined:
+#
+#   grep -r B115200 /usr/include
+#
+# Then generate the actual list:
+#
+#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
+#           < /usr/include/asm-generic/termbits.h
+#
+# This one was generated on a Debian Stretch system, leaving out the "0" rate,
+# which is synonymous to "hang-up".
+
+zstyle -a ":completion:${curcontext}:" baud-rates rates ||
+    rates=( 50 75 110 134 150 200 300 600
+            1200 1800 2400 4800 9600
+            19200 38400 57600
+            115200 230400 460800 500000 576000 921600
+            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
+
+zstyle -s ":completion:${curcontext}:" max-baud-rate tmp && opts[-u]=$tmp
+zstyle -s ":completion:${curcontext}:" min-baud-rate tmp && opts[-l]=$tmp
+zstyle -s ":completion:${curcontext}:" baud-rate-filter tmp && opts[-f]=$tmp
+
+if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then
+    local -i min max
+    min=${opts[-l]:-0}
+    max=${opts[-u]:-${${(On)rates}[1]}}
+    rates=( ${(M)rates:#${~:-<$min-$max>}} )
+fi
+
+if (( ${+opts[-f]} )); then
+    set -- $rates
+    rates=( )
+    for item; do
+        ${opts[-f]} $item && rates+=( $item )
+    done
+fi
+
+tag=${opts[-t]:-baud-rate}
+desc=${opts[-d]:-baud rate}
+
+# -1V removes dupes (which there shouldn't be) and otherwise leaves the
+# order in the $rates array intact.
+_wanted -1V $tag expl $desc compadd -a $expl -- rates
-- 
2.8.1


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

* Re: [PATCHv3] Refactor baud rate completion
  2016-05-01 13:27     ` [PATCHv3] " Frank Terbeck
@ 2016-05-01 22:21       ` Frank Terbeck
  2016-05-02 12:55       ` Oliver Kiddle
  1 sibling, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-01 22:21 UTC (permalink / raw)
  To: zsh-workers; +Cc: Ryan Wilson

Frank Terbeck wrote:
[...]
>   This revised patch fixes that. I hope this is the last
>   iteration and if so I'll push it in a bit.
>
>  Completion/BSD/Command/_cu       |  2 +-
>  Completion/Unix/Command/_gdb     |  4 +-
>  Completion/Unix/Command/_joe     |  2 +-
>  Completion/Unix/Command/_picocom | 27 +------------
>  Completion/Unix/Command/_screen  |  2 +-
>  Completion/Unix/Type/_baudrate   | 84 ++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 89 insertions(+), 32 deletions(-)
>  create mode 100644 Completion/Unix/Type/_baudrate
[...]

So that's what I did. I've been playing with it for a while and it seems
to work. If anyone needs to complete baud rates from now on, go ahead
and use this one. :)


Regards, Frank


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

* Re: [PATCHv3] Refactor baud rate completion
  2016-05-01 13:27     ` [PATCHv3] " Frank Terbeck
  2016-05-01 22:21       ` Frank Terbeck
@ 2016-05-02 12:55       ` Oliver Kiddle
  2016-05-03 21:01         ` Frank Terbeck
                           ` (2 more replies)
  1 sibling, 3 replies; 19+ messages in thread
From: Oliver Kiddle @ 2016-05-02 12:55 UTC (permalink / raw)
  To: zsh-workers

Frank Terbeck wrote:
> This adds a new helper function _baudrate and uses it in place of
> private solutions in various existing completions.

Some comments on this: the normal convention is for helper functions
to have plural names. The logic being that all baud rates are added
as matches. So this should be named _baudrates or _baud_rates.

Secondly, the convention for completion functions is two spaces for
indentation. See Etc/completion-style-guide. Annoyingly, there's quite a
few functions that don't follow this but it'd be nice if we could avoid
adding more.

> +#     -t TAG       Use TAG as the tag value in _wanted call.
> +#
> +#     -d DESC      Use DESC as the description value in _wanted call.

It is usually more flexible to just accept normal compadd options for
descriptions and tags and pass them on to compadd fairly directly. It
then will work in conjunction with other helpers like _alternative.
_pdf is a good example. Using _wanted here isn't entirely necessary:
_description would be sufficient and avoids nesting tag loops.

> +# It is also possible to override the arguments to -f, -u and -l via styles in
> +# a similar fashion:
> +#
> +#   zstyle ':completion:*:*:screen:*' max-baud-rate 9600
> +#   zstyle ':completion:*:*:screen:*' min-baud-rate 1200
> +#   zstyle ':completion:*:*:screen:*' baud-filter some_function_name

The original concept with styles was that style's could have fairly
generic names because the context allows you to select the detailed
context. So perhaps consider allowing this to work as, for example:
  zstyle ':completion:*:*:screen:*:baud-rates' max-value 9600

Oliver


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

* Re: [PATCHv3] Refactor baud rate completion
  2016-05-02 12:55       ` Oliver Kiddle
@ 2016-05-03 21:01         ` Frank Terbeck
  2016-05-07 21:53         ` Frank Terbeck
  2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
  2 siblings, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-03 21:01 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

Hi Oliver,

thanks for taking your time to look over the code. I'll address these as
soon as I can, though on weekdays my spare time is severely limited at
the moment.


Oliver Kiddle wrote:
> Frank Terbeck wrote:
>> This adds a new helper function _baudrate and uses it in place of
>> private solutions in various existing completions.
>
> Some comments on this: the normal convention is for helper functions
> to have plural names. The logic being that all baud rates are added
> as matches. So this should be named _baudrates or _baud_rates.

Sure that's simple enough.

> Secondly, the convention for completion functions is two spaces for
> indentation. See Etc/completion-style-guide. Annoyingly, there's quite a
> few functions that don't follow this but it'd be nice if we could avoid
> adding more.

Huh. I wasn't aware of this one at all. But it's easy enough to fix.

>> +#     -t TAG       Use TAG as the tag value in _wanted call.
>> +#
>> +#     -d DESC      Use DESC as the description value in _wanted call.
>
> It is usually more flexible to just accept normal compadd options for
> descriptions and tags and pass them on to compadd fairly directly. It
> then will work in conjunction with other helpers like _alternative.
> _pdf is a good example. Using _wanted here isn't entirely necessary:
> _description would be sufficient and avoids nesting tag loops.

I'll take a look at _pdf and the possibility to use _description. I kind
of expected there to be a way to propagate stuff to compadd, but was too
lazy to find out. :)

>> +# It is also possible to override the arguments to -f, -u and -l via styles in
>> +# a similar fashion:
>> +#
>> +#   zstyle ':completion:*:*:screen:*' max-baud-rate 9600
>> +#   zstyle ':completion:*:*:screen:*' min-baud-rate 1200
>> +#   zstyle ':completion:*:*:screen:*' baud-filter some_function_name
>
> The original concept with styles was that style's could have fairly
> generic names because the context allows you to select the detailed
> context. So perhaps consider allowing this to work as, for example:
>   zstyle ':completion:*:*:screen:*:baud-rates' max-value 9600

Sounds reasonable. I'll take a look at this as well.


Regards, Frank


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

* Re: [PATCHv3] Refactor baud rate completion
  2016-05-02 12:55       ` Oliver Kiddle
  2016-05-03 21:01         ` Frank Terbeck
@ 2016-05-07 21:53         ` Frank Terbeck
  2016-05-11 15:08           ` Oliver Kiddle
  2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
  2 siblings, 1 reply; 19+ messages in thread
From: Frank Terbeck @ 2016-05-07 21:53 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

Oliver Kiddle wrote:
[...]
> It is usually more flexible to just accept normal compadd options for
> descriptions and tags and pass them on to compadd fairly directly. It
> then will work in conjunction with other helpers like _alternative.
> _pdf is a good example. Using _wanted here isn't entirely necessary:
> _description would be sufficient and avoids nesting tag loops.

So, _pdf does this:

    _description files expl 'PDF file'
    _files "$@" "$expl[@]" -g "*.(#i)pdf$ext(-.)"

which made me think that the following would be a reasonable call:

    _description -1V baud-rates expl 'baud rate'
    compadd "$@" "$expl[@]" -- "${rates[@]}"

Passing "$@" to compadd makes _arguments parameters like this work:

  '-s[line speed]:line speed:_baudrates' \

Because that makes the helper pass the -X ... option containing "line
speed" to compadd. However "$@" also contains -J option-s-1, which makes
compadd create a sorted group, which is not that useful here.

Passing -V to _description adds -V to "expl", but compadd seems to use
the first argument it finds. But I can't just put "$@" behind expl, in
the compadd call because in that case I won't get the description set in
the _arguments call, if _baudrates was called from _arguments.

I don't know if there is a simple way to make it work the way I'd like
(unsorted group as well as inheriting the right description), so I ended
up doing this:

    _description -1V baud-rates expl 'baud rate'
    compadd "${(@)argv/#-J/-V}" "$expl[@]" -- "${rates[@]}"

That feels pretty dirty, but it seems to work.

The completion-style-guide mentions the following:

    _description -1V tag expl '...'
    compadd "$expl[@]" - ...

But that would discard any descriptions given in an _arguments call.

Better ideas welcome.


Regards, Frank


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

* [PATCH 0/6] Update baud rate completion with Oliver's comments in mind
  2016-05-02 12:55       ` Oliver Kiddle
  2016-05-03 21:01         ` Frank Terbeck
  2016-05-07 21:53         ` Frank Terbeck
@ 2016-05-07 22:09         ` Frank Terbeck
  2016-05-07 22:09           ` [PATCH 1/6] _baudrate → _baudrates Frank Terbeck
                             ` (5 more replies)
  2 siblings, 6 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-07 22:09 UTC (permalink / raw)
  To: zsh-workers; +Cc: Oliver Kiddle

This should address Oliver's comments from workers-38390.

Frank Terbeck (6):
  _baudrate → _baudrates
  _baudrates: Use 2 space indentation
  Use _baudrates helper instead of _baudrate
  _baudrates: Fit better into the general completion framework
  _cu: Remove old -d option of _baudrates
  _baudrates: Make style lookups fit better with the rest of compsys

 Completion/BSD/Command/_cu       |  2 +-
 Completion/Unix/Command/_gdb     |  2 +-
 Completion/Unix/Command/_joe     |  2 +-
 Completion/Unix/Command/_picocom |  2 +-
 Completion/Unix/Command/_screen  |  2 +-
 Completion/Unix/Type/_baudrate   | 84 ----------------------------------------
 Completion/Unix/Type/_baudrates  | 78 +++++++++++++++++++++++++++++++++++++
 7 files changed, 83 insertions(+), 89 deletions(-)
 delete mode 100644 Completion/Unix/Type/_baudrate
 create mode 100644 Completion/Unix/Type/_baudrates

-- 
2.8.1


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

* [PATCH 1/6] _baudrate → _baudrates
  2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
@ 2016-05-07 22:09           ` Frank Terbeck
  2016-05-07 22:09           ` [PATCH 2/6] _baudrates: Use 2 space indentation Frank Terbeck
                             ` (4 subsequent siblings)
  5 siblings, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-07 22:09 UTC (permalink / raw)
  To: zsh-workers; +Cc: Oliver Kiddle

Oliver notes that helper functions usually have plural names by
convention.
---
 Completion/Unix/Type/_baudrate  | 84 -----------------------------------------
 Completion/Unix/Type/_baudrates | 84 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 84 deletions(-)
 delete mode 100644 Completion/Unix/Type/_baudrate
 create mode 100644 Completion/Unix/Type/_baudrates

diff --git a/Completion/Unix/Type/_baudrate b/Completion/Unix/Type/_baudrate
deleted file mode 100644
index c169284..0000000
--- a/Completion/Unix/Type/_baudrate
+++ /dev/null
@@ -1,84 +0,0 @@
-#autoload
-
-# Offer a list of baud-rates. Usage:
-#
-#   _baudrate [OPTION(s)...]
-#
-# Available options:
-#
-#     -u LIMIT     Upper limit. LIMIT is the maximum value the offered list
-#                  will contain, if the complete list includes LIMIT exactly.
-#
-#     -l LIMIT     Lower limit. Like -u but for the lower boundary.
-#
-#     -f FUNCTION  If given FUNCION is used as a predicate to filter the
-#                  value in the complete list to generate an arbitrary
-#                  sub-set.
-#
-#     -t TAG       Use TAG as the tag value in _wanted call.
-#
-#     -d DESC      Use DESC as the description value in _wanted call.
-#
-# The default complete list of available baud rates is also configurable via
-# the 'baud-rates' style:
-#
-#   zstyle ':completion:*' baud-rates 23 42 666
-#
-# It is also possible to override the arguments to -f, -u and -l via styles in
-# a similar fashion:
-#
-#   zstyle ':completion:*:*:screen:*' max-baud-rate 9600
-#   zstyle ':completion:*:*:screen:*' min-baud-rate 1200
-#   zstyle ':completion:*:*:screen:*' baud-rate-filter some_function_name
-
-local -A opts
-local expl tag desc tmp
-local -a rates
-
-zparseopts -E -A opts u: l: f: d: t:
-
-# The following uses a generated list; first find out where the B* macros are
-# defined:
-#
-#   grep -r B115200 /usr/include
-#
-# Then generate the actual list:
-#
-#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
-#           < /usr/include/asm-generic/termbits.h
-#
-# This one was generated on a Debian Stretch system, leaving out the "0" rate,
-# which is synonymous to "hang-up".
-
-zstyle -a ":completion:${curcontext}:" baud-rates rates ||
-    rates=( 50 75 110 134 150 200 300 600
-            1200 1800 2400 4800 9600
-            19200 38400 57600
-            115200 230400 460800 500000 576000 921600
-            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
-
-zstyle -s ":completion:${curcontext}:" max-baud-rate tmp && opts[-u]=$tmp
-zstyle -s ":completion:${curcontext}:" min-baud-rate tmp && opts[-l]=$tmp
-zstyle -s ":completion:${curcontext}:" baud-rate-filter tmp && opts[-f]=$tmp
-
-if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then
-    local -i min max
-    min=${opts[-l]:-0}
-    max=${opts[-u]:-${${(On)rates}[1]}}
-    rates=( ${(M)rates:#${~:-<$min-$max>}} )
-fi
-
-if (( ${+opts[-f]} )); then
-    set -- $rates
-    rates=( )
-    for item; do
-        ${opts[-f]} $item && rates+=( $item )
-    done
-fi
-
-tag=${opts[-t]:-baud-rate}
-desc=${opts[-d]:-baud rate}
-
-# -1V removes dupes (which there shouldn't be) and otherwise leaves the
-# order in the $rates array intact.
-_wanted -1V $tag expl $desc compadd -a $expl -- rates
diff --git a/Completion/Unix/Type/_baudrates b/Completion/Unix/Type/_baudrates
new file mode 100644
index 0000000..9e87e7a
--- /dev/null
+++ b/Completion/Unix/Type/_baudrates
@@ -0,0 +1,84 @@
+#autoload
+
+# Offer a list of baud-rates. Usage:
+#
+#   _baudrates [OPTION(s)...]
+#
+# Available options:
+#
+#     -u LIMIT     Upper limit. LIMIT is the maximum value the offered list
+#                  will contain, if the complete list includes LIMIT exactly.
+#
+#     -l LIMIT     Lower limit. Like -u but for the lower boundary.
+#
+#     -f FUNCTION  If given FUNCION is used as a predicate to filter the
+#                  value in the complete list to generate an arbitrary
+#                  sub-set.
+#
+#     -t TAG       Use TAG as the tag value in _wanted call.
+#
+#     -d DESC      Use DESC as the description value in _wanted call.
+#
+# The default complete list of available baud rates is also configurable via
+# the 'baud-rates' style:
+#
+#   zstyle ':completion:*' baud-rates 23 42 666
+#
+# It is also possible to override the arguments to -f, -u and -l via styles in
+# a similar fashion:
+#
+#   zstyle ':completion:*:*:screen:*' max-baud-rate 9600
+#   zstyle ':completion:*:*:screen:*' min-baud-rate 1200
+#   zstyle ':completion:*:*:screen:*' baud-rate-filter some_function_name
+
+local -A opts
+local expl tag desc tmp
+local -a rates
+
+zparseopts -E -A opts u: l: f: d: t:
+
+# The following uses a generated list; first find out where the B* macros are
+# defined:
+#
+#   grep -r B115200 /usr/include
+#
+# Then generate the actual list:
+#
+#   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
+#           < /usr/include/asm-generic/termbits.h
+#
+# This one was generated on a Debian Stretch system, leaving out the "0" rate,
+# which is synonymous to "hang-up".
+
+zstyle -a ":completion:${curcontext}:" baud-rates rates ||
+    rates=( 50 75 110 134 150 200 300 600
+            1200 1800 2400 4800 9600
+            19200 38400 57600
+            115200 230400 460800 500000 576000 921600
+            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
+
+zstyle -s ":completion:${curcontext}:" max-baud-rate tmp && opts[-u]=$tmp
+zstyle -s ":completion:${curcontext}:" min-baud-rate tmp && opts[-l]=$tmp
+zstyle -s ":completion:${curcontext}:" baud-rate-filter tmp && opts[-f]=$tmp
+
+if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then
+    local -i min max
+    min=${opts[-l]:-0}
+    max=${opts[-u]:-${${(On)rates}[1]}}
+    rates=( ${(M)rates:#${~:-<$min-$max>}} )
+fi
+
+if (( ${+opts[-f]} )); then
+    set -- $rates
+    rates=( )
+    for item; do
+        ${opts[-f]} $item && rates+=( $item )
+    done
+fi
+
+tag=${opts[-t]:-baud-rate}
+desc=${opts[-d]:-baud rate}
+
+# -1V removes dupes (which there shouldn't be) and otherwise leaves the
+# order in the $rates array intact.
+_wanted -1V $tag expl $desc compadd -a $expl -- rates
-- 
2.8.1


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

* [PATCH 2/6] _baudrates: Use 2 space indentation
  2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
  2016-05-07 22:09           ` [PATCH 1/6] _baudrate → _baudrates Frank Terbeck
@ 2016-05-07 22:09           ` Frank Terbeck
  2016-05-07 22:53             ` Frank Terbeck
  2016-05-07 22:09           ` [PATCH 3/6] Use _baudrates helper instead of _baudrate Frank Terbeck
                             ` (3 subsequent siblings)
  5 siblings, 1 reply; 19+ messages in thread
From: Frank Terbeck @ 2016-05-07 22:09 UTC (permalink / raw)
  To: zsh-workers; +Cc: Oliver Kiddle

As per the completion-style-guide.
---
 Completion/Unix/Type/_baudrates | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/Completion/Unix/Type/_baudrates b/Completion/Unix/Type/_baudrates
index 9e87e7a..c6425f0 100644
--- a/Completion/Unix/Type/_baudrates
+++ b/Completion/Unix/Type/_baudrates
@@ -45,35 +45,35 @@ zparseopts -E -A opts u: l: f: d: t:
 # Then generate the actual list:
 #
 #   sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \
-#           < /usr/include/asm-generic/termbits.h
+    #           < /usr/include/asm-generic/termbits.h
 #
 # This one was generated on a Debian Stretch system, leaving out the "0" rate,
 # which is synonymous to "hang-up".
 
 zstyle -a ":completion:${curcontext}:" baud-rates rates ||
-    rates=( 50 75 110 134 150 200 300 600
-            1200 1800 2400 4800 9600
-            19200 38400 57600
-            115200 230400 460800 500000 576000 921600
-            1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
+  rates=( 50 75 110 134 150 200 300 600
+          1200 1800 2400 4800 9600
+          19200 38400 57600
+          115200 230400 460800 500000 576000 921600
+          1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
 
 zstyle -s ":completion:${curcontext}:" max-baud-rate tmp && opts[-u]=$tmp
 zstyle -s ":completion:${curcontext}:" min-baud-rate tmp && opts[-l]=$tmp
 zstyle -s ":completion:${curcontext}:" baud-rate-filter tmp && opts[-f]=$tmp
 
 if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then
-    local -i min max
-    min=${opts[-l]:-0}
-    max=${opts[-u]:-${${(On)rates}[1]}}
-    rates=( ${(M)rates:#${~:-<$min-$max>}} )
+  local -i min max
+  min=${opts[-l]:-0}
+  max=${opts[-u]:-${${(On)rates}[1]}}
+  rates=( ${(M)rates:#${~:-<$min-$max>}} )
 fi
 
 if (( ${+opts[-f]} )); then
-    set -- $rates
-    rates=( )
-    for item; do
-        ${opts[-f]} $item && rates+=( $item )
-    done
+  set -- $rates
+  rates=( )
+  for item; do
+    ${opts[-f]} $item && rates+=( $item )
+  done
 fi
 
 tag=${opts[-t]:-baud-rate}
-- 
2.8.1


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

* [PATCH 3/6] Use _baudrates helper instead of _baudrate
  2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
  2016-05-07 22:09           ` [PATCH 1/6] _baudrate → _baudrates Frank Terbeck
  2016-05-07 22:09           ` [PATCH 2/6] _baudrates: Use 2 space indentation Frank Terbeck
@ 2016-05-07 22:09           ` Frank Terbeck
  2016-05-07 22:09           ` [PATCH 4/6] _baudrates: Fit better into the general completion framework Frank Terbeck
                             ` (2 subsequent siblings)
  5 siblings, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-07 22:09 UTC (permalink / raw)
  To: zsh-workers; +Cc: Oliver Kiddle

---
 Completion/BSD/Command/_cu       | 2 +-
 Completion/Unix/Command/_gdb     | 2 +-
 Completion/Unix/Command/_joe     | 2 +-
 Completion/Unix/Command/_picocom | 2 +-
 Completion/Unix/Command/_screen  | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
index 4b9f25d..ec79501 100644
--- a/Completion/BSD/Command/_cu
+++ b/Completion/BSD/Command/_cu
@@ -3,5 +3,5 @@
 _arguments -s -A '-*' \
   '-d[do not block waiting for a carrier to be detected]' \
   '-l[line to use]:line:(/dev/(cuaU#<->|ttyS<->)(N%c))' \
-  '-s[line speed]:line speed:_baudrate -d "line speed"' \
+  '-s[line speed]:line speed:_baudrates -d "line speed"' \
   '(-*)1:host:'
diff --git a/Completion/Unix/Command/_gdb b/Completion/Unix/Command/_gdb
index d5eed5a..510e6f1 100644
--- a/Completion/Unix/Command/_gdb
+++ b/Completion/Unix/Command/_gdb
@@ -37,7 +37,7 @@ else
   (-[csx]) _files && return 0 ;;
   (-e)     _description files expl executable
            _files "$expl[@]" -g '*(-*)' && return 0 ;;
-  (-b)     _baudrate && return 0 ;;
+  (-b)     _baudrates && return 0 ;;
   esac
 
   w=( "${(@)words[2,-1]}" )
diff --git a/Completion/Unix/Command/_joe b/Completion/Unix/Command/_joe
index 91c437e..592c34a 100644
--- a/Completion/Unix/Command/_joe
+++ b/Completion/Unix/Command/_joe
@@ -3,7 +3,7 @@
 _arguments \
   '-asis[characters with codes >127 will be displayed non-inverted]' \
   '-backpath[backup file directory]:backup file directory:_files -/' \
-  '-baud[inserts delays for baud rates below 19200]:baud rate:_baudrate' \
+  '-baud[inserts delays for baud rates below 19200]:baud rate:_baudrates' \
   '-beep[beep on command errors or when cursor goes past extremes]' \
   '-columns[sets the number of screen columns]:num of columns' \
   '-csmode[continued search mode]' \
diff --git a/Completion/Unix/Command/_picocom b/Completion/Unix/Command/_picocom
index c9d3be0..4b8b3ea 100644
--- a/Completion/Unix/Command/_picocom
+++ b/Completion/Unix/Command/_picocom
@@ -32,7 +32,7 @@ function _picocom_escape () {
 function _picocom () {
     local -a args
 
-    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_baudrate'
+    args=( '(--baud -b)'{--baud,-b}'[define baud-rate to set the terminal to]:baud rate:_baudrates'
            '(--flow -f)'{--flow,-f}'[define type of flow control to use]:flow control:_picocom_flowcontrol'
            '(--parity -p)'{--parity,-p}'[define type of parity to use]:parity mode:_picocom_paritymode'
            '(--databits -d)'{--databits,-d}'[define the number of databits per word]:data bits:_picocom_databits'
diff --git a/Completion/Unix/Command/_screen b/Completion/Unix/Command/_screen
index f4d2ef9..ebc8ba1 100644
--- a/Completion/Unix/Command/_screen
+++ b/Completion/Unix/Command/_screen
@@ -99,7 +99,7 @@ if [[ -n $state ]]; then
       if (( CURRENT == 1 )) && [[ $PREFIX == /dev/* ]]; then
 	  _path_files -g '*(%)'
       elif (( CURRENT == 2 )) && [[ ${words[1]} == /dev/* ]]; then
-	  _baudrate
+	  _baudrates
       elif (( CURRENT > 2 )) && [[ ${words[1]} == /dev/* ]]; then
 	  _message "no more parameters"
       else
-- 
2.8.1


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

* [PATCH 4/6] _baudrates: Fit better into the general completion framework
  2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
                             ` (2 preceding siblings ...)
  2016-05-07 22:09           ` [PATCH 3/6] Use _baudrates helper instead of _baudrate Frank Terbeck
@ 2016-05-07 22:09           ` Frank Terbeck
  2016-05-07 22:09           ` [PATCH 5/6] _cu: Remove old -d option of _baudrates Frank Terbeck
  2016-05-07 22:09           ` [PATCH 6/6] _baudrates: Make style lookups fit better with the rest of compsys Frank Terbeck
  5 siblings, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-07 22:09 UTC (permalink / raw)
  To: zsh-workers; +Cc: Oliver Kiddle

This should work better in concert with other helpers and builtins of
the completion system by accepting arguments that would be handed to
compadd.
---
 Completion/Unix/Type/_baudrates | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/Completion/Unix/Type/_baudrates b/Completion/Unix/Type/_baudrates
index c6425f0..c1ee3f4 100644
--- a/Completion/Unix/Type/_baudrates
+++ b/Completion/Unix/Type/_baudrates
@@ -15,10 +15,6 @@
 #                  value in the complete list to generate an arbitrary
 #                  sub-set.
 #
-#     -t TAG       Use TAG as the tag value in _wanted call.
-#
-#     -d DESC      Use DESC as the description value in _wanted call.
-#
 # The default complete list of available baud rates is also configurable via
 # the 'baud-rates' style:
 #
@@ -31,11 +27,11 @@
 #   zstyle ':completion:*:*:screen:*' min-baud-rate 1200
 #   zstyle ':completion:*:*:screen:*' baud-rate-filter some_function_name
 
+local tmp
+local -a expl rates
 local -A opts
-local expl tag desc tmp
-local -a rates
 
-zparseopts -E -A opts u: l: f: d: t:
+zparseopts -E -A opts u: l: f:
 
 # The following uses a generated list; first find out where the B* macros are
 # defined:
@@ -76,9 +72,7 @@ if (( ${+opts[-f]} )); then
   done
 fi
 
-tag=${opts[-t]:-baud-rate}
-desc=${opts[-d]:-baud rate}
-
 # -1V removes dupes (which there shouldn't be) and otherwise leaves the
 # order in the $rates array intact.
-_wanted -1V $tag expl $desc compadd -a $expl -- rates
+_description -1V baud-rates expl 'baud rate'
+compadd "${(@)argv/#-J/-V}" "$expl[@]" -- "${rates[@]}"
-- 
2.8.1


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

* [PATCH 5/6] _cu: Remove old -d option of _baudrates
  2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
                             ` (3 preceding siblings ...)
  2016-05-07 22:09           ` [PATCH 4/6] _baudrates: Fit better into the general completion framework Frank Terbeck
@ 2016-05-07 22:09           ` Frank Terbeck
  2016-05-07 22:09           ` [PATCH 6/6] _baudrates: Make style lookups fit better with the rest of compsys Frank Terbeck
  5 siblings, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-07 22:09 UTC (permalink / raw)
  To: zsh-workers; +Cc: Oliver Kiddle

---
 Completion/BSD/Command/_cu | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
index ec79501..8c0d1ef 100644
--- a/Completion/BSD/Command/_cu
+++ b/Completion/BSD/Command/_cu
@@ -3,5 +3,5 @@
 _arguments -s -A '-*' \
   '-d[do not block waiting for a carrier to be detected]' \
   '-l[line to use]:line:(/dev/(cuaU#<->|ttyS<->)(N%c))' \
-  '-s[line speed]:line speed:_baudrates -d "line speed"' \
+  '-s[line speed]:line speed:_baudrates' \
   '(-*)1:host:'
-- 
2.8.1


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

* [PATCH 6/6] _baudrates: Make style lookups fit better with the rest of compsys
  2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
                             ` (4 preceding siblings ...)
  2016-05-07 22:09           ` [PATCH 5/6] _cu: Remove old -d option of _baudrates Frank Terbeck
@ 2016-05-07 22:09           ` Frank Terbeck
  5 siblings, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-07 22:09 UTC (permalink / raw)
  To: zsh-workers; +Cc: Oliver Kiddle

To quote Oliver Kiddle:
> The original concept with styles was that style's could have fairly
> generic names because the context allows you to select the detailed
> context. So perhaps consider allowing this to work as, for example:
>   zstyle ':completion:*:*:screen:*:baud-rates' max-value 9600
---
 Completion/Unix/Type/_baudrates | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Completion/Unix/Type/_baudrates b/Completion/Unix/Type/_baudrates
index c1ee3f4..d43b9f1 100644
--- a/Completion/Unix/Type/_baudrates
+++ b/Completion/Unix/Type/_baudrates
@@ -23,9 +23,9 @@
 # It is also possible to override the arguments to -f, -u and -l via styles in
 # a similar fashion:
 #
-#   zstyle ':completion:*:*:screen:*' max-baud-rate 9600
-#   zstyle ':completion:*:*:screen:*' min-baud-rate 1200
-#   zstyle ':completion:*:*:screen:*' baud-rate-filter some_function_name
+#   zstyle ':completion:*:*:screen:*:baud-rates' max-value 9600
+#   zstyle ':completion:*:*:screen:*:baud-rates' min-value 1200
+#   zstyle ':completion:*:*:screen:*:baud-rates' filter some_function_name
 
 local tmp
 local -a expl rates
@@ -53,9 +53,9 @@ zstyle -a ":completion:${curcontext}:" baud-rates rates ||
           115200 230400 460800 500000 576000 921600
           1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 )
 
-zstyle -s ":completion:${curcontext}:" max-baud-rate tmp && opts[-u]=$tmp
-zstyle -s ":completion:${curcontext}:" min-baud-rate tmp && opts[-l]=$tmp
-zstyle -s ":completion:${curcontext}:" baud-rate-filter tmp && opts[-f]=$tmp
+zstyle -s ":completion:${curcontext}:baud-rates" max-value tmp && opts[-u]=$tmp
+zstyle -s ":completion:${curcontext}:baud-rates" min-value tmp && opts[-l]=$tmp
+zstyle -s ":completion:${curcontext}:baud-rates" filter tmp && opts[-f]=$tmp
 
 if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then
   local -i min max
-- 
2.8.1


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

* Re: [PATCH 2/6] _baudrates: Use 2 space indentation
  2016-05-07 22:09           ` [PATCH 2/6] _baudrates: Use 2 space indentation Frank Terbeck
@ 2016-05-07 22:53             ` Frank Terbeck
  0 siblings, 0 replies; 19+ messages in thread
From: Frank Terbeck @ 2016-05-07 22:53 UTC (permalink / raw)
  To: zsh-workers; +Cc: Oliver Kiddle

Frank Terbeck wrote:
> -#           < /usr/include/asm-generic/termbits.h
> +    #           < /usr/include/asm-generic/termbits.h

I blame emacs' shell-script-mode's indentation for this. I'll fix this
locally before committing.


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

* Re: [PATCHv3] Refactor baud rate completion
  2016-05-07 21:53         ` Frank Terbeck
@ 2016-05-11 15:08           ` Oliver Kiddle
  0 siblings, 0 replies; 19+ messages in thread
From: Oliver Kiddle @ 2016-05-11 15:08 UTC (permalink / raw)
  To: zsh-workers

On 7 May, Frank Terbeck wrote:
> I don't know if there is a simple way to make it work the way I'd like
> (unsorted group as well as inheriting the right description), so I ended
> up doing this:
>
>     _description -1V baud-rates expl 'baud rate'
>     compadd "${(@)argv/#-J/-V}" "$expl[@]" -- "${rates[@]}"
>
> That feels pretty dirty, but it seems to work.

That looks like the best approach to me. It's the compadd interface
that's dirty and we're too late to fix that.

> The completion-style-guide mentions the following:
>
>     _description -1V tag expl '...'
>     compadd "$expl[@]" - ...
>
> But that would discard any descriptions given in an _arguments call.

The style guide could be improved to recommend passing on the
arguments.

Oliver


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

end of thread, other threads:[~2016-05-11 15:15 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-01  1:12 [PATCH] Add completion for picocom utility Frank Terbeck
2016-05-01  3:27 ` Ryan Wilson
2016-05-01 10:57   ` Frank Terbeck
2016-05-01 12:47     ` [PATCH] Refactor baud rate completion Frank Terbeck
2016-05-01 13:14     ` [PATCHv2] " Frank Terbeck
2016-05-01 13:27     ` [PATCHv3] " Frank Terbeck
2016-05-01 22:21       ` Frank Terbeck
2016-05-02 12:55       ` Oliver Kiddle
2016-05-03 21:01         ` Frank Terbeck
2016-05-07 21:53         ` Frank Terbeck
2016-05-11 15:08           ` Oliver Kiddle
2016-05-07 22:09         ` [PATCH 0/6] Update baud rate completion with Oliver's comments in mind Frank Terbeck
2016-05-07 22:09           ` [PATCH 1/6] _baudrate → _baudrates Frank Terbeck
2016-05-07 22:09           ` [PATCH 2/6] _baudrates: Use 2 space indentation Frank Terbeck
2016-05-07 22:53             ` Frank Terbeck
2016-05-07 22:09           ` [PATCH 3/6] Use _baudrates helper instead of _baudrate Frank Terbeck
2016-05-07 22:09           ` [PATCH 4/6] _baudrates: Fit better into the general completion framework Frank Terbeck
2016-05-07 22:09           ` [PATCH 5/6] _cu: Remove old -d option of _baudrates Frank Terbeck
2016-05-07 22:09           ` [PATCH 6/6] _baudrates: Make style lookups fit better with the rest of compsys Frank Terbeck

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