]> code.delx.au - gnu-emacs/blobdiff - lisp/which-func.el
*** empty log message ***
[gnu-emacs] / lisp / which-func.el
index 1bcd0ea97c9d1afbc70e3dc3ecab54a88f7cccdd..c594945d89e43993d6a30b836857928ba75c167b 100644 (file)
@@ -1,4 +1,4 @@
-;;; which-func.el --- Print current function in mode line
+;;; which-func.el --- print current function in mode line
 
 ;; Copyright (C) 1994, 1997, 1998, 2001 Free Software Foundation, Inc.
 
@@ -127,7 +127,7 @@ and you want to simplify them for the mode line
 
 (defvar which-func-mode nil
   "Non-nil means display current function name in mode line.
-This makes a difference only if `which-function-mode' is non-nil")
+This makes a difference only if `which-function-mode' is non-nil.")
 (make-variable-buffer-local 'which-func-mode)
 ;;(put 'which-func-mode 'permanent-local t)
 
@@ -153,17 +153,24 @@ It creates the Imenu index for the buffer, if necessary."
      (setq which-func-mode nil))))
 
 (defun which-func-update ()
-  ;; Update the string containing the current function.
-  (when which-func-mode
-    (condition-case info
-       (progn
-         (setq which-func-current (or (which-function) which-func-unknown))
-         (unless (string= which-func-current which-func-previous)
-           (force-mode-line-update)
-           (setq which-func-previous which-func-current)))
-      (error
-       (which-func-mode -1)
-       (error "Error in which-func-update: %s" info)))))
+  "Update the Which-Function mode display for all windows."
+  (walk-windows 'which-func-update-1 nil 'visible))
+
+(defun which-func-update-1 (window)
+  "Update the Which-Function mode display for window WINDOW."
+  (save-selected-window
+    (select-window window)
+    ;; Update the string containing the current function.
+    (when which-func-mode
+      (condition-case info
+         (progn
+           (setq which-func-current (or (which-function) which-func-unknown))
+           (unless (string= which-func-current which-func-previous)
+             (force-mode-line-update)
+             (setq which-func-previous which-func-current)))
+       (error
+        (which-func-mode -1)
+        (error "Error in which-func-update: %s" info))))))
 
 ;;;###autoload
 (defalias 'which-func-mode 'which-function-mode)
@@ -192,12 +199,22 @@ and off otherwise."
     (dolist (buf (buffer-list))
       (with-current-buffer buf (setq which-func-mode nil)))))
 
+(defvar which-function-imenu-failed nil
+  "Locally t in a buffer if `imenu--make-index-alist' found nothing there.")
+
 (defun which-function ()
   "Return current function name based on point.
 Uses `imenu--index-alist' or `add-log-current-defun-function'.
 If no function name is found, return nil."
   (let (name)
-    ;; First try using imenu support.
+    ;; If Imenu is loaded, try to make an index alist with it.
+    (when (and (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)
       (let ((pair (car-safe imenu--index-alist))
            (rest (cdr-safe imenu--index-alist)))
@@ -219,4 +236,4 @@ If no function name is found, return nil."
 
 (provide 'which-func)
 
-;; which-func.el ends here
+;;; which-func.el ends here