comparison lisp/which-func.el @ 21697:ecfe9bc12b7f

Fix header comments. (which-func-mode): Add autoload cookie. (which-func-mode-global): Customize.
author Dave Love <fx@gnu.org>
date Tue, 21 Apr 1998 18:56:02 +0000
parents e95a88dc6110
children 79c7369b9ab4
comparison
equal deleted inserted replaced
21696:2f8ab139c8f1 21697:ecfe9bc12b7f
1 ;;; which-func.el --- Print current function in mode line 1 ;;; which-func.el --- Print current function in mode line
2 2
3 ;; Copyright (C) 1994, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 1997, 1998 Free Software Foundation, Inc.
4 4
5 ;; Author: Alex Rezinsky <alexr@msil.sps.mot.com> 5 ;; Author: Alex Rezinsky <alexr@msil.sps.mot.com>
6 ;; Keywords: mode-line imenu 6 ;; Keywords: mode-line, imenu, tools
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
9 9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify 10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by 11 ;; it under the terms of the GNU General Public License as published by
20 ;; You should have received a copy of the GNU General Public License 20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA. 23 ;; Boston, MA 02111-1307, USA.
24 24
25 ;;; COMMENTARY 25 ;;; Commentary:
26 ;;; ---------- 26
27 ;;; This package prints name of function where your current point is 27 ;; This package prints name of function where your current point is
28 ;;; located in mode line. It assumes that you work with imenu package 28 ;; located in mode line. It assumes that you work with imenu package
29 ;;; and imenu--index-alist is up to date. 29 ;; and imenu--index-alist is up to date.
30 30
31 ;;; KNOWN BUGS 31 ;; KNOWN BUGS
32 ;;; ---------- 32 ;; ----------
33 ;;; Really this package shows not "function where the current point 33 ;; Really this package shows not "function where the current point is
34 ;;; is located now", but "nearest function which defined above the 34 ;; located now", but "nearest function which defined above the current
35 ;;; current point". So if your current point is located after end of 35 ;; point". So if your current point is located after end of function
36 ;;; function FOO but before begin of function BAR, FOO will be 36 ;; FOO but before begin of function BAR, FOO will be displayed in mode
37 ;;; displayed in mode line. 37 ;; line.
38 38
39 ;;; TODO LIST 39 ;; TODO LIST
40 ;;; --------- 40 ;; ---------
41 ;;; 1. Dependence on imenu package should be removed. Separate 41 ;; 1. Dependence on imenu package should be removed. Separate
42 ;;; function determination mechanism should be used to determine the end 42 ;; function determination mechanism should be used to determine the end
43 ;;; of a function as well as the beginning of a function. 43 ;; of a function as well as the beginning of a function.
44 ;;; 2. This package should be realized with the help of overlay 44 ;; 2. This package should be realized with the help of overlay
45 ;;; properties instead of imenu--index-alist variable. 45 ;; properties instead of imenu--index-alist variable.
46 46
47 ;;; THANKS TO 47 ;;; History:
48 ;;; --------- 48
49 ;;; Per Abrahamsen <abraham@iesd.auc.dk> 49 ;; THANKS TO
50 ;;; Some ideas (inserting in mode-line, using of post-command hook 50 ;; ---------
51 ;;; and toggling this mode) have been borrowed from his package 51 ;; Per Abrahamsen <abraham@iesd.auc.dk>
52 ;;; column.el 52 ;; Some ideas (inserting in mode-line, using of post-command hook
53 ;;; Peter Eisenhauer <pipe@fzi.de> 53 ;; and toggling this mode) have been borrowed from his package
54 ;;; Bug fixing in case nested indexes. 54 ;; column.el
55 ;;; Terry Tateyama <ttt@ursa0.cs.utah.edu> 55 ;; Peter Eisenhauer <pipe@fzi.de>
56 ;;; Suggestion to use find-file-hooks for first imenu 56 ;; Bug fixing in case nested indexes.
57 ;;; index building. 57 ;; Terry Tateyama <ttt@ursa0.cs.utah.edu>
58 58 ;; Suggestion to use find-file-hooks for first imenu
59 ;;; Variables for customization 59 ;; index building.
60 ;;; --------------------------- 60
61 ;;; 61 ;;; Code:
62
63 ;; Variables for customization
64 ;; ---------------------------
65 ;;
62 (defvar which-func-unknown "???" 66 (defvar which-func-unknown "???"
63 "String to display in the mode line when current function is unknown.") 67 "String to display in the mode line when current function is unknown.")
64 68
65 (defgroup which-func nil 69 (defgroup which-func nil
66 "Mode to display the current function name in the modeline." 70 "Mode to display the current function name in the modeline."
94 (defcustom which-func-format '(" [" which-func-current "]") 98 (defcustom which-func-format '(" [" which-func-current "]")
95 "Format for displaying the function in the mode line." 99 "Format for displaying the function in the mode line."
96 :group 'which-func 100 :group 'which-func
97 :type 'sexp) 101 :type 'sexp)
98 102
103 ;;;###autoload
104 (defcustom which-func-mode-global nil
105 "*Toggle `which-func-mode'.
106 You must modify via \\[customize] for this variable to have an effect."
107 :set #'(lambda (symbol value)
108 (which-func-mode (or value 0)))
109 :initialize 'custom-initialize-default
110 :type 'boolean
111 :group 'which-func
112 :require 'which-func)
113
99 ;;; Code, nothing to customize below here 114 ;;; Code, nothing to customize below here
100 ;;; ------------------------------------- 115 ;;; -------------------------------------
101 ;;; 116 ;;;
102 (require 'imenu) 117 (require 'imenu)
103 118
104 (defvar which-func-current which-func-unknown) 119 (defvar which-func-current which-func-unknown)
105 (defvar which-func-previous which-func-unknown) 120 (defvar which-func-previous which-func-unknown)
106 (make-variable-buffer-local 'which-func-current) 121 (make-variable-buffer-local 'which-func-current)
107 (make-variable-buffer-local 'which-func-previous) 122 (make-variable-buffer-local 'which-func-previous)
108 123
109 (defvar which-func-mode-global nil
110 "Non-nil means display current function name in mode line.")
111
112 (defvar which-func-mode nil 124 (defvar which-func-mode nil
113 "Non-nil means display current function name in mode line. 125 "Non-nil means display current function name in mode line.
114 This makes a difference only if which-func-mode-global is non-nil") 126 This makes a difference only if `which-func-mode-global' is non-nil")
115 (make-variable-buffer-local 'which-func-mode) 127 (make-variable-buffer-local 'which-func-mode)
116 (put 'which-func-mode 'permanent-local t) 128 (put 'which-func-mode 'permanent-local t)
117 129
118 (add-hook 'find-file-hooks 'which-func-ff-hook t) 130 (add-hook 'find-file-hooks 'which-func-ff-hook t)
119 131
145 (ding) 157 (ding)
146 (remove-hook 'post-command-hook 'which-func-update) 158 (remove-hook 'post-command-hook 'which-func-update)
147 (which-func-mode -1) ; Function mode off 159 (which-func-mode -1) ; Function mode off
148 (message "Error in which-func-update: %s" info)))) 160 (message "Error in which-func-update: %s" info))))
149 161
162 ;;;###autoload
150 (defun which-func-mode (&optional arg) 163 (defun which-func-mode (&optional arg)
151 "Toggle Which Function mode, globally. 164 "Toggle Which Function mode, globally.
152 When Which Function mode is enabled, the current function name is 165 When Which Function mode is enabled, the current function name is
153 continuously displayed in the mode line, in certain major modes. 166 continuously displayed in the mode line, in certain major modes.
154 167
172 (setq which-func-mode 185 (setq which-func-mode
173 (or (eq which-func-modes t) 186 (or (eq which-func-modes t)
174 (member major-mode which-func-modes)))))) 187 (member major-mode which-func-modes))))))
175 188
176 (defun which-function () 189 (defun which-function ()
177 "Returns current function name based on point. 190 "Return current function name based on point.
178 If imenu--index-alist does not exist, or is empty or if point 191 If `imenu--index-alist' does not exist, or is empty or if point
179 is located before first function, returns nil." 192 is located before first function, returns nil."
180 (and 193 (and
181 (boundp 'imenu--index-alist) 194 (boundp 'imenu--index-alist)
182 imenu--index-alist 195 imenu--index-alist
183 (let ((pair (car-safe imenu--index-alist)) 196 (let ((pair (car-safe imenu--index-alist))