annotate lisp/which-func.el @ 25279:03cb8fb8ab28

(reftex-pop-to-bibtex-entry): Fixed conflict with pop-up-frames. (reftex-special-environment-parsers): New constant. (reftex-label-alist): car of an entry can also be a function. (reftex-what-special-env): new function. (reftex-label-location): Call `reftex-what-special-env'. (reftex-compile-variables): Check for symbol in `reftex-label-alist'. (reftex-what-environment): fixed bug with stacked environments of same kind (e.g. enumerate). (reftex-process-string): Preserve default directory. (reftex-label-alist-builtin): changed prefixes of endnote and footnote. Also the magic words. (reftex-reference): Interprete new option `reftex-fref-is-default'. (reftex-replace-prefix-escapes): Interprete new `%S' format. (reftex-toc-mouse-view-line): Command removed (had no binding). (reftex-everything-regexp): New function. (reftex-nearest-match): Made better. (reftex-toc-find-section): Use new version of `reftex-nearest-match'. (reftex-insert-docstruct): adapted to work with the index stuff. (reftex-parse-from-file): Find index entries as well. (reftex-toc-toggle-index): New function (reftex-toc-map): `i' is now used to togle the index, File boundaries has been moved to `F'. (reftex-select-label-map): Toggling display of file boundaries is now on the `F' key, for consistency with `reftex-toc-map'. (reftex-erase-all-selection-and-index-buffers): Renamed from `reftex-erase-all-selection-buffer'. Now also kills the index buffers. (reftex-viewing-cross-references): Customization group renamed from reftex-viewing-cross-references-and-citations. (reftex-index-macro-regexp, reftex-find-index-entry-regexp-format): New variables (reftex-macros-with-index): New variable (reftex-add-index-macros): New function (reftex-renumber-simple-labels, reftex-translate): Allow for multiple labels in a single ref command. (reftex-index-support): New customization group (reftex-support-index, reftex-index-special-chars, reftex-index-macros, reftex-index-default-macro, reftex-index-default-tag, reftex-index-math-format, reftex-index-section-letters, reftex-index-include-context, reftex-index-follow-mode, reftex-index-header-face, reftex-index-section-face, reftex-index-tag-face, reftex-index-face): New options (reftex-index-map, reftex-index-menu, reftex-last-index-file, reftex-index-tag, reftex-index-return-marker, reftex-index-restriction-indicator, reftex-index-restriction-data, reftex-index-macro-regexp, reftex-index-level-re, reftex-index-key-end-re, reftex-find-index-entry-regexp-format, reftex-everything-regexp-no-index, reftex-index-re, reftex-macros-with-index, reftex-index-macro-alist): New variables (reftex-index-help, reftex-index-macros-builtin, reftex-key-to-index-macro-alist, reftex-query-index-macro-prompt, reftex-query-index-macro-help): New constants (reftex-index-selection-or-word, reftex-index, reftex-default-index, reftex-update-default-index, reftex-index-complete-tag, reftex-index-select-tag, reftex-index-complete-key, reftex-index-update-taglist, reftex-index-globally, reftex-index-mode, reftex-index-show-entry, reftex-display-index, reftex-insert-index, reftex-index-insert-new-letter, reftex-get-restriction, reftex-index-pre-command-hook, reftex-index-post-command-hook, reftex-index-show-help, reftex-index-next, reftex-index-previous, reftex-index-toggle-follow, reftex-index-toggle-context, reftex-index-view-entry, reftex-index-goto-entry-and-hide, reftex-index-goto-entry, reftex-index-mouse-goto-line-and-hide, reftex-index-quit, reftex-index-quit-and-kill, reftex-index-goto-toc, reftex-index-rescan, reftex-index-Rescan, reftex-index-revert, reftex-index-switch-index-tag, reftex-index-restrict-to-section, reftex-index-widen, reftex-index-restriction-forward, reftex-index-restriction-backward, reftex-index-visit-location, reftex-index-analyze-entry, reftex-index-globalize, reftex-index-edit, reftex-index-toggle-range-beginning, reftex-index-toggle-range-end, reftex-index-edit-key, reftex-index-edit-attribute, reftex-index-edit-visual, reftex-index-edit-part, reftex-index-level-down, reftex-index-level-up, reftex-index-kill, reftex-index-undo, reftex-index-change-entry, reftex-index-goto-letter, reftex-add-index-macros, reftex-ensure-index-support, reftex-index-info-safe, reftex-index-info): New functions. Most of the code moved to other files.
author Carsten Dominik <dominik@science.uva.nl>
date Mon, 16 Aug 1999 07:38:41 +0000
parents ce2b5ccac297
children f85f374e5395
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
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
3 ;; Copyright (C) 1994, 1997, 1998 Free Software Foundation, Inc.
20321
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>
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
6 ;; Keywords: mode-line, imenu, tools
20321
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
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
25 ;;; Commentary:
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
26
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
27 ;; This package prints name of function where your current point is
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
28 ;; located in mode line. It assumes that you work with imenu package
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
29 ;; and imenu--index-alist is up to date.
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
31 ;; KNOWN BUGS
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
32 ;; ----------
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
33 ;; Really this package shows not "function where the current point is
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
34 ;; located now", but "nearest function which defined above the current
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
35 ;; point". So if your current point is located after end of function
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
36 ;; FOO but before begin of function BAR, FOO will be displayed in mode
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
37 ;; line.
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
39 ;; TODO LIST
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
40 ;; ---------
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
41 ;; 1. Dependence on imenu package should be removed. Separate
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
42 ;; function determination mechanism should be used to determine the end
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
43 ;; of a function as well as the beginning of a function.
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
44 ;; 2. This package should be realized with the help of overlay
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
45 ;; properties instead of imenu--index-alist variable.
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
46
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
47 ;;; History:
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
49 ;; THANKS TO
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
50 ;; ---------
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
51 ;; Per Abrahamsen <abraham@iesd.auc.dk>
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
52 ;; Some ideas (inserting in mode-line, using of post-command hook
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
53 ;; and toggling this mode) have been borrowed from his package
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
54 ;; column.el
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
55 ;; Peter Eisenhauer <pipe@fzi.de>
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
56 ;; Bug fixing in case nested indexes.
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
57 ;; Terry Tateyama <ttt@ursa0.cs.utah.edu>
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
58 ;; Suggestion to use find-file-hooks for first imenu
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
59 ;; index building.
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
61 ;;; Code:
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
62
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
63 ;; Variables for customization
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
64 ;; ---------------------------
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
65 ;;
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (defvar which-func-unknown "???"
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 "String to display in the mode line when current function is unknown.")
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68
21653
e95a88dc6110 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20573
diff changeset
69 (defgroup which-func nil
e95a88dc6110 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20573
diff changeset
70 "Mode to display the current function name in the modeline."
e95a88dc6110 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20573
diff changeset
71 :group 'tools
e95a88dc6110 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20573
diff changeset
72 :version "20.3")
e95a88dc6110 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20573
diff changeset
73
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (defcustom which-func-modes
23018
114211878bf9 (which-func-modes): Add fortran-mode.
Richard M. Stallman <rms@gnu.org>
parents: 22308
diff changeset
75 '(emacs-lisp-mode c-mode c++-mode perl-mode makefile-mode sh-mode
114211878bf9 (which-func-modes): Add fortran-mode.
Richard M. Stallman <rms@gnu.org>
parents: 22308
diff changeset
76 fortran-mode)
22134
29c2db002dd5 (which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 21964
diff changeset
77 "List of major modes for which Which Function mode should be used.
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 For other modes it is disabled. If this is equal to t,
22134
29c2db002dd5 (which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 21964
diff changeset
79 then Which Function mode is enabled in any major mode that supports it."
20321
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 '(choice (const :tag "All modes" t)
22134
29c2db002dd5 (which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 21964
diff changeset
82 (repeat (symbol :tag "Major mode"))))
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
21964
390352ec56c6 (which-func-non-auto-modes): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 21960
diff changeset
84 (defcustom which-func-non-auto-modes nil
390352ec56c6 (which-func-non-auto-modes): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 21960
diff changeset
85 "List of major modes where Which Function mode is inactive till Imenu is used.
22134
29c2db002dd5 (which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 21964
diff changeset
86 This means that Which Function mode won't really do anything
29c2db002dd5 (which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 21964
diff changeset
87 until you use Imenu, in these modes. Note that files
29c2db002dd5 (which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 21964
diff changeset
88 larger than `which-func-maxout' behave in this way too;
29c2db002dd5 (which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 21964
diff changeset
89 Which Function mode doesn't do anything until you use Imenu."
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 :group 'which-func
22134
29c2db002dd5 (which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 21964
diff changeset
91 :type '(repeat (symbol :tag "Major mode")))
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (defcustom which-func-maxout 100000
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 "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
95 Zero means compute the Imenu menu regardless of size."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 :group 'which-func
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 :type 'integer)
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 (defcustom which-func-format '(" [" which-func-current "]")
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "Format for displaying the function in the mode line."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 :group 'which-func
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 :type 'sexp)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
104 ;;;###autoload
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
105 (defcustom which-func-mode-global nil
24649
ce2b5ccac297 (which-func-mode-global): Doc fix.
Dave Love <fx@gnu.org>
parents: 24550
diff changeset
106 "*Toggle `which-func-mode' globally.
ce2b5ccac297 (which-func-mode-global): Doc fix.
Dave Love <fx@gnu.org>
parents: 24550
diff changeset
107 Setting this variable directly does not take effect;
ce2b5ccac297 (which-func-mode-global): Doc fix.
Dave Love <fx@gnu.org>
parents: 24550
diff changeset
108 use either \\[customize] or the function `which-func-mode'."
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
109 :set #'(lambda (symbol value)
23355
4486a6940607 (which-func-mode-global): Make :set function
Karl Heuer <kwzh@gnu.org>
parents: 23350
diff changeset
110 (which-func-mode (if value 1 0)))
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
111 :initialize 'custom-initialize-default
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
112 :type 'boolean
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
113 :group 'which-func
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
114 :require 'which-func)
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
115
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;;; Code, nothing to customize below here
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ;;; -------------------------------------
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;;;
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (require 'imenu)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (defvar which-func-current which-func-unknown)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (defvar which-func-previous which-func-unknown)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (make-variable-buffer-local 'which-func-current)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (make-variable-buffer-local 'which-func-previous)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (defvar which-func-mode nil
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 "Non-nil means display current function name in mode line.
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
128 This makes a difference only if `which-func-mode-global' is non-nil")
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (make-variable-buffer-local 'which-func-mode)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (put 'which-func-mode 'permanent-local t)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (add-hook 'find-file-hooks 'which-func-ff-hook t)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (defun which-func-ff-hook ()
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 "File find hook for Which Function mode.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 It creates the Imenu index for the buffer, if necessary."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (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
138 (setq which-func-mode which-func-mode-global)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (setq which-func-mode nil))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
22308
87366acfb1e9 (which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents: 22134
diff changeset
141 (condition-case nil
87366acfb1e9 (which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents: 22134
diff changeset
142 (if (and which-func-mode
87366acfb1e9 (which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents: 22134
diff changeset
143 (not (member major-mode which-func-non-auto-modes))
87366acfb1e9 (which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents: 22134
diff changeset
144 (or (< buffer-saved-size which-func-maxout)
87366acfb1e9 (which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents: 22134
diff changeset
145 (= which-func-maxout 0)))
87366acfb1e9 (which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents: 22134
diff changeset
146 (setq imenu--index-alist
87366acfb1e9 (which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents: 22134
diff changeset
147 (save-excursion (funcall imenu-create-index-function))))
87366acfb1e9 (which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents: 22134
diff changeset
148 (error
87366acfb1e9 (which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents: 22134
diff changeset
149 (setq which-func-mode nil))))
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defun which-func-update ()
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 ;; Update the string containing the current function.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (condition-case info
20573
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
154 (progn
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
155 (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
156 (setq which-func-current which-func-unknown))
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
157 (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
158 (progn
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
159 (force-mode-line-update)
b46523ef0e0a (which-func-update): Fix paren error.
Richard M. Stallman <rms@gnu.org>
parents: 20322
diff changeset
160 (setq which-func-previous which-func-current))))
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (error
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (ding)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (remove-hook 'post-command-hook 'which-func-update)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (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
165 (message "Error in which-func-update: %s" info))))
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
21960
79c7369b9ab4 (which-function-mode): New alias.
Richard M. Stallman <rms@gnu.org>
parents: 21697
diff changeset
167 ;; This is the name people would normally expect.
79c7369b9ab4 (which-function-mode): New alias.
Richard M. Stallman <rms@gnu.org>
parents: 21697
diff changeset
168 ;;;###autoload
79c7369b9ab4 (which-function-mode): New alias.
Richard M. Stallman <rms@gnu.org>
parents: 21697
diff changeset
169 (defalias 'which-function-mode 'which-func-mode)
79c7369b9ab4 (which-function-mode): New alias.
Richard M. Stallman <rms@gnu.org>
parents: 21697
diff changeset
170
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
171 ;;;###autoload
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (defun which-func-mode (&optional arg)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 "Toggle Which Function mode, globally.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 When Which Function mode is enabled, the current function name is
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 continuously displayed in the mode line, in certain major modes.
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 With prefix arg, turn Which Function mode on iff arg is positive,
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 and off otherwise."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (interactive "P")
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (if (or (and (null arg) which-func-mode-global)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (<= (prefix-numeric-value arg) 0))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;; Turn it off
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (if which-func-mode-global
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (progn
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (remove-hook 'post-command-hook 'which-func-update)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (setq which-func-mode-global nil)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (setq which-func-mode nil)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (force-mode-line-update)))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;;Turn it on
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (if which-func-mode-global
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ()
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (add-hook 'post-command-hook 'which-func-update)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (setq which-func-mode-global t)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (setq which-func-mode
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (or (eq which-func-modes t)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (member major-mode which-func-modes))))))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (defun which-function ()
21697
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
199 "Return current function name based on point.
ecfe9bc12b7f Fix header comments.
Dave Love <fx@gnu.org>
parents: 21653
diff changeset
200 If `imenu--index-alist' does not exist, or is empty or if point
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 is located before first function, returns nil."
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (and
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (boundp 'imenu--index-alist)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 imenu--index-alist
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (let ((pair (car-safe imenu--index-alist))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (rest (cdr-safe imenu--index-alist))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (name nil))
23350
df3df03d8a19 (which-function): Handle case when (car imenu--index-alist) is nil.
Karl Heuer <kwzh@gnu.org>
parents: 23018
diff changeset
208 (while (and (or rest pair)
df3df03d8a19 (which-function): Handle case when (car imenu--index-alist) is nil.
Karl Heuer <kwzh@gnu.org>
parents: 23018
diff changeset
209 (or (not (number-or-marker-p (cdr pair)))
df3df03d8a19 (which-function): Handle case when (car imenu--index-alist) is nil.
Karl Heuer <kwzh@gnu.org>
parents: 23018
diff changeset
210 (> (point) (cdr pair))))
20321
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (setq name (car pair))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (setq pair (car-safe rest))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (setq rest (cdr-safe rest)))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 name)))
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (provide 'which-func)
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
d638e4de74aa Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; which-func.el ends here