summary refs log tree commit diff
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-26 08:36:43 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-26 08:36:43 +0000
commit96a30526c2d82a848cbca51bef626b24905ededf (patch)
tree47ca9eb571ab64a934e38fc5d9eabbc58e605a16
parent0c4eb61e906251971b1d4053365189f251cd18b6 (diff)
downloadzsh-96a30526c2d82a848cbca51bef626b24905ededf.tar.gz
zsh-96a30526c2d82a848cbca51bef626b24905ededf.tar.xz
zsh-96a30526c2d82a848cbca51bef626b24905ededf.zip
better perl module completion from Adam (10892)
-rw-r--r--ChangeLog3
-rw-r--r--Completion/User/_perl_modules59
2 files changed, 40 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index dd066357d..54f010e2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2000-04-26  Sven Wischnowsky  <wischnow@informatik.hu-berlin.de>
 
+	* Adam Spiers: 10892: Completion/User/_perl_modules: ensure perl
+	is there and better pattern for searching modules
+
 	* Tanaka Akira: 10890: Completion/User/_gunzip,
 	Completion/User/_gzip, Completion/User/_zcat: new completion for
 	GNU zip commands
diff --git a/Completion/User/_perl_modules b/Completion/User/_perl_modules
index c909055ba..01c2eefa5 100644
--- a/Completion/User/_perl_modules
+++ b/Completion/User/_perl_modules
@@ -1,6 +1,5 @@
 #compdef pmpath pmvers pmdesc pmload pmexp pmeth pmls pmcat pman pmfunc podgrep podtoc podpath
 #
-#
 # _perl_modules - zsh completion function
 #
 # Adam Spiers <adam@spiers.net>
@@ -8,40 +7,56 @@
 # Calculate all installed Perl modules.  The result is cached
 # for future use.
 #
-# Bugs:
-#   - can't cope with multiple installs of Perl
+# Available styles:
+#
+# * try-to-use-pminst
+#
+#   Set this if you have pminst and want to use it.  The zsh code
+#   actually produces better results because pminst misses modules of
+#   the form Foo/bar/Baz.pm through its clumsy -d && /^[A-Z]/ && prune
+#   algorithm (the zsh code does almost the same, but only misses
+#   modules which don't begin with an uppercase letter).
 
-# Change this if you have pminst and want to use it.  The zsh code
-# actually produces better results because pminst misses modules of
-# the form Foo/bar/Baz.pm through its clumsy -d && /^[A-Z]/ && prune
-# algorithm (the zsh code does almost the same, but only misses modules
-# which don't begin with an uppercase letter).
-local try_to_use_pminst=0
+local opts
+zparseopts -D -a opts S: q
 
 if [[ ${+_perl_modules} -eq 0 ]]; then
-  if [[ $try_to_use_pminst -ne 0 ]] && which pminst >/dev/null; then
+  if zstyle -t ":completion:${curcontext}:modules" try-to-use-pminst \
+     && which pminst >/dev/null; then
     _perl_modules=( $(pminst) )
   else
     local inc libdir new_pms
-    inc=( $( perl -e 'print "@INC"' ) )
-    typeset -agU _perl_modules	# _perl_modules is global, no duplicates
+    if which perl >/dev/null; then
+      inc=( $( perl -e 'print "@INC"' ) )
+    else
+      # If perl isn't there, one wonders why the user's trying to
+      # complete Perl modules.  Maybe her $path is wrong?
+
+      setopt localoptions extendedglob
+      inc=( /usr/lib/perl5{,/{site_perl/,}<5->.([0-9]##)}(N) 
+            ${(s.:.)PERL5LIB} )
+    fi
+
+    typeset -agU _perl_modules  # _perl_modules is global, no duplicates
     _perl_modules=( )
 
     for libdir in $inc; do
-        # Ignore cwd - could be too expensive e.g. if we're near /
-        if [[ $libdir == '.' ]]; then break; fi
+      # Ignore cwd - could be too expensive e.g. if we're near /
+      if [[ $libdir == '.' ]]; then break; fi
 
-	# Find all modules
-	cd $libdir
-        new_pms=( {[A-Z]*/**/,}*.pm(N) )
-	cd $OLDPWD
+      # Find all modules
+      cd $libdir
+      new_pms=( {[A-Z]*/***/,}*.pm~*blib*(N) )
+      cd $OLDPWD
 
-	# Convert to Perl nomenclature
-	new_pms=( ${new_pms:r:fs#/#::#} )
+      # Convert to Perl nomenclature
+      new_pms=( ${new_pms:r:fs#/#::#} )
 
-        _perl_modules=( $new_pms $_perl_modules )
+      _perl_modules=( $new_pms $_perl_modules )
     done
   fi
 fi
 
-compadd - $_perl_modules
+local expl
+
+_wanted modules expl 'Perl modules' compadd "$opts[@]" - $_perl_modules