# HG changeset patch # User Anton Shestakov # Date 2018-08-10 01:09:52 # Node ID 69876534caf2e8afb521b001b7c02d8f072ff023 # Parent 8ff14f8fe2d321ed6b8649dbdc50dbff21d7f57f zsh_completion: declare appropriate local parameters for ->string form When ->string form is used for _arguments, the function that calls it must declare appropriate local parameters. Managing local return value is needed to tell the completion system if our function succeeded in suggesting something or not, plus without that `hg diff -` doesn't look right. While at it, fix a copypaste error (s/diff_files/revert_files/). Docs: http://zsh.sourceforge.net/Doc/Release/Completion-System.html Differential Revision: https://phab.mercurial-scm.org/D4264 diff --git a/contrib/zsh_completion b/contrib/zsh_completion --- a/contrib/zsh_completion +++ b/contrib/zsh_completion @@ -581,7 +581,9 @@ typeset -A _hg_cmd_globals } _hg_cmd_diff() { + local context state state_descr line ret=1 typeset -A opt_args + _arguments -s -S : $_hg_global_opts $_hg_diff_opts $_hg_ignore_space_opts \ $_hg_pat_opts $_hg_subrepos_opts \ '*'{-r+,--rev=}'[revision]:revision:_hg_revrange' \ @@ -591,17 +593,19 @@ typeset -A _hg_cmd_globals '--reverse[produce a diff that undoes the changes]' \ '(--unified -U)'{-U+,--unified=}'[number of lines of context to show]:' \ '--stat[output diffstat-style summary of changes]' \ - '*:file:->diff_files' + '*:file:->diff_files' && ret=0 if [[ $state == 'diff_files' ]] then if [[ -n $opt_args[-r] ]] then - _hg_files + _hg_files && ret=0 else - _hg_committable + _hg_committable && ret=0 fi fi + + return ret } _hg_cmd_export() { @@ -796,7 +800,7 @@ typeset -A _hg_cmd_globals } _hg_cmd_resolve() { - local context state line + local context state state_descr line ret=1 typeset -A opt_args _arguments -s -S : $_hg_global_opts $_hg_mergetool_opts $_hg_pat_opts \ @@ -805,17 +809,19 @@ typeset -A _hg_cmd_globals '(--list -l --mark -m --unmark -u)'{-l,--list}'[list state of files needing merge]:*:merged files:->resolve_files' \ '(--mark -m --list -l --unmark -u)'{-m,--mark}'[mark files as resolved]:*:unresolved files:_hg_unresolved' \ '(--unmark -u --list -l --mark -m)'{-u,--unmark}'[unmark files as resolved]:*:resolved files:_hg_resolved' \ - '*:file:_hg_unresolved' + '*:file:_hg_unresolved' && ret=0 if [[ $state == 'resolve_files' ]] then _alternative 'files:resolved files:_hg_resolved' \ - 'files:unresolved files:_hg_unresolved' + 'files:unresolved files:_hg_unresolved' && ret=0 fi + + return ret } _hg_cmd_revert() { - local context state line + local context state state_descr line ret=1 typeset -A opt_args _arguments -s -S : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \ @@ -823,19 +829,21 @@ typeset -A _hg_cmd_globals '(--rev -r)'{-r+,--rev=}'[revision to revert to]:revision:_hg_labels' \ '(--no-backup -C)'{-C,--no-backup}'[do not save backup copies of files]' \ '(--date -d)'{-d+,--date=}'[tipmost revision matching date]:date code:' \ - '*:file:->diff_files' + '*:file:->revert_files' && ret=0 - if [[ $state == 'diff_files' ]] + if [[ $state == 'revert_files' ]] then if [[ -n $opt_args[-r] ]] then - _hg_files + _hg_files && ret=0 else typeset -a status_files _hg_status mard - _wanted files expl 'modified, added, removed or deleted file' _multi_parts / status_files + _wanted files expl 'modified, added, removed or deleted file' _multi_parts / status_files && ret=0 fi fi + + return ret } _hg_cmd_rollback() {