* PATCH: git subcommand completion formatting
@ 2015-06-17 22:32 Oliver Kiddle
2015-06-17 22:48 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Oliver Kiddle @ 2015-06-17 22:32 UTC (permalink / raw)
To: Zsh workers
_git uses _describe inside a big tag loop for different tags. This
results in different formatting widths for different command types.
This isn't so apparent with group-name and format styles set but from a
default setup, it looks quite wrong, e.g:
% zsh -f
% autoload -U compinit;compinit
% git c<tab>
As far as I can tell, there's no use of _describe features that are too
hard to do manually (like common description grouping). This does
things directly with compadd and _alternative.
Oliver
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 3e72886..a44de40 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5023,7 +5023,16 @@ __git_ignore_line_inside_arguments () {
(( $+functions[_git_commands] )) ||
_git_commands () {
- local -a main_porcelain_commands
+ local -a cmdtypes
+ cmdtypes=( main_porcelain_commands user_commands
+ third_party_commands ancillary_manipulator_commands
+ ancillary_interrogator_commands interaction_commands
+ plumbing_manipulator_commands plumbing_interrogator_commands
+ plumbing_sync_commands plumbing_sync_helper_commands
+ plumbing_internal_helper_commands
+ )
+ local -a $cmdtypes
+
main_porcelain_commands=(
add:'add file contents to index'
am:'apply patches from a mailbox'
@@ -5062,7 +5071,6 @@ _git_commands () {
submodule:'initialize, update, or inspect submodules'
tag:'create, list, delete or verify tag object signed with GPG')
- local -a ancillary_manipulator_commands
ancillary_manipulator_commands=(
config:'get and set repository or global options'
fast-export:'data exporter'
@@ -5077,7 +5085,6 @@ _git_commands () {
repack:'pack unpacked objects in a repository'
replace:'create, list, delete refs to replace objects')
- local -a ancillary_interrogator_commands
ancillary_interrogator_commands=(
blame:'show what revision and author last modified each line of a file'
cherry:'find commits not merged upstream'
@@ -5095,7 +5102,6 @@ _git_commands () {
verify-tag:'check GPG signature of tags'
whatchanged:'show commit-logs and differences they introduce')
- local -a interaction_commands
interaction_commands=(
archimport:'import an Arch repository into git'
cvsexportcommit:'export a single commit to a CVS checkout'
@@ -5107,7 +5113,6 @@ _git_commands () {
send-email:'send collection of patches as emails'
svn:'bidirectional operation between a Subversion repository and git')
- local -a plumbing_manipulator_commands
plumbing_manipulator_commands=(
apply:'apply patch to files and/or to index'
checkout-index:'copy files from index to working directory'
@@ -5127,7 +5132,6 @@ _git_commands () {
update-ref:'update object name stored in a reference safely'
write-tree:'create tree from the current index')
- local -a plumbing_interrogator_commands
plumbing_interrogator_commands=(
cat-file:'provide content or type information for repository objects'
diff-files:'compare files in working tree and index'
@@ -5147,7 +5151,6 @@ _git_commands () {
var:'show git logical variable'
verify-pack:'validate packed git archive files')
- local -a plumbing_sync_commands
plumbing_sync_commands=(
daemon:'run a really simple server for git repositories'
fetch-pack:'receive missing objects from another repository'
@@ -5155,7 +5158,6 @@ _git_commands () {
send-pack:'push objects over git protocol to another repository'
update-server-info:'update auxiliary information file to help dumb servers')
- local -a plumbing_sync_helper_commands
plumbing_sync_helper_commands=(
http-fetch:'download from remote git repository via HTTP'
http-push:'push objects over HTTP/DAV to another repository'
@@ -5165,7 +5167,6 @@ _git_commands () {
upload-archive:'send archive back to git-archive'
upload-pack:'send objects packed back to git fetch-pack')
- local -a plumbing_internal_helper_commands
plumbing_internal_helper_commands=(
check-attr:'display gitattributes information'
check-ignore:'debug gitignore/exclude files'
@@ -5178,91 +5179,40 @@ _git_commands () {
patch-id:'compute unique ID for a patch'
stripspace:'filter out empty lines')
- local -a user_commands
zstyle -a :completion:$curcontext: user-commands user_commands
- local -a third_party_commands
local command
for command in $_git_third_party_commands; do
(( $+commands[git-${command%%:*}] )) && third_party_commands+=$command
done
- local -a aliases unique_aliases
+ local -a aliases
__git_extract_aliases
- local alias
- for alias in $aliases; do
- local name=${alias%%:*}
- (( main_porcelain_commands[(I)$name:*] ||
- user_commands[(I)$name:*] ||
- third_party_commands[(I)$name:*] ||
- ancillary_manipulator_commands[(I)$name:*] ||
- ancillary_interrogator_commands[(I)$name:*] ||
- interaction_commands[(I)$name:*] ||
- plumbing_manipulator_commands[(I)$name:*] ||
- plumbing_interrogator_commands[(I)$name:*] ||
- plumbing_sync_commands[(I)$name:*] ||
- plumbing_sync_helper_commands[(I)$name:*] ||
- plumbing_internal_helper_commands[(I)$name:*] )) || unique_aliases+=$alias
+ local cmdtype len dup sep
+ local -a allcmds allmatching alts disp
+
+ zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
+ for cmdtype in $cmdtypes aliases; do
+ if [[ $cmdtype = aliases ]]; then
+ for dup in ${${aliases%:*}:*allcmds}; do
+ aliases=( ${aliases:#$dup:*} )
+ done
+ fi
+ local -a ${cmdtype}_m
+ set -A ${cmdtype}_m ${(P)cmdtype%%:*}
+ allcmds+=( ${(P)${:-${cmdtype}_m}} )
done
-
- integer ret=1
-
- _tags \
- aliases \
- main-porcelain-commands \
- user-commands \
- third-party-commands \
- ancillary-manipulator-commands \
- ancillary-interrogator-commands \
- interaction-commands \
- plumbing-manipulator-commands \
- plumbing-interrogator-commands \
- plumbing-sync-commands \
- plumbing-sync-helper-commands \
- plumbing-internal-helper-commands
-
- while _tags; do
-
- _requested aliases && \
- _describe -t aliases 'alias' unique_aliases && ret=0
-
- _requested main-porcelain-commands && \
- _describe -t main-porcelain-commands 'main porcelain command' main_porcelain_commands && ret=0
-
- _requested user-commands && \
- _describe -t user-commands 'user command' user_commands && ret=0
-
- _requested third-party-commands && \
- _describe -t third-party-commands 'third-party command' third_party_commands && ret=0
-
- _requested ancillary-manipulator-commands && \
- _describe -t ancillary-manipulator-commands 'ancillary manipulator command' ancillary_manipulator_commands && ret=0
-
- _requested ancillary-interrogator-commands && \
- _describe -t ancillary-interrogator-commands 'ancillary interrogator command' ancillary_interrogator_commands && ret=0
-
- _requested interaction-commands && \
- _describe -t interaction-commands 'interaction command' interaction_commands && ret=0
-
- _requested plumbing-manipulator-commands && \
- _describe -t plumbing-manipulator-commands 'plumbing manipulator command' plumbing_manipulator_commands && ret=0
-
- _requested plumbing-interrogator-commands && \
- _describe -t plumbing-interrogator-commands 'plumbing interrogator command' plumbing_interrogator_commands && ret=0
-
- _requested plumbing-sync-commands && \
- _describe -t plumbing-sync-commands 'plumbing sync command' plumbing_sync_commands && ret=0
-
- _requested plumbing-sync-helper-commands && \
- _describe -t plumbing-sync-helper-commands 'plumbing sync helper command' plumbing_sync_helper_commands && ret=0
-
- _requested plumbing-internal-helper-commands && \
- _describe -t plumbing-internal-helper-commands 'plumbing internal helper command' plumbing_internal_helper_commands && ret=0
-
- (( ret )) || break
+ zstyle -T ":completion:${curcontext}:" verbose && disp=(-ld '${cmdtype}_d')
+ compadd -O allmatching -a allcmds
+ len=${#${(O)allmatching//?/.}[1]} # length of longest match
+ for cmdtype in aliases $cmdtypes; do
+ local -a ${cmdtype}_d
+ (( $#disp )) && set -A ${cmdtype}_d \
+ ${${(Pr.COLUMNS-4.)cmdtype/(#s)(#m)[^:]##:/${(r.len.)MATCH[1,-2]} $sep }%% #}
+ alts+=( "${cmdtype//_/-}:${${cmdtype//_/ }%%(e|)s}:compadd ${(e)disp} -a ${cmdtype}_m" )
done
- return ret
+ _alternative $alts
}
(( $+functions[__git_aliases] )) ||
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: git subcommand completion formatting
2015-06-17 22:32 PATCH: git subcommand completion formatting Oliver Kiddle
@ 2015-06-17 22:48 ` Bart Schaefer
2015-06-17 23:05 ` Oliver Kiddle
2015-06-19 14:54 ` Oliver Kiddle
0 siblings, 2 replies; 4+ messages in thread
From: Bart Schaefer @ 2015-06-17 22:48 UTC (permalink / raw)
To: Zsh workers
On Jun 18, 12:32am, Oliver Kiddle wrote:
}
} As far as I can tell, there's no use of _describe features that are too
} hard to do manually (like common description grouping). This does
} things directly with compadd and _alternative.
I see you handled the list-separator style. What about max-matches-width?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: git subcommand completion formatting
2015-06-17 22:48 ` Bart Schaefer
@ 2015-06-17 23:05 ` Oliver Kiddle
2015-06-19 14:54 ` Oliver Kiddle
1 sibling, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2015-06-17 23:05 UTC (permalink / raw)
To: Zsh workers
Bart wrote:
> }
> } As far as I can tell, there's no use of _describe features that are too
> } hard to do manually (like common description grouping). This does
> } things directly with compadd and _alternative.
>
> I see you handled the list-separator style. What about max-matches-width?
That doesn't truncate the width of individual matches, it prevents
grouping of matches with a common description where that grouping would
exceed the width. As there is no grouping, or even matches with common
descriptions, I don't think that's applicable.
Oliver
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: git subcommand completion formatting
2015-06-17 22:48 ` Bart Schaefer
2015-06-17 23:05 ` Oliver Kiddle
@ 2015-06-19 14:54 ` Oliver Kiddle
1 sibling, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2015-06-19 14:54 UTC (permalink / raw)
To: Zsh workers
Bart wrote:
> I see you handled the list-separator style.
There are, however, a few other functions with a hard coded list
separators. This fixes them.
Oliver
diff --git a/Completion/Unix/Type/_email_addresses b/Completion/Unix/Type/_email_addresses
index 926e8b4..7d5c942 100644
--- a/Completion/Unix/Type/_email_addresses
+++ b/Completion/Unix/Type/_email_addresses
@@ -88,7 +88,7 @@ _email-local() {
_email_addresses() {
local -a plugins reply list args
local -A opts files
- local plugin rcfile muttrc expl ret fret
+ local plugin rcfile muttrc expl sep ret fret
local __specialx='][()<>@,;:\\".'
local __spacex=" " # Space, tab
@@ -159,7 +159,8 @@ _email_addresses() {
if (( fret == 300 )); then
if (( ! $+opts[-c] )) && [[ $opts[-n] = $plugin ]]; then
- zformat -a list ' -- ' "${reply[@]}"
+ zstyle -s ":completion:${curcontext}:$curtag" list-separator sep || sep=--
+ zformat -a list " $sep " "${reply[@]}"
_wanted mail-aliases expl 'alias' compadd "$@" \
-d list - ${reply%%:*} && ret=0
else
diff --git a/Completion/Zsh/Command/_fc b/Completion/Zsh/Command/_fc
index 1589244..68456cc 100644
--- a/Completion/Zsh/Command/_fc
+++ b/Completion/Zsh/Command/_fc
@@ -1,7 +1,7 @@
#compdef fc history r
local curcontext="$curcontext" state state_descr line ret=1
-local list events num cmd
+local events num cmd sep
typeset -A opt_args
local fc_common fc_hist fc_r
@@ -67,21 +67,20 @@ case $service in
esac
if [[ -n $state ]]; then
+ zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
if [[ -z ${line:#*=*} ]] && compset -P '*='; then
_message -e replacements 'replacement'
elif [[ -prefix [0-9] ]]; then
- events=( ${(ps.\0.)"$(printf '%s:%s\0' ${(kv)history})"} )
- zformat -a list " -- " "$events[@]"
- _wanted -2V events expl "$state_descr" compadd -M "B:0=" -ld list - \
- "${events[@]%%:*}"
+ events=( ${(0)"$(printf "%-${#HISTNO}.${#HISTNO}s $sep %s\0" "${(kv)history[@]}")"} )
+ _wanted -2V events expl "$state_descr" compadd -M "B:0=" -ld events - \
+ "${events[@]%% *}"
elif [[ -prefix - ]]; then
- for num cmd in ${(kv)history}; do
+ for num cmd in "${(kv@)history}"; do
(( num=num - HISTNO ))
- events+=( $num:$cmd )
+ events+=( "${(r.1+$#HISTNO.)num} $sep $cmd" )
done
- zformat -a list " -- " "$events[@]"
- _wanted -2V events expl "$state_descr" compadd -ld list - \
- "${events[@]%%:*}"
+ _wanted -2V events expl "$state_descr" compadd -ld events - \
+ "${events[@]%% *}"
else
_wanted events expl "$state_descr" compadd -S '' - \
${${history%%[=[:IFS:]]*}:#[0-9-]*} || _guard "[0-9]#" event
diff --git a/Completion/Zsh/Command/_zpty b/Completion/Zsh/Command/_zpty
index ef4ac4b..99251aa 100644
--- a/Completion/Zsh/Command/_zpty
+++ b/Completion/Zsh/Command/_zpty
@@ -1,6 +1,6 @@
#compdef zpty
-local state line list names expl curcontext="$curcontext"
+local state line list names expl sep curcontext="$curcontext"
typeset -A opt_args
_arguments -C -s -S \
@@ -50,8 +50,9 @@ if [[ $state = name ]]; then
fi
list=( ${${(f)"$(zpty)"}#*\) } )
names=( ${list%%:*} )
- if zstyle -T ":completion:${curcontext}" verbose; then
- zformat -a list ' --' ${${(f)"$(zpty)"}#*\) }
+ if zstyle -T ":completion:${curcontext}:" verbose; then
+ zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
+ zformat -a list " $sep" ${${(f)"$(zpty)"}#*\) }
_wanted names expl 'zpty command name' compadd -d list -a names
else
_wanted names expl 'zpty command name' compadd -a names
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-06-19 15:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-17 22:32 PATCH: git subcommand completion formatting Oliver Kiddle
2015-06-17 22:48 ` Bart Schaefer
2015-06-17 23:05 ` Oliver Kiddle
2015-06-19 14:54 ` Oliver Kiddle
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).