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

PATCH: completion for perldoc



Here's a completion system for perldoc.  It's my first stab at
completions with the new system, so be warned: you may need to change
some glaring mistakes.  If it's very wrong, let me know; OTOH if it's
OKish then maybe there's more where that came from.

(Completion/User is the right place, right?)

Oh, and the zle -R bit doesn't work: it displays the text and then
immediately erases it.  No doubt this is some misunderstanding on my
part.


diff -urN zsh-3.1.6-clean/Completion/User/_perl_basepods zsh-3.1.6-adam/Completion/User/_perl_basepods
--- zsh-3.1.6-clean/Completion/User/_perl_basepods	Thu Jan  1 01:00:00 1970
+++ zsh-3.1.6-adam/Completion/User/_perl_basepods	Sun Sep  5 22:24:50 1999
@@ -0,0 +1,30 @@
+#autoload
+#
+# _perl_basepods - zsh completion function
+#
+# Adam Spiers <adam@xxxxxxxxxx>
+#
+# Calculate all installed Perl base pods (perlfunc, perlfaq etc.).
+# The result is cached for future use.
+#
+
+if [[ ${+_perl_basepods} -eq 0 ]]; then
+  typeset -agU _perl_basepods
+
+  if which basdepods >/dev/null; then
+    _perl_basepods=( ${$(basepods):t:r} )
+  else
+    local podpath
+    podpath=$(perl -MConfig -e 'print "$Config{installprivlib}/pod"')
+    if [[ ! -e $podpath/perl.pod ]]; then
+      echo "Couldn't find perl.pod from Config.pm; giving up."
+      return 1
+    else
+      cd $podpath
+      _perl_basepods=( *.pod(:r:t) )
+      cd $OLDPWD
+    fi
+  fi
+fi
+
+compadd - $_perl_basepods
diff -urN zsh-3.1.6-clean/Completion/User/_perl_builtin_funcs zsh-3.1.6-adam/Completion/User/_perl_builtin_funcs
--- zsh-3.1.6-clean/Completion/User/_perl_builtin_funcs	Thu Jan  1 01:00:00 1970
+++ zsh-3.1.6-adam/Completion/User/_perl_builtin_funcs	Sun Sep  5 22:24:50 1999
@@ -0,0 +1,29 @@
+#autoload
+#
+# _perl_builtin_funcs - zsh completion function
+#
+# Adam Spiers <adam@xxxxxxxxxx>
+#
+# Calculate all built-in Perl functions.  The result is cached
+# for future use.
+#
+
+if [[ ${+_perl_builtin_funcs} -eq 0 ]]; then
+  typeset -agU _perl_builtin_funcs
+  local perlfunc
+
+  if perlfunc=`man -w perlfunc 2>&1`; then
+    _perl_builtin_funcs=( `perl -lne '
+                             $in_funcs++, next if /Alphabetical/;     \
+                             next unless $in_funcs;                   \
+                             if (/^\.Ip "(\w+)/) {                    \
+                               print $1 unless $func{$1}; $func{$1}++ \
+                             }' $perlfunc`
+               )
+  else
+    echo "Couldn't find perlfunc man page; giving up."
+    return 1
+  fi
+fi
+
+compadd - $_perl_builtin_funcs
diff -urN zsh-3.1.6-clean/Completion/User/_perl_modules zsh-3.1.6-adam/Completion/User/_perl_modules
--- zsh-3.1.6-clean/Completion/User/_perl_modules	Thu Jan  1 01:00:00 1970
+++ zsh-3.1.6-adam/Completion/User/_perl_modules	Sun Sep  5 22:24:50 1999
@@ -0,0 +1,47 @@
+#compdef pmpath pmvers pmdesc pmload pmexp pmeth pmls pmcat pman pmfunc podgrep podtoc podpath
+#
+#
+# _perl_modules - zsh completion function
+#
+# Adam Spiers <adam@xxxxxxxxxx>
+#
+# Calculate all installed Perl modules.  The result is cached
+# for future use.
+#
+# Bugs:
+#   - can't cope with multiple installs of Perl
+
+# 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
+
+if [[ ${+_perl_modules} -eq 0 ]]; then
+  if [[ $try_to_use_pminst -ne 0 ]] && 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
+    _perl_modules=( )
+
+    for libdir in $inc; do
+        # 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
+
+	# Convert to Perl nomenclature
+	new_pms=( ${new_pms:r:fs#/#::#} )
+
+        _perl_modules=( $new_pms $_perl_modules )
+    done
+  fi
+fi
+
+compadd - $_perl_modules
diff -urN zsh-3.1.6-clean/Completion/User/_perldoc zsh-3.1.6-adam/Completion/User/_perldoc
--- zsh-3.1.6-clean/Completion/User/_perldoc	Thu Jan  1 01:00:00 1970
+++ zsh-3.1.6-adam/Completion/User/_perldoc	Sun Sep  5 22:31:18 1999
@@ -0,0 +1,23 @@
+#compdef perldoc
+#
+#
+# _perldoc - zsh completion function for perldoc
+#
+# Adam Spiers <adam@xxxxxxxxxx>
+#
+# Behaviour should be roughly equivalent to:
+# compctl -k perl_modules -k perl_basepods -f 
+#           -x 'c[-1,-f]' -k perl_funcs --
+#	  + -k man_pages
+#     perldoc
+
+if [[ $CURRENT -eq 3 && $words[2] == '-f' ]]; then
+  _perl_builtin_funcs
+elif [[ $CURRENT -eq 3 && $words[2] == '-q' ]]; then
+  zle -R "I can't read your mind!"
+else
+  _perl_modules
+  _perl_basepods
+  _path_files -/ -g '*.(pod|pm)'
+fi
+



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