diff lisp/progmodes/which-func.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children b9eee0a7bef5
line wrap: on
line diff
--- a/lisp/progmodes/which-func.el	Thu Apr 15 01:08:34 2004 +0000
+++ b/lisp/progmodes/which-func.el	Fri Apr 16 12:51:06 2004 +0000
@@ -76,7 +76,7 @@
 
 (defcustom which-func-modes
   '(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode makefile-mode
-		    sh-mode fortran-mode f90-mode)
+		    sh-mode fortran-mode f90-mode ada-mode)
   "List of major modes for which Which Function mode should be used.
 For other modes it is disabled.  If this is equal to t,
 then Which Function mode is enabled in any major mode that supports it."
@@ -198,7 +198,8 @@
                   (or (eq which-func-modes t)
                       (member major-mode which-func-modes))))))
     ;; Turn it off
-    (cancel-timer which-func-update-timer)
+    (when (timerp which-func-update-timer)
+      (cancel-timer which-func-update-timer))
     (setq which-func-update-timer nil)
     (dolist (buf (buffer-list))
       (with-current-buffer buf (setq which-func-mode nil)))))
@@ -206,20 +207,37 @@
 (defvar which-function-imenu-failed nil
   "Locally t in a buffer if `imenu--make-index-alist' found nothing there.")
 
+(defvar which-func-functions nil
+  "List of functions for `which-function' to call with no arguments.
+It calls them sequentially, and if any returns non-nil,
+`which-function' uses that name and stops looking for the name.")
+
 (defun which-function ()
   "Return current function name based on point.
-Uses `imenu--index-alist' or `add-log-current-defun-function'.
+Uses `which-function-functions', `imenu--index-alist'
+or `add-log-current-defun-function'.
 If no function name is found, return nil."
   (let (name)
+    ;; Try the which-function-functions functions first.
+    (let ((hooks which-func-functions))
+      (while hooks
+	(let ((value (funcall (car hooks))))
+	  (when value
+	    (setq name value
+		  hooks nil)))
+	(setq hooks (cdr hooks))))
+
     ;; If Imenu is loaded, try to make an index alist with it.
-    (when (and (boundp 'imenu--index-alist) (null imenu--index-alist)
+    (when (and (null name)
+	       (boundp 'imenu--index-alist) (null imenu--index-alist)
 	       (null which-function-imenu-failed))
       (imenu--make-index-alist)
       (unless imenu--index-alist
 	(make-local-variable 'which-function-imenu-failed)
 	(setq which-function-imenu-failed t)))
     ;; If we have an index alist, use it.
-    (when (and (boundp 'imenu--index-alist) imenu--index-alist)
+    (when (and (null name)
+	       (boundp 'imenu--index-alist) imenu--index-alist)
       (let ((alist imenu--index-alist)
             (minoffset (point-max))
             offset elem pair mark)
@@ -253,4 +271,5 @@
 
 (provide 'which-func)
 
+;;; arch-tag: fa8a55c7-bfe3-4ffc-95ab-01bf21796827
 ;;; which-func.el ends here