Anonymous avatar Anonymous committed 6694a65

Created

Comments (0)

Files changed (16)

+1998-01-13  Hrvoje Niksic  <hniksic@srce.hr>
+
+	* old-prim/profile.el (profile-results): Use call-count-profile-table.
+	(profile-call-count-results): New function.
+
+1998-01-12  SL Baur  <steve@altair.xemacs.org>
+
+	* pretty-print.el: Reformat comments.
+
+1997-12-27  Jens-Ulrik Holger Petersen  <petersen@kurims.kyoto-u.ac.jp>
+
+	* pretty-print.el (pp-internal): Make it autoloaded.  Docstring typo.
+
+1997-12-17  Jens-Ulrik Holger Petersen  <petersen@kurims.kyoto-u.ac.jp>
+
+	* pretty-print.el (pp-internal-sexp): Protect fboundp call with
+	symbolp test.  Necessary to be able to print a value of `(-3 smthg)'
+	for example.
+
+1998-01-11  SL Baur  <steve@altair.xemacs.org>
+
+	* Makefile (ELCS): Add pretty-print.el.
+	Update to latest package spec.
+	
+1997-12-10  Christoph Wedler  <wedler@fmi.uni-passau.de>
+
+	* find-func.el (find-function-noselect): `regexp-quote'
+	function name FUNCTION.
+
+1998-01-02  SL Baur  <steve@altair.xemacs.org>
+
+	* _pkg.el (xemacs-devel): Updated package-provide spec.
+
+1998-01-01  SL Baur  <steve@altair.xemacs.org>
+
+	* ielm.el: New file.
+
+1997-12-24  SL Baur  <steve@altair.xemacs.org>
+
+	* elp.el: Remove bytecompile time dependency on reporter
+
+	* Makefile: Added find-func.el, regexp-opt.el, and reposition.el.
+
+1997-12-23  SL Baur  <steve@altair.xemacs.org>
+
+	* docref.el: Updated commentary.
+
+	* Makefile: Created.
+# Makefile for XEmacs development lisp code
+
+# This file is part of XEmacs.
+
+# XEmacs is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+
+# XEmacs is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with XEmacs; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# This XEmacs package contains independent single file lisp packages
+
+VERSION = 1.05
+PACKAGE = xemacs-devel
+PKG_TYPE = single-file
+REQUIRES = xemacs-base
+CATEGORY = libs
+
+ELCS = bench.elc docref.elc eldoc.elc elp.elc find-func.elc find-gc.elc \
+	ielm.elc lisp-file-db.elc profile.elc pretty-print.elc regexp-opt.elc \
+	reposition.elc trace.elc
+
+include ../../XEmacs.rules
+
+all:: $(ELCS) auto-autoloads.elc custom-load.elc
+
+srckit: srckit-std
+
+binkit: binkit-sourceonly
+;;; bench.el --- benchmarking utility for emacsen
+
+;; Copyright (C) 1987,88,89,90,93,94,95,96 Free Software Foundation, Inc.
+;; $Id$	
+;; $Source$
+;; $Revision$
+;; $Author$
+;; $Date$
+
+;; Author: Shane Holder <holder@rsn.hp.com>
+;; Adapted-By: Steve Baur <steve@altair.xemacs.org>
+;; Further adapted by: Shane Holder <holder@rsn.hp.com>
+;; Keywords: internal, maint
+
+;; This file is part of XEmacs.
+
+;; XEmacs is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; XEmacs is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with XEmacs; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+;; 02111-1307, USA.
+
+;;; Commentary:
+
+;; Adapted from Shane Holder's bench.el by steve@altair.xemacs.org.
+
+;; To run
+;; Extract the shar file in /tmp, or modify bench-lisp-file to
+;; point to the gnus.el file.
+;; At the shell prompt emacs -q --no-site-file <= don't load users .emacs or site-file
+;; M-x byte-compile-file "/tmp/bench.el"
+;; M-x load-file "/tmp/bench.elc"
+;; In the scratch buffer (bench 1)
+
+
+;; All bench marks must be named bench-mark-<something>
+;; Results are put in bench-mark-<something-times which is a list of
+;;  times for the runs.
+;; If the bench mark is not simple then there needs to be a
+;;  corresponding bench-handler-<something>
+
+;;; Code:
+
+;; Use elp to profile benchmarks
+(require 'cl)				;Emacs doesn't have when and cdar
+
+;-----------------------------------------------------------------------------
+(defvar bench-mark-hanoi-times nil)
+
+(defun bench-handler-hanoi (times)
+  (let ((start-time))
+  (while (> times 0)
+;    (setq start-time (bench-get-time))
+    (bench-mark-hanoi)
+;    (setq bench-mark-hanoi-times (cons (- (bench-get-time) start-time ) bench-mark-hanoi-times ))
+    (setq times (- times 1))))
+)
+
+(defun bench-mark-hanoi ()
+  "How long to complete the tower of hanoi."
+  (hanoi 4))
+
+;-----------------------------------------------------------------------------
+(defvar bench-mark-font-lock-buffer nil "buffer used for bench-mark-fontlock")
+
+(defun bench-handler-font-lock (times)
+  (setq bench-mark-font-lock-buffer (find-file bench-lisp-file))
+  (while (> times 0)
+    (bench-mark-font-lock)
+    (font-lock-mode)			; Turn it off
+    (setq times (- times 1)))
+  (kill-buffer bench-mark-font-lock-buffer)
+)
+
+(defun bench-mark-font-lock ()
+  "How long to fonitfy a large file."
+  (font-lock-fontify-buffer)
+)
+
+;-----------------------------------------------------------------------------
+(defvar bench-mark-scrolling-buffer nil "buffer used for bench-mark-scrolling")
+
+(defun bench-handler-scrolling (times)
+  (setq bench-mark-scrolling-buffer (find-file bench-lisp-file))
+  (set-buffer bench-mark-scrolling-buffer)
+;  (setq scroll-step 1)
+  (font-lock-mode -1)
+  (goto-char (point-min))		;Start at point min
+  (let ((temp-times times))
+    (while (> temp-times 0)
+      (bench-mark-scrolling-down)
+      (bench-mark-scrolling-up)
+      (setq temp-times (- temp-times 1))))
+
+  (font-lock-fontify-buffer)
+
+  (goto-char (point-min))		;Start at point min
+  (let ((temp-times times))
+    (while (> temp-times 0)
+      (bench-mark-scrolling-down-fontified)
+      (bench-mark-scrolling-up-fontified)
+      (setq temp-times (- temp-times 1))))
+  (kill-buffer bench-mark-scrolling-buffer)
+)
+
+(defun bench-mark-scrolling-down ()
+  "How long does it take to scroll down through a large file.
+Expect point to be at point min"
+  (let ((buffer-read-only t))
+    (while (< (point) (point-max))
+      (next-line 1)
+      (sit-for 0))))
+
+(defun bench-mark-scrolling-up ()
+  "How long does it take to scroll up through a large fontified ile."
+  (let ((buffer-read-only t))
+    (while (> (point) (point-min))
+      (previous-line 1)
+      (sit-for 0))))
+
+(defun bench-mark-scrolling-down-fontified ()
+  "How long does it take to scroll down through a large fontified file."
+  (let ((buffer-read-only t))
+    (goto-char (point-min))
+    (while (< (point) (point-max))
+      (next-line 1)
+      (sit-for 0))))
+
+(defun bench-mark-scrolling-up-fontified ()
+  "How long does it take to scroll up through a large fontified ile."
+  (let ((buffer-read-only t))
+    (while (> (point) (point-min))
+      (previous-line 1)
+      (sit-for 0))))
+
+;-----------------------------------------------------------------------------
+
+(defun bench-handler-make-frames (times)
+  (let ((temp-times times)
+	(frame))
+    (while (> temp-times 0)
+      (setq frame (bench-mark-make-frame)) ;Make frame
+      (bench-mark-delete-frame frame)	;Delete frame
+      (setq temp-times (- temp-times 1))))
+
+  (let ((temp-times times)
+	(frames))
+    (while (> temp-times 0)
+      (setq frames (cons (bench-mark-make-multiple-frames) frames)) ;Make frames
+      (setq temp-times (- temp-times 1)))
+
+    (setq temp-times times)
+
+    (while (> temp-times 0)
+      (bench-mark-delete-multiple-frames (car frames))	;Delete frames
+      (setq frames (cdr frames))
+      (setq temp-times (- temp-times 1))))
+
+)
+
+(defun bench-mark-make-frame ()
+  "How quickly can emacs create a new frame."
+  (make-frame))
+
+(defun bench-mark-delete-frame (frame)
+  "How quickly can emacs create a new frame."
+  (delete-frame frame))
+
+(defun bench-mark-make-multiple-frames ()
+  "How quickly can emacs create a new frame."
+  (make-frame))
+
+(defun bench-mark-delete-multiple-frames (frame)
+  "How quickly can emacs create a new frame."
+  (delete-frame frame))
+
+
+;-----------------------------------------------------------------------------
+(defconst bench-mark-make-words-buffer nil)
+(defconst bench-mark-make-words-buffer-name "*bench-mark-make-words*")
+(defconst bench-mark-make-words-number-of-words 10000)
+
+(defun bench-handler-make-words (times)
+  (setq bench-mark-make-words-buffer (get-buffer-create bench-mark-make-words-buffer-name))
+  (set-buffer bench-mark-make-words-buffer)
+  (while (> times 0)
+    (bench-mark-make-words)
+    (erase-buffer)
+    (setq times (- times 1)))
+  (kill-buffer bench-mark-make-words-buffer)
+)
+
+(defun bench-mark-make-words ()
+  "How long does it take to generate lots of random words."
+  (let ((tmp-words bench-mark-make-words-number-of-words))
+    (while (not (= tmp-words 0))
+      (let ((word-len (random 10)))
+	(while (not (= word-len 0))
+	  (insert (+ ?a (random 25)))
+	  (setq word-len (- word-len 1))))
+      (insert "\n")
+      (setq tmp-words (- tmp-words 1)))))
+
+;-----------------------------------------------------------------------------
+(defconst bench-mark-sort-words-buffer-name "*bench-mark-sort-words*")
+(defconst bench-mark-sort-words-buffer nil)
+(defconst bench-mark-sort-words-number-words 10000)
+
+(defun bench-handler-sort-words (times)
+  (setq bench-mark-sort-words-buffer (get-buffer-create bench-mark-sort-words-buffer-name))
+  (switch-to-buffer bench-mark-sort-words-buffer)
+  (while (> times 0)
+    (bench-pre-sort-words)			;Generate the random words
+    (bench-mark-sort-words)			;Sort those puppies
+    (erase-buffer)
+    (setq times (- times 1)))
+  (kill-buffer bench-mark-sort-words-buffer)
+)
+
+(defun bench-pre-sort-words ()
+  "How long does it take to generate lots of random words."
+  (let ((tmp-words bench-mark-sort-words-number-words))
+    (while (not (= tmp-words 0))
+      (let ((word-len (random 10)))
+	(while (not (= word-len 0))
+	  (insert (+ ?a (random 25)))
+	  (setq word-len (- word-len 1))))
+      (insert "\n")
+      (setq tmp-words (- tmp-words 1)))))
+
+(defun bench-mark-sort-words ()
+  (sort-lines nil (point-min) (point-max))
+)
+
+;-----------------------------------------------------------------------------
+; Byte compile a file
+(defun bench-handler-byte-compile (times)
+  (while (> times 0)
+    (bench-mark-byte-compile)
+    (setq times (- times 1)))
+)
+
+(defun bench-mark-byte-compile ()
+  "How long does it take to byte-compile a large lisp file"
+  (byte-compile-file bench-lisp-file)
+)
+
+;-----------------------------------------------------------------------------
+; Run through a loop
+
+(defconst bench-mark-loop-count 250000)
+
+(defun bench-handler-loop (times)
+  (while (> times 0)
+    (bench-mark-loop)
+    (setq times (- times 1)))
+)
+
+(defun bench-mark-loop ()
+  "How long does it take to run through a loop."
+  (let ((count bench-mark-loop-count))
+    (let ((i 0) (gcount 0))
+      (while (< i count)
+	(increment)
+	(setq i (1+ i)))
+      (message "gcount = %d" gcount))))
+
+(defun increment ()
+  "Increment a variable for bench-mark-loop."
+  (setq gcount (1+ gcount)))
+
+;-----------------------------------------------------------------------------
+(defconst bench-mark-large-list-list-size 500000
+  "Size of list to use in small list creation/garbage collection")
+(defconst bench-mark-large-list-num-lists 10)
+
+(defun bench-handler-large-list (times)
+  (let ((tmp-foo bench-mark-large-list-num-lists))
+    (while (> tmp-foo 0)
+      (bench-mark-large-list)
+      (setq tmp-foo (- tmp-foo 1))))
+)
+
+(defun bench-mark-large-list ()
+  (make-list bench-mark-large-list-list-size '1)
+)
+
+;-----------------------------------------------------------------------------
+(defun bench-mark-large-list-garbage-collect (times)
+  (garbage-collect)
+)
+
+;-----------------------------------------------------------------------------
+(defconst bench-mark-small-list-list-size 10
+  "Size of list to use in small list creation/garbage collection")
+
+(defconst bench-mark-small-list-num-lists 100000
+  "Number of lists to use in small list creation/garbage collections")
+
+(defun bench-handler-small-list (times)
+  (let ((tmp-foo bench-mark-small-list-num-lists))
+    (while (> tmp-foo 0)
+      (bench-mark-small-list)
+      (setq tmp-foo (- tmp-foo 1)))
+))
+
+(defun bench-mark-small-list ()
+  (make-list bench-mark-small-list-list-size '1)
+)
+
+;-----------------------------------------------------------------------------
+(defun bench-mark-small-list-garbage-collect (times)
+  (garbage-collect)
+)
+
+;-----------------------------------------------------------------------------
+(defconst bench-mark-insert-into-empty-buffer-num-words 100000)
+
+(defun bench-handler-insert-into-empty-buffer (times)
+  (set-buffer (get-buffer-create "*tmp*"))
+  (bench-mark-insert-into-empty-buffer)
+  (erase-buffer)
+  (kill-buffer "*tmp*")
+)
+
+(defun bench-mark-insert-into-empty-buffer ()
+  (let ((a bench-mark-insert-into-empty-buffer-num-words))
+    (while (> a 0)
+      (insert "0123456789\n")
+      (setq a (1- a))))
+)
+
+;=============================================================================
+(defconst bench-version (let ((rcsvers "$Revision$"))
+			  (substring rcsvers 11 (- (length rcsvers) 2)))
+  "*Version number of bench.el")
+
+(defconst temp-dir (file-name-as-directory
+		    (or (getenv "TMPDIR")
+			(getenv "TMP")
+			(getenv "TEMP")
+			"/tmp/")))
+
+(defconst bench-large-lisp-file (concat temp-dir "./bench-large.el")
+  "Large lisp file to use in benchmarks should be /temp-dir/bench-text.el")
+
+(defconst bench-small-lisp-file (concat temp-dir "./bench-small.el")
+  "Large lisp file to use in benchmarks should be /temp-dir/bench-text.el")
+
+(defconst bench-lisp-file bench-large-lisp-file)
+
+(defconst bench-pre-bench-hook nil
+  "Hook for individual bench mark initialization.")
+
+(defconst bench-post-bench-hook nil
+  "Hook for individual bench mark statistic collection.")
+
+(defconst bench-mark-function-alist 
+  '(
+    (bench-handler-hanoi . "Tower of Hanoi")
+    (bench-handler-font-lock               . "Font Lock")
+    (bench-handler-scrolling               . "Large File scrolling")
+    (bench-handler-make-frames             . "Frame Creation")
+    (bench-handler-make-words              . "Generate Words")
+    (bench-handler-sort-words              . "Sort Buffer")
+    (bench-handler-byte-compile            . "Large File bytecompilation")
+    (bench-handler-loop                    . "Loop Computation")
+    (bench-handler-large-list              . "Make a Few Large Size List")
+    (bench-mark-large-list-garbage-collect . "Garbage Collection Large Size List")
+    (bench-handler-small-list              . "Make Several Small Size List")
+    (bench-mark-small-list-garbage-collect  . "Garbage Collection Small Size List")
+    (bench-handler-insert-into-empty-buffer . "Text Insertion")
+))
+
+(defconst bench-enabled-profiling nil
+  "If non-nil and the underlying emacs supports it, do function profiling.")
+
+(defconst bench-mark-profile-buffer "*Profile*"
+  "Buffer used for collection of profiling data.")
+
+(setq gc-cons-threshold 40000000)
+
+(defconst bench-small-frame-alist '((height . 24) (width . 80)))
+(defconst bench-medium-frame-alist '((height . 48) (width . 80)))
+(defconst bench-large-frame-alist '((height . 72) (width . 80)))
+
+(defsubst bench-get-time ()
+  ;; Stolen from elp
+  ;; get current time in seconds and microseconds. I throw away the
+  ;; most significant 16 bits of seconds since I doubt we'll ever want
+  ;; to profile lisp on the order of 18 hours. See notes at top of file.
+  (let ((now (current-time)))
+    (+ (float (nth 1 now)) (/ (float (nth 2 now)) 1000000.0))))
+
+(defun bench-init ()
+  "Initialize profiling for bench marking package."
+  (if (fboundp 'start-profiling)
+      (let ((buf (get-buffer-create bench-mark-profile-buffer)))
+	(erase-buffer buf)
+	(when (profiling-active-p)
+	  (stop-profiling)
+	  (clear-profiling-info)))
+    (message "Profiling not available in this XEmacs.")
+    (sit-for 2)))
+
+(defun bench-test-init ()
+  "Initialize profiling for bench marking package."
+  (if (fboundp 'start-profiling)
+      (let ((buf (get-buffer-create bench-mark-profile-buffer)))
+	(erase-buffer buf)
+	(when (profiling-active-p)
+	  (stop-profiling)
+	  (clear-profiling-info)))
+    (message "Profiling not available in this XEmacs.")
+    (sit-for 2))
+  (setq bench-lisp-file bench-small-lisp-file)
+  (setq bench-mark-make-words-number-of-words 100)
+  (setq bench-mark-sort-words-number-of-words 100)
+  (setq bench-mark-loop-count 10000)
+  (setq bench-mark-large-list-list-size 500)
+  (setq bench-mark-small-list-num-lists 100)
+  (setq bench-mark-insert-into-empty-buffer-num-words 100)
+  
+)
+
+(defun bench-profile-start (test-name)
+  "Turn on profiling for test `test-name'."
+  (when (and bench-enabled-profiling
+	     (fboundp 'start-profiling))
+    (when (profiling-active-p)
+      (stop-profiling))
+    (let ((buf (get-buffer-create bench-mark-profile-buffer)))
+      (save-excursion
+	(set-buffer buf)
+	(insert "Test `" test-name "'\n")
+	(start-profiling)))))
+
+(defun bench-profile-stop (test-name)
+  "Turn off profiling for test `test-name'."
+  (when (and bench-enabled-profiling
+	     (fboundp 'stop-profiling))
+    (stop-profiling)
+    (let ((buf (get-buffer-create bench-mark-profile-buffer)))
+      (save-excursion
+	(set-buffer buf)
+	(insert (with-output-to-string
+		 (pretty-print-profiling-info)) "\n")))
+    (clear-profiling-info)))
+
+(add-hook 'bench-pre-bench-hook 'bench-profile-start)
+(add-hook 'bench-post-bench-hook 'bench-profile-stop)
+
+(defun bench-post ()
+"Post processing of elp results"
+; I can't figure out a good way to sort the lines numerically.
+; If someone comes up with a good way, let me know.
+  (goto-char (point-min))
+  (next-line 2)
+  (sort-lines nil (point) (point-max))
+  (mail-results (current-buffer))
+)
+
+(defun bench (arg)
+  "Run a series of benchmarks."
+  (interactive "p")
+  (elp-instrument-package "bench-mark") ;Only instrument functions
+                                        ;beginning with bench-mark
+  (bench-init)
+  (if (fboundp 'byte-optimize)		;Turn off byte-compile optimization in XEmacs
+      (setq byte-optimize nil))
+  (if (fboundp 'menu-bar-mode)
+      (menu-bar-mode -1))			;Turn off menu-bar
+  (let ((benches bench-mark-function-alist))
+    (while benches
+      (let ((test-name (cdar benches)))
+	(run-hook-with-args 'bench-pre-bench-hook test-name)
+	(message "Running %s - %s." (symbol-name (caar benches)) test-name)
+	(funcall (caar benches) arg)
+	(setq benches (cdr benches))
+	(run-hook-with-args 'bench-post-bench-hook test-name))
+      ))
+  (elp-results)
+  (bench-post)
+)
+
+(defun bench-test (arg)
+  "Run all the tests but with smaller values so the tests run quicker.
+This way I don't have to sit around to see if the tests complete"
+  (interactive "p")
+  (elp-instrument-package "bench-mark") ;Only instrument functions
+                                        ;beginning with bench-mark
+  (bench-test-init)
+  (if (fboundp 'byte-optimize)		;Turn off byte-compile optimization in XEmacs
+      (setq byte-optimize nil))
+  (if (fboundp 'menu-bar-mode)
+      (menu-bar-mode -1))			;Turn off menu-bar
+  (let ((benches bench-mark-function-alist))
+    (while benches
+      (let ((test-name (cdar benches)))
+	(run-hook-with-args 'bench-pre-bench-hook test-name)
+	(message "Running %s - %s." (symbol-name (caar benches)) test-name)
+	(funcall (caar benches) arg)
+	(setq benches (cdr benches))
+	(run-hook-with-args 'bench-post-bench-hook test-name))
+      ))
+  (elp-results)
+  (bench-post)
+)
+
+
+(defconst bench-send-results-to "holder@rsn.hp.com")
+(defconst bench-subject "Bench Mark Results")
+(defconst bench-system-form (format "
+
+Please fill in as much of the following as you can
+and then hit C-cC-c to send.
+
+CPU Manufacturer (Intel,HP,DEC,etc.): 
+CPU Type (Pentium,Alpha): 
+CPU Speed: 
+RAM (in meg): 
+Emacs Version: %s
+Emacs (version): %s
+Compile line:
+Bench Version: %s
+" emacs-version (emacs-version) bench-version))
+
+(defun mail-results (buffer)
+  (mail nil bench-send-results-to bench-subject)
+  (sit-for 0)
+  (goto-char (point-max))
+  (insert bench-system-form)
+  (insert-buffer buffer)
+)
+;;; bench.el ends here
+;;; docref.el --- Simple cross references for Elisp documentation strings
+
+;; Copyright (C) 1994 Free Software Foundation, Inc.
+
+;; Author: Vadim Geshel <vadik@unas.cs.kiev.ua>
+;; Created: 12 Jul 1994
+;; Keywords: docs, help, lisp
+
+;; This file is part of XEmacs.
+
+;; XEmacs is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; XEmacs is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with XEmacs; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+;; 02111-1307, USA.
+
+;;; Synched up with: FSF 19.34.
+
+;;; Commentary:
+
+;; #### It's not clear we really wish to keep this one around.
+
+;; original name was cross-ref.el.
+
+;; This package allows you to use a simple form of cross references in
+;; your Emacs Lisp documentation strings. Cross-references look like
+;; \\(type@[label@]data), where type defines a method for retrieving
+;; reference informatin, data is used by a method routine as an argument,
+;; and label "represents" the reference in text. If label is absent, data
+;; is used instead.
+;; 
+;; Special reference labeled `back', when present, can be used to return
+;; to the previous contents of help buffer.
+;;
+;; Cross-referencing currently is intended for use in doc strings only
+;; and works only in temporary buffers (created by `with-output-to-temp-buffer').
+;; List of temp buffers in which cross-referencing is to be active is specified
+;; by variable DOCREF-BUFFERS-LIST, which contains only "*Help*" by default.
+;;
+;; Documentation strings for this package's functions and variables can serve
+;; as examples of usage.
+;;
+;;; Customization:
+;; 
+;; See source. The main customization variable is `docref-methods-alist'.
+;; It consists of (type . function) pairs, where type is a string which
+;; corresponds to type in cross-references and function is called with
+;; one argument - reference `data' - when a reference is activated.
+;;
+;;; Installation:
+;;
+;; Place this file somewhere in your load-path, byte-compiled it, and add
+;; (require 'cross-ref)
+;; to your .emacs.
+
+;;; Code:
+
+;; User customizable variables
+
+(defvar docref-highlight-p t
+  "*If non-nil, \\(f@docref-subst) highlights cross-references.
+Under window system it highlights them with face defined by
+\\(v@docref-highlight-face), on character terminal highlighted references
+look like cross-references in info mode.")
+
+(defvar docref-highlight-face 'highlight
+  "*Face used to highlight cross-references (used by \\(f@docref-subst))")
+
+(defvar docref-methods-alist
+  '(("f" . docref-describe-function)	; reference to a function documentation
+    ("v" . docref-describe-variable)	; reference to a variable documentation
+    ("F" . docref-read-file)		; reference to a file contents
+    ("s" . docref-use-string)		; reference to a string 
+    ("V" . docref-use-variable-value)	; reference to variable value
+    ("0" . beep))			; just highlighted text
+  "Alist which maps cross-reference ``types'' to retrieval functions.
+
+The car of each element is a string that serves as `type' in cross-references.
+\(See \\(f@docref-subst)).  The cdr is a function of one argument,
+to be called to find this reference.")
+
+(defvar docref-back-label "\nback"
+  "Label to use by \\(f@docref-subst) for the go-back reference.")
+
+(defvar docref-back-reference nil
+  "If non-nil, this is a go-back reference to add to the current buffer.
+The value specifies how to go back.  It should be suitable for use
+as the second argument to \\(f@docref-insert-label).
+\\(f@docref-subst) uses this to set up the go-back reference.")
+
+(defvar docref-last-active-buffer)
+
+;;;###autoload
+(defun docref-setup ()
+  "Process docref cross-references in the current buffer.
+See also \\(f@docref-subst)."
+  (interactive)
+  (docref-subst (current-buffer))
+  (docref-mode))
+
+(defvar docref-mode-map nil)
+(or docref-mode-map
+    (let ((map (make-sparse-keymap)))
+      (define-key map [mouse-2] 'docref-follow-mouse)
+      (define-key map "\C-c\C-b" 'docref-go-back)
+      (define-key map "\C-c\C-c" 'docref-follow)
+      (setq docref-mode-map map)))
+
+(defun docref-mode ()
+  "Major mode for help buffers that contain cross references.
+To follow a reference, move to it and type \\[docref-follow], or use
+\\[docref-follow-mouse].  The command \\[docref-go-back] can used to go
+back to where you came from."
+  (interactive)
+  (kill-all-local-variables)
+  (setq major-mode 'docref-mode)
+  (setq mode-name "Docref")
+  (use-local-map docref-mode-map)
+  (run-hooks 'docref-mode))
+
+(defun docref-subst (buf)
+  "Parse documentation cross-references in buffer BUF.
+
+Find cross-reference information in a buffer and
+highlight them with face defined by \\(v@docref-highlight-face).
+
+Cross-reference has the following format: \\ (TYPE[@LABEL]@DATA), where
+TYPE defines method used to retrieve xref data (like reading from file or
+calling \\(f@describe-function)), DATA is an argument to this method
+\(like file name or function name), and LABEL is displayed in text using
+\\(v@docref-highlight-face).
+
+The special reference `back' can be used to return back.
+The variable \\(v@docref-back-label) specifies the label to use for that.
+
+See \\(v@docref-methods-alist) for currently defined methods."
+  (interactive "b")
+  (save-excursion
+    (set-buffer buf)
+    (goto-char (point-min))
+    ;; The docref-seen property indicates that we have processed this
+    ;; buffer's contents already, so don't do it again.
+    (if (not (get-text-property (point-min) 'docref-seen))
+	(let ((old-modified (buffer-modified-p)))
+	  (while (re-search-forward "[\\](\\([^\)\@]+\\)\\(@[^\)\@]+\\)?@\\([^\)]*\\))"
+				    nil t)
+	    (let* ((start (match-beginning 0))
+		   (type (buffer-substring (match-beginning 1) (match-end 1)))
+		   (data (buffer-substring (match-beginning 3) (match-end 3)))
+		   (label
+		    (if (match-beginning 2)
+			(buffer-substring (+ (match-beginning 2) 1) (match-end 2))
+		      data)))
+	      (replace-match "" t)
+	      (docref-insert-label label (cons type data))))
+
+	  ;; Make a back-reference in this buffer, if desired.
+	  ;; (This is true if called from docref-follow.)
+	  (if docref-back-reference
+	      (progn
+		(goto-char (point-max))
+		(put-text-property (point-min) (1+ (point-min))
+				   'docref-back-position (point))
+		(docref-insert-label docref-back-label docref-back-reference)))
+	  (put-text-property (point-min) (1+ (point-min)) 'docref-seen t)
+	  (set-buffer-modified-p old-modified)))))
+
+(defun docref-insert-label (string ref)
+  (let ((label (concat string))
+	(pos (point)))
+    ;; decorate the label
+    (let ((leading-space-end (save-match-data
+			       (if (string-match "^\\([ \t\n]+\\)" label)
+				   (match-end 1)
+				 0)))
+	  (trailing-space-start (save-match-data
+				  (if (string-match "\\([ \t\n]+\\)$" label)
+				      (match-beginning 1)
+				    (length label)))))
+      (if docref-highlight-p	      
+;;	  XEmacs: we support faces on TTY's.
+;;	  (if (not window-system)
+;;	      (setq label
+;;		    (concat (substring label 0 leading-space-end)
+;;			    "(*note "
+;;			    (substring label leading-space-end trailing-space-start)
+;;			    ")"
+;;			    (substring label trailing-space-start)))
+	    ;; window-system
+	    (put-text-property leading-space-end
+			       trailing-space-start
+			       'face docref-highlight-face label))
+      (put-text-property 0 (length label) 'docref ref label)
+      (insert label))))
+
+(defun docref-follow-mouse (click)
+  "Follow the cross-reference that you click on."
+  (interactive "e")
+  (save-excursion
+    ;; XEmacs changes here.
+    (let* ((window (event-window click))
+	   (pos (event-point click))
+	   (docref-last-active-buffer (current-buffer)))
+      (set-buffer (window-buffer window))
+      (docref-follow pos))))
+
+(defun docref-go-back ()
+  "Go back to the previous contents of help buffer."
+  (interactive)
+  (let ((pos (get-text-property (point-min) 'docref-back-position)))
+    (if	pos
+	(docref-follow pos)
+      (error "No go-back reference"))))
+
+(defun docref-follow (&optional pos)
+  "Follow cross-reference at point.
+For the cross-reference format, see \\(f@docref-subst).
+The special reference named `back' can be used to return back"
+  (interactive)
+  (or pos (setq pos (point)))
+  (let ((docref-data (get-text-property pos 'docref)))
+    (if docref-data
+	;; There is a reference at point.  Follow it.
+	(let* ((type (car docref-data))
+	       (name (cdr docref-data))
+	       (method (assoc type docref-methods-alist))
+	       (cur-contents (buffer-string))
+	       (opoint (point))
+	       (docref-back-reference (cons "s" cur-contents))
+	       success)
+	  (if (null method)
+	      (error "Unknown cross-reference type: %s" type))
+	  (unwind-protect
+	      (save-excursion
+		(funcall (cdr method) name)
+		(setq success t))
+	    (or success
+		(progn
+		  ;; (cdr method) got an error.
+		  ;; Put back the text that we had.
+		  (erase-buffer)
+		  (insert cur-contents)
+		  (goto-char opoint)))
+	    (set-buffer-modified-p nil))))))
+
+;; Builtin methods for accessing a reference.
+
+(defun docref-describe-function (data)
+  (save-excursion
+    (if (boundp 'docref-last-active-buffer)
+	(set-buffer docref-last-active-buffer))
+    (describe-function (intern data))))
+  
+(defun docref-describe-variable (data)
+  (save-excursion
+    (if (boundp 'docref-last-active-buffer)
+	(set-buffer docref-last-active-buffer))
+    (describe-variable (intern data))))
+
+(defun docref-read-file (data)
+  (with-output-to-temp-buffer (buffer-name)
+    (erase-buffer)
+    (insert-file-contents (expand-file-name data))))
+
+(defun docref-use-string (data)
+  (with-output-to-temp-buffer (buffer-name)
+    (erase-buffer)
+    (insert data)))
+
+(defun docref-use-variable-value (data)
+  (let ((sym (intern data)))
+    (with-output-to-temp-buffer (buffer-name)
+      (erase-buffer)
+      (princ (symbol-value sym)))))
+
+(provide 'docref)
+
+;;; docref.el ends here
+;;; eldoc.el --- show function arglist or variable docstring in echo area
+
+;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+
+;; Author: Noah Friedman <friedman@prep.ai.mit.edu>
+;; Maintainer: friedman@prep.ai.mit.edu
+;; Keywords: extensions
+;; Created: 1995-10-06
+
+;; $Id$
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; This program was inspired by the behavior of the "mouse documentation
+;; window" on many Lisp Machine systems; as you type a function's symbol
+;; name as part of a sexp, it will print the argument list for that
+;; function.  Behavior is not identical; for example, you need not actually
+;; type the function name, you need only move point around in a sexp that
+;; calls it.  Also, if point is over a documented variable, it will print
+;; the one-line documentation for that variable instead, to remind you of
+;; that variable's meaning.
+
+;; One useful way to enable this minor mode is to put the following in your
+;; .emacs:
+;;
+;;      (autoload 'turn-on-eldoc-mode "eldoc" nil t)
+;;      (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
+;;      (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
+;;      (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
+
+;;; Code:
+
+;; Use idle timers if available in the version of emacs running.
+;; Please don't change this to use `require'; this package works as-is in
+;; XEmacs (which doesn't have timer.el as of 19.14), and I would like to
+;; maintain compatibility with that since I must use it sometimes.  --Noah
+(or (featurep 'timer)
+    (load "timer" t))
+
+(defgroup eldoc nil
+  "Show function arglist or variable docstring in echo area."
+  :group 'extensions)
+
+;;;###autoload
+(defcustom eldoc-mode nil
+  "*If non-nil, show the defined parameters for the elisp function near point.
+
+For the emacs lisp function at the beginning of the sexp which point is
+within, show the defined parameters for the function in the echo area.
+This information is extracted directly from the function or macro if it is
+in pure lisp.  If the emacs function is a subr, the parameters are obtained
+from the documentation string if possible.
+
+If point is over a documented variable, print that variable's docstring
+instead.
+
+This variable is buffer-local."
+  :type 'boolean
+  :group 'eldoc)
+(make-variable-buffer-local 'eldoc-mode)
+
+(defcustom eldoc-idle-delay 0.50
+  "*Number of seconds of idle time to wait before printing.
+If user input arrives before this interval of time has elapsed after the
+last input, no documentation will be printed.
+
+If this variable is set to 0, no idle time is required."
+  :type 'number
+  :group 'eldoc)
+
+(defcustom eldoc-minor-mode-string " ElDoc"
+  "*String to display in mode line when Eldoc Mode is enabled."
+  :type 'string
+  :group 'eldoc)
+
+;; Put this minor mode on the global minor-mode-alist.
+(or (assq 'eldoc-mode (default-value 'minor-mode-alist))
+    (setq-default minor-mode-alist
+                  (append (default-value 'minor-mode-alist)
+                          '((eldoc-mode eldoc-minor-mode-string)))))
+
+(defcustom eldoc-argument-case 'upcase
+  "Case to display argument names of functions, as a symbol.
+This has two preferred values: `upcase' or `downcase'.
+Actually, any name of a function which takes a string as an argument and
+returns another string is acceptable."
+  :type '(choice (const upcase) (const downcase))
+  :group 'eldoc)
+
+;; No user options below here.
+
+;; Commands after which it is appropriate to print in the echo area.
+;; Eldoc does not try to print function arglists, etc. after just any command,
+;; because some commands print their own messages in the echo area and these
+;; functions would instantly overwrite them.  But self-insert-command as well
+;; as most motion commands are good candidates.
+;; This variable contains an obarray of symbols; do not manipulate it
+;; directly.  Instead, use `eldoc-add-command' and `eldoc-remove-command'.
+(defvar eldoc-message-commands nil)
+
+;; This is used by eldoc-add-command to initialize eldoc-message-commands
+;; as an obarray.
+;; It should probably never be necessary to do so, but if you
+;; choose to increase the number of buckets, you must do so before loading
+;; this file since the obarray is initialized at load time.
+;; Remember to keep it a prime number to improve hash performance.
+(defvar eldoc-message-commands-table-size 31)
+
+;; Bookkeeping; the car contains the last symbol read from the buffer.
+;; The cdr contains the string last displayed in the echo area, so it can
+;; be printed again if necessary without reconsing.
+(defvar eldoc-last-data (cons nil nil))
+(defvar eldoc-last-message nil)
+
+;; Idle timers are supported in Emacs 19.31 and later.
+(defvar eldoc-use-idle-timer-p (fboundp 'run-with-idle-timer))
+
+;; eldoc's timer object, if using idle timers
+(defvar eldoc-timer nil)
+
+;; idle time delay currently in use by timer.
+;; This is used to determine if eldoc-idle-delay is changed by the user.
+(defvar eldoc-current-idle-delay eldoc-idle-delay)
+
+
+;;;###autoload
+(defun eldoc-mode (&optional prefix)
+  "*Enable or disable eldoc mode.
+See documentation for the variable of the same name for more details.
+
+If called interactively with no prefix argument, toggle current condition
+of the mode.
+If called with a positive or negative prefix argument, enable or disable
+the mode, respectively."
+  (interactive "P")
+  (setq eldoc-last-message nil)
+  (cond (eldoc-use-idle-timer-p
+         (add-hook 'post-command-hook 'eldoc-schedule-timer)
+         (add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area))
+        (t
+         ;; Use post-command-idle-hook if defined, otherwise use
+         ;; post-command-hook.  The former is only proper to use in Emacs
+         ;; 19.30; that is the first version in which it appeared, but it
+         ;; was obsolesced by idle timers in Emacs 19.31.
+         (add-hook (if (boundp 'post-command-idle-hook)
+                  'post-command-idle-hook
+                'post-command-hook)
+              'eldoc-print-current-symbol-info)
+         ;; quick and dirty hack for seeing if this is XEmacs
+         (and (fboundp 'display-message)
+              (add-hook 'pre-command-hook
+                        'eldoc-pre-command-refresh-echo-area))))
+  (setq eldoc-mode (if prefix
+                       (>= (prefix-numeric-value prefix) 0)
+                     (not eldoc-mode)))
+  (and (interactive-p)
+       (if eldoc-mode
+           (message "eldoc-mode is enabled")
+         (message "eldoc-mode is disabled")))
+  eldoc-mode)
+
+;;;###autoload
+(defun turn-on-eldoc-mode ()
+  "Unequivocally turn on eldoc-mode (see variable documentation)."
+  (interactive)
+  (eldoc-mode 1))
+
+;; Idle timers are part of Emacs 19.31 and later.
+(defun eldoc-schedule-timer ()
+  (or (and eldoc-timer
+           (memq eldoc-timer timer-idle-list))
+      (setq eldoc-timer
+            (run-with-idle-timer eldoc-idle-delay t
+                                 'eldoc-print-current-symbol-info)))
+
+  ;; If user has changed the idle delay, update the timer.
+  (cond ((not (= eldoc-idle-delay eldoc-current-idle-delay))
+         (setq eldoc-current-idle-delay eldoc-idle-delay)
+         (timer-set-idle-time eldoc-timer eldoc-idle-delay t))))
+
+;; This function goes on pre-command-hook for XEmacs or when using idle
+;; timers in Emacs.  Motion commands clear the echo area for some reason,
+;; which make eldoc messages flicker or disappear just before motion
+;; begins.  This function reprints the last eldoc message immediately
+;; before the next command executes, which does away with the flicker.
+;; This doesn't seem to be required for Emacs 19.28 and earlier.
+(defun eldoc-pre-command-refresh-echo-area ()
+  (and eldoc-last-message
+       (if (eldoc-display-message-no-interference-p)
+           (eldoc-message eldoc-last-message)
+         (setq eldoc-last-message nil))))
+
+(defun eldoc-message (&rest args)
+  (let ((omessage eldoc-last-message))
+    (cond ((eq (car args) eldoc-last-message))
+          ((or (null args)
+               (null (car args)))
+           (setq eldoc-last-message nil))
+          (t
+           (setq eldoc-last-message (apply 'format args))))
+    ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages
+    ;; are recorded in a log.  Do not put eldoc messages in that log since
+    ;; they are Legion.
+    (if (fboundp 'display-message)
+        ;; XEmacs 19.13 way of preventing log messages.
+        (if eldoc-last-message
+            (display-message 'no-log eldoc-last-message)
+          (and omessage
+               (clear-message 'no-log)))
+      (let ((message-log-max nil))
+        (if eldoc-last-message
+            (message "%s" eldoc-last-message)
+          (and omessage
+               (message nil))))))
+  eldoc-last-message)
+
+
+(defun eldoc-print-current-symbol-info ()
+  (and (eldoc-display-message-p)
+       (let ((current-symbol (eldoc-current-symbol))
+             (current-fnsym  (eldoc-fnsym-in-current-sexp)))
+         (or (cond ((eq current-symbol current-fnsym)
+                    (or (eldoc-print-fnsym-args current-fnsym)
+                        (eldoc-print-var-docstring current-symbol)))
+                   (t
+                    (or (eldoc-print-var-docstring current-symbol)
+                        (eldoc-print-fnsym-args current-fnsym))))
+             (eldoc-message nil)))))
+
+;; Decide whether now is a good time to display a message.
+(defun eldoc-display-message-p ()
+  (and (eldoc-display-message-no-interference-p)
+       (cond (eldoc-use-idle-timer-p
+              ;; If this-command is non-nil while running via an idle
+              ;; timer, we're still in the middle of executing a command,
+              ;; e.g. a query-replace where it would be annoying to
+              ;; overwrite the echo area.
+              (and (not this-command)
+                   (symbolp last-command)
+                   (intern-soft (symbol-name last-command)
+                                eldoc-message-commands)))
+             (t
+              ;; If we don't have idle timers, this function is
+              ;; running on post-command-hook directly; that means the
+              ;; user's last command is still on `this-command', and we
+              ;; must wait briefly for input to see whether to do display.
+              (and (symbolp this-command)
+                   (intern-soft (symbol-name this-command)
+                                eldoc-message-commands)
+                   (sit-for eldoc-idle-delay))))))
+
+(defun eldoc-display-message-no-interference-p ()
+  (and eldoc-mode
+       (not executing-kbd-macro)
+       ;; Having this mode operate in an active minibuffer/echo area causes
+       ;; interference with what's going on there.
+       (not cursor-in-echo-area)
+       (not (eq (selected-window) (minibuffer-window)))))
+
+(defun eldoc-print-fnsym-args (sym)
+  (interactive)
+  (let ((args nil))
+    (cond ((not (and sym
+                     (symbolp sym)
+                     (fboundp sym))))
+          ((eq sym (car eldoc-last-data))
+           (setq args (cdr eldoc-last-data)))
+          ((subrp (eldoc-symbol-function sym))
+           (setq args (or (eldoc-function-argstring-from-docstring sym)
+                          (eldoc-docstring-first-line (documentation sym t))))
+           (setcar eldoc-last-data sym)
+           (setcdr eldoc-last-data args))
+          (t
+           (setq args (eldoc-function-argstring sym))
+           (setcar eldoc-last-data sym)
+           (setcdr eldoc-last-data args)))
+    (and args
+         (eldoc-message "%s: %s" sym args))))
+
+(defun eldoc-fnsym-in-current-sexp ()
+  (let ((p (point)))
+    (eldoc-beginning-of-sexp)
+    (prog1
+        ;; Don't do anything if current word is inside a string.
+        (if (= (or (char-after (1- (point))) 0) ?\")
+            nil
+          (eldoc-current-symbol))
+      (goto-char p))))
+
+(defun eldoc-beginning-of-sexp ()
+  (let ((parse-sexp-ignore-comments t))
+    (condition-case err
+        (while (progn
+                 (forward-sexp -1)
+                 (or (= (or (char-after (1- (point)))) ?\")
+                     (> (point) (point-min)))))
+      (error nil))))
+
+;; returns nil unless current word is an interned symbol.
+(defun eldoc-current-symbol ()
+  (let ((c (char-after (point))))
+    (and c
+         (memq (char-syntax c) '(?w ?_))
+         (intern-soft (current-word)))))
+
+;; Do indirect function resolution if possible.
+(defun eldoc-symbol-function (fsym)
+  (let ((defn (and (fboundp fsym)
+                   (symbol-function fsym))))
+    (and (symbolp defn)
+         (condition-case err
+             (setq defn (indirect-function fsym))
+           (error (setq defn nil))))
+    defn))
+
+(defun eldoc-function-argstring (fn)
+  (let* ((prelim-def (eldoc-symbol-function fn))
+         (def (if (eq (car-safe prelim-def) 'macro)
+                  (cdr prelim-def)
+                prelim-def))
+         (arglist (cond ((null def) nil)
+                        ((byte-code-function-p def)
+                         (if (fboundp 'compiled-function-arglist)
+                             (funcall 'compiled-function-arglist def)
+                           (aref def 0)))
+                        ((eq (car-safe def) 'lambda)
+                         (nth 1 def))
+                        (t t))))
+    (eldoc-function-argstring-format arglist)))
+
+(defun eldoc-function-argstring-format (arglist)
+  (cond ((not (listp arglist))
+         (setq arglist nil))
+        ((symbolp (car arglist))
+         (setq arglist
+               (mapcar (function (lambda (s)
+                                   (if (memq s '(&optional &rest))
+                                       (symbol-name s)
+                                     (funcall eldoc-argument-case
+                                              (symbol-name s)))))
+                       arglist)))
+        ((stringp (car arglist))
+         (setq arglist
+               (mapcar (function (lambda (s)
+                                   (if (member s '("&optional" "&rest"))
+                                       s
+                                     (funcall eldoc-argument-case s))))
+                       arglist))))
+  (concat "(" (mapconcat 'identity arglist " ") ")"))
+
+
+(defun eldoc-print-var-docstring (sym)
+  (eldoc-print-docstring sym (documentation-property
+                              sym 'variable-documentation t)))
+
+;; Print the brief (one-line) documentation string for the symbol.
+(defun eldoc-print-docstring (symbol doc)
+  (and doc
+       (eldoc-message "%s" (eldoc-docstring-message symbol doc))))
+
+;; If the entire line cannot fit in the echo area, the variable name may be
+;; truncated or eliminated entirely from the output to make room.
+;; Any leading `*' in the docstring (which indicates the variable is a user
+;; option) is not printed."
+(defun eldoc-docstring-message (symbol doc)
+  (and doc
+       (let ((name (symbol-name symbol)))
+         (setq doc (eldoc-docstring-first-line doc))
+         (save-match-data
+           (let* ((doclen (+ (length name) (length ": ") (length doc)))
+                  ;; Subtract 1 from window width since emacs seems not to
+                  ;; write any chars to the last column, at least for some
+                  ;; terminal types.
+                  (strip (- doclen (1- (window-width (minibuffer-window))))))
+             (cond ((> strip 0)
+                    (let* ((len (length name)))
+                      (cond ((>= strip len)
+                             (format "%s" doc))
+                            (t
+                             ;;(setq name (substring name 0 (- len strip)))
+                             ;;
+                             ;; Show the end of the partial variable name,
+                             ;; rather than the beginning, since the former
+                             ;; is more likely to be unique given package
+                             ;; namespace conventions.
+                             (setq name (substring name strip))
+                             (format "%s: %s" name doc)))))
+                   (t
+                    (format "%s: %s" symbol doc))))))))
+
+(defun eldoc-docstring-first-line (doc)
+  (save-match-data
+    (and (string-match "\n" doc)
+         (setq doc (substring doc 0 (match-beginning 0))))
+    (and (string-match "^\\*" doc)
+         (setq doc (substring doc 1))))
+  doc)
+
+
+;; Alist of predicate/action pairs.
+;; Each member of the list is a sublist consisting of a predicate function
+;; used to determine if the arglist for a function can be found using a
+;; certain pattern, and a function which returns the actual arglist from
+;; that docstring.
+;;
+;; The order in this table is significant, since later predicates may be
+;; more general than earlier ones.
+;;
+;; Compiler note for Emacs/XEmacs versions which support dynamic loading:
+;; these functions will be compiled to bytecode, but can't be lazy-loaded
+;; even if you set byte-compile-dynamic; to do that would require making
+;; them named top-level defuns, which is not particularly desirable either.
+(defvar eldoc-function-argstring-from-docstring-method-table
+  (list
+   ;; Try first searching for args starting with symbol name.
+   ;; This is to avoid matching parenthetical remarks in e.g. sit-for.
+   (list (function (lambda (doc fn)
+                     (string-match (format "^(%s[^\n)]*)$" fn) doc)))
+         (function (lambda (doc)
+                     ;; end does not include trailing ")" sequence.
+                     (let ((end (- (match-end 0) 1)))
+                       (if (string-match " +" doc (match-beginning 0))
+                           (substring doc (match-end 0) end)
+                         "")))))
+
+   ;; Try again not requiring this symbol name in the docstring.
+   ;; This will be the case when looking up aliases.
+   (list (function (lambda (doc fn)
+                     ;; save-restriction has a pathological docstring in
+                     ;; Emacs/XEmacs 19.
+                     (and (not (eq fn 'save-restriction))
+                          (string-match "^([^\n)]+)$" doc))))
+         (function (lambda (doc)
+                     ;; end does not include trailing ")" sequence.
+                     (let ((end (- (match-end 0) 1)))
+                       (and (string-match " +" doc (match-beginning 0))
+                            (substring doc (match-end 0) end))))))
+
+   ;; Emacs subr docstring style:
+   ;;   (fn arg1 arg2 ...): description...
+   (list (function (lambda (doc fn)
+                     (string-match "^([^\n)]+):" doc)))
+         (function (lambda (doc)
+                     ;; end does not include trailing "):" sequence.
+                     (let ((end (- (match-end 0) 2)))
+                       (and (string-match " +" doc (match-beginning 0))
+                            (substring doc (match-end 0) end))))))
+
+   ;; XEmacs subr docstring style:
+   ;;   "arguments: (arg1 arg2 ...)
+   (list (function (lambda (doc fn)
+                     (string-match "^arguments: (\\([^\n)]+\\))" doc)))
+         (function (lambda (doc)
+                     ;; also skip leading paren, but the first word is
+                     ;; actually an argument, not the function name.
+                     (substring doc (match-beginning 1) (match-end 1)))))
+
+   ;; This finds the argstring for `condition-case'.  Any others?
+   (list (function (lambda (doc fn)
+                     (string-match
+                      (format "^Usage looks like \\((%s[^\n)]*)\\)\\.$" fn)
+                      doc)))
+         (function (lambda (doc)
+                     ;; end does not include trailing ")" sequence.
+                     (let ((end (- (match-end 1) 1)))
+                       (and (string-match " +" doc (match-beginning 1))
+                            (substring doc (match-end 0) end))))))
+
+   ;; This finds the argstring for `setq-default'.  Any others?
+   (list (function (lambda (doc fn)
+                     (string-match (format "^[ \t]+\\((%s[^\n)]*)\\)$" fn)
+                                   doc)))
+         (function (lambda (doc)
+                     ;; end does not include trailing ")" sequence.
+                     (let ((end (- (match-end 1) 1)))
+                       (and (string-match " +" doc (match-beginning 1))
+                            (substring doc (match-end 0) end))))))
+
+   ;; This finds the argstring for `start-process'.  Any others?
+   (list (function (lambda (doc fn)
+                     (string-match "^Args are +\\([^\n]+\\)$" doc)))
+         (function (lambda (doc)
+                     (substring doc (match-beginning 1) (match-end 1)))))
+
+   ;; These common subrs don't have arglists in their docstrings.  So cheat.
+   (list (function (lambda (doc fn)
+                     (memq fn '(and or list + -))))
+         (function (lambda (doc)
+                     ;; The value nil is a placeholder; otherwise, the
+                     ;; following string may be compiled as a docstring,
+                     ;; and not a return value for the function.
+                     ;; In interpreted lisp form they are
+                     ;; indistinguishable; it only matters for compiled
+                     ;; forms.
+                     nil
+                     "&rest args")))
+   ))
+
+(defun eldoc-function-argstring-from-docstring (fn)
+  (let ((docstring (documentation fn 'raw))
+        (table eldoc-function-argstring-from-docstring-method-table)
+        (doc nil)
+        (doclist nil))
+    (save-match-data
+      (while table
+        (cond ((funcall (car (car table)) docstring fn)
+               (setq doc (funcall (car (cdr (car table))) docstring))
+               (setq table nil))
+              (t
+               (setq table (cdr table)))))
+
+      (cond ((not (stringp doc))
+             nil)
+            ((string-match "&" doc)
+             (let ((p 0)
+                   (l (length doc)))
+               (while (< p l)
+                 (cond ((string-match "[ \t\n]+" doc p)
+                        (setq doclist
+                              (cons (substring doc p (match-beginning 0))
+                                    doclist))
+                        (setq p (match-end 0)))
+                       (t
+                        (setq doclist (cons (substring doc p) doclist))
+                        (setq p l))))
+               (eldoc-function-argstring-format (nreverse doclist))))
+            (t
+             (concat "(" (funcall eldoc-argument-case doc) ")"))))))
+
+
+;; When point is in a sexp, the function args are not reprinted in the echo
+;; area after every possible interactive command because some of them print
+;; their own messages in the echo area; the eldoc functions would instantly
+;; overwrite them unless it is more restrained.
+;; These functions do display-command table management.
+
+(defun eldoc-add-command (&rest cmds)
+  (or eldoc-message-commands
+      (setq eldoc-message-commands
+            (make-vector eldoc-message-commands-table-size 0)))
+
+  (let (name sym)
+    (while cmds
+      (setq name (car cmds))
+      (setq cmds (cdr cmds))
+
+      (cond ((symbolp name)
+             (setq sym name)
+             (setq name (symbol-name sym)))
+            ((stringp name)
+             (setq sym (intern-soft name))))
+
+      (and (symbolp sym)
+           (fboundp sym)
+           (set (intern name eldoc-message-commands) t)))))
+
+(defun eldoc-add-command-completions (&rest names)
+  (while names
+      (apply 'eldoc-add-command
+             (all-completions (car names) obarray 'fboundp))
+      (setq names (cdr names))))
+
+(defun eldoc-remove-command (&rest cmds)
+  (let (name)
+    (while cmds
+      (setq name (car cmds))
+      (setq cmds (cdr cmds))
+
+      (and (symbolp name)
+           (setq name (symbol-name name)))
+
+      (if (fboundp 'unintern)
+          (unintern name eldoc-message-commands)
+        (let ((s (intern-soft name eldoc-message-commands)))
+          (and s
+               (makunbound s)))))))
+
+(defun eldoc-remove-command-completions (&rest names)
+  (while names
+    (apply 'eldoc-remove-command
+           (all-completions (car names) eldoc-message-commands))
+    (setq names (cdr names))))
+
+;; Prime the command list.
+(eldoc-add-command-completions
+ "backward-" "beginning-of-" "delete-other-windows" "delete-window"
+ "end-of-" "forward-" "indent-for-tab-command" "goto-" "mouse-set-point"
+ "next-" "other-window" "previous-" "recenter" "scroll-"
+ "self-insert-command" "split-window-")
+
+(provide 'eldoc)
+
+;;; eldoc.el ends here
+;;; elp.el --- Emacs Lisp Profiler
+
+;; Copyright (C) 1994 Free Software Foundation, Inc.
+
+;; Author:        1994-1996 Barry A. Warsaw
+;; Maintainer:    tools-help@python.org
+;; Created:       26-Feb-1994
+;; Version:       2.37
+;; Last Modified: 1996/10/23 04:06:58
+;; Keywords:      debugging lisp tools
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+;;; Commentary:
+;;
+;; If you want to profile a bunch of functions, set elp-function-list
+;; to the list of symbols, then do a M-x elp-instrument-list.  This
+;; hacks those functions so that profiling information is recorded
+;; whenever they are called.  To print out the current results, use
+;; M-x elp-results.  If you want output to go to standard-output
+;; instead of a separate buffer, setq elp-use-standard-output to
+;; non-nil.  With elp-reset-after-results set to non-nil, profiling
+;; information will be reset whenever the results are displayed.  You
+;; can also reset all profiling info at any time with M-x
+;; elp-reset-all.
+;;
+;; You can also instrument all functions in a package, provided that
+;; the package follows the GNU coding standard of a common textual
+;; prefix.  Use M-x elp-instrument-package for this.
+;;
+;; If you want to sort the results, set elp-sort-by-function to some
+;; predicate function.  The three most obvious choices are predefined:
+;; elp-sort-by-call-count, elp-sort-by-average-time, and
+;; elp-sort-by-total-time.  Also, you can prune from the output, all
+;; functions that have been called fewer than a given number of times
+;; by setting elp-report-limit.
+;;
+;; Elp can instrument byte-compiled functions just as easily as
+;; interpreted functions, but it cannot instrument macros.  However,
+;; when you redefine a function (e.g. with eval-defun), you'll need to
+;; re-instrument it with M-x elp-instrument-function.  This will also
+;; reset profiling information for that function.  Elp can handle
+;; interactive functions (i.e. commands), but of course any time spent
+;; idling for user prompts will show up in the timing results.
+;;
+;; You can also designate a `master' function.  Profiling times will
+;; be gathered for instrumented functions only during execution of
+;; this master function.  Thus, if you have some defuns like:
+;;
+;;  (defun foo () (do-something-time-intensive))
+;;  (defun bar () (foo))
+;;  (defun baz () (bar) (foo))
+;;
+;; and you want to find out the amount of time spent in bar and foo,
+;; but only during execution of bar, make bar the master.  The call of
+;; foo from baz will not add to foo's total timing sums.  Use M-x
+;; elp-set-master and M-x elp-unset-master to utilize this feature.
+;; Only one master function can be set at a time.
+
+;; You can restore any function's original function definition with
+;; elp-restore-function.  The other instrument, restore, and reset
+;; functions are provided for symmetry.
+
+;; Here is a list of variable you can use to customize elp:
+;;   elp-function-list
+;;   elp-reset-after-results
+;;   elp-sort-by-function
+;;   elp-report-limit
+;;
+;; Here is a list of the interactive commands you can use:
+;;   elp-instrument-function
+;;   elp-restore-function
+;;   elp-instrument-list
+;;   elp-restore-list
+;;   elp-instrument-package
+;;   elp-restore-all
+;;   elp-reset-function
+;;   elp-reset-list
+;;   elp-reset-all
+;;   elp-set-master
+;;   elp-unset-master
+;;   elp-results
+;;   elp-submit-bug-report
+
+;; Note that there are plenty of factors that could make the times
+;; reported unreliable, including the accuracy and granularity of your
+;; system clock, and the overhead spent in lisp calculating and
+;; recording the intervals.  I figure the latter is pretty constant,
+;; so while the times may not be entirely accurate, I think they'll
+;; give you a good feel for the relative amount of work spent in the
+;; various lisp routines you are profiling.  Note further that times
+;; are calculated using wall-clock time, so other system load will
+;; affect accuracy too.  You cannot profile anything longer than ~18
+;; hours since I throw away the most significant 16 bits of seconds
+;; returned by current-time: 2^16 == 65536 seconds == ~1092 minutes ==
+;; ~18 hours.  I doubt you will ever want to profile stuff on the
+;; order of 18 hours anyway.
+
+;;; Background:
+;;
+;; This program was inspired by the only two existing Emacs Lisp
+;; profilers that I'm aware of, Boaz Ben-Zvi's profile.el, and Root
+;; Boy Jim's profiler.el. Both were written for Emacs 18 and both were
+;; pretty good first shots at profiling, but I found that they didn't
+;; provide the functionality or interface that I wanted, so I wrote
+;; this.  I've tested elp in XEmacs 19 and Emacs 19.  There's no point
+;; in even trying to make this work with Emacs 18.
+
+;; Unlike previous profilers, elp uses Emacs 19's built-in function
+;; current-time to return interval times.  This obviates the need for
+;; both an external C program and Emacs processes to communicate with
+;; such a program, and thus simplifies the package as a whole.
+
+;; TBD:
+;; Make this act like a real profiler, so that it records time spent
+;; in all branches of execution.
+
+;;; Code:
+
+
+;; start of user configuration variables
+;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
+
+(defgroup elp nil
+  "Emacs Lisp Profiler"
+  :group 'lisp)
+
+
+(defcustom elp-function-list nil
+  "*List of functions to profile.
+Used by the command `elp-instrument-list'."
+  :type '(repeat function)
+  :group 'elp)
+
+(defcustom elp-reset-after-results t
+  "*Non-nil means reset all profiling info after results are displayed.
+Results are displayed with the `elp-results' command."
+  :type 'boolean
+  :group 'elp)
+
+(defcustom elp-sort-by-function 'elp-sort-by-total-time
+  "*Non-nil specifies elp results sorting function.
+These functions are currently available:
+
+  elp-sort-by-call-count   -- sort by the highest call count
+  elp-sort-by-total-time   -- sort by the highest total time
+  elp-sort-by-average-time -- sort by the highest average times
+
+You can write you're own sort function. It should adhere to the
+interface specified by the PRED argument for the `sort' defun.  Each
+\"element of LIST\" is really a 4 element vector where element 0 is
+the call count, element 1 is the total time spent in the function,
+element 2 is the average time spent in the function, and element 3 is
+the symbol's name string."
+  :type 'function
+  :group 'elp)
+
+(defcustom elp-report-limit 1
+  "*Prevents some functions from being displayed in the results buffer.
+If a number, no function that has been called fewer than that number
+of times will be displayed in the output buffer.  If nil, all
+functions will be displayed."
+  :type '(choice integer
+		 (const :tag "All" nil))
+  :group 'elp)
+
+(defcustom elp-use-standard-output nil
+  "*Non-nil says to output to `standard-output' instead of a buffer."
+  :type 'boolean
+  :group 'elp)
+
+(defcustom elp-recycle-buffers-p t
+  "*Nil says to not recycle the `elp-results-buffer'.
+In other words, a new unique buffer is create every time you run
+\\[elp-results]."
+  :type 'boolean
+  :group 'elp)
+
+
+;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+;; end of user configuration variables
+
+
+(defconst elp-version "2.37"
+  "ELP version number.")
+
+(defconst elp-help-address "tools-help@python.org"
+  "Address accepting submissions of bug reports and questions.")
+
+(defvar elp-results-buffer "*ELP Profiling Results*"
+  "Buffer name for outputting profiling results.")
+
+(defconst elp-timer-info-property 'elp-info
+  "ELP information property name.")
+
+(defvar elp-all-instrumented-list nil
+  "List of all functions currently being instrumented.")
+
+(defvar elp-record-p t
+  "Controls whether functions should record times or not.
+This variable is set by the master function.")
+
+(defvar elp-master nil
+  "Master function symbol.")
+
+
+;;;###autoload
+(defun elp-instrument-function (funsym)
+  "Instrument FUNSYM for profiling.
+FUNSYM must be a symbol of a defined function."
+  (interactive "aFunction to instrument: ")
+  ;; restore the function.  this is necessary to avoid infinite
+  ;; recursion of already instrumented functions (i.e. elp-wrapper
+  ;; calling elp-wrapper ad infinitum).  it is better to simply
+  ;; restore the function than to throw an error.  this will work
+  ;; properly in the face of eval-defun because if the function was
+  ;; redefined, only the timer info will be nil'd out since
+  ;; elp-restore-function is smart enough not to trash the new
+  ;; definition.
+  (elp-restore-function funsym)
+  (let* ((funguts (symbol-function funsym))
+	 (infovec (vector 0 0 funguts))
+	 (newguts '(lambda (&rest args))))
+    ;; we cannot profile macros
+    (and (eq (car-safe funguts) 'macro)
+	 (error "ELP cannot profile macro: %s" funsym))
+    ;; TBD: at some point it might be better to load the autoloaded
+    ;; function instead of throwing an error.  if we do this, then we
+    ;; probably want elp-instrument-package to be updated with the
+    ;; newly loaded list of functions.  i'm not sure it's smart to do
+    ;; the autoload here, since that could have side effects, and
+    ;; elp-instrument-function is similar (in my mind) to defun-ish
+    ;; type functionality (i.e. it shouldn't execute the function).
+    (and (eq (car-safe funguts) 'autoload)
+	 (error "ELP cannot profile autoloaded function: %s" funsym))
+    ;; put rest of newguts together
+    (if (commandp funsym)
+	(setq newguts (append newguts '((interactive)))))
+    (setq newguts (append newguts (list
+				   (list 'elp-wrapper
+					 (list 'quote funsym)
+					 (list 'and
+					       '(interactive-p)
+					       (not (not (commandp funsym))))
+					 'args))))
+    ;; to record profiling times, we set the symbol's function
+    ;; definition so that it runs the elp-wrapper function with the
+    ;; function symbol as an argument.  We place the old function
+    ;; definition on the info vector.
+    ;;
+    ;; The info vector data structure is a 3 element vector.  The 0th
+    ;; element is the call-count, i.e. the total number of times this
+    ;; function has been entered.  This value is bumped up on entry to
+    ;; the function so that non-local exists are still recorded. TBD:
+    ;; I haven't tested non-local exits at all, so no guarantees.
+    ;;
+    ;; The 1st element is the total amount of time in usecs that have
+    ;; been spent inside this function.  This number is added to on
+    ;; function exit.
+    ;;
+    ;; The 2nd element is the old function definition list.  This gets
+    ;; funcall'd in between start/end time retrievals. I believe that
+    ;; this lets us profile even byte-compiled functions.
+
+    ;; put the info vector on the property list
+    (put funsym elp-timer-info-property infovec)
+
+    ;; set the symbol's new profiling function definition to run
+    ;; elp-wrapper
+    (fset funsym newguts)
+
+    ;; add this function to the instrumentation list
+    (or (memq funsym elp-all-instrumented-list)
+	(setq elp-all-instrumented-list
+	      (cons funsym elp-all-instrumented-list)))
+    ))
+
+;;;###autoload
+(defun elp-restore-function (funsym)
+  "Restore an instrumented function to its original definition.
+Argument FUNSYM is the symbol of a defined function."
+  (interactive "aFunction to restore: ")
+  (let ((info (get funsym elp-timer-info-property)))
+    ;; delete the function from the all instrumented list
+    (setq elp-all-instrumented-list
+	  (delq funsym elp-all-instrumented-list))
+
+    ;; if the function was the master, reset the master
+    (if (eq funsym elp-master)
+	(setq elp-master nil
+	      elp-record-p t))
+
+    ;; zap the properties
+    (put funsym elp-timer-info-property nil)
+
+    ;; restore the original function definition, but if the function
+    ;; wasn't instrumented do nothing.  we do this after the above
+    ;; because its possible the function got un-instrumented due to
+    ;; circumstances beyond our control.  Also, check to make sure
+    ;; that the current function symbol points to elp-wrapper.  If
+    ;; not, then the user probably did an eval-defun, or loaded a
+    ;; byte-compiled version, while the function was instrumented and
+    ;; we don't want to destroy the new definition.  can it ever be
+    ;; the case that a lisp function can be compiled instrumented?
+    (and info
+	 (not (compiled-function-p (symbol-function funsym)))
+	 (assq 'elp-wrapper (symbol-function funsym))
+	 (fset funsym (aref info 2)))))
+
+;;;###autoload
+(defun elp-instrument-list (&optional list)
+  "Instrument for profiling, all functions in `elp-function-list'.
+Use optional LIST if provided instead."
+  (interactive "PList of functions to instrument: ")
+  (let ((list (or list elp-function-list)))
+    (mapcar 'elp-instrument-function list)))
+
+;;;###autoload
+(defun elp-instrument-package (prefix)
+  "Instrument for profiling, all functions which start with PREFIX.
+For example, to instrument all ELP functions, do the following:
+
+    \\[elp-instrument-package] RET elp- RET"
+  (interactive "sPrefix of package to instrument: ")
+  (elp-instrument-list
+   (mapcar 'intern (all-completions prefix obarray
+				    (function
+				     (lambda (sym)
+				       (and (fboundp sym)
+					    (not (eq (car-safe
+						      (symbol-function sym))
+						     'macro)))))))))
+
+(defun elp-restore-list (&optional list)
+  "Restore the original definitions for all functions in `elp-function-list'.
+Use optional LIST if provided instead."
+  (interactive "PList of functions to restore: ")
+  (let ((list (or list elp-function-list)))
+    (mapcar 'elp-restore-function list)))
+
+(defun elp-restore-all ()
+  "Restores the original definitions of all functions being profiled."
+  (interactive)
+  (elp-restore-list elp-all-instrumented-list))
+
+
+(defun elp-reset-function (funsym)
+  "Reset the profiling information for FUNSYM."
+  (interactive "aFunction to reset: ")
+  (let ((info (get funsym elp-timer-info-property)))
+    (or info
+	(error "%s is not instrumented for profiling." funsym))
+    (aset info 0 0)			;reset call counter
+    (aset info 1 0.0)			;reset total time
+    ;; don't muck with aref 2 as that is the old symbol definition
+    ))
+
+(defun elp-reset-list (&optional list)
+  "Reset the profiling information for all functions in `elp-function-list'.
+Use optional LIST if provided instead."
+  (interactive "PList of functions to reset: ")
+  (let ((list (or list elp-function-list)))
+    (mapcar 'elp-reset-function list)))
+
+(defun elp-reset-all ()
+  "Reset the profiling information for all functions being profiled."
+  (interactive)
+  (elp-reset-list elp-all-instrumented-list))
+
+(defun elp-set-master (funsym)
+  "Set the master function for profiling."
+  (interactive "aMaster function: ")
+  ;; when there's a master function, recording is turned off by
+  ;; default
+  (setq elp-master funsym
+	elp-record-p nil)
+  ;; make sure master function is instrumented
+  (or (memq funsym elp-all-instrumented-list)
+      (elp-instrument-function funsym)))
+
+(defun elp-unset-master ()
+  "Unsets the master function."
+  (interactive)
+  ;; when there's no master function, recording is turned on by default.
+  (setq elp-master nil
+	elp-record-p t))
+
+
+(defsubst elp-get-time ()
+  ;; get current time in seconds and microseconds. I throw away the
+  ;; most significant 16 bits of seconds since I doubt we'll ever want
+  ;; to profile lisp on the order of 18 hours. See notes at top of file.
+  (let ((now (current-time)))
+    (+ (float (nth 1 now)) (/ (float (nth 2 now)) 1000000.0))))
+
+(defun elp-wrapper (funsym interactive-p args)
+  "This function has been instrumented for profiling by the ELP.
+ELP is the Emacs Lisp Profiler.  To restore the function to its
+original definition, use \\[elp-restore-function] or \\[elp-restore-all]."
+  ;; turn on recording if this is the master function
+  (if (and elp-master
+	   (eq funsym elp-master))
+      (setq elp-record-p t))
+  ;; get info vector and original function symbol
+  (let* ((info (get funsym elp-timer-info-property))
+	 (func (aref info 2))
+	 result)
+    (or func
+	(error "%s is not instrumented for profiling." funsym))
+    (if (not elp-record-p)
+	;; when not recording, just call the original function symbol
+	;; and return the results.
+	(setq result
+	      (if interactive-p
+		  (call-interactively func)
+		(apply func args)))
+      ;; we are recording times
+      (let ((enter-time (elp-get-time)))
+	;; increment the call-counter
+	(aset info 0 (1+ (aref info 0)))
+	;; now call the old symbol function, checking to see if it
+	;; should be called interactively.  make sure we return the
+	;; correct value
+	(setq result
+	      (if interactive-p
+		  (call-interactively func)
+		(apply func args)))
+	;; calculate total time in function
+	(aset info 1 (+ (aref info 1) (- (elp-get-time) enter-time)))
+	))
+    ;; turn off recording if this is the master function
+    (if (and elp-master
+	     (eq funsym elp-master))
+	(setq elp-record-p nil))
+    result))
+
+
+;; shut the byte-compiler up
+(defvar elp-field-len nil)
+(defvar elp-cc-len nil)
+(defvar elp-at-len nil)
+(defvar elp-et-len nil)
+
+(defun elp-sort-by-call-count (vec1 vec2)
+  ;; sort by highest call count.  See `sort'.
+  (>= (aref vec1 0) (aref vec2 0)))
+
+(defun elp-sort-by-total-time (vec1 vec2)
+  ;; sort by highest total time spent in function. See `sort'.
+  (>= (aref vec1 1) (aref vec2 1)))
+
+(defun elp-sort-by-average-time (vec1 vec2)
+  ;; sort by highest average time spent in function. See `sort'.
+  (>= (aref vec1 2) (aref vec2 2)))
+
+(defsubst elp-pack-number (number width)
+  ;; pack the NUMBER string into WIDTH characters, watching out for
+  ;; very small or large numbers
+  (if (<= (length number) width)
+      number
+    ;; check for very large or small numbers
+    (if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number)
+	(concat (substring
+		 (substring number (match-beginning 1) (match-end 1))
+		 0
+		 (- width (match-end 2) (- (match-beginning 2)) 3))
+		"..."
+		(substring number (match-beginning 2) (match-end 2)))
+      (concat (substring number 0 width)))))
+
+(defun elp-output-result (resultvec)
+  ;; output the RESULTVEC into the results buffer. RESULTVEC is a 4 or
+  ;; more element vector where aref 0 is the call count, aref 1 is the
+  ;; total time spent in the function, aref 2 is the average time
+  ;; spent in the function, and aref 3 is the symbol's string
+  ;; name. All other elements in the vector are ignored.
+  (let* ((cc (aref resultvec 0))
+	 (tt (aref resultvec 1))
+	 (at (aref resultvec 2))
+	 (symname (aref resultvec 3))
+	 callcnt totaltime avetime)
+    (setq callcnt (number-to-string cc)
+	  totaltime (number-to-string tt)
+	  avetime (number-to-string at))
+    ;; possibly prune the results
+    (if (and elp-report-limit
+	     (numberp elp-report-limit)
+	     (< cc elp-report-limit))
+	nil
+      (insert symname)
+      (insert-char 32 (+ elp-field-len (- (length symname)) 2))
+      ;; print stuff out, formatting it nicely
+      (insert callcnt)
+      (insert-char 32 (+ elp-cc-len (- (length callcnt)) 2))
+      (let ((ttstr (elp-pack-number totaltime elp-et-len))
+	    (atstr (elp-pack-number avetime elp-at-len)))
+	(insert ttstr)
+	(insert-char 32 (+ elp-et-len (- (length ttstr)) 2))
+	(insert atstr))
+      (insert "\n"))))
+
+;;;###autoload
+(defun elp-results ()
+  "Display current profiling results.
+If `elp-reset-after-results' is non-nil, then current profiling
+information for all instrumented functions are reset after results are
+displayed."
+  (interactive)
+  (let ((curbuf (current-buffer))
+	(resultsbuf (if elp-recycle-buffers-p
+			(get-buffer-create elp-results-buffer)
+		      (generate-new-buffer elp-results-buffer))))
+    (set-buffer resultsbuf)
+    (erase-buffer)
+    (beginning-of-buffer)
+    ;; get the length of the longest function name being profiled
+    (let* ((longest 0)
+	   (title "Function Name")
+	   (titlelen (length title))
+	   (elp-field-len titlelen)
+	   (cc-header "Call Count")
+	   (elp-cc-len    (length cc-header))
+	   (et-header "Elapsed Time")
+	   (elp-et-len    (length et-header))
+	   (at-header "Average Time")
+	   (elp-at-len    (length at-header))
+	   (resvec
+	    (mapcar
+	     (function
+	      (lambda (funsym)
+		(let* ((info (get funsym elp-timer-info-property))
+		       (symname (format "%s" funsym))
+		       (cc (aref info 0))
+		       (tt (aref info 1)))
+		  (if (not info)
+		      (insert "No profiling information found for: "
+			      symname)
+		    (setq longest (max longest (length symname)))
+		    (vector cc tt (if (zerop cc)
+				      0.0 ;avoid arithmetic div-by-zero errors
+				    (/ (float tt) (float cc)))
+			    symname)))))
+	     elp-all-instrumented-list))
+	   )				; end let*
+      (insert title)
+      (if (> longest titlelen)
+	  (progn
+	    (insert-char 32 (- longest titlelen))
+	    (setq elp-field-len longest)))
+      (insert "  " cc-header "  " et-header "  " at-header "\n")
+      (insert-char ?= elp-field-len)
+      (insert "  ")
+      (insert-char ?= elp-cc-len)
+      (insert "  ")
+      (insert-char ?= elp-et-len)
+      (insert "  ")
+      (insert-char ?= elp-at-len)
+      (insert "\n")
+      ;; if sorting is enabled, then sort the results list. in either
+      ;; case, call elp-output-result to output the result in the
+      ;; buffer
+      (if elp-sort-by-function
+	  (setq resvec (sort resvec elp-sort-by-function)))
+      (mapcar 'elp-output-result resvec))
+    ;; now pop up results buffer
+    (set-buffer curbuf)
+    (pop-to-buffer resultsbuf)
+    ;; copy results to standard-output?
+    (if (or elp-use-standard-output noninteractive)
+	(princ (buffer-substring (point-min) (point-max))))
+    ;; reset profiling info if desired
+    (and elp-reset-after-results
+	 (elp-reset-all))))
+
+
+;;(eval-when-compile
+;;  (require 'reporter))
+
+;;;###autoload
+(defun elp-submit-bug-report ()
+  "Submit via mail, a bug report on elp."
+  (interactive)
+  (and
+   (y-or-n-p "Do you want to submit a report on elp? ")
+   (require 'reporter)
+   (reporter-submit-bug-report
+    elp-help-address (concat "elp " elp-version)
+    '(elp-report-limit
+      elp-reset-after-results
+      elp-sort-by-function))))
+
+
+(provide 'elp)
+
+;;; elp.el ends here
+;;; find-func.el --- find the definition of the Emacs Lisp function near point
+
+;; Copyright (C) 1997 Free Software Foundation, Inc.
+
+;; Author: Jens Petersen <petersen@kurims.kyoto-u.ac.jp>
+;; Maintainer: petersen@kurims.kyoto-u.ac.jp
+;; Keywords: emacs-lisp, functions
+;; Created: 97/07/25
+;; URL: <http://www.kurims.kyoto-u.ac.jp/~petersen/emacs-lisp/>
+
+;; $Id$
+
+;; This file is part of XEmacs.
+
+;; XEmacs is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; XEmacs is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with XEmacs; see the file COPYING.  If not, write to the 
+;; Free Software Foundation, 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+;;
+;; The funniest thing about this is that I can't imagine why a package
+;; so obviously useful as this hasn't been written before!!
+;;
+;; Put this file in your `load-path', byte-compile it and add the
+;; following code in your init file:
+;;
+;; ;;; find-func
+;; (load "find-func")
+;; (global-set-key [(control ?c) ?f] 'find-function)
+;; (global-set-key [(control ?c) ?4 ?f] 'find-function-other-window)
+;; (global-set-key [(control ?c) ?5 ?f] 'find-function-other-frame)
+;; (global-set-key [(control ?c) ?k] 'find-function-on-key)
+;;
+;; and away you go!  It does pretty much what you would expect,
+;; putting the cursor at the definition of the function at point.
+;;
+;; In XEmacs the source file of dumped functions is recorded (and can
+;; be accessed with the function `compiled-function-annotation', which
+;; doesn't exist in Emacs), so in XEmacs non-primitive dumped
+;; functions can also be found.  Unfortunately this is not possible in
+;; Emacs.  It would be nice if the location of primitive functions in
+;; the C code was also recorded!
+
+;; The code is adapted from `describe-function', `describe-key'
+;; ("help.el") and `fff-find-loaded-emacs-lisp-function' (Noah Friedman's
+;; "fff.el").
+
+;;; To do:
+;;
+;; o improve handling of advice'd functions? (at the moment it goes to
+;; the advice, not the actual definition)
+;;
+;; o `find-function-other-frame' is not quite right when the function
+;; is in the current buffer.
+;;
+;;;; Code:
+
+(defgroup find-function nil
+  "Find the definition of the Emacs Lisp function near point."
+  :group 'lisp)
+
+;;; User variables:
+
+(defcustom find-function-source-path nil
+  "The default list of directories where find-function searches.
+
+If this variable is `nil' then find-function searches `load-path' by
+default."
+  :type '(choice (const :tag "Use `load-path'" nil)
+		 (repeat :tag "Directories"
+			 :menu-tag "List"
+			 :value ("")
+			 directory))
+  :group 'find-function)
+
+
+;;; Functions:
+
+(defun find-function-noselect (function)
+  "Returns a pair `(buffer . point)' pointing to the definition of FUNCTION.
+
+Finds the Emacs Lisp library containing the definition of FUNCTION
+in a buffer and the point of the definition.  The buffer is
+not selected.
+
+The library where FUNCTION is defined is searched for in
+`find-function-source-path', if non `nil', otherwise in `load-path'."
+  (if (not function)
+      (error "You didn't specify a function"))
+  (and (subrp (symbol-function function))
+       (error "%s is a primitive function" function))
+  (let ((def (symbol-function function))
+	library aliases)
+    (while (symbolp def)
+      (or (eq def function)
+	  (if aliases
+	      (setq aliases (concat aliases
+				    (format ", which is an alias for %s"
+					    (symbol-name def))))
+	    (setq aliases (format "an alias for %s" (symbol-name def)))))
+      (setq function (symbol-function function)
+	    def (symbol-function function)))
+    (if aliases
+	(message aliases))
+    (setq library
+	  (cond ((eq (car-safe def) 'autoload)
+		 (nth 1 def))
+		((describe-function-find-file function))
+		((compiled-function-p def)
+		 (substring (compiled-function-annotation def) 0 -4))
+		((eq 'macro (car-safe def))
+		 (and (compiled-function-p (cdr def))
+		      (substring (compiled-function-annotation (cdr def)) 0 -4)))))
+    (if (null library)
+	(error (format "Don't know where `%s' is defined" function)))
+    (if (string-match "\\.el\\(c\\)\\'" library)
+	(setq library (substring library 0 (match-beginning 1))))
+    (let* ((path find-function-source-path)
+	   (filename (if (file-exists-p library)
+			 library
+		       (if (string-match "\\(\\.el\\)\\'" library)
+			   (setq library (substring library 0
+						    (match-beginning
+						     1))))
+		       (or (locate-library (concat library ".el") t path)
+			   (locate-library library t path)))))
+      (if (not filename)
+	  (error "The library \"%s\" is not in the path." library))
+      (with-current-buffer (find-file-noselect filename)
+	(save-match-data
+	  (let (;; avoid defconst, defgroup, defvar (any others?)
+		(regexp
+		 (format "^\\s-*(def[^cgv\W]\\w+\\*?\\s-+%s\\s-"
+			 (regexp-quote (symbol-name function))))
+		(syntable (syntax-table)))
+	    (set-syntax-table emacs-lisp-mode-syntax-table)
+	    (goto-char (point-min))
+	    (if (prog1
+		    (re-search-forward regexp nil t)
+		  (set-syntax-table syntable))
+		(progn
+		  (beginning-of-line)
+		  (cons (current-buffer) (point)))
+	      (error "Cannot find definition of `%s'" function))))))))
+
+(defun find-function-read-function ()
+  "Read and return a function, defaulting to the one near point.
+
+`function-at-point' is used to select the default function."
+  (let ((fn (function-at-point))
+	(enable-recursive-minibuffers t)
+	val)
+    (setq val (completing-read
+	       (if fn
+		   (format "Find function (default %s): " fn)
+		 "Find function: ")
+	       obarray 'fboundp t nil 'function-history))
+    (list (if (equal val "")
+	      fn (intern val)))))
+
+(defun find-function-do-it (function switch-fn)
+  "Find Emacs Lisp FUNCTION in a buffer and display it with SWITCH-FN.
+Point is saved in the buffer if it is one of the current buffers."
+  (let ((orig-point (point))
+	(orig-buffers (buffer-list))
+	(buffer-point (find-function-noselect function)))
+    (when buffer-point
+      (funcall switch-fn (car buffer-point))
+      (when (memq (car buffer-point) orig-buffers)
+	(push-mark orig-point))
+      (goto-char (cdr buffer-point))
+      (recenter 0))))
+
+;;;###autoload
+(defun find-function (function)
+  "Find the definition of the function near point in the current window.
+
+Finds the Emacs Lisp library containing the definition of the function
+near point (selected by `function-at-point') in a buffer and
+places point before the definition.  Point is saved in the buffer if
+it is one of the current buffers.
+
+The library where FUNCTION is defined is searched for in
+`find-function-source-path', if non `nil', otherwise in `load-path'."
+  (interactive (find-function-read-function))
+  (find-function-do-it function 'switch-to-buffer))
+
+;;;###autoload
+(defun find-function-other-window (function)
+  "Find the definition of the function near point in the other window.
+
+Finds the Emacs Lisp library containing the definition of the function
+near point (selected by `function-at-point') in a buffer and
+places point before the definition.  Point is saved in the buffer if
+it is one of the current buffers.
+
+The library where FUNCTION is defined is searched for in
+`find-function-source-path', if non `nil', otherwise in `load-path'."
+  (interactive (find-function-read-function))
+  (find-function-do-it function 'switch-to-buffer-other-window))
+
+;;;###autoload
+(defun find-function-other-frame (function)
+  "Find the definition of the function near point in the another frame.
+
+Finds the Emacs Lisp library containing the definition of the function
+near point (selected by `function-at-point') in a buffer and
+places point before the definition.  Point is saved in the buffer if
+it is one of the current buffers.
+
+The library where FUNCTION is defined is searched for in
+`find-function-source-path', if non `nil', otherwise in `load-path'."
+  (interactive (find-function-read-function))
+  (find-function-do-it function 'switch-to-buffer-other-frame))
+
+;;;###autoload
+(defun find-function-on-key (key)
+  "Find the function that KEY invokes.  KEY is a string.
+Point is saved if FUNCTION is in the current buffer."
+  (interactive "kFind function on key: ")
+  (let ((defn (key-or-menu-binding key)))
+    (if (or (null defn) (integerp defn))
+        (message "%s is undefined" (key-description key))
+      (if (and (consp defn) (not (eq 'lambda (car-safe defn))))
+	  (message "runs %s" (prin1-to-string defn))
+	(find-function-other-window defn)))))
+
+;;;###autoload
+(defun find-function-at-point ()
+  "Find directly the function at point in the other window."
+  (interactive)
+  (let ((symb (function-at-point)))
+    (when symb
+      (find-function-other-window symb))))
+
+;; (define-key ctl-x-map "F" 'find-function) ; conflicts with `facemenu-keymap'
+
+;;;###autoload
+(define-key ctl-x-4-map "F" 'find-function-other-window)