annotate lisp/progmodes/which-func.el @ 78230:84cf1e2214c5

Switch license to GPLv3 or later.
author Glenn Morris <rgm@gnu.org>
date Wed, 25 Jul 2007 04:25:44 +0000
parents e3694f1cb928
children c1ec1c8a8d2e 69b5e2969dfe 95d0cdf160ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
1 ;;; which-func.el --- print current function in mode line
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
2
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 72144
diff changeset
3 ;; Copyright (C) 1994, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007
61089
dc55bf752d7c (which-function): Be robust in the face of an
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58774
diff changeset
4 ;; Free Software Foundation, Inc.
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
5
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
6 ;; Author: Alex Rezinsky <alexr@msil.sps.mot.com>
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
7 ;; (doesn't seem to be responsive any more)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
8 ;; Keywords: mode-line, imenu, tools
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
9
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
11
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
15 ;; any later version.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
16
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
21
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63463
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63463
diff changeset
25 ;; Boston, MA 02110-1301, USA.
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
26
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
27 ;;; Commentary:
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
28
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
29 ;; This package prints name of function where your current point is
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
30 ;; located in mode line. It assumes that you work with imenu package
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
31 ;; and imenu--index-alist is up to date.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
32
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
33 ;; KNOWN BUGS
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
34 ;; ----------
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
35 ;; Really this package shows not "function where the current point is
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
36 ;; located now", but "nearest function which defined above the current
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
37 ;; point". So if your current point is located after end of function
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
38 ;; FOO but before begin of function BAR, FOO will be displayed in mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
39 ;; line.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
40 ;; - if two windows display the same buffer, both windows
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
41 ;; show the same `which-func' information.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
42
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
43 ;; TODO LIST
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
44 ;; ---------
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
45 ;; 1. Dependence on imenu package should be removed. Separate
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
46 ;; function determination mechanism should be used to determine the end
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
47 ;; of a function as well as the beginning of a function.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
48 ;; 2. This package should be realized with the help of overlay
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
49 ;; properties instead of imenu--index-alist variable.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
50
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
51 ;;; History:
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
52
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
53 ;; THANKS TO
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
54 ;; ---------
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
55 ;; Per Abrahamsen <abraham@iesd.auc.dk>
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
56 ;; Some ideas (inserting in mode-line, using of post-command hook
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
57 ;; and toggling this mode) have been borrowed from his package
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
58 ;; column.el
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
59 ;; Peter Eisenhauer <pipe@fzi.de>
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
60 ;; Bug fixing in case nested indexes.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
61 ;; Terry Tateyama <ttt@ursa0.cs.utah.edu>
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
62 ;; Suggestion to use find-file-hook for first imenu
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
63 ;; index building.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
64
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
65 ;;; Code:
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
66
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
67 ;; Variables for customization
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
68 ;; ---------------------------
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
69 ;;
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
70 (defvar which-func-unknown "???"
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
71 "String to display in the mode line when current function is unknown.")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
72
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
73 (defgroup which-func nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
74 "Mode to display the current function name in the modeline."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
75 :group 'tools
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
76 :version "20.3")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
77
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
78 (defcustom which-func-modes
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
79 '(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode makefile-mode
52691
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
80 sh-mode fortran-mode f90-mode ada-mode)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
81 "List of major modes for which Which Function mode should be used.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
82 For other modes it is disabled. If this is equal to t,
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
83 then Which Function mode is enabled in any major mode that supports it."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
84 :group 'which-func
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
85 :type '(choice (const :tag "All modes" t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
86 (repeat (symbol :tag "Major mode"))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
87
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
88 (defcustom which-func-non-auto-modes nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
89 "List of major modes where Which Function mode is inactive till Imenu is used.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
90 This means that Which Function mode won't really do anything
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
91 until you use Imenu, in these modes. Note that files
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
92 larger than `which-func-maxout' behave in this way too;
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
93 Which Function mode doesn't do anything until you use Imenu."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
94 :group 'which-func
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
95 :type '(repeat (symbol :tag "Major mode")))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
96
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
97 (defcustom which-func-maxout 500000
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
98 "Don't automatically compute the Imenu menu if buffer is this big or bigger.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
99 Zero means compute the Imenu menu regardless of size."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
100 :group 'which-func
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
101 :type 'integer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
102
56442
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
103 (defvar which-func-keymap
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
104 (let ((map (make-sparse-keymap)))
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
105 (define-key map [mode-line mouse-1] 'beginning-of-defun)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
106 (define-key map [mode-line mouse-2]
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
107 (lambda ()
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
108 (interactive)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
109 (if (eq (point-min) 1)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
110 (narrow-to-defun)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
111 (widen))))
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
112 (define-key map [mode-line mouse-3] 'end-of-defun)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
113 map)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
114 "Keymap to display on mode line which-func.")
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
115
63457
581fdd0b552d Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-417
Miles Bader <miles@gnu.org>
parents: 62858
diff changeset
116 (defface which-func
63463
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
117 ;; Whether `font-lock-function-name-face' is an appropriate face to
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
118 ;; inherit depends on the mode-line face; define several variants based
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
119 ;; on the default mode-line face.
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
120 '(;; The default mode-line face on a high-color display is a relatively
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
121 ;; light color ("grey75"), and only the light-background variant of
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
122 ;; `font-lock-function-name-face' is visible against it.
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
123 (((class color) (min-colors 88) (background light))
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
124 :inherit font-lock-function-name-face)
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
125 ;; The default mode-line face on other display types is inverse-video;
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
126 ;; it seems that only in the dark-background case is
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
127 ;; `font-lock-function-name-face' visible against it.
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
128 (((class grayscale mono) (background dark))
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
129 :inherit font-lock-function-name-face)
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
130 (((class color) (background light))
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
131 :inherit font-lock-function-name-face)
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
132 ;; If none of the above cases, use an explicit color chosen to contrast
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
133 ;; well with the default mode-line face.
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
134 (((class color) (min-colors 88) (background dark))
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
135 :foreground "Blue1")
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
136 (((background dark))
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
137 :foreground "Blue1")
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
138 (t
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
139 :foreground "LightSkyBlue"))
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
140 "Face used to highlight mode line function names."
56442
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
141 :group 'which-func)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
142
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
143 (defcustom which-func-format
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
144 `("["
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
145 (:propertize which-func-current
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
146 local-map ,which-func-keymap
63457
581fdd0b552d Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-417
Miles Bader <miles@gnu.org>
parents: 62858
diff changeset
147 face which-func
56442
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
148 ;;mouse-face highlight ; currently not evaluated :-(
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
149 help-echo "mouse-1: go to beginning, mouse-2: toggle rest visibility, mouse-3: go to end")
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
150 "]")
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
151 "Format for displaying the function in the mode line."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
152 :group 'which-func
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
153 :type 'sexp)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
154 ;;;###autoload (put 'which-func-format 'risky-local-variable t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
155
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
156 (defvar which-func-cleanup-function nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
157 "Function to transform a string before displaying it in the mode line.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
158 The function is called with one argument, the string to display.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
159 Its return value is displayed in the modeline.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
160 If nil, no function is called. The default value is nil.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
161
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
162 This feature can be useful if Imenu is set up to make more
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
163 detailed entries (e.g., containing the argument list of a function),
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
164 and you want to simplify them for the mode line
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
165 \(e.g., removing the parameter list to just have the function name.)")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
166
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
167 ;;; Code, nothing to customize below here
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
168 ;;; -------------------------------------
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
169 ;;;
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
170 (require 'imenu)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
171
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
172 (defvar which-func-table (make-hash-table :test 'eq :weakness 'key))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
173
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
174 (defconst which-func-current
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
175 '(:eval (gethash (selected-window) which-func-table which-func-unknown)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
176 ;;;###autoload (put 'which-func-current 'risky-local-variable t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
177
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
178 (defvar which-func-mode nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
179 "Non-nil means display current function name in mode line.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
180 This makes a difference only if `which-function-mode' is non-nil.")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
181 (make-variable-buffer-local 'which-func-mode)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
182 ;;(put 'which-func-mode 'permanent-local t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
183
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
184 (add-hook 'find-file-hook 'which-func-ff-hook t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
185
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
186 (defun which-func-ff-hook ()
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
187 "File find hook for Which Function mode.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
188 It creates the Imenu index for the buffer, if necessary."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
189 (setq which-func-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
190 (and which-function-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
191 (or (eq which-func-modes t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
192 (member major-mode which-func-modes))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
193
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
194 (condition-case nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
195 (if (and which-func-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
196 (not (member major-mode which-func-non-auto-modes))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
197 (or (null which-func-maxout)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
198 (< buffer-saved-size which-func-maxout)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
199 (= which-func-maxout 0)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
200 (setq imenu--index-alist
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
201 (save-excursion (funcall imenu-create-index-function))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
202 (error
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
203 (setq which-func-mode nil))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
204
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
205 (defun which-func-update ()
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
206 ;; "Update the Which-Function mode display for all windows."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
207 ;; (walk-windows 'which-func-update-1 nil 'visible))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
208 (which-func-update-1 (selected-window)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
209
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
210 (defun which-func-update-1 (window)
56689
f54e121491eb (which-func-update-1): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 56442
diff changeset
211 "Update the Which Function mode display for window WINDOW."
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
212 (with-selected-window window
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
213 (when which-func-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
214 (condition-case info
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
215 (let ((current (which-function)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
216 (unless (equal current (gethash window which-func-table))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
217 (puthash window current which-func-table)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
218 (force-mode-line-update)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
219 (error
62858
c23f28be371c (which-func-update-1): Turn the mode
Richard M. Stallman <rms@gnu.org>
parents: 61089
diff changeset
220 (setq which-func-mode nil)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
221 (error "Error in which-func-update: %s" info))))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
222
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
223 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
224 (defalias 'which-func-mode 'which-function-mode)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
225
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
226 (defvar which-func-update-timer nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
227
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
228 ;; This is the name people would normally expect.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
229 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
230 (define-minor-mode which-function-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
231 "Toggle Which Function mode, globally.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
232 When Which Function mode is enabled, the current function name is
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
233 continuously displayed in the mode line, in certain major modes.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
234
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
235 With prefix ARG, turn Which Function mode on iff arg is positive,
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
236 and off otherwise."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
237 :global t :group 'which-func
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
238 (if which-function-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
239 ;;Turn it on
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
240 (progn
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
241 (setq which-func-update-timer
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
242 (run-with-idle-timer idle-update-delay t 'which-func-update))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
243 (dolist (buf (buffer-list))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
244 (with-current-buffer buf
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
245 (setq which-func-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
246 (or (eq which-func-modes t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
247 (member major-mode which-func-modes))))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
248 ;; Turn it off
53618
bd715b02e44e David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52691
diff changeset
249 (when (timerp which-func-update-timer)
bd715b02e44e David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents: 52691
diff changeset
250 (cancel-timer which-func-update-timer))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
251 (setq which-func-update-timer nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
252 (dolist (buf (buffer-list))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
253 (with-current-buffer buf (setq which-func-mode nil)))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
254
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
255 (defvar which-function-imenu-failed nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
256 "Locally t in a buffer if `imenu--make-index-alist' found nothing there.")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
257
52691
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
258 (defvar which-func-functions nil
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
259 "List of functions for `which-function' to call with no arguments.
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
260 It calls them sequentially, and if any returns non-nil,
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
261 `which-function' uses that name and stops looking for the name.")
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
262
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
263 (defun which-function ()
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
264 "Return current function name based on point.
72144
2824d0383afd (which-function): Fix documentation/comment typo.
Nick Roberts <nickrob@snap.net.nz>
parents: 68773
diff changeset
265 Uses `which-func-functions', `imenu--index-alist'
52691
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
266 or `add-log-current-defun-function'.
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
267 If no function name is found, return nil."
58774
212ad195d26f (which-function): Use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56689
diff changeset
268 (let ((name
72144
2824d0383afd (which-function): Fix documentation/comment typo.
Nick Roberts <nickrob@snap.net.nz>
parents: 68773
diff changeset
269 ;; Try the `which-func-functions' functions first.
58774
212ad195d26f (which-function): Use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56689
diff changeset
270 (run-hook-with-args-until-success 'which-func-functions)))
52691
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
271
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
272 ;; If Imenu is loaded, try to make an index alist with it.
52691
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
273 (when (and (null name)
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
274 (boundp 'imenu--index-alist) (null imenu--index-alist)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
275 (null which-function-imenu-failed))
61089
dc55bf752d7c (which-function): Be robust in the face of an
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58774
diff changeset
276 (imenu--make-index-alist t)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
277 (unless imenu--index-alist
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
278 (make-local-variable 'which-function-imenu-failed)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
279 (setq which-function-imenu-failed t)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
280 ;; If we have an index alist, use it.
52691
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
281 (when (and (null name)
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
282 (boundp 'imenu--index-alist) imenu--index-alist)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
283 (let ((alist imenu--index-alist)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
284 (minoffset (point-max))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
285 offset elem pair mark)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
286 (while alist
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
287 (setq elem (car-safe alist)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
288 alist (cdr-safe alist))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
289 ;; Elements of alist are either ("name" . marker), or
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
290 ;; ("submenu" ("name" . marker) ... ).
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
291 (unless (listp (cdr elem))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
292 (setq elem (list elem)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
293 (while elem
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
294 (setq pair (car elem)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
295 elem (cdr elem))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
296 (and (consp pair)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
297 (number-or-marker-p (setq mark (cdr pair)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
298 (if (>= (setq offset (- (point) mark)) 0)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
299 (if (< offset minoffset) ; find the closest item
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
300 (setq minoffset offset
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
301 name (car pair)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
302 ;; Entries in order, so can skip all those after point.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
303 (setq elem nil)))))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
304 ;; Try using add-log support.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
305 (when (and (null name) (boundp 'add-log-current-defun-function)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
306 add-log-current-defun-function)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
307 (setq name (funcall add-log-current-defun-function)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
308 ;; Filter the name if requested.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
309 (when name
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
310 (if which-func-cleanup-function
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
311 (funcall which-func-cleanup-function name)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
312 name))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
313
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
314 (provide 'which-func)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
315
61089
dc55bf752d7c (which-function): Be robust in the face of an
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58774
diff changeset
316 ;; arch-tag: fa8a55c7-bfe3-4ffc-95ab-01bf21796827
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
317 ;;; which-func.el ends here