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

PATCH: pws-N: Utter and final completion startup system, maybe



This makes compinit and compinstall functions, using typeset -gA to create
the associative arrays.  This will be incompatible with everyone's
initialization scripts, although sourcing compinit probably ought to work
with a few complaints and leaving a lot of unneeded parameters behind.
If you run compinstall to reinstall it in .zshrc, it's best to delete
the '. ..../compinstall' line, because it doesn't recognize that any more.

The handling of directories by compinstall is messier, because it has to
make sure that the directory for compinit is in the fpath.  So I made that
a shell parameter, which is also used by compinit instead of passing it
down.

The directory problem should, however, now be under control.  For most
installations, it is intended that the completion functions including
compinit and compdump are already in the $fpath.  Other users will have to
run compinstall, which will decide.

The documentation may need to be clearer, but as I've been staring at it
too much anyway this requires concrete suggestions rather than `the
documentation needs to be clearer'.

--- Completion/Core/compinit.cifn	Wed Jun 23 10:40:39 1999
+++ Completion/Core/compinit	Fri Jun 25 17:43:27 1999
@@ -41,15 +41,13 @@
 # See the file `compdump' for how to speed up initialisation.
 
 # If we got the `-d'-flag, we will automatically dump the new state (at
-# the end).
-# `-f dir' is used to pass down the directory where this file was
-#   found.  This is necessary if functionargzero is not set.
-# If we were given an argument, this will be taken as the name of the
-# file in which to store the dump.
-
-_i_fdir=''
-_i_dumpfile=''
-_i_autodump=0
+# the end).  This takes the dumpfile as an argument.
+
+emulate -L zsh
+
+typeset _i_dumpfile _i_files _i_line _i_done _i_dir _i_autodump=0
+typeset _i_tag _i_file
+
 while [[ $# -gt 0 && $1 = -[df] ]]; do
   if [[ "$1" = -d ]]; then
     _i_autodump=1
@@ -59,26 +57,21 @@
       shift
     fi
   elif [[ "$1" = -f ]]; then
-    # Used by compinstall to pass down directory where compinit was found
+    # Not used any more; use _compdir
     shift
-    _i_fdir="$1"
     shift
   fi
 done
-# Get the directory if we don't have it already and we can
-if [[ -z "$_i_fdir" && -o functionargzero && $0 = */* ]]; then
-  _i_fdir=${0:h}
-fi
 
 # The associative array containing the definitions for the commands.
 # Definitions for patterns will be stored in the normal array `_patcomps'.
 
-typeset -A _comps
+typeset -gA _comps
 _patcomps=()
 
 # This is the associative array used for configuration.
 
-typeset -A compconfig
+typeset -gA compconfig
 
 # Standard initialisation for `compconfig'.
 if [[ -n $_i_dumpfile ]]; then
@@ -301,15 +294,13 @@
 if [[ $#_i_files -lt 20 ]]; then
   # Too few files:  we need some more directories
   # Assume that we need to add the compinit directory to fpath.
-  if [[ -n $_i_fdir ]]; then
-    if [[ $_i_fdir = */Core ]]; then
+  if [[ -n $_compdir ]]; then
+    if [[ $_compdir = */Core ]]; then
       # Add all the Completion subdirectories
-      fpath=(${_i_fdir:h}/*(/) $fpath)
-    elif [[ -d $_i_fdir/Core ]]; then
+      fpath=(${_compdir:h}/*(/) $fpath)
+    elif [[ -d $_compdir/Core ]]; then
       # Likewise
-      fpath=(${_i_fdir}/*(/) $fpath)
-    else
-      fpath=($_i_fdir $fpath)
+      fpath=(${_compdir}/*(/) $fpath)
     fi
     _i_files=( ${^~fpath:/.}/_(|*[^~])(N:t) )
   fi
@@ -327,7 +318,7 @@
 _i_done=''
 
 # Make sure compdump is available, even if we aren't going to use it.
-autoload -U compdump
+autoload -U compdump compinstall
 
 # If we have a dump file, load it.
 
@@ -337,7 +328,6 @@
     builtin . "$compconfig[dumpfile]"
     _i_done=yes
   fi
-  unset _i_line
 fi
 if [[ -z "$_i_done" ]]; then
   for _i_dir in $fpath; do
@@ -361,8 +351,6 @@
     done
   done
 
-  unset _i_dir _i_line _i_file _i_tag
-
   # If autodumping was requested, do it now.
 
   if [[ $_i_autodump = 1 ]]; then
@@ -370,4 +358,5 @@
   fi
 fi
 
-unset _i_files _i_initname _i_done _i_autodump _i_fdir _i_dumpfile
+unfunction compinit
+autoload -U compinit
--- Completion/Core/compinstall.cifn	Wed Jun 23 10:40:39 1999
+++ Completion/Core/compinstall	Fri Jun 25 16:39:05 1999
@@ -3,7 +3,7 @@
 # available in some directory; they should have been installed with the
 # the shell (except we haven't written that yet).
 #
-# Source this script (e.g. `. /path/compinstall') and answer the questions.
+# Run this script as a function and answer the questions.
 #
 # Normally, this will alter ~/.zshrc (or wherever ZDOTDIR puts it), but you
 # can make that unwritable and it will leave the lines in a temporary file
@@ -23,33 +23,13 @@
 #  - Could add code for setting other completers and options.
 #  - Could add keys for context-sensitive help.
 
-# Save the options.  We will need to trap ^C to make sure they get
-# restored properly.
-typeset -A _ci_options
-_ci_options=($(setopt kshoptionprint;setopt))
-[[ -o kshoptionprint ]] || _ci_options[kshoptionprint]=off
-[[ -o monitor ]] && _ci_options[monitor]=on
-[[ -o zle ]] && _ci_options[zle]=on
-
-emulate zsh
-
-TRAPINT() { 
-  unsetopt ${(k)_ci_options[(R)off]}
-  setopt ${(k)_ci_options[(R)on]}
-
-  unset _ci_options _ci_f _ci_fdir _ci_files _ci_dumpfile _ci_lines
-  unset _ci_type _ci_completer _ci_accept _ci_cprompt _ci_startline
-  unset _ci_endline _ci_ifile _ci_tmpf _ci_defaults _ci_compconf _ci_warn
-  unset _ci_dtype _ci_existing _ci_line
-
-  if (( $1 )); then
-    print Aborted.
-    unfunction TRAPINT
-    return 1
-  fi
-  return 0
-}
 
+emulate -L zsh
+
+typeset _ci_options _ci_f _ci_fdir _ci_files _ci_dumpfile _ci_lines
+typeset _ci_type _ci_completer _ci_accept _ci_cprompt _ci_startline
+typeset _ci_endline _ci_ifile _ci_tmpf _ci_compconf _ci_warn
+typeset _ci_dtype _ci_existing _ci_line
 
 # Look for the defaults.
 _ci_startline='# The following lines were added by compinstall'
@@ -60,6 +40,7 @@
 _ci_existing=''
 
 typeset -A _ci_defaults
+
 if [[ -f $_ci_ifile ]]; then
   # This assumes the lines haven't been altered by the user too much
   # after they were added.
@@ -83,10 +64,12 @@
       fi
       _ci_existing="${_ci_existing}  $_ci_line
 "
-    elif [[ $_ci_line[1] = . && $_ci_line[2] = */compinit ]]; then
-      # parse the line sourcing compinit
-      [[ $_ci_line[3] = -f ]]  && _ci_fdir=$_ci_line[4]
+    elif [[ $_ci_line[1] = compinit ]]; then
+      # parse the line running compinit
+      [[ $_ci_line[2] = -f ]]  && _ci_fdir=$_ci_line[3]
       [[ $_ci_line[-2] = -d ]] && _ci_dumpfile=$_ci_line[-1]
+    elif [[ $_ci_line[1] = _compdir=* ]]; then
+      _ci_fdir=${_ci_line[1]##_compdir=}
     elif [[ $_ci_line[1] = compconf ]]; then
       # parse a compconf component as second argument (should be completer)
       [[ $_ci_line[2] = completer=* ]] &&
@@ -94,7 +77,7 @@
       [[ $_ci_line[-1] == \\ ]] && _ci_compconf=1
       _ci_existing="${_ci_existing}$_ci_line
 "
-    elif [[ $_ci_line[1] != \#* ]]; then
+    elif [[ $_ci_line[1] != \#* && $_ci_line[1] != (autoload|\[\[) ]]; then
       if [[ -z $_ci_warn ]]; then
 	_ci_warn=1
 	print "Warning:  existing lines in compinstall setup not understood:"
@@ -192,7 +175,10 @@
   [[ -s $_ci_dumpfile ]] || rm -f $_ci_dumpfile
 fi
 
-_ci_lines="${_ci_lines}. $_ci_fdir/compinit -f $_ci_fdir -d"
+_ci_lines="${_ci_lines}_compdir=$_ci_fdir
+[[ -z \$fpath[(r)\$_compdir] ]] && fpath=(\$_compdir \$fpath)
+autoload -U compinit
+compinit -d"
 [[ $_ci_dtype != standard ]] && _ci_lines="${_ci_lines} $_ci_dumpfile"
 _ci_lines="${_ci_lines}
 "
@@ -362,6 +348,7 @@
   print "\nSuccessfully appended lines to $_ci_ifile."
 fi
 
-TRAPINT 0
+unfunction compinstall
+autoload -U compinstall
 
 return 0
--- Doc/Zsh/compsys.yo.cifn	Wed Jun 23 10:38:40 1999
+++ Doc/Zsh/compsys.yo	Fri Jun 25 16:56:11 1999
@@ -49,7 +49,7 @@
 texinode(Initialization)(Control Functions)()(Completion System)
 sect(Initialization)
 
-The script tt(compinstall) can be run by a user to set up the completion
+The function tt(compinstall) can be run by a user to set up the completion
 system for use.  It will usually insert code into tt(.zshrc), although if
 that is not writable it will save it in another file and tell you that
 file's locations.  Note that it is up to you to make sure that the lines
@@ -62,10 +62,10 @@
 The new code will take effect next time you start the shell, or run
 tt(.zshrc) by hand.
 
-You can run it as `tt(source )var(<path>)tt(/compinstall)' or
-`tt(. )var(<path>)tt(/compinstall)', where var(<path>) is where the
-completion functions are stored.  It will ask you various questions about
-how you would like completion set up.  It is in two parts; the basic part
+To run it, you will need to make sure it is a directory mentioned in your
+tt($fpath) parameter, and that it is autoloaded (`tt(autoload -U
+compinstall)' is recommended).  It will ask you various questions about how
+you would like completion set up.  It is in two parts; the basic part
 locates the completion files and decides where to put your personal
 dumpfile, used to speed up initialization after the first time.  After
 that, you will be asked if you wish to go on to the advanced set-up; if you
@@ -86,27 +86,24 @@
 the current session when run directly by the user; if you have run
 tt(compinstall) it will be called automatically from your tt(.zshrc).
 
-To initialize the system, the script tt(compinit) should be sourced with
-`tt(source )var(<path>)tt(/compinit)' or
-`tt(. )var(<path>)tt(/compinit)'. This will define a few utility functions,
-arrange for all the necessary shell functions to be autoloaded, and will
-then re-bind all keys that do completion to use the new system.
+To initialize the system, the function tt(compinit) should be in a
+directory mentioned in the tt($fpath) variable, and should be autoloaded
+(`tt(autoload -U compinit)' is recommended).  When run, it will define a
+few utility functions, arrange for all the necessary shell functions to be
+autoloaded, and will then re-bind all keys that do completion to use the
+new system.
 
 To speed up the running of tt(compinit), it can be made to produce a dumped
 configuration which will be read in on future invocations.  The easiest way
-to do this is by adding the option tt(-d) whenever tt(compinit) is sourced.
+to do this is by adding the option tt(-d) whenever tt(compinit) is run.
 In this case the dumped file is tt(.zcompdump) in the same directory as the
 startup files (i.e. tt($ZDOTDIR) or tt($HOME)); alternatively, an explicit
 file name can be given following the tt(-d).  On the next call to
 tt(compinit -d), the dumped file will be read instead.
 
-The other option accepted by tt(compinit) is tt(-f )var(dir), which gives
-the directory in which tt(compinit) resides.  If you source tt(compinit) by
-its full pathname, and the option tt(FUNCTION_ARGZERO) is set, as it is by
-default unless tt(zsh) is emulating tt(sh) or tt(ksh), this is unnecessary
-as tt(compinit) can deduce the directory for itself.  It is used to
-check if the directory should be added to the function search path to find
-the completion functions (see below).
+If the parameter tt(_compdir) is set, tt(compinit) uses it has a directory
+where completion functions can be found; this is only necessary if they are
+not already in the function search path.
 
 If the number of completion files changes, tt(compinit) will recognise this
 and produce a new dump file.  However, if the name of a function or the
@@ -117,25 +114,27 @@
 The dumping is actually done by another function, tt(compdump), but you
 will only need to run this yourself if you change the configuration
 (e.g. using tt(compdef)) and then want to dump the new one.  The name of
-the old dumped file will be remembered for this purpose.  Note that
-tt(compdump) is a genuine function and should be called by name.
+the old dumped file will be remembered for this purpose.
 
 subsect(Autoloaded files)
 
 The convention for autoloaded functions used in completion is that they
 start with an underscore; as already mentioned, the tt(fpath/FPATH)
-parameter must contain the directory in which they are stored.  If
-tt(compinit) does not find enough files beginning with an underscore (fewer
-than twenty) in the search path, it will try to find more by adding its own
-directory to the search path.  If you keep all the completion files in this
-directory, this means you never have to alter tt(fpath/FPATH) yourself.
+parameter must contain the directory in which they are stored.  If tt(zsh)
+was properly installed on your system, then tt(fpath/FPATH) automatically
+contains the required directories.
+
+For incomplete installations, if tt(compinit) does not find enough files
+beginning with an underscore (fewer than twenty) in the search path, it
+will try to find more by adding the directory tt(_compdir) to the search
+path; if you have run tt(compinstall), this will be set automatically.
 Furthermore, if the directory in question ends in the path segment
 tt(Core), or has a subdirectory named tt(Core), tt(compinit) will add all
 subdirectories of the directory where tt(Core) is to the path: this allows
 the functions to be in the same format as in the tt(zsh) source
 distribution.
 
-When tt(compinit) is sourced, it searches all such files accessible via
+When tt(compinit) is run, it searches all such files accessible via
 tt(fpath/FPATH) and reads the first line of each of them.  This line should
 contain one of the tags described below. Files whose first line does not
 start with one of these tags are not considered to be part of the

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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