]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/which-func.el
(gud-tooltip-dereference): Add missing optional argument.
[gnu-emacs] / lisp / progmodes / which-func.el
index 1f1930a3241bd55a9f230181efc13ab60bb8cfb3..8ca7eb188ec7f36422aa530754005c6cec752d74 100644 (file)
@@ -1,6 +1,7 @@
 ;;; which-func.el --- print current function in mode line
 
-;; Copyright (C) 1994, 1997, 1998, 2001, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006
+;;           Free Software Foundation, Inc.
 
 ;; Author:   Alex Rezinsky <alexr@msil.sps.mot.com>
 ;;           (doesn't seem to be responsive any more)
@@ -20,8 +21,8 @@
 
 ;; 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.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -76,7 +77,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."
@@ -99,7 +100,54 @@ Zero means compute the Imenu menu regardless of size."
   :group 'which-func
   :type 'integer)
 
-(defcustom which-func-format '("[" which-func-current "]")
+(defvar which-func-keymap
+  (let ((map (make-sparse-keymap)))
+    (define-key map [mode-line mouse-1] 'beginning-of-defun)
+    (define-key map [mode-line mouse-2]
+      (lambda ()
+       (interactive)
+       (if (eq (point-min) 1)
+           (narrow-to-defun)
+         (widen))))
+    (define-key map [mode-line mouse-3] 'end-of-defun)
+    map)
+  "Keymap to display on mode line which-func.")
+
+(defface which-func
+  ;; Whether `font-lock-function-name-face' is an appropriate face to
+  ;; inherit depends on the mode-line face; define several variants based
+  ;; on the default mode-line face.
+  '(;; The default mode-line face on a high-color display is a relatively
+    ;; light color ("grey75"), and only the light-background variant of
+    ;; `font-lock-function-name-face' is visible against it.
+    (((class color) (min-colors 88) (background light))
+     :inherit font-lock-function-name-face)
+    ;; The default mode-line face on other display types is inverse-video;
+    ;; it seems that only in the dark-background case is
+    ;; `font-lock-function-name-face' visible against it.
+    (((class grayscale mono) (background dark))
+     :inherit font-lock-function-name-face)
+    (((class color) (background light))
+     :inherit font-lock-function-name-face)
+    ;; If none of the above cases, use an explicit color chosen to contrast
+    ;; well with the default mode-line face.
+    (((class color) (min-colors 88) (background dark))
+     :foreground "Blue1")
+    (((background dark))
+     :foreground "Blue1")
+    (t
+     :foreground "LightSkyBlue"))
+  "Face used to highlight mode line function names."
+  :group 'which-func)
+
+(defcustom which-func-format
+  `("["
+    (:propertize which-func-current
+                local-map ,which-func-keymap
+                face which-func
+                ;;mouse-face highlight ; currently not evaluated :-(
+                help-echo "mouse-1: go to beginning, mouse-2: toggle rest visibility, mouse-3: go to end")
+    "]")
   "Format for displaying the function in the mode line."
   :group 'which-func
   :type 'sexp)
@@ -160,7 +208,7 @@ It creates the Imenu index for the buffer, if necessary."
   (which-func-update-1 (selected-window)))
 
 (defun which-func-update-1 (window)
-  "Update the Which-Function mode display for window WINDOW."
+  "Update the Which Function mode display for window WINDOW."
   (with-selected-window window
     (when which-func-mode
       (condition-case info
@@ -169,7 +217,7 @@ It creates the Imenu index for the buffer, if necessary."
              (puthash window current which-func-table)
              (force-mode-line-update)))
        (error
-        (which-func-mode -1)
+        (setq which-func-mode nil)
         (error "Error in which-func-update: %s" info))))))
 
 ;;;###autoload
@@ -198,7 +246,8 @@ and off otherwise."
                   (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 +255,31 @@ and off otherwise."
 (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)
+  (let ((name
+        ;; Try the `which-function-functions' functions first.
+        (run-hook-with-args-until-success 'which-func-functions)))
+
     ;; 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)
+      (imenu--make-index-alist t)
       (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,5 +313,5 @@ If no function name is found, return nil."
 
 (provide 'which-func)
 
-;;; arch-tag: fa8a55c7-bfe3-4ffc-95ab-01bf21796827
+;; arch-tag: fa8a55c7-bfe3-4ffc-95ab-01bf21796827
 ;;; which-func.el ends here