annotate lisp/which-func.el @ 21246:6c16216d0e69

(insert_from_string_1, replace_range): Use STRING_MULTIBYTE to determine whether string is multibyte.
author Richard M. Stallman <rms@gnu.org>
date Sat, 21 Mar 1998 17:48:54 +0000
parents b46523ef0e0a
children e95a88dc6110
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20322
10d9f05af2cb Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 20321
diff changeset
1 ;;; which-func.el --- Print current function in mode line
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1994, 1997 Free Software Foundation, Inc.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Alex Rezinsky <alexr@msil.sps.mot.com>
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: mode-line imenu
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; COMMENTARY
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; ----------
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; This package prints name of function where your current point is
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; located in mode line. It assumes that you work with imenu package
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; and imenu--index-alist is up to date.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; KNOWN BUGS
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; ----------
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; Really this package shows not "function where the current point
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; is located now", but "nearest function which defined above the
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;; current point". So if your current point is located after end of
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;; function FOO but before begin of function BAR, FOO will be
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;; displayed in mode line.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;; TODO LIST
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;; ---------
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;; 1. Dependence on imenu package should be removed. Separate
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;; function determination mechanism should be used to determine the end
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; of a function as well as the beginning of a function.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;; 2. This package should be realized with the help of overlay
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; properties instead of imenu--index-alist variable.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;; THANKS TO
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;; ---------
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; Per Abrahamsen <abraham@iesd.auc.dk>
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;; Some ideas (inserting in mode-line, using of post-command hook
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;; and toggling this mode) have been borrowed from his package
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;; column.el
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;; Peter Eisenhauer <pipe@fzi.de>
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; Bug fixing in case nested indexes.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;; Terry Tateyama <ttt@ursa0.cs.utah.edu>
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; Suggestion to use find-file-hooks for first imenu
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;; index building.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;; Variables for customization
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;; ---------------------------
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;;
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (defvar which-func-unknown "???"
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 "String to display in the mode line when current function is unknown.")
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (defcustom which-func-modes
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 '(emacs-lisp-mode c-mode c++-mode perl-mode makefile-mode sh-mode)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 "List of major modes for which `which-func-mode' should be used.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 For other modes it is disabled. If this is equal to t,
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 then current-function recognition is enabled in any mode."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 :group 'which-func
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 :type '(choice (const :tag "All modes" t)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (list (symbol :tag "Major mode"))))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (defcustom which-func-amodes '(emacs-lisp-mode c-mode c++-mode)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 "List of major modes for which the Imenu menu should be computed automatically.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 It is computed when you visit a file in one of these major modes.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 If the variable's value is nil, then the Imenu menu is not computed
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 automatically in any mode. Note that the menu is never computed
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 automatically if the buffer size exceeds `which-func-maxout'."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 :group 'which-func
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 :type '(list (symbol :tag "Major mode")))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (defcustom which-func-maxout 100000
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 "Don't automatically compute the Imenu menu if buffer is this big or bigger.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 Zero means compute the Imenu menu regardless of size."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 :group 'which-func
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 :type 'integer)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (defcustom which-func-format '(" [" which-func-current "]")
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 "Format for displaying the function in the mode line."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 :group 'which-func
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 :type 'sexp)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;;; Code, nothing to customize below here
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;; -------------------------------------
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;;;
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (require 'imenu)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (defvar which-func-current which-func-unknown)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (defvar which-func-previous which-func-unknown)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (make-variable-buffer-local 'which-func-current)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (make-variable-buffer-local 'which-func-previous)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (defvar which-func-mode-global nil
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 "Non-nil means display current function name in mode line.")
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (defvar which-func-mode nil
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 "Non-nil means display current function name in mode line.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 This makes a difference only if which-func-mode-global is non-nil")
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (make-variable-buffer-local 'which-func-mode)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (put 'which-func-mode 'permanent-local t)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (add-hook 'find-file-hooks 'which-func-ff-hook t)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (defun which-func-ff-hook ()
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 "File find hook for Which Function mode.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 It creates the Imenu index for the buffer, if necessary."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (if (or (eq which-func-modes t) (member major-mode which-func-modes))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (setq which-func-mode which-func-mode-global)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (setq which-func-mode nil))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (if (and which-func-mode
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (member major-mode which-func-amodes)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (or (< buffer-saved-size which-func-maxout)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (= which-func-maxout 0)))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (setq imenu--index-alist
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (save-excursion (funcall imenu-create-index-function)))))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (defun which-func-update ()
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; Update the string containing the current function.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (condition-case info
20573
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
132 (progn
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
133 (if (not (setq which-func-current (which-function)))
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
134 (setq which-func-current which-func-unknown))
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
135 (if (not (string= which-func-current which-func-previous))
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
136 (progn
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
137 (force-mode-line-update)
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
138 (setq which-func-previous which-func-current))))
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (error
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (ding)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (remove-hook 'post-command-hook 'which-func-update)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (which-func-mode -1) ; Function mode off
20573
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
143 (message "Error in which-func-update: %s" info))))
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (defun which-func-mode (&optional arg)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 "Toggle Which Function mode, globally.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 When Which Function mode is enabled, the current function name is
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 continuously displayed in the mode line, in certain major modes.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 With prefix arg, turn Which Function mode on iff arg is positive,
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 and off otherwise."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (interactive "P")
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (if (or (and (null arg) which-func-mode-global)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (<= (prefix-numeric-value arg) 0))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 ;; Turn it off
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (if which-func-mode-global
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (progn
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (remove-hook 'post-command-hook 'which-func-update)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (setq which-func-mode-global nil)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (setq which-func-mode nil)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (force-mode-line-update)))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;;Turn it on
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (if which-func-mode-global
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ()
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (add-hook 'post-command-hook 'which-func-update)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (setq which-func-mode-global t)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (setq which-func-mode
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (or (eq which-func-modes t)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (member major-mode which-func-modes))))))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (defun which-function ()
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 "Returns current function name based on point.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 If imenu--index-alist does not exist, or is empty or if point
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 is located before first function, returns nil."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (and
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (boundp 'imenu--index-alist)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 imenu--index-alist
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (let ((pair (car-safe imenu--index-alist))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (rest (cdr-safe imenu--index-alist))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (name nil))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (while (and pair (or (not (number-or-marker-p (cdr pair)))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (> (point) (cdr pair))))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (setq name (car pair))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (setq pair (car-safe rest))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (setq rest (cdr-safe rest)))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 name)))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (provide 'which-func)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;; which-func.el ends here