zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: PATCH: error handling in _complete_help
Date: Sun, 07 Apr 2013 12:28:37 -0700	[thread overview]
Message-ID: <130407122837.ZM622@torch.brasslantern.com> (raw)

Something I had sitting around that seemed like a good test for "git push".

This uses an "always" block instead of "trap" to clean up various function
overrides in _complete_help, because some errors would cause _complete_help
to exit without running the traps, leaving completion broken.  Most of the
change is indentation.

diff --git a/Completion/Base/Widget/_complete_help b/Completion/Base/Widget/_complete_help
index 99f2f2d..949a496 100644
--- a/Completion/Base/Widget/_complete_help
+++ b/Completion/Base/Widget/_complete_help
@@ -6,41 +6,41 @@ _complete_help() {
   local _sort_tags=_help_sort_tags text i j k tmp
   typeset -A help_funcs help_tags help_sfuncs help_styles
 
-  compadd() { return 1 }
-  zstyle() {
-    local _f="${${(@)${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(dispatch|wanted|requested|all_labels|next_label)}% *}"
-
-    [[ -z "$_f" ]] && _f="${${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(dispatch|wanted|requested|all_labels|next_label)}"
-
-    if [[ "$help_sfuncs[$2]" != *${_f}* ||
-          "$help_styles[${2}${_f}]" != *${3}* ]]; then
-
-      [[ "$help_sfuncs[$2]" != *${_f}* ]] && help_sfuncs[$2]+=$'\0'"${_f}"
-      local _t
-
-      case "$1" in
-      -s) _t='[string] ';;
-      -a) _t='[array]  ';;
-      -h) _t='[assoc]  ';;
-      *)  _t='[boolean]';;
-      esac
-      help_styles[${2}${_f}]+=",${_t} ${3}:${_f}"
-    fi
-
-    # No need to call the completers more than once with different match specs.
-
-    if [[ "$3" = matcher-list ]]; then
-      set -A "$4" ''
-    else
-      builtin zstyle "$@"
-    fi
+  {
+    compadd() { return 1 }
+    zstyle() {
+      local _f="${${(@)${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(dispatch|wanted|requested|all_labels|next_label)}% *}"
+  
+      [[ -z "$_f" ]] && _f="${${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(dispatch|wanted|requested|all_labels|next_label)}"
+  
+      if [[ "$help_sfuncs[$2]" != *${_f}* ||
+            "$help_styles[${2}${_f}]" != *${3}* ]]; then
+  
+        [[ "$help_sfuncs[$2]" != *${_f}* ]] && help_sfuncs[$2]+=$'\0'"${_f}"
+        local _t
+  
+        case "$1" in
+        -s) _t='[string] ';;
+        -a) _t='[array]  ';;
+        -h) _t='[assoc]  ';;
+        *)  _t='[boolean]';;
+        esac
+        help_styles[${2}${_f}]+=",${_t} ${3}:${_f}"
+      fi
+  
+      # No need to call the completers more than once with different match specs.
+  
+      if [[ "$3" = matcher-list ]]; then
+        set -A "$4" ''
+      else
+        builtin zstyle "$@"
+      fi
+    }
+
+    ${1:-_main_complete}
+  } always {
+    unfunction compadd zstyle
   }
-  trap 'unfunction compadd zstyle' EXIT INT
-
-  ${1:-_main_complete}
-
-  unfunction compadd zstyle
-  trap - EXIT INT
 
   for i in "${(@ok)help_funcs}"; do
     text+=$'\n'"tags in context :completion:${i}:"


                 reply	other threads:[~2013-04-07 19:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=130407122837.ZM622@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).