From ecafbba26bcac902cdd75895030e7b1c7e5e71b7 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Thu, 22 Nov 2001 00:08:32 +0000 Subject: [PATCH] (which-function): Call imenu--make-index-alist if necessary to get a list of functions. (which-function-imenu-failed): New variable. (which-func-update): Handle all visible windows. (which-func-update-1): New subroutine broken out of which-func-update. --- lisp/ChangeLog | 6 ++++++ lisp/which-func.el | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0a842a59c66..596e010d931 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,11 @@ 2001-11-21 Richard M. Stallman + * which-func.el (which-function): Call imenu--make-index-alist + if necessary to get a list of functions. + (which-function-imenu-failed): New variable. + (which-func-update): Handle all visible windows. + (which-func-update-1): New subroutine broken out of which-func-update. + * files.el (temporary-file-directory, null-device) (small-temporary-file-directory): Definitions moved up. diff --git a/lisp/which-func.el b/lisp/which-func.el index f183fd0e2a4..c594945d89e 100644 --- a/lisp/which-func.el +++ b/lisp/which-func.el @@ -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))) -- 2.39.2