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

PATCH: pws-N: completion dump file



This is part of the attempt to sort out the completion initialization
horror.  

First, the default dumpfile becomes ${ZDOTDIR:-$HOME}/.zcompdump.  This is
partly because we now expect the completion functions to be installed
centrally, so that dumping in the same directory is not going to work.
This name was the final fallback in any case, so it means we can remove a
whole lot of checking about whether files are writeable etc.; if this isn't
writeable, all bets are off anyway.  This will mean a change for most
existing users of new completion; you can delete the old compinit.dump.

Also, compdump becomes a real live function, which unfunctions and
autoloads itself at the end to save space; time shouldn't be an issue here,
since normally it only gets run once anyway.  This is one less reason for
knowing about the actual locations of the completion files.

If we can do the same for compinit (which will need more rewriting) and if
functions are installed correctly and the default fpath used, everything
should then work with `autoload compinit; compinit -d'.  Maybe -d should
become the default and -D be introduced for no dump?

In that case, I would propose to make compinstall also a self-unfunctioning
function to complete the set, so that there are no more sourced files,
which is what Andrej suggested months ago.

--- Completion/Core/compdump.in1	Fri Jun 18 16:58:18 1999
+++ Completion/Core/compdump	Wed Jun 23 10:40:39 1999
@@ -1,4 +1,4 @@
-# This is a file to be sourced to dump the definitions for new-style
+# This is a function to dump the definitions for new-style
 # completion defined by 'compinit' in the same directory.  The output
 # should be directed into the "compinit.dump" in the same directory as
 # compinit. If you rename init, just stick .dump onto the end of whatever
@@ -9,12 +9,14 @@
 # To do this, simply remove the .dump file, start a new shell, and
 # create the .dump file as before.  Again, compinit -d handles this
 # automatically.
-#
-# It relies on KSH_ARRAYS not being set.
 
 # Print the number of files used for completion. This is used in compinit
 # to see if auto-dump should re-dump the dump-file.
 
+emulate -L zsh
+
+typeset _d_file _d_f _d_bks _d_line _d_als
+
 _d_file=${compconfig[dumpfile]-${0:h}/compinit.dump}
 
 typeset -U _d_files
@@ -22,8 +24,6 @@
 
 print "#files: $#_d_files" > $_d_file
 
-unset _d_files
-
 # First dump the arrays _comps and _patcomps.  The quoting hieroglyphyics
 # ensure that a single quote inside a variable is itself correctly quoted.
 
@@ -88,4 +88,5 @@
 
 print >> $_d_file
 
-unset _d_line _d_zle _d_bks _d_als _d_f _f_file
+unfunction compdump
+autoload -U compdump
--- Completion/Core/compinit.in1	Wed Jun 23 09:50:20 1999
+++ Completion/Core/compinit	Wed Jun 23 10:40:39 1999
@@ -84,31 +84,7 @@
 if [[ -n $_i_dumpfile ]]; then
   # Explicitly supplied dumpfile.
   compconfig[dumpfile]="$_i_dumpfile"
-elif [[ -o functionargzero ]]; then
-  # We can deduce it from the name of this script
-  compconfig[dumpfile]="$0.dump"
-elif [[ -n $_i_fdir ]]; then
-  # We were told what directory to use.
-  compconfig[dumpfile]="$_i_fdir/compinit.dump"
 else
-  compconfig[dumpfile]=''
-fi
-
-if [[ -n $compconfig[dumpfile] ]]; then
-  # Check the file is writeable.  If it doesn't exist, the
-  # only safe way is to try and create it.
-  if [[ -f $compconfig[dumpfile] ]]; then
-    [[ -w $compconfig[dumpfile] ]] || compconfig[dumpfile]=''
-  elif touch $compconfig[dumpfile] >& /dev/null; then
-    rm -f $compconfig[dumpfile]
-  else
-    compconfig[dumpfile]=''
-  fi
-fi
-
-if [[ -z $compconfig[dumpfile] ]]; then
-  # If no dumpfile given, or it was not writeable, then use
-  # user's ZDOTDIR.
   compconfig[dumpfile]="${ZDOTDIR:-$HOME}/.zcompdump"
 fi
 
@@ -350,6 +326,9 @@
 
 _i_done=''
 
+# Make sure compdump is available, even if we aren't going to use it.
+autoload -U compdump
+
 # If we have a dump file, load it.
 
 if [[ -f "$compconfig[dumpfile]" ]]; then
@@ -386,8 +365,8 @@
 
   # If autodumping was requested, do it now.
 
-  if [[ -n ${_i_fdir} && $_i_autodump = 1 ]]; then
-    builtin . ${_i_fdir}/compdump
+  if [[ $_i_autodump = 1 ]]; then
+    compdump
   fi
 fi
 
--- Completion/Core/compinstall.in1	Mon May 31 09:56:05 1999
+++ Completion/Core/compinstall	Wed Jun 23 10:40:39 1999
@@ -166,7 +166,7 @@
 # Set up the dumpfile
 _ci_dtype=existing
 if [[ -z $_ci_dumpfile ]]; then
-  _ci_dumpfile="${_ci_fdir}/compinit.dump"
+  _ci_dumpfile="${ZDOTDIR:-$HOME}/.zcompdump"
   _ci_dtype=standard
 fi
 
@@ -184,7 +184,6 @@
 I will force completion to dump its status, which will speed up the shell's
 start-up considerably.  However, I can't write the file I'd like to, namely
 ${_ci_dumpfile}.  Please edit a replacement."
-  _ci_dumpfile='~/.compinit.dump'
   vared _ci_dumpfile
   while ! touch ${~_ci_dumpfile} >& /dev/null; do
     print "Sorry, I can't write that either.  Try again."
--- Doc/Zsh/compsys.yo.in1	Wed Jun 23 10:35:53 1999
+++ Doc/Zsh/compsys.yo	Wed Jun 23 10:38:40 1999
@@ -95,19 +95,16 @@
 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.
-In this case the dumped file will have the same name as the sourced file,
-but with tt(.dump) appended to the end, or, if that is not writable by the
-user, the file 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.
+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 in two
-ways: to find the program tt(compdump) used by the tt(-d) option, and to
+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).
 
@@ -117,10 +114,11 @@
 change, it is easiest to delete the dump file by hand so that the next time
 tt(compinit) will re-create it.
 
-The dumping is actually done by another script, tt(compdump), but you will
-only need to source this yourself if you change the configuration
+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.
+the old dumped file will be remembered for this purpose.  Note that
+tt(compdump) is a genuine function and should be called by name.
 
 subsect(Autoloaded files)
 

-- 
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