]> code.delx.au - gnu-emacs/blobdiff - lisp/which-func.el
(texinfo-make-menu): Make region-end a marker.
[gnu-emacs] / lisp / which-func.el
index c55e392c23d7078b4aeae8a1632d28ebba363d2c..b77f0bcd65bc3e5c02c84abf0f7133069fc3f538 100644 (file)
   :version "20.3")
 
 (defcustom which-func-modes 
-  '(emacs-lisp-mode c-mode c++-mode perl-mode makefile-mode sh-mode)
-  "List of major modes for which `which-func-mode' should be used.
+  '(emacs-lisp-mode c-mode c++-mode perl-mode makefile-mode sh-mode
+                   fortran-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 current-function recognition is enabled in any mode."
+then Which Function mode is enabled in any major mode that supports it."
   :group 'which-func
   :type '(choice (const :tag "All modes" t)
-                (list (symbol :tag "Major mode"))))
+                (repeat (symbol :tag "Major mode"))))
 
 (defcustom which-func-non-auto-modes nil
   "List of major modes where Which Function mode is inactive till Imenu is used.
-
-Note that the menu is never computed automatically if the buffer size
-exceeds `which-func-maxout'."
-
+This means that Which Function mode won't really do anything
+until you use Imenu, in these modes.  Note that files
+larger than `which-func-maxout' behave in this way too;
+Which Function mode doesn't do anything until you use Imenu."
   :group 'which-func
-  :type '(list (symbol :tag "Major mode")))
+  :type '(repeat (symbol :tag "Major mode")))
 
 (defcustom which-func-maxout 100000
   "Don't automatically compute the Imenu menu if buffer is this big or bigger.
@@ -105,7 +106,7 @@ Zero means compute the Imenu menu regardless of size."
   "*Toggle `which-func-mode'.
 You must modify via \\[customize] for this variable to have an effect."
   :set #'(lambda (symbol value)
-          (which-func-mode (or value 0)))
+          (which-func-mode (if value 1 0)))
   :initialize 'custom-initialize-default
   :type    'boolean
   :group   'which-func
@@ -136,12 +137,15 @@ It creates the Imenu index for the buffer, if necessary."
       (setq which-func-mode which-func-mode-global)
     (setq which-func-mode nil))
 
-  (if (and which-func-mode
-           (not (member major-mode which-func-non-auto-modes))
-           (or (< buffer-saved-size which-func-maxout)
-               (= which-func-maxout 0)))
-      (setq imenu--index-alist
-           (save-excursion (funcall imenu-create-index-function)))))
+  (condition-case nil
+      (if (and which-func-mode
+              (not (member major-mode which-func-non-auto-modes))
+              (or (< buffer-saved-size which-func-maxout)
+                  (= which-func-maxout 0)))
+         (setq imenu--index-alist
+               (save-excursion (funcall imenu-create-index-function))))
+    (error
+     (setq which-func-mode nil))))
 
 (defun which-func-update ()
   ;; Update the string containing the current function.
@@ -200,8 +204,9 @@ is located before first function, returns nil."
    (let ((pair (car-safe imenu--index-alist))
          (rest (cdr-safe imenu--index-alist))
          (name nil))
-     (while (and pair (or (not (number-or-marker-p (cdr pair)))
-                         (> (point) (cdr pair))))
+     (while (and (or rest pair)
+                (or (not (number-or-marker-p (cdr pair)))
+                    (> (point) (cdr pair))))
        (setq name (car pair))
        (setq pair (car-safe rest))
        (setq rest (cdr-safe rest)))