Mercurial > emacs
comparison lisp/which-func.el @ 32190:af0c1b2c3d6e
(which-func-format): Remove spurious space.
(which-func-mode): Don't make it permanent-local.
(which-func-ff-hook): Allow which-func-maxout to be nil.
(which-func-update): Simplify a bit. Only run if which-func-mode is t.
(which-func-mode): Simplify.
Use post-command-idle-hook rather than post-command-hook.
Go through all buffers and update their state.
(which-function): Also try add-log-current-defun-function.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 05 Oct 2000 23:13:07 +0000 |
parents | f85f374e5395 |
children | 683f3781ab81 |
comparison
equal
deleted
inserted
replaced
32189:921a2e8fa97e | 32190:af0c1b2c3d6e |
---|---|
69 (defgroup which-func nil | 69 (defgroup which-func nil |
70 "Mode to display the current function name in the modeline." | 70 "Mode to display the current function name in the modeline." |
71 :group 'tools | 71 :group 'tools |
72 :version "20.3") | 72 :version "20.3") |
73 | 73 |
74 (defcustom which-func-modes | 74 (defcustom which-func-modes |
75 '(emacs-lisp-mode c-mode c++-mode perl-mode makefile-mode sh-mode | 75 '(emacs-lisp-mode c-mode c++-mode perl-mode makefile-mode sh-mode |
76 fortran-mode) | 76 fortran-mode) |
77 "List of major modes for which Which Function mode should be used. | 77 "List of major modes for which Which Function mode should be used. |
78 For other modes it is disabled. If this is equal to t, | 78 For other modes it is disabled. If this is equal to t, |
79 then Which Function mode is enabled in any major mode that supports it." | 79 then Which Function mode is enabled in any major mode that supports it." |
94 "Don't automatically compute the Imenu menu if buffer is this big or bigger. | 94 "Don't automatically compute the Imenu menu if buffer is this big or bigger. |
95 Zero means compute the Imenu menu regardless of size." | 95 Zero means compute the Imenu menu regardless of size." |
96 :group 'which-func | 96 :group 'which-func |
97 :type 'integer) | 97 :type 'integer) |
98 | 98 |
99 (defcustom which-func-format '(" [" which-func-current "]") | 99 (defcustom which-func-format '("[" which-func-current "]") |
100 "Format for displaying the function in the mode line." | 100 "Format for displaying the function in the mode line." |
101 :group 'which-func | 101 :group 'which-func |
102 :type 'sexp) | 102 :type 'sexp) |
103 | 103 |
104 ;;;###autoload | 104 ;;;###autoload |
136 | 136 |
137 (defvar which-func-mode nil | 137 (defvar which-func-mode nil |
138 "Non-nil means display current function name in mode line. | 138 "Non-nil means display current function name in mode line. |
139 This makes a difference only if `which-func-mode-global' is non-nil") | 139 This makes a difference only if `which-func-mode-global' is non-nil") |
140 (make-variable-buffer-local 'which-func-mode) | 140 (make-variable-buffer-local 'which-func-mode) |
141 (put 'which-func-mode 'permanent-local t) | 141 ;;(put 'which-func-mode 'permanent-local t) |
142 | 142 |
143 (add-hook 'find-file-hooks 'which-func-ff-hook t) | 143 (add-hook 'find-file-hooks 'which-func-ff-hook t) |
144 | 144 |
145 (defun which-func-ff-hook () | 145 (defun which-func-ff-hook () |
146 "File find hook for Which Function mode. | 146 "File find hook for Which Function mode. |
147 It creates the Imenu index for the buffer, if necessary." | 147 It creates the Imenu index for the buffer, if necessary." |
148 (if (or (eq which-func-modes t) (member major-mode which-func-modes)) | 148 (setq which-func-mode |
149 (setq which-func-mode which-func-mode-global) | 149 (and which-func-mode-global |
150 (setq which-func-mode nil)) | 150 (or (eq which-func-modes t) (member major-mode which-func-modes)))) |
151 | 151 |
152 (condition-case nil | 152 (condition-case nil |
153 (if (and which-func-mode | 153 (if (and which-func-mode |
154 (not (member major-mode which-func-non-auto-modes)) | 154 (not (member major-mode which-func-non-auto-modes)) |
155 (or (< buffer-saved-size which-func-maxout) | 155 (or (null which-func-maxout) |
156 (< buffer-saved-size which-func-maxout) | |
156 (= which-func-maxout 0))) | 157 (= which-func-maxout 0))) |
157 (setq imenu--index-alist | 158 (setq imenu--index-alist |
158 (save-excursion (funcall imenu-create-index-function)))) | 159 (save-excursion (funcall imenu-create-index-function)))) |
159 (error | 160 (error |
160 (setq which-func-mode nil)))) | 161 (setq which-func-mode nil)))) |
161 | 162 |
162 (defun which-func-update () | 163 (defun which-func-update () |
163 ;; Update the string containing the current function. | 164 ;; Update the string containing the current function. |
164 (condition-case info | 165 (when which-func-mode |
165 (progn | 166 (condition-case info |
166 (if (not (setq which-func-current (which-function))) | 167 (progn |
167 (setq which-func-current which-func-unknown)) | 168 (setq which-func-current (or (which-function) which-func-unknown)) |
168 (if (not (string= which-func-current which-func-previous)) | 169 (unless (string= which-func-current which-func-previous) |
169 (progn | |
170 (force-mode-line-update) | 170 (force-mode-line-update) |
171 (setq which-func-previous which-func-current)))) | 171 (setq which-func-previous which-func-current))) |
172 (error | 172 (error |
173 (ding) | 173 (which-func-mode -1) |
174 (remove-hook 'post-command-hook 'which-func-update) | 174 (error "Error in which-func-update: %s" info))))) |
175 (which-func-mode -1) ; Function mode off | |
176 (message "Error in which-func-update: %s" info)))) | |
177 | 175 |
178 ;; This is the name people would normally expect. | 176 ;; This is the name people would normally expect. |
179 ;;;###autoload | 177 ;;;###autoload |
180 (defalias 'which-function-mode 'which-func-mode) | 178 (defalias 'which-function-mode 'which-func-mode) |
181 | 179 |
183 (defun which-func-mode (&optional arg) | 181 (defun which-func-mode (&optional arg) |
184 "Toggle Which Function mode, globally. | 182 "Toggle Which Function mode, globally. |
185 When Which Function mode is enabled, the current function name is | 183 When Which Function mode is enabled, the current function name is |
186 continuously displayed in the mode line, in certain major modes. | 184 continuously displayed in the mode line, in certain major modes. |
187 | 185 |
188 With prefix arg, turn Which Function mode on iff arg is positive, | 186 With prefix ARG, turn Which Function mode on iff arg is positive, |
189 and off otherwise." | 187 and off otherwise." |
190 (interactive "P") | 188 (interactive "P") |
191 (if (or (and (null arg) which-func-mode-global) | 189 (setq which-func-mode-global |
192 (<= (prefix-numeric-value arg) 0)) | 190 (or (and (null arg) which-func-mode-global) |
191 (<= (prefix-numeric-value arg) 0))) | |
192 (if which-func-mode-global | |
193 ;; Turn it off | 193 ;; Turn it off |
194 (if which-func-mode-global | 194 (progn |
195 (progn | 195 (remove-hook 'post-command-idle-hook 'which-func-update) |
196 (remove-hook 'post-command-hook 'which-func-update) | 196 (dolist (buf (buffer-list)) |
197 (setq which-func-mode-global nil) | 197 (with-current-buffer buf (setq which-func-mode nil)))) |
198 (setq which-func-mode nil) | |
199 (force-mode-line-update))) | |
200 ;;Turn it on | 198 ;;Turn it on |
201 (if which-func-mode-global | 199 (add-hook 'post-command-idle-hook 'which-func-update) |
202 () | 200 (dolist (buf (buffer-list)) |
203 (add-hook 'post-command-hook 'which-func-update) | 201 (with-current-buffer buf |
204 (setq which-func-mode-global t) | 202 (setq which-func-mode |
205 (setq which-func-mode | 203 (or (eq which-func-modes t) |
206 (or (eq which-func-modes t) | 204 (member major-mode which-func-modes))))))) |
207 (member major-mode which-func-modes)))))) | |
208 | 205 |
209 (defun which-function () | 206 (defun which-function () |
210 "Return current function name based on point. | 207 "Return current function name based on point. |
211 If `imenu--index-alist' does not exist, or is empty or if point | 208 If `imenu--index-alist' does not exist, or is empty or if point |
212 is located before first function, returns nil." | 209 is located before first function, returns nil." |
213 (and | 210 (let (name) |
214 (boundp 'imenu--index-alist) | 211 ;; First try using imenu support. |
215 imenu--index-alist | 212 (when (and (boundp 'imenu--index-alist) imenu--index-alist) |
216 (let ((pair (car-safe imenu--index-alist)) | 213 (let ((pair (car-safe imenu--index-alist)) |
217 (rest (cdr-safe imenu--index-alist)) | 214 (rest (cdr-safe imenu--index-alist))) |
218 (name nil)) | 215 (while (and (or rest pair) |
219 (while (and (or rest pair) | 216 (or (not (number-or-marker-p (cdr pair))) |
220 (or (not (number-or-marker-p (cdr pair))) | 217 (> (point) (cdr pair)))) |
221 (> (point) (cdr pair)))) | 218 (setq name (car pair)) |
222 (setq name (car pair)) | 219 (setq pair (car-safe rest)) |
223 (setq pair (car-safe rest)) | 220 (setq rest (cdr-safe rest))))) |
224 (setq rest (cdr-safe rest))) | 221 ;; Try using add-log support. |
225 (and name | 222 (when (and (null name) (boundp 'add-log-current-defun-function) |
226 (if which-func-cleanup-function | 223 add-log-current-defun-function) |
227 (funcall which-func-cleanup-function name) | 224 (setq name (funcall add-log-current-defun-function))) |
228 name))))) | 225 ;; Filter the name if requested. |
226 (when name | |
227 (if which-func-cleanup-function | |
228 (funcall which-func-cleanup-function name) | |
229 name)))) | |
229 | 230 |
230 (provide 'which-func) | 231 (provide 'which-func) |
231 | 232 |
232 ;; which-func.el ends here | 233 ;; which-func.el ends here |