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

PATCH: Re: vi editting troubles



I wrote:

> Bart Schaefer wrote:
> 
> > On May 23, 11:18am, Wayne Davison wrote:
> > > 
> > > An off-the-cuff suggestion:  Would it be possible to have the C code
> > > call a "set completion defaults" shell function
> > 
> > The problem with any shell-function-based solution is that it requires a
> > special case for the `localoptions' setting.
> > 
> > Better, perhaps, would be to augment the _comp_options variable with a
> > _comp_setup variable, which would look something like this:
> > 
> >     _comp_setup='setopt ${_comp_options[@]} localtraps;
> > 		 exec </dev/null;
> > 		 trap - ZERR'
> > 
> > and then `eval' that variable in any function that is an entry point into
> > the completion system.
> 
> Hm, not one reply so far (unless I've missed something).
> 
> This is of course better than what I suggested in 14449 because I always
> forget about eval.  I'd even volunteer to make that change... or is
> anyone really against it?

Here it is.  There are still some functions in Base/Widget that don't
eval $_comp_setup but they either call _main_complete later or something
entirely different anyway (and use emulate -L or some such), so I wasn't
sure if we should use it there, too.  Some part of my brain says yes,
other parts say no or `for some...'.

Bye
  Sven

Index: Completion/compinit
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/compinit,v
retrieving revision 1.4
diff -u -r1.4 compinit
--- Completion/compinit	2001/04/29 19:12:14	1.4
+++ Completion/compinit	2001/05/29 11:54:54
@@ -139,7 +139,18 @@
     NO_cshnullglob
     NO_allexport
     NO_aliases
+    NO_errexit
 )
+
+# And this one should be `eval'ed at the beginning of every entry point
+# to the completion system.  It sets up what we currently consider a
+# sane environment.  That means we set the options above, make sure we
+# have a valid stdin descriptor (zle closes it before calling widgets)
+# and don't get confused by user's ZERR trap handlers.
+
+_comp_setup='setopt localoptions localtraps ${_comp_options[@]};
+             exec </dev/null;
+             trap - ZERR'
 
 # These can hold names of functions that are to be called before/after all
 # matches have been generated.
Index: Completion/Base/Completer/_expand_alias
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Completer/_expand_alias,v
retrieving revision 1.1
diff -u -r1.1 _expand_alias
--- Completion/Base/Completer/_expand_alias	2001/04/02 11:06:52	1.1
+++ Completion/Base/Completer/_expand_alias	2001/05/29 11:54:54
@@ -2,7 +2,7 @@
 
 local word expl tmp pre sel what
 
-setopt localoptions ${_comp_options[@]}
+eval "$_comp_setup"
 
 if [[ -n $funcstack[2] ]]; then
   if [[ "$funcstack[2]" = _prefix ]]; then
Index: Completion/Base/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_main_complete,v
retrieving revision 1.1
diff -u -r1.1 _main_complete
--- Completion/Base/Core/_main_complete	2001/04/02 11:03:18	1.1
+++ Completion/Base/Core/_main_complete	2001/05/29 11:54:54
@@ -16,12 +16,7 @@
 # which makes the output of setopt and unsetopt reflect a different
 # state than the global one for which you are completing.
 
-setopt localoptions ${_comp_options[@]}
-
-exec </dev/null	# ZLE closes stdin, which can cause errors
-
-# Failed returns from this code are not real errors
-setopt localtraps noerrexit ; trap - ZERR
+eval "$_comp_setup"
 
 local func funcs ret=1 tmp _compskip format nm call match min max i num\
       _completers _completer _completer_num curtag _comp_force_list \
Index: Completion/Base/Widget/_bash_completions
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_bash_completions,v
retrieving revision 1.1
diff -u -r1.1 _bash_completions
--- Completion/Base/Widget/_bash_completions	2001/04/02 11:14:07	1.1
+++ Completion/Base/Widget/_bash_completions	2001/05/29 11:54:54
@@ -25,7 +25,7 @@
 # that will not have been overridden, so you should add '~' to the
 # list of keys at the top of the for-loop.
 
-setopt localoptions ${_comp_options[@]}
+eval "$_comp_setup"
 
 local key=$KEYS[-1] expl
 
Index: Completion/Base/Widget/_complete_debug
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_complete_debug,v
retrieving revision 1.1
diff -u -r1.1 _complete_debug
--- Completion/Base/Widget/_complete_debug	2001/04/02 11:14:23	1.1
+++ Completion/Base/Widget/_complete_debug	2001/05/29 11:54:54
@@ -1,8 +1,6 @@
 #compdef -k complete-word \C-x?
 
-setopt localoptions ${_comp_options[@]}
-
-setopt localtraps noerrexit ; trap - ZERR
+eval "$_comp_setup"
 
 (( $+_debug_count )) || integer -g _debug_count
 local tmp=${TMPPREFIX}${$}${words[1]:t}$[++_debug_count]
Index: Completion/Base/Widget/_complete_help
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_complete_help,v
retrieving revision 1.1
diff -u -r1.1 _complete_help
--- Completion/Base/Widget/_complete_help	2001/04/02 11:14:40	1.1
+++ Completion/Base/Widget/_complete_help	2001/05/29 11:54:54
@@ -1,9 +1,7 @@
 #compdef -k complete-word \C-xh
 
 _complete_help() {
-  setopt localoptions ${_comp_options[@]}
-
-  exec </dev/null	# ZLE closes stdin, which can cause errors
+  eval "$_comp_setup"
 
   local _sort_tags=_help_sort_tags text i j k tmp
   typeset -A help_funcs help_tags help_sfuncs help_styles
Index: Completion/Base/Widget/_correct_word
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_correct_word,v
retrieving revision 1.1
diff -u -r1.1 _correct_word
--- Completion/Base/Widget/_correct_word	2001/04/02 11:15:29	1.1
+++ Completion/Base/Widget/_correct_word	2001/05/29 11:54:54
@@ -7,7 +7,7 @@
 # If configurations keys with the prefix `correctword_' are
 # given they override those starting with `correct_'.
 
-setopt localoptions ${_comp_options[@]}
+eval "$_comp_setup"
 
 local curcontext="$curcontext"
 
Index: Completion/Base/Widget/_expand_word
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_expand_word,v
retrieving revision 1.1
diff -u -r1.1 _expand_word
--- Completion/Base/Widget/_expand_word	2001/04/02 11:15:46	1.1
+++ Completion/Base/Widget/_expand_word	2001/05/29 11:54:54
@@ -2,7 +2,7 @@
 
 # Simple completion front-end implementing expansion.
 
-setopt localoptions ${_comp_options[@]}
+eval "$_comp_setup"
 
 local curcontext="$curcontext"
 
Index: Completion/Base/Widget/_history_complete_word
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_history_complete_word,v
retrieving revision 1.1
diff -u -r1.1 _history_complete_word
--- Completion/Base/Widget/_history_complete_word	2001/04/02 11:16:19	1.1
+++ Completion/Base/Widget/_history_complete_word	2001/05/29 11:54:54
@@ -15,7 +15,7 @@
 #   range -- range of history words to complete
 
 _history_complete_word () {
-  setopt localoptions ${_comp_options[@]}
+  eval "$_comp_setup"
 
   local expl direction stop curcontext="$curcontext"
 
Index: Completion/Base/Widget/_next_tags
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_next_tags,v
retrieving revision 1.1
diff -u -r1.1 _next_tags
--- Completion/Base/Widget/_next_tags	2001/04/02 11:16:51	1.1
+++ Completion/Base/Widget/_next_tags	2001/05/29 11:54:54
@@ -3,7 +3,7 @@
 # Main widget.
 
 _next_tags() {
-  setopt localoptions ${_comp_options[@]}
+  eval "$_comp_setup"
 
   local ins ops="$PREFIX$SUFFIX"
 

-- 
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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