;;; which-func.el --- print current function in mode line
-;; Copyright (C) 1994, 1997-1998, 2001-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1997-1998, 2001-2014 Free Software Foundation,
+;; Inc.
;; Author: Alex Rezinsky <alexr@msil.sps.mot.com>
;; (doesn't seem to be responsive any more)
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."
:group 'which-func
- :version "24.2" ; explicit list -> t
+ :version "24.3" ; explicit list -> t
:type '(choice (const :tag "All modes" t)
(repeat (symbol :tag "Major mode"))))
mouse-3: go to end")
"]")
"Format for displaying the function in the mode line."
- :version "24.2" ; added mouse-face
+ :version "24.2" ; added mouse-face; 24point2 is correct
:group 'which-func
:type 'sexp)
;;;###autoload (put 'which-func-format 'risky-local-variable t)
(defconst which-func-current
'(:eval (replace-regexp-in-string
"%" "%%"
- (gethash (selected-window) which-func-table which-func-unknown))))
+ (or (gethash (selected-window) which-func-table)
+ which-func-unknown))))
;;;###autoload (put 'which-func-current 'risky-local-variable t)
-(defvar which-func-mode nil
+(defvar-local 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.")
-(make-variable-buffer-local 'which-func-mode)
-;;(put 'which-func-mode 'permanent-local t)
(add-hook 'find-file-hook 'which-func-ff-hook t)
(defun which-func-ff-hook ()
"File find hook for Which Function mode.
It creates the Imenu index for the buffer, if necessary."
- (setq which-func-mode
- (and which-function-mode
- (or (eq which-func-modes t)
- (member major-mode which-func-modes))))
+ (unless (local-variable-p 'which-func-mode)
+ (setq which-func-mode
+ (and which-function-mode
+ (or (eq which-func-modes t)
+ (member major-mode which-func-modes)))))
(condition-case err
(if (and which-func-mode
(error "Error in which-func-update: %S" info))))))
;;;###autoload
-(defun which-func-mode (&optional arg)
- (which-function-mode arg))
-(make-obsolete 'which-func-mode 'which-function-mode "24.1")
+(define-obsolete-function-alias 'which-func-mode 'which-function-mode "24.1")
(defvar which-func-update-timer nil)
;;Turn it on
(progn
(setq which-func-update-timer
- (run-with-idle-timer idle-update-delay t 'which-func-update))
+ (run-with-idle-timer idle-update-delay t #'which-func-update))
(dolist (buf (buffer-list))
(with-current-buffer buf
- (setq which-func-mode
- (or (eq which-func-modes t)
- (member major-mode which-func-modes))))))
- ;; Turn it off
- (dolist (buf (buffer-list))
- (with-current-buffer buf (setq which-func-mode nil)))))
+ (unless (local-variable-p 'which-func-mode)
+ (setq which-func-mode
+ (or (eq which-func-modes t)
+ (member major-mode which-func-modes)))))))))
(defvar which-function-imenu-failed nil
"Locally t in a buffer if `imenu--make-index-alist' found nothing there.")
(when (and (null name)
(boundp 'imenu--index-alist) (null imenu--index-alist)
(null which-function-imenu-failed))
- (imenu--make-index-alist t)
+ (ignore-errors (imenu--make-index-alist t))
(unless imenu--index-alist
(set (make-local-variable 'which-function-imenu-failed) t)))
;; If we have an index alist, use it.
namestack (cons (car pair) namestack)
alist (cdr pair)))
- ((number-or-marker-p (setq mark (cdr pair)))
+ ((or (number-or-marker-p (setq mark (cdr pair)))
+ (and (overlayp mark)
+ (setq mark (overlay-start mark))))
(when (and (>= (setq offset (- (point) mark)) 0)
(< offset minoffset)) ; Find the closest item.
(setq minoffset offset
\f
;;; Integration with other packages
+(defvar ediff-window-A)
+(defvar ediff-window-B)
+(defvar ediff-window-C)
+
+;; FIXME: Why does ediff require special support?
(defun which-func-update-ediff-windows ()
"Update Which-Function mode display for Ediff windows.
This function is meant to be called from `ediff-select-hook'."
- (when (eq major-mode 'ediff-mode)
+ (when (and (derived-mode-p 'ediff-mode) which-function-mode)
(when ediff-window-A
(which-func-update-1 ediff-window-A))
(when ediff-window-B