annotate lisp/progmodes/which-func.el @ 111870:b47e85affa59

Derive from prog-mode, use derived-mode-p, and fix up various minor style issues in lisp/progmodes. * lisp/progmodes/vhdl-mode.el (vhdl-write-file-hooks-init) (vhdl-hs-minor-mode, vhdl-ps-print-init): Fix make-local-variable -> make-local-hook. * lisp/progmodes/sh-script.el (sh-require-final-newline): Remove. (sh-set-shell): Don't set require-final-newline since it's already done by prog-mode. * lisp/progmodes/modula2.el (m2-mode): Don't make m2-end-comment-column since we never set it. * lisp/progmodes/ebrowse.el (ebrowse-set-tree-indentation): Use read-string and standard prompt. * lisp/progmodes/dcl-mode.el (dcl-mode-map): Move init into declaration. * lisp/progmodes/meta-mode.el (meta-mode-abbrev-table): Merge init and decl. (meta-common-mode-syntax-table): Rename from meta-mode-syntax-table. (meta-common-mode-map): Rename from meta-mode-map. Remove C-m binding, which is a user preference, not mode specific. (meta-common-mode): New major mode; replace meta-common-initialization. * lisp/progmodes/js.el (js-mode): Call syntax-propertize rather than messing around with font-lock. * lisp/progmodes/etags.el (select-tags-table-mode): Derive from special-mode. * lisp/progmodes/octave-mod.el (octave-mode): * lisp/progmodes/gdb-mi.el (gdb-inferior-io-mode, gdb-threads-mode) (gdb-memory-mode, gdb-disassembly-mode, gdb-breakpoints-mode) (gdb-frames-mode, gdb-locals-mode, gdb-registers-mode): Let define-derived-mode do its job. * lisp/progmodes/cpp.el (cpp-edit-mode-map): Move initialization into declaration. (cpp-edit-mode): Use define-derived-mode. (cpp-edit-load): Use derived-mode-p. * lisp/progmodes/mixal-mode.el (mixal-mode): * lisp/progmodes/f90.el (f90-mode): * lisp/progmodes/cfengine.el (cfengine-mode): Don't bother setting require-final-newline since prog-mode does it already. * lisp/progmodes/cc-cmds.el (c-update-modeline): Use match-string. * lisp/progmodes/asm-mode.el (asm-mode-map): Fix menu setup. * lisp/progmodes/antlr-mode.el: Require cc-mode upfront. (antlr-mode-syntax-table, antlr-action-syntax-table): Initialize in the declaration. (antlr-directory-dependencies, antlr-show-makefile-rules): Use derived-mode-p. (antlr-language-option): Don't assume point-min==1. (antlr-mode): Use define-derived-mode. * lisp/progmodes/ada-mode.el: Use derived-mode-p. (ada-mode): Use define-derived-mode. Use hack-local-variables-hook. * lisp/progmodes/vhdl-mode.el (vhdl-mode): * lisp/progmodes/verilog-mode.el (verilog-mode): * lisp/progmodes/vera-mode.el (vera-mode): * lisp/progmodes/sql.el (sql-mode): * lisp/progmodes/scheme.el (scheme-mode): * lisp/progmodes/perl-mode.el (perl-mode): * lisp/progmodes/octave-inf.el (inferior-octave-mode): * lisp/progmodes/autoconf.el (autoconf-mode): * lisp/progmodes/m4-mode.el (m4-mode): * lisp/progmodes/inf-lisp.el (inferior-lisp-mode): * lisp/progmodes/idlwave.el (idlwave-mode): * lisp/progmodes/icon.el (icon-mode): * lisp/progmodes/idlw-help.el (idlwave-help-mode): * lisp/progmodes/dcl-mode.el (dcl-mode): * lisp/progmodes/idlw-shell.el (idlwave-shell-mode): * lisp/progmodes/ebrowse.el (ebrowse-tree-mode, ebrowse-electric-list-mode) (ebrowse-member-mode, ebrowse-electric-position-mode): Use define-derived-mode. * lisp/progmodes/xscheme.el (xscheme-start) (local-set-scheme-interaction-buffer, scheme-interaction-mode): * lisp/progmodes/which-func.el (which-function): * lisp/progmodes/vhdl-mode.el (vhdl-set-style): * lisp/progmodes/verilog-mode.el (verilog-set-compile-command) (verilog-modify-compile-command, verilog-error-regexp-add-xemacs) (verilog-set-define, verilog-auto-reeval-locals): * lisp/progmodes/sql.el (sql-product-font-lock, sql-interactive-mode): * lisp/progmodes/simula.el (simula-mode): * lisp/progmodes/scheme.el (scheme-mode-variables, dsssl-mode): * lisp/progmodes/python.el (python-check, python-mode): * lisp/progmodes/prolog.el (prolog-mode-variables): * lisp/progmodes/gud.el (gud-tooltip-activate-mouse-motions): * lisp/progmodes/ebrowse.el (ebrowse-view-file-other-frame): * lisp/progmodes/delphi.el (delphi-mode): * lisp/progmodes/cc-styles.el (c-setup-paragraph-variables): * lisp/progmodes/cc-mode.el (c-basic-common-init, c-common-init) (c-font-lock-init): Move make-local-variable to their setq. * lisp/progmodes/xscheme.el (exit-scheme-interaction-mode) (xscheme-enter-interaction-mode, xscheme-enter-debugger-mode) (xscheme-debugger-mode-p, xscheme-send-string-1): * lisp/progmodes/tcl.el (inferior-tcl-proc, tcl-current-word) (tcl-load-file, tcl-restart-with-file): * lisp/progmodes/ps-mode.el (ps-run-running): * lisp/progmodes/gdb-mi.el (gud-watch, gdb-mouse-set-clear-breakpoint): * lisp/progmodes/js.el (js--get-all-known-symbols): * lisp/progmodes/inf-lisp.el (inferior-lisp-proc): * lisp/progmodes/idlwave.el (idlwave-beginning-of-statement) (idlwave-template, idlwave-update-buffer-routine-info) (idlwave-update-current-buffer-info) (idlwave-get-routine-info-from-buffers, idlwave-choose) (idlwave-scan-class-info, idlwave-fix-keywords) (idlwave-list-buffer-load-path-shadows): * lisp/progmodes/idlw-toolbar.el (idlwave-toolbar, idlwave-toolbar-add) (idlwave-toolbar-remove): * lisp/progmodes/idlw-shell.el (idlwave-shell-save-and-action) (idlwave-shell-file-name, idlwave-shell-electric-debug-all-off) (idlwave-shell-menu-def): * lisp/progmodes/idlw-complete-structtag.el (idlwave-prepare-structure-tag-completion): * lisp/progmodes/gud.el (gud-set-buffer): * lisp/progmodes/f90.el (f90-backslash-not-special): * lisp/progmodes/delphi.el (delphi-find-unit): Use derived-mode-p.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 10 Dec 2010 15:00:25 -0500
parents 6c35da413ade
children 417b1e4d63cd
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
98407
352e7f3ed660 (which-func-imenu-joiner-function): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 98406
diff changeset
3 ;; Copyright (C) 1994, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 103096
diff changeset
4 ;; 2007, 2008, 2009, 2010 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
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
51349
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
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
15 ;; (at your option) any later version.
51349
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
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
24
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
25 ;;; Commentary:
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 ;; This package prints name of function where your current point is
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
28 ;; located in mode line. It assumes that you work with imenu package
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
29 ;; and imenu--index-alist is up to date.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
30
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
31 ;; KNOWN BUGS
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 ;; Really this package shows not "function where the current point is
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
34 ;; located now", but "nearest function which defined above the current
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
35 ;; point". So if your current point is located after end of function
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
36 ;; 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
37 ;; line.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
38 ;; - if two windows display the same buffer, both windows
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
39 ;; show the same `which-func' information.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
40
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
41 ;; TODO LIST
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 ;; 1. Dependence on imenu package should be removed. Separate
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
44 ;; function determination mechanism should be used to determine the end
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
45 ;; of a function as well as the beginning of a function.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
46 ;; 2. This package should be realized with the help of overlay
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
47 ;; properties instead of imenu--index-alist variable.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
48
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
49 ;;; History:
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 ;; THANKS TO
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 ;; Per Abrahamsen <abraham@iesd.auc.dk>
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
54 ;; Some ideas (inserting in mode-line, using of post-command hook
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
55 ;; and toggling this mode) have been borrowed from his package
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
56 ;; column.el
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
57 ;; Peter Eisenhauer <pipe@fzi.de>
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
58 ;; Bug fixing in case nested indexes.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
59 ;; Terry Tateyama <ttt@ursa0.cs.utah.edu>
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
60 ;; Suggestion to use find-file-hook for first imenu
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
61 ;; index building.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
62
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
63 ;;; Code:
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 ;; Variables for customization
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 ;;
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
68 (defvar which-func-unknown "???"
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
69 "String to display in the mode line when current function is unknown.")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
70
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
71 (defgroup which-func nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
72 "Mode to display the current function name in the modeline."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
73 :group 'tools
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
74 :version "20.3")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
75
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
76 (defcustom which-func-modes
81825
69b5e2969dfe (which-func-modes): Add `python-mode'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 75347
diff changeset
77 '(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode python-mode
84390
28620c3d5a1a Added diff-mode to `which-func-modes'.
Masatake YAMATO <jet@gyve.org>
parents: 82365
diff changeset
78 makefile-mode sh-mode fortran-mode f90-mode ada-mode
28620c3d5a1a Added diff-mode to `which-func-modes'.
Masatake YAMATO <jet@gyve.org>
parents: 82365
diff changeset
79 diff-mode)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
80 "List of major modes for which Which Function mode should be used.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
81 For other modes it is disabled. If this is equal to t,
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
82 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
83 :group 'which-func
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
84 :type '(choice (const :tag "All modes" t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
85 (repeat (symbol :tag "Major mode"))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
86
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
87 (defcustom which-func-non-auto-modes nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
88 "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
89 This means that Which Function mode won't really do anything
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
90 until you use Imenu, in these modes. Note that files
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
91 larger than `which-func-maxout' behave in this way too;
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
92 Which Function mode doesn't do anything until you use Imenu."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
93 :group 'which-func
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
94 :type '(repeat (symbol :tag "Major mode")))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
95
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
96 (defcustom which-func-maxout 500000
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
97 "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
98 Zero means compute the Imenu menu regardless of size."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
99 :group 'which-func
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
100 :type 'integer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
101
56442
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
102 (defvar which-func-keymap
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
103 (let ((map (make-sparse-keymap)))
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
104 (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
105 (define-key map [mode-line mouse-2]
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
106 (lambda ()
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
107 (interactive)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
108 (if (eq (point-min) 1)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
109 (narrow-to-defun)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
110 (widen))))
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
111 (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
112 map)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
113 "Keymap to display on mode line which-func.")
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
114
63457
581fdd0b552d Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-417
Miles Bader <miles@gnu.org>
parents: 62858
diff changeset
115 (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
116 ;; 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
117 ;; 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
118 ;; 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
119 '(;; 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
120 ;; 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
121 ;; `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
122 (((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
123 :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
124 ;; 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
125 ;; 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
126 ;; `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
127 (((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
128 :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
129 (((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
130 :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
131 ;; 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
132 ;; 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
133 (((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
134 :foreground "Blue1")
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
135 (((background dark))
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
136 :foreground "Blue1")
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
137 (t
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
138 :foreground "LightSkyBlue"))
ad343539d42b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents: 63457
diff changeset
139 "Face used to highlight mode line function names."
56442
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
140 :group 'which-func)
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
141
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
142 (defcustom which-func-format
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
143 `("["
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
144 (:propertize which-func-current
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
145 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
146 face which-func
56442
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
147 ;;mouse-face highlight ; currently not evaluated :-(
109708
b1689e2cce22 which-func.el (which-func-format): Split help-echo text into lines.
Juanma Barranquero <lekktu@gmail.com>
parents: 106815
diff changeset
148 help-echo "mouse-1: go to beginning\n\
b1689e2cce22 which-func.el (which-func-format): Split help-echo text into lines.
Juanma Barranquero <lekktu@gmail.com>
parents: 106815
diff changeset
149 mouse-2: toggle rest visibility\n\
b1689e2cce22 which-func.el (which-func-format): Split help-echo text into lines.
Juanma Barranquero <lekktu@gmail.com>
parents: 106815
diff changeset
150 mouse-3: go to end")
56442
e8032355ca23 (which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 53618
diff changeset
151 "]")
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
152 "Format for displaying the function in the mode line."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
153 :group 'which-func
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
154 :type 'sexp)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
155 ;;;###autoload (put 'which-func-format 'risky-local-variable t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
156
111766
7bd5c179aeff * progmodes/which-func.el (which-func-imenu-joiner-function):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109708
diff changeset
157 (defvar which-func-imenu-joiner-function (lambda (x) (car (last x)))
98407
352e7f3ed660 (which-func-imenu-joiner-function): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 98406
diff changeset
158 "Function to join together multiple levels of imenu nomenclature.
352e7f3ed660 (which-func-imenu-joiner-function): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 98406
diff changeset
159 Called with a single argument, a list of strings giving the names
352e7f3ed660 (which-func-imenu-joiner-function): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 98406
diff changeset
160 of the menus we had to traverse to get to the item. Returns a
352e7f3ed660 (which-func-imenu-joiner-function): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 98406
diff changeset
161 single string, the new name of the item.")
98406
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
162
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
163 (defvar which-func-cleanup-function nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
164 "Function to transform a string before displaying it in the mode line.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
165 The function is called with one argument, the string to display.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
166 Its return value is displayed in the modeline.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
167 If nil, no function is called. The default value is nil.
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 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
170 detailed entries (e.g., containing the argument list of a function),
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
171 and you want to simplify them for the mode line
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
172 \(e.g., removing the parameter list to just have the function name.)")
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 ;;; Code, nothing to customize below here
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
175 ;;; -------------------------------------
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
176 ;;;
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
177 (require 'imenu)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
178
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
179 (defvar which-func-table (make-hash-table :test 'eq :weakness 'key))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
180
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
181 (defconst which-func-current
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
182 '(:eval (gethash (selected-window) which-func-table which-func-unknown)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
183 ;;;###autoload (put 'which-func-current 'risky-local-variable t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
184
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
185 (defvar which-func-mode nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
186 "Non-nil means display current function name in mode line.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
187 This makes a difference only if `which-function-mode' is non-nil.")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
188 (make-variable-buffer-local 'which-func-mode)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
189 ;;(put 'which-func-mode 'permanent-local t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
190
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
191 (add-hook 'find-file-hook 'which-func-ff-hook t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
192
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
193 (defun which-func-ff-hook ()
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
194 "File find hook for Which Function mode.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
195 It creates the Imenu index for the buffer, if necessary."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
196 (setq which-func-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
197 (and which-function-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
198 (or (eq which-func-modes t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
199 (member major-mode which-func-modes))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
200
111823
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
201 (condition-case err
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
202 (if (and which-func-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
203 (not (member major-mode which-func-non-auto-modes))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
204 (or (null which-func-maxout)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
205 (< buffer-saved-size which-func-maxout)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
206 (= which-func-maxout 0)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
207 (setq imenu--index-alist
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
208 (save-excursion (funcall imenu-create-index-function))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
209 (error
111823
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
210 (message "which-func-ff-hook error: %S" err)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
211 (setq which-func-mode nil))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
212
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
213 (defun which-func-update ()
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
214 ;; "Update the Which-Function mode display for all windows."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
215 ;; (walk-windows 'which-func-update-1 nil 'visible))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
216 (which-func-update-1 (selected-window)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
217
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
218 (defun which-func-update-1 (window)
56689
f54e121491eb (which-func-update-1): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 56442
diff changeset
219 "Update the Which Function mode display for window WINDOW."
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
220 (with-selected-window window
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
221 (when which-func-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
222 (condition-case info
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
223 (let ((current (which-function)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
224 (unless (equal current (gethash window which-func-table))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
225 (puthash window current which-func-table)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
226 (force-mode-line-update)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
227 (error
62858
c23f28be371c (which-func-update-1): Turn the mode
Richard M. Stallman <rms@gnu.org>
parents: 61089
diff changeset
228 (setq which-func-mode nil)
111823
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
229 (error "Error in which-func-update: %S" info))))))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
230
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
231 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
232 (defalias 'which-func-mode 'which-function-mode)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
233
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
234 (defvar which-func-update-timer nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
235
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
236 ;; This is the name people would normally expect.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
237 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
238 (define-minor-mode which-function-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
239 "Toggle Which Function mode, globally.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
240 When Which Function mode is enabled, the current function name is
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
241 continuously displayed in the mode line, in certain major modes.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
242
78487
419c5c316b51 Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78234
diff changeset
243 With prefix ARG, turn Which Function mode on if arg is positive,
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
244 and off otherwise."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
245 :global t :group 'which-func
111766
7bd5c179aeff * progmodes/which-func.el (which-func-imenu-joiner-function):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109708
diff changeset
246 (when (timerp which-func-update-timer)
7bd5c179aeff * progmodes/which-func.el (which-func-imenu-joiner-function):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109708
diff changeset
247 (cancel-timer which-func-update-timer))
7bd5c179aeff * progmodes/which-func.el (which-func-imenu-joiner-function):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109708
diff changeset
248 (setq which-func-update-timer nil)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
249 (if which-function-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
250 ;;Turn it on
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
251 (progn
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
252 (setq which-func-update-timer
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
253 (run-with-idle-timer idle-update-delay t 'which-func-update))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
254 (dolist (buf (buffer-list))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
255 (with-current-buffer buf
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
256 (setq which-func-mode
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
257 (or (eq which-func-modes t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
258 (member major-mode which-func-modes))))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
259 ;; Turn it off
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
260 (dolist (buf (buffer-list))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
261 (with-current-buffer buf (setq which-func-mode nil)))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
262
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
263 (defvar which-function-imenu-failed nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
264 "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
265
52691
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
266 (defvar which-func-functions nil
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
267 "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
268 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
269 `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
270
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
271 (defun which-function ()
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
272 "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
273 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
274 or `add-log-current-defun-function'.
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
275 If no function name is found, return nil."
58774
212ad195d26f (which-function): Use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56689
diff changeset
276 (let ((name
72144
2824d0383afd (which-function): Fix documentation/comment typo.
Nick Roberts <nickrob@snap.net.nz>
parents: 68773
diff changeset
277 ;; Try the `which-func-functions' functions first.
58774
212ad195d26f (which-function): Use
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56689
diff changeset
278 (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
279
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
280 ;; 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
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) (null imenu--index-alist)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
283 (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
284 (imenu--make-index-alist t)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
285 (unless imenu--index-alist
111870
b47e85affa59 Derive from prog-mode, use derived-mode-p, and fix up various
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111823
diff changeset
286 (set (make-local-variable 'which-function-imenu-failed) t)))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
287 ;; 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
288 (when (and (null name)
ccda1b53b035 (which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
289 (boundp 'imenu--index-alist) imenu--index-alist)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
290 (let ((alist imenu--index-alist)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
291 (minoffset (point-max))
98406
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
292 offset pair mark imstack namestack)
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
293 ;; Elements of alist are either ("name" . marker), or
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
294 ;; ("submenu" ("name" . marker) ... ). The list can be
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
295 ;; arbitrarily nested.
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
296 (while (or alist imstack)
111823
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
297 (if (null alist)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
298 (setq alist (car imstack)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
299 namestack (cdr namestack)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
300 imstack (cdr imstack))
98406
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
301
111823
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
302 (setq pair (car-safe alist)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
303 alist (cdr-safe alist))
98406
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
304
111823
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
305 (cond
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
306 ((atom pair)) ; Skip anything not a cons.
98406
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
307
111823
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
308 ((imenu--subalist-p pair)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
309 (setq imstack (cons alist imstack)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
310 namestack (cons (car pair) namestack)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
311 alist (cdr pair)))
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
312
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
313 ((number-or-marker-p (setq mark (cdr pair)))
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
314 (when (and (>= (setq offset (- (point) mark)) 0)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
315 (< offset minoffset)) ; Find the closest item.
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
316 (setq minoffset offset
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
317 name (if (null which-func-imenu-joiner-function)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
318 (car pair)
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
319 (funcall
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
320 which-func-imenu-joiner-function
6c35da413ade * lisp/progmodes/which-func.el (which-func-ff-hook): Log the error message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111766
diff changeset
321 (reverse (cons (car pair) namestack))))))))))))
98406
6d3479368dfd Daniel Colascione <danc at merrillpress.com>
Glenn Morris <rgm@gnu.org>
parents: 94673
diff changeset
322
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
323 ;; Try using add-log support.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
324 (when (and (null name) (boundp 'add-log-current-defun-function)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
325 add-log-current-defun-function)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
326 (setq name (funcall add-log-current-defun-function)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
327 ;; Filter the name if requested.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
328 (when name
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
329 (if which-func-cleanup-function
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
330 (funcall which-func-cleanup-function name)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
331 name))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
332
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
333 (provide 'which-func)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
334
61089
dc55bf752d7c (which-function): Be robust in the face of an
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 58774
diff changeset
335 ;; arch-tag: fa8a55c7-bfe3-4ffc-95ab-01bf21796827
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
336 ;;; which-func.el ends here