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

[PATCH] _numbers: align descriptions



  % zstyle ':completion:*:*:units' list-separator --
  % compdef _foo foo
  % _foo() { _numbers size {ABC,K,Ki,M,Mi,G,Gi,T,Ti,XYZ}:description }
  % foo 1<TAB>

before:

  ABC -- description  Ki -- description   Mi -- description   ...
  K -- description    M -- description    G -- description    ...

after:

  ABC -- description  Ki  -- description  Mi  -- description  ...
  K   -- description  M   -- description  G   -- description  ...

there are probably other cases like this, if so maybe some kind of
helper would be nice. but until then

ps: compdescribe produces display strings with two spaces before the
separator, like '<match>  <sep> <desc>'. i think that's because it uses
the same constant for that gap that it uses for the gap between two
combined matches on the same line. but it seems like it probably should
not be like that, especially considering every single 'user-space'
function that produces its own display strings uses just one space

dana


diff --git a/Completion/Base/Utility/_numbers b/Completion/Base/Utility/_numbers
index 069fc75a4..8e95a837c 100644
--- a/Completion/Base/Utility/_numbers
+++ b/Completion/Base/Utility/_numbers
@@ -37,7 +37,8 @@
 # _description is called with the x token set to make the completed
 # list of suffixes available to the normal format style
 
-local desc tag range suffixes suffix suffixfmt pat='<->' partial=''
+local MATCH MBEGIN MEND
+local desc tag range suffixes suffix suffixfmt pad pat='<->' partial=''
 local -a expl formats
 local -a default max min keep tags units
 local -i i
@@ -56,7 +57,9 @@ desc="${1:-number}" tag="${tags[2]:-numbers}"
 if (( $#argv )) && compset -P "$pat"; then
   zstyle -s ":completion:${curcontext}:units" list-separator sep || sep=--
   _description -V units expl unit
-  disp=( ${${argv#:}/:/ $sep } )
+  pad=${#${(O)${${argv%%:*}//?/.}}[1]} # length of longest suffix
+  disp=( ${${argv#:}/(#m)[^:]##/${(pr<$pad>< >)MATCH}} ) # pad suffixes
+  disp=( ${disp/:/ $sep } )
   compadd -M 'r:|/=* r:|=*' -d disp "$keep[@]" "$expl[@]" - ${${argv#:}%%:*}
   return
 elif [[ -prefix $~pat || $PREFIX = $~partial ]]; then





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