Commits

steveb  committed 25e2108

Update to find-func.el

  • Participants
  • Parent commits 2f7f028

Comments (0)

Files changed (3)

+1998-06-15  Jens-Ulrik Petersen  <petersen@kurims.kyoto-u.ac.jp>
+
+	* find-func.el: Version 0.21 released.
+	Improvements to the preamble.  Require "loadhist".
+	(find-function-source-path): Simplified the custom type.
+	(find-function-recenter-line): New variable to control center of
+	definition.
+	(find-function-after-hook): New variable.
+	(find-function-search-for-symbol): `regexp-quote' the symbol name: 
+	needed to find-function `mapcar*' for example.  [Patch from Hrvoje
+	Niksic <hniksic@srce.hr>]
+	(find-function-search-for-symbol): Include library name in error
+	message when symbol can't be found.
+	(find-function-noselect): Improved docstring.  Don't include
+	`library' in let [Thanks to Bob Weiner <weiner@altrasoft.com>].
+	Use `symbol-file' instead of `describe-symbol-find-file'.  Protect
+	`compiled-function-annotation' call and keep it for older
+	XEmacsen.  Use `file-name-sans-extension' for compiled functions.
+	(find-function-read): Separate `completing-read' calls for
+	variables and functions, and use `variable-history'.
+	(find-function-do-it): Mention new `find-function-recenter-line'
+	and `find-function-after-hook' in docstring.  Use them.
+	(find-function): Mention `find-function-recenter-line' and
+	`find-function-after-hook' in docstring.
+	(find-function-other-window): Remove most of docstring and add
+	reference to `find-function' instead.
+	(find-function-other-frame): Ditto.
+	(find-variable-noselect): Use `symbol-file' instead of
+	`describe-symbol-find-file'.
+	(find-variable): Mention `find-function-recenter-line' and
+	`find-function-after-hook' in docstring.
+	(find-variable-other-window): Remove most of docstring and add
+	reference to `find-variable' instead.
+	(find-variable-other-frame): Ditto.
+	(find-function-on-key): Simplified.
+
 1998-04-20  Karl M. Hegbloom  <karlheg@bittersweet.inetarena.com>
 
 	* hide-copyleft.el (more-copylefts-to-hide): Added defcustom.
 
 # This XEmacs package contains independent single file lisp packages
 
-VERSION = 1.12
+VERSION = 1.13
 AUTHOR_VERSION =
 MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
 PACKAGE = xemacs-devel

File find-func.el

 ;; 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/>
-;; Version: 0.20
+;; URL: <http://www.kurims.kyoto-u.ac.jp/~petersen/xemacs/>
+;; Version: 0.21
 
 ;; $Id$
 
 
 ;; 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,
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 ;;
 ;; ;;; 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)
-;; (global-set-key [(control ?c) ?v] 'find-variable)
-;; (global-set-key [(control ?c) ?4 ?v] 'find-variable-other-window)
-;; (global-set-key [(control ?c) ?5 ?v] 'find-variable-other-frame)
 ;;
-;; and away you go!  It does pretty much what you would expect,
-;; putting the cursor at the definition of the function or variable at
-;; point.
+;; and away you go!  The default given keybindings as the ones
+;; protected by autoload cookies at the bottom of this file.  It does
+;; pretty much what you would expect, putting the cursor at the
+;; definition of the function or variable at point.
 ;;
-;; In XEmacs the source file of all loaded Lisp function and variable
-;; definitions is now recorded in `load-history'.  So in XEmacs all
-;; non-primitive functions and variables can be found.  Unfortunately
-;; in Emacs, only loaded function can be found.  It would be nice if
-;; the location of primitive functions in the C code was also
-;; recorded!
+;; In XEmacs the source filename of every dumped or loaded Lisp symbol
+;; definition is now recorded in `load-history'.  So in XEmacs all
+;; non-primitive functions and variables can be found in principle.
+;; (I say "in principle" since the system is not perfect.  For example
+;; although it is unusual it can happen that say a variable and
+;; function of the same name are defined defined in different files,
+;; which may lead to incorrect results.)  Unfortunately in Emacs, only
+;; symbols loaded from startup can be found.  It would be nice if the
+;; location of primitive functions in the C code was also recorded!
 
 ;; The code started out from `describe-function', `describe-key'
 ;; ("help.el") and `fff-find-loaded-emacs-lisp-function' (Noah Friedman's
 ;; "fff.el").
 
-;;; To do:
+;;; Problems:
 ;;
-;; o improve handling of advice'd functions? (at the moment it goes to
-;; the advice, not the actual definition)
+;; o `find-function-other-{frame,window}' is not quite right when the
+;; function is in the current buffer (an XEmacs bug?).
 ;;
-;; 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)
+(require 'loadhist)
 
 ;;; User variables:
 
+(defgroup find-function nil
+  "Finds the definition of the Emacs Lisp symbol near point."
+;;   :prefix "find-function"
+  :group 'lisp)
+
 ;; (defcustom find-function-method-function 'switch-to-buffer-other-window 
 ;;   "The default function used to display the buffer of the definition.
 ;; 
 
 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))
+  :type '(repeat directory)
   :group 'find-function)
 
+(defcustom find-function-recenter-line 1
+  "The window line-number from which to start displaying a symbol definition.
+A value of nil implies center the beginning of the definition.
+See the function `center-to-window-line' for more information, and
+`find-function' and `find-variable'."
+  :group 'find-function)
+
+(defcustom find-function-after-hook nil
+  "Hook run after finding symbol definition.
+
+See the functions `find-function' and `find-variable'."
+  :group 'find-function)
 
 ;;; Functions:
 
   (let* ((path find-function-source-path)
 	 (filename (if (file-exists-p library)
 		       library
+		     ;; use `file-name-sans-extension' here? (if it gets fixed)
 		     (if (string-match "\\(\\.el\\)\\'" library)
 			 (setq library (substring library 0
-						  (match-beginning
-						   1))))
+						  (match-beginning 1))))
 		     (or (locate-library (concat library ".el") t path)
 			 (locate-library library t path)))))
     (if (not filename)
 	(let ((regexp (format (if variable-p
 				  find-variable-regexp
 				find-function-regexp)
-			      symbol))
+			      (regexp-quote (symbol-name symbol))))
 	      (syn-table (syntax-table)))
 	  (unwind-protect
 	      (progn
 		    (progn
 		      (beginning-of-line)
 		      (cons (current-buffer) (point)))
-		  (error "Cannot find definition of `%s'" symbol)))
+		  (error "Cannot find definition of `%s' in library \"%s\"" 
+			 symbol library)))
 	    (set-syntax-table syn-table)))))))
 
 (defun find-function-noselect (function)
-  "Returns a pair `(buffer . point)' pointing to the definition of 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 the file where FUNCTION is defined is not known, then it 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)
+	aliases)
     (while (symbolp def)
       (or (eq def function)
 	  (if aliases
     (let ((library
 	   (cond ((eq (car-safe def) 'autoload)
 		  (nth 1 def))
-		 ((describe-symbol-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))))))
+		 ((symbol-file function))
+		 ((fboundp 'compiled-function-annotation)
+		  (cond ((compiled-function-p def)
+			 (file-name-sans-extension
+			  (compiled-function-annotation def)))
+			((eq 'macro (car-safe def))
+			 (and (compiled-function-p (cdr def))
+			      (file-name-sans-extension
+			       (compiled-function-annotation (cdr def))))))))))
       (find-function-search-for-symbol function nil library))))
 
 (defun find-function-read (&optional variable-p)
 			 'function-at-point)))
 	(enable-recursive-minibuffers t)
 	val)
-    (setq val (completing-read
-	       (concat "Find "
-		       (if variable-p
-			   "variable"
-			 "function")
-		       (if symb
-			   (format " (default %s)" symb))
-		       ": ")
-	       obarray (if variable-p 'boundp 'fboundp)
-	       t nil 'function-history))
+    (setq val (if variable-p
+		  (completing-read
+		   (concat "Find variable"
+			   (if symb
+			       (format " (default %s)" symb))
+			   ": ")
+		   obarray 'boundp t nil 'variable-history)
+		(completing-read
+		 (concat "Find function"
+			 (if symb
+			     (format " (default %s)" symb))
+			 ": ")
+		 obarray 'fboundp t nil 'function-history)))
     (list (if (equal val "")
-	      symb (intern val)))))
+	      symb
+	    (intern val)))))
 
 (defun find-function-do-it (symbol variable-p switch-fn)
   "Find Emacs Lisp SYMBOL in a buffer and display it with SWITCH-FN.
 If VARIABLE-P is nil, a function definition is searched for, otherwise 
-a variable definition is searched for.
+a variable definition is searched for.  The start of a definition is
+centered according to the variable `find-function-recenter-line'.
+See also `find-function-after-hook'.
 
 Point is saved in the buffer if it is one of the current buffers."
   (let ((orig-point (point))
       (when (memq (car buffer-point) orig-buffers)
 	(push-mark orig-point))
       (goto-char (cdr buffer-point))
-      (recenter 0))))
+      (recenter find-function-recenter-line)
+      (run-hooks find-function-after-hook))))
 
 ;;;###autoload
 (defun find-function (function)
 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'."
+`find-function-source-path', if non `nil', otherwise in `load-path'.
+See also `find-function-recenter-line' and `find-function-after-hook'."
   (interactive (find-function-read))
   (find-function-do-it function nil 'switch-to-buffer))
 
 (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'."
+See `find-function' for more details."
   (interactive (find-function-read))
   (find-function-do-it function nil 'switch-to-buffer-other-window))
 
 (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'."
+See `find-function' for more details."
   (interactive (find-function-read))
   (find-function-do-it function nil 'switch-to-buffer-other-frame))
 
       (error "You didn't specify a variable"))
   (and (built-in-variable-type variable)
        (error "%s is a primitive variable" variable))
-    (let ((library (describe-symbol-find-file variable)))
-      (find-function-search-for-symbol variable 'variable library)))
+  (let ((library (symbol-file variable)))
+    (find-function-search-for-symbol variable 'variable library)))
 
 ;;;###autoload
 (defun find-variable (variable)
 it is one of the current buffers.
 
 The library where VARIABLE is defined is searched for in
-`find-function-source-path', if non `nil', otherwise in `load-path'."
+`find-function-source-path', if non `nil', otherwise in `load-path'.
+See also `find-function-recenter-line' and `find-function-after-hook'."
   (interactive (find-function-read 'variable))
   (find-function-do-it variable t 'switch-to-buffer))
 
 (defun find-variable-other-window (variable)
   "Find the definition of the variable near point in the other window.
 
-Finds the Emacs Lisp library containing the definition of the variable
-near point (selected by `variable-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 VARIABLE is defined is searched for in
-`find-function-source-path', if non `nil', otherwise in `load-path'."
+See `find-variable' for more details."
   (interactive (find-function-read 'variable))
   (find-function-do-it variable t 'switch-to-buffer-other-window))
 
 (defun find-variable-other-frame (variable)
   "Find the definition of the variable near point in the another frame.
 
-Finds the Emacs Lisp library containing the definition of the variable
-near point (selected by `variable-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 VARIABLE is defined is searched for in
-`find-function-source-path', if non `nil', otherwise in `load-path'."
+See `find-variable' for more details."
   (interactive (find-function-read 'variable))
   (find-function-do-it variable t 'switch-to-buffer-other-frame))
 
   "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)))
+  (let ((defn (key-or-menu-binding key))
+	(key-desc (key-description 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))
+        (message "%s is unbound" key-desc)
+      (if (consp defn)
+	  (message "%s runs %s" key-desc (prin1-to-string defn))
 	(find-function-other-window defn)))))
 
 ;;;###autoload
 ;;;###autoload(define-key ctl-x-5-map "V" 'find-variable-other-frame)
 
 (provide 'find-func)
+
 ;;; find-func.el ends here