[comp.emacs] describe-perl-symbol for GNU Emacs

jv@mh.nl (Johan Vromans) (06/29/90)

This little goodie I coocked up recently. It provides a one-line help
message for most perl symbols. Simply point at (or just after) the
symbol of function name, and call 'describe-perl-symbol for a
one-liner.

To install: unload the sharchive, move the descriptive text
"perl-descr.txt" to any convenient place, and adjust the variable
'perl-doc-file' accordingly.

This code is loosely based on 'describe-lisp-symbol', so I think the
GPL applies.

Have fun!

Submitted-by: jv@squirrel
Archive-name: perl-descr/part01

---- Cut Here and unpack ----
#!/bin/sh
# This is perl-descr, a shell archive (shar 3.24)
# made 06/28/1990 15:11 UTC by jv@squirrel
# Source directory /u/jv/elisp/src/perldescr
#
# existing files WILL be overwritten
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   2730 -r--r--r-- perl-descr.el
#   7268 -r--r--r-- perl-descr.txt
#
if touch 2>&1 | fgrep '[-amc]' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= perl-descr.el ==============
echo "x - extracting perl-descr.el (Text)"
sed 's/^X//' << 'SHAR_EOF' > perl-descr.el &&
X;; @(#)@ perl-descr.el	1.3 - describe-perl-symbol
X
X;; This file defines the function 'describe-perl-symbol, which
X;; displays a one-line information on a perl symbol.
X
X;; Based on 'describe-lisp-symbol' and others.
X;; Hacked for Perl by Johan Vromans <jv@mh.nl>
X
X(defvar perl-doc-file "~/elisp/perl-descr.txt"
X  "*Where the documentation file can be found.")
X
X(defun perl-symbol-at-point ()
X  "Get the closest Perl symbol to point, but don't change your
Xposition. Has a preference for looking backward when not
Xdirectly on a symbol."
X
X  (let ((perl-wordchars "a-zA-Z0-9_") start end symbol)
X	      
X    (save-excursion
X
X      ;; first see if you're just past a symbol
X      (if (looking-at "\\s-*[][{}()]+")
X	  (skip-chars-backward " \n\t\r({[]})")
X
X	;; else move forward one character, presumably either a \w or
X	;; a symbol
X	(or (= (point) (point-max))
X	    (forward-char 1)))
X
X      (if (eql (aref perl-mode-syntax-table (preceding-char)) 2)
X	  ;; just past a \\w
X	  (progn
X	    (skip-chars-backward perl-wordchars)
X	    (setq start (point))
X	    ; Get identifier. Include leading $ % @ .
X	    (if (= (point) (point-min))
X		nil
X	      (backward-char 1)
X	      (if (looking-at "[$%@]")
X		  (setq start (point)))
X	      (forward-char 1))
X	    (skip-chars-forward perl-wordchars))
X	;; else a symbol?
X	  (progn
X	    (skip-chars-backward " \n\t") ; back whitespace
X	    (backward-char 1)
X	    (setq start (point))
X	    (if (looking-at "[$@][^ \n\t]") ; special variable
X		(forward-char 1)
X	      (if (= (point) (point-min))
X		  nil
X		(backward-char 1)
X		(if (looking-at "[$@]")
X		    (setq start (point)))
X		(forward-char 1)))
X	    (forward-char 1)))
X      (buffer-substring start (point)))))
X
X(defun describe-perl-symbol (symbol)
X  "Display the documentation of SYMBOL, an Perl operator."
X  (interactive
X    (let ((fn (perl-symbol-at-point))
X	  (enable-recursive-minibuffers t)
X	  (case-fold-search nil)	;require that case match for search
X	  val args-file regexp)
X      (setq val (read-from-minibuffer
X		  (if fn
X		      (format "Symbol (default %s): " fn)
X		    "Symbol: ")))
X      (if (string= val "")
X	  (setq val fn))
X      (setq regexp (concat "^" (regexp-quote val) "[ \t(]"))
X      (if (not (get-file-buffer doc-file))
X	  (progn
X	    (setq args-file
X	      (find-file-noselect doc-file))
X	    (set-buffer args-file)
X	    (rename-buffer "*PERL-DOC*")
X	    (setq buffer-read-only t)))
X      (set-buffer (get-file-buffer doc-file))
X      (goto-char (point-min))
X      (list (if (re-search-forward regexp (point-max) t)
X		(save-excursion
X		  (beginning-of-line 1)
X		  (let ((lnstart (point)))
X		    (end-of-line)
X		    (message "%s" (buffer-substring lnstart (point)))))
X	      (error (format "No definition for %s" val)))))))
SHAR_EOF
$TOUCH -am 0628170690 perl-descr.el &&
chmod 0444 perl-descr.el ||
echo "restore of perl-descr.el failed"
set `wc -c perl-descr.el`;Wc_c=$1
if test "$Wc_c" != "2730"; then
	echo original size 2730, current size $Wc_c
fi
# ============= perl-descr.txt ==============
echo "x - extracting perl-descr.txt (Text)"
sed 's/^X//' << 'SHAR_EOF' > perl-descr.txt &&
X# @(#)@ perl-descr.txt 1.3 - describe-perl-symbol [text]
X/PATTERN/io
Xaccept(NEWSOCKET,GENERICSOCKET)
Xatan2(X,Y)
Xbind(SOCKET,NAME)
Xbinmode(FILEHANDLE)
Xchdir(EXPR)
Xchmod(LIST)
Xchop[(LIST|VAR)]
Xchown(LIST)
Xchroot(FILENAME)
Xclose(FILEHANDLE)
Xclosedir(DIRHANDLE)
Xconnect(SOCKET,NAME)
Xcos(EXPR)
Xcrypt(PLAINTEXT,SALT)
Xdbmclose(ASSOC_ARRAY)
Xdbmopen(ASSOC,DBNAME,MODE)
Xdefined(EXPR)
Xdelete($ASSOC{KEY})
Xdie(LIST)
Xdo(BLOCK|EXPR|SUBR([LIST]))
Xdump(LABEL)
Xeach(ASSOC_ARRAY)
Xendgrent
Xendhostent
Xendnetent
Xendprotoent
Xendpwent
Xendservent
Xeof[([FILEHANDLE])]
Xeval(EXPR)
Xexec(LIST)
Xexit(EXPR)
Xexp(EXPR)
Xfcntl(FILEHANDLE,FUNCTION,SCALAR)
Xfileno(FILEHANDLE)
Xflock(FILEHANDLE,OPERATION)
Xfork
Xgetc[(FILEHANDLE)]
Xgetgrent
Xgetgrgid(GID)
Xgetgrnam(NAME)
Xgethostbyaddr(ADDR,ADDRTYPE)
Xgethostbyname(NAME)
Xgethostent
Xgetlogin
Xgetnetbyaddr(ADDR,ADDRTYPE)
Xgetnetbyname(NAME)
Xgetnetent
Xgetpeername(SOCKET)
Xgetpgrp(PID)
Xgetppid
Xgetpriority(WHICH,WHO)
Xgetprotobyname(NAME)
Xgetprotobynumber(NUMBER)
Xgetprotoent
Xgetpwent
Xgetpwnam(NAME)
Xgetpwuid(UID)
Xgetservbyname(NAME,PROTO)
Xgetservbyport(PORT,PROTO)
Xgetservent
Xgetsockname(SOCKET)
Xgetsockopt(SOCKET,LEVEL,OPTNAME)
Xgmtime(EXPR)
Xgoto(LABEL)
Xgrep(EXPR,LIST)
Xhex(EXPR)
Xindex(STR,SUBSTR)
Xint(EXPR)
Xioctl(FILEHANDLE,FUNCTION,SCALAR)
Xjoin(EXPR,LIST)
Xkeys(ASSOC_ARRAY)
Xkill(LIST)
Xlast[(LABEL)]
Xlength(EXPR)
Xlink(OLDFILE,NEWFILE)
Xlisten(SOCKET,QUEUESIZE)
Xlocal(LIST)
Xlocaltime(EXPR)
Xlog(EXPR)
Xlstat(EXPR|FILEHANDLE|VAR)
Xm/PATTERN/io
Xmkdir(FILENAME,MODE)
Xnext[(LABEL)]
Xoct(EXPR)
Xopen(FILEHANDLE[,EXPR])
Xopendir(DIRHANDLE,EXPR)
Xord(EXPR)
Xpack(TEMPLATE,LIST)
Xpipe(READHANDLE,WRITEHANDLE)
Xpop(ARRAY)
Xprint[(FILEHANDLE [LIST])]
Xprintf([FILEHANDLE] LIST)
Xpush(ARRAY,LIST)
Xq/STRING/
Xqq/STRING/
Xrand[(EXPR)]
Xread(FILEHANDLE,SCALAR,LENGTH)
Xreaddir(DIRHANDLE)
Xreadlink(EXPR)
Xrecv(SOCKET,SCALAR,LEN,FLAGS)
Xredo[(LABEL)]
Xrename(OLDNAME,NEWNAME)
Xreset[(EXPR)]
Xreturn(LIST)
Xreverse(LIST)
Xrewinddir(DIRHANDLE)
Xrindex(STR,SUBSTR)
Xrmdir(FILENAME)
Xs/PATTERN/REPLACEMENT/gieo
Xseek(FILEHANDLE,POSITION,WHENCE)
Xseekdir(DIRHANDLE,POS)
Xselect(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
Xsend(SOCKET,MSG,FLAGS[,TO])
Xsetgrent
Xsethostent(STAYOPEN)
Xsetnetent(STAYOPEN)
Xsetpgrp(PID,PGRP)
Xsetpriority(WHICH,WHO,PRIORITY)
Xsetprotoent(STAYOPEN)
Xsetpwent
Xsetservent(STAYOPEN)
Xsetsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
Xshift[(ARRAY)]
Xshutdown(SOCKET,HOW)
Xsin(EXPR)
Xsleep[(EXPR)]
Xsocket(SOCKET,DOMAIN,TYPE,PROTOCOL)
Xsocketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
Xsort([SUBROUTINE] LIST)
Xsplice(ARRAY,OFFSET[,LENGTH[,LIST]])
Xsplit[(/PATTERN/[,EXPR[,LIMIT]])]
Xsprintf(FORMAT,LIST)
Xsqrt(EXPR)
Xsrand(EXPR)
Xstat(EXPR|FILEHANDLE|VAR)
Xstudy[(SCALAR)]
Xsubstr(EXPR,OFFSET,LEN)
Xsymlink(OLDFILE,NEWFILE)
Xsyscall(LIST)
Xsystem(LIST)
Xtell[(FILEHANDLE)]
Xtelldir(DIRHANDLE)
Xtime
Xtimes
Xtr/SEARCHLIST/REPLACEMENTLIST/
Xumask[(EXPR)]
Xundef[(EXPR)]
Xunlink(LIST)
Xunpack(TEMPLATE,EXPR)
Xunshift(ARRAY,LIST)
Xutime(LIST)
Xvalues(ASSOC_ARRAY)
Xvec(EXPR,OFFSET,BITS)
Xwait
Xwantarray
Xwarn(LIST)
Xwrite[(EXPR|FILEHANDLE)]
Xy/SEARCHLIST/REPLACEMENTLIST/
X$_	The default input and pattern-searching space.
X$.	The current input line number of the last filehandle that was read.
X$/	The input record separator, newline by default.
X$,	The output field separator for the print operator.
X$"	The separator which joins elements of arrays interpolated in strings.
X$\	The output record separator for the print operator.
X$#	The output format for printed numbers. Initial value is %.20g.
X$*	Set to 1 to do multiline matching within a string, 0 to assume strings contain a single line. Default is 0.
X$?	The status returned by the last backtick (``) command, pipe close or system operator.
X$]	The perl version string as displayed with perl -v.
X$[	The index of the first element in an array, and of the first character in a substring. Default is 0.
X$;	The subscript separator for multi-dimensional array emulation. Default is "\034".
X$!	If used in a numeric context, yields the current value of errno. If used in a string context, yields the corresponding error string.
X$@	The perl error message from the last eval or do @var{EXPR} command.
X$:	The set of characters after which a string may be broken to fill continuation fields (starting with ^) in a format.
X$0	The name of the file containing the perl script being executed.
X$$	The process number of the perl running this script. Altered (in the child process) by fork().
X$<	The real uid of this process.
X$>	The effective uid of this process.
X$(	The real gid of this process.
X$)	The effective gid of this process.
X$%	The current page number of the currently selected output channel.
X$=	The page length of the current output channel. Default is 60 lines.
X$-	The number of lines left on the page.
X$~	The name of the current report format.
X$^	The name of the current top-of-page format.
X$|	If set to nonzero, forces a flush after every write or print on the currently selected output channel. Default is 0. The following variables are always local to the current block:
X$&	The string matched by the last pattern match.
X$`	The string preceding what was matched by the last pattern match.
X$'	The string following what was matched by the last pattern match.
X$+	The last bracket matched by the last search pattern.
X$1..$9	Contains the subpattern from the corresponding set of parentheses in the last pattern matched.
X@ARGV	Contains the command line arguments for the script (not including the command name). See $0 for the command name.
X@INC	Contains the list of places to look for perl scripts to be evaluated by the do EXPR command.
X@_	Parameter array for subroutines. Also used by split if not in array context.
X%ENV	Contains the current environment.
X%SIG	Used to set signal handlers for various signals.
X+	Addition.
X-	Subtraction.
X*	Multiplication.
X/	Division.
X%	Modulo division.
X|	Bitwise or.
X&	Bitwise and.
X^	Bitwise exclusive or.
X>>	Bitwise shift right.
X<<	Bitwise shift left.
X**	Exponentiation.
X.	Concatenate strings.
Xx	Repeat string.
X++	Auto-increment (magical on strings).
X--	Auto--decrement.
X? :	Alternation (if-then-else) operator.
X||	Logical or.
X&&	Logical and.
X==	Numeric equality.
X!=	Numeric inequality.
Xeq	String equality.
Xne	String inequality.
X>	Numeric greater than.
X<	Numeric less than.
Xgt	String greater than.
Xlt	String less than.
X<=	Numeric less than or equal to.
X>=	Numeric greater than or equal to.
Xle	String less than or equal.
Xge	String greater than or equal.
X=~	Search pattern, substitution, or translation.
X!~	Search pattern, substitution, or translation (negated).
X..	Alternation, also range operator.
X,	Comma operator.
X-r	File is readable by effective uid.
X-w	File is writable by effective uid.
X-x	File is executable by effective uid.
X-o	File is owned by effective uid.
X-R	File is readable by real uid.
X-W	File is writable by real uid.
X-X	File is executable by real uid.
X-O	File is owned by real uid.
X-e	File exists .
X-z	File has zero size.
X-s	File has non-zero size.
X-f	File is a plain file.
X-d	File is a directory.
X-l	File is a symbolic link.
X-S	File is a socket .
X-p	File is a named pipe (FIFO).
X-b	File is a block special file.
X-c	File is a character special file.
X-u	File has setuid bit set.
X-g	File has setgid bit set.
X-k	File has sticky bit set.
X-t	Tests if filehandle (STDIN by default) is opened to a tty.
X-T	File is a text file.
X-B	File is a non-text (binary) file.
SHAR_EOF
$TOUCH -am 0628170490 perl-descr.txt &&
chmod 0444 perl-descr.txt ||
echo "restore of perl-descr.txt failed"
set `wc -c perl-descr.txt`;Wc_c=$1
if test "$Wc_c" != "7268"; then
	echo original size 7268, current size $Wc_c
fi
exit 0
--
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------