about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2011-08-03 09:36:49 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2011-08-03 09:36:49 +0000
commit771b059a526effbddb895fb041e30b3a5e038b48 (patch)
tree071e4c5e91689d0525f5e44eac777fbdb37e3caa
parentd557905eb63f5fa087675e05ba82210c86dde358 (diff)
downloadzsh-771b059a526effbddb895fb041e30b3a5e038b48.tar.gz
zsh-771b059a526effbddb895fb041e30b3a5e038b48.tar.xz
zsh-771b059a526effbddb895fb041e30b3a5e038b48.zip
29635: Improve _complete_debug syntax and handling of fd's
-rw-r--r--ChangeLog7
-rw-r--r--Completion/Base/Widget/_complete_debug26
2 files changed, 22 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index fec3754f1..3c0265440 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-08-03  Peter Stephenson  <pws@csr.com>
+
+	* 29635: Completion/Base/Widget/_complete_debug: Improve file
+	descriptor handling and standardise syntax.
+
 2011-07-29  Frank Terbeck  <ft@bewatermyfriend.org>
 
 	* Luka Perkov: 29624: Completion/Unix/Command/_quilt: Improve
@@ -15184,5 +15189,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5412 $
+* $Revision: 1.5413 $
 *****************************************************
diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug
index 39350b5c5..eff0f8e28 100644
--- a/Completion/Base/Widget/_complete_debug
+++ b/Completion/Base/Widget/_complete_debug
@@ -6,21 +6,27 @@ eval "$_comp_setup"
 local tmp=${TMPPREFIX}${$}${words[1]:t}$[++_debug_count]
 local pager w="${(qq)words}"
 
-exec 3>&-	# Too bad if somebody else is using it ...
-[[ -t 2 ]] && { exec 3>&2 2>| $tmp ; trap 'exec 2>&3 3>&-' EXIT INT }
+integer debug_fd=-1
+{
+  if [[ -t 2 ]]; then
+    exec {debug_fd}>&2 2>| $tmp
+  fi
 
-setopt xtrace
-: $ZSH_NAME $ZSH_VERSION
-${1:-_main_complete}
-integer ret=$?
-unsetopt xtrace
+  setopt xtrace
+  : $ZSH_NAME $ZSH_VERSION
+  ${1:-_main_complete}
+  integer ret=$?
+  unsetopt xtrace
 
-[[ -t 3 ]] && {
+  if (( debug_fd != -1 )); then
     zstyle -s ':completion:complete-debug::::' pager pager
     print -sR "${pager:-${PAGER:-${VISUAL:-${EDITOR:-more}}}} ${(q)tmp} ;: $w"
     _message -r "Trace output left in $tmp (up-history to view)"
-    [[ $compstate[nmatches] -le 1 && $compstate[list] != *force* ]] &&
+    if [[ $compstate[nmatches] -le 1 && $compstate[list] != *force* ]]; then
         compstate[list]='list force messages'
+    fi
+  fi
+} always {
+  (( debug_fd != -1 )) && exec 2>&$debug_fd {debug_fd}>&-
 }
-
 return ret