zsh-workers
 help / color / mirror / code / Atom feed
From: Adam Spiers <adam@thelonious.new.ox.ac.uk>
To: zsh workers mailing list <zsh-workers@math.gatech.edu>
Subject: PATCH: completion for perldoc
Date: Sun, 5 Sep 1999 22:38:14 +0100	[thread overview]
Message-ID: <19990905223814.A7518@thelonious.new.ox.ac.uk> (raw)

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@spiers.net>
+#
+# 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@spiers.net>
+#
+# 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@spiers.net>
+#
+# 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@spiers.net>
+#
+# 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
+


             reply	other threads:[~1999-09-05 21:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-05 21:38 Adam Spiers [this message]
1999-09-06  9:28 Sven Wischnowsky
1999-09-06 10:07 ` Adam Spiers
1999-09-06 11:37 Sven Wischnowsky
1999-09-06 18:18 ` Adam Spiers
1999-09-06 18:21   ` Adam Spiers
1999-09-07  8:57     ` Peter Stephenson
1999-09-07  9:18       ` Adam Spiers
1999-09-07  8:32 Sven Wischnowsky
1999-09-07  9:49 ` Adam Spiers
1999-09-07  8:59 Sven Wischnowsky
1999-09-07  9:02 Sven Wischnowsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19990905223814.A7518@thelonious.new.ox.ac.uk \
    --to=adam@thelonious.new.ox.ac.uk \
    --cc=adam@spiers.net \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).