2003-05-30 23:31:15 +00:00
|
|
|
;;; which-func.el --- print current function in mode line
|
|
|
|
|
2008-09-30 03:42:56 +00:00
|
|
|
;; Copyright (C) 1994, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006
|
2011-01-02 15:50:46 -08:00
|
|
|
;; 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
2003-05-30 23:31:15 +00:00
|
|
|
|
|
|
|
;; Author: Alex Rezinsky <alexr@msil.sps.mot.com>
|
|
|
|
;; (doesn't seem to be responsive any more)
|
|
|
|
;; Keywords: mode-line, imenu, tools
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 07:25:26 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2003-05-30 23:31:15 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 07:25:26 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2003-05-30 23:31:15 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 07:25:26 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2003-05-30 23:31:15 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; This package prints name of function where your current point is
|
|
|
|
;; located in mode line. It assumes that you work with imenu package
|
|
|
|
;; and imenu--index-alist is up to date.
|
|
|
|
|
|
|
|
;; KNOWN BUGS
|
|
|
|
;; ----------
|
|
|
|
;; Really this package shows not "function where the current point is
|
|
|
|
;; located now", but "nearest function which defined above the current
|
|
|
|
;; point". So if your current point is located after end of function
|
|
|
|
;; FOO but before begin of function BAR, FOO will be displayed in mode
|
|
|
|
;; line.
|
|
|
|
;; - if two windows display the same buffer, both windows
|
|
|
|
;; show the same `which-func' information.
|
|
|
|
|
|
|
|
;; TODO LIST
|
|
|
|
;; ---------
|
|
|
|
;; 1. Dependence on imenu package should be removed. Separate
|
|
|
|
;; function determination mechanism should be used to determine the end
|
|
|
|
;; of a function as well as the beginning of a function.
|
|
|
|
;; 2. This package should be realized with the help of overlay
|
|
|
|
;; properties instead of imenu--index-alist variable.
|
|
|
|
|
|
|
|
;;; History:
|
|
|
|
|
|
|
|
;; THANKS TO
|
|
|
|
;; ---------
|
|
|
|
;; Per Abrahamsen <abraham@iesd.auc.dk>
|
|
|
|
;; Some ideas (inserting in mode-line, using of post-command hook
|
|
|
|
;; and toggling this mode) have been borrowed from his package
|
|
|
|
;; column.el
|
|
|
|
;; Peter Eisenhauer <pipe@fzi.de>
|
|
|
|
;; Bug fixing in case nested indexes.
|
|
|
|
;; Terry Tateyama <ttt@ursa0.cs.utah.edu>
|
|
|
|
;; Suggestion to use find-file-hook for first imenu
|
|
|
|
;; index building.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;; Variables for customization
|
|
|
|
;; ---------------------------
|
|
|
|
;;
|
|
|
|
(defvar which-func-unknown "???"
|
|
|
|
"String to display in the mode line when current function is unknown.")
|
|
|
|
|
|
|
|
(defgroup which-func nil
|
|
|
|
"Mode to display the current function name in the modeline."
|
|
|
|
:group 'tools
|
|
|
|
:version "20.3")
|
|
|
|
|
|
|
|
(defcustom which-func-modes
|
2007-07-12 04:37:06 +00:00
|
|
|
'(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode python-mode
|
2007-09-08 04:35:39 +00:00
|
|
|
makefile-mode sh-mode fortran-mode f90-mode ada-mode
|
|
|
|
diff-mode)
|
2003-05-30 23:31:15 +00:00
|
|
|
"List of major modes for which Which Function mode should be used.
|
|
|
|
For other modes it is disabled. If this is equal to t,
|
|
|
|
then Which Function mode is enabled in any major mode that supports it."
|
|
|
|
:group 'which-func
|
|
|
|
:type '(choice (const :tag "All modes" t)
|
|
|
|
(repeat (symbol :tag "Major mode"))))
|
|
|
|
|
|
|
|
(defcustom which-func-non-auto-modes nil
|
|
|
|
"List of major modes where Which Function mode is inactive till Imenu is used.
|
|
|
|
This means that Which Function mode won't really do anything
|
|
|
|
until you use Imenu, in these modes. Note that files
|
|
|
|
larger than `which-func-maxout' behave in this way too;
|
|
|
|
Which Function mode doesn't do anything until you use Imenu."
|
|
|
|
:group 'which-func
|
|
|
|
:type '(repeat (symbol :tag "Major mode")))
|
|
|
|
|
|
|
|
(defcustom which-func-maxout 500000
|
|
|
|
"Don't automatically compute the Imenu menu if buffer is this big or bigger.
|
|
|
|
Zero means compute the Imenu menu regardless of size."
|
|
|
|
:group 'which-func
|
|
|
|
:type 'integer)
|
|
|
|
|
2004-07-17 08:10:28 +00:00
|
|
|
(defvar which-func-keymap
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [mode-line mouse-1] 'beginning-of-defun)
|
|
|
|
(define-key map [mode-line mouse-2]
|
|
|
|
(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(if (eq (point-min) 1)
|
|
|
|
(narrow-to-defun)
|
|
|
|
(widen))))
|
|
|
|
(define-key map [mode-line mouse-3] 'end-of-defun)
|
|
|
|
map)
|
|
|
|
"Keymap to display on mode line which-func.")
|
|
|
|
|
2005-06-15 00:14:41 +00:00
|
|
|
(defface which-func
|
2005-06-15 04:35:23 +00:00
|
|
|
;; Whether `font-lock-function-name-face' is an appropriate face to
|
|
|
|
;; inherit depends on the mode-line face; define several variants based
|
|
|
|
;; on the default mode-line face.
|
|
|
|
'(;; The default mode-line face on a high-color display is a relatively
|
|
|
|
;; light color ("grey75"), and only the light-background variant of
|
|
|
|
;; `font-lock-function-name-face' is visible against it.
|
|
|
|
(((class color) (min-colors 88) (background light))
|
|
|
|
:inherit font-lock-function-name-face)
|
|
|
|
;; The default mode-line face on other display types is inverse-video;
|
|
|
|
;; it seems that only in the dark-background case is
|
|
|
|
;; `font-lock-function-name-face' visible against it.
|
|
|
|
(((class grayscale mono) (background dark))
|
|
|
|
:inherit font-lock-function-name-face)
|
|
|
|
(((class color) (background light))
|
|
|
|
:inherit font-lock-function-name-face)
|
|
|
|
;; If none of the above cases, use an explicit color chosen to contrast
|
|
|
|
;; well with the default mode-line face.
|
|
|
|
(((class color) (min-colors 88) (background dark))
|
|
|
|
:foreground "Blue1")
|
|
|
|
(((background dark))
|
|
|
|
:foreground "Blue1")
|
|
|
|
(t
|
|
|
|
:foreground "LightSkyBlue"))
|
|
|
|
"Face used to highlight mode line function names."
|
2004-07-17 08:10:28 +00:00
|
|
|
:group 'which-func)
|
|
|
|
|
|
|
|
(defcustom which-func-format
|
|
|
|
`("["
|
|
|
|
(:propertize which-func-current
|
|
|
|
local-map ,which-func-keymap
|
2005-06-15 00:14:41 +00:00
|
|
|
face which-func
|
2004-07-17 08:10:28 +00:00
|
|
|
;;mouse-face highlight ; currently not evaluated :-(
|
2010-08-03 18:39:37 +02:00
|
|
|
help-echo "mouse-1: go to beginning\n\
|
|
|
|
mouse-2: toggle rest visibility\n\
|
|
|
|
mouse-3: go to end")
|
2004-07-17 08:10:28 +00:00
|
|
|
"]")
|
2003-05-30 23:31:15 +00:00
|
|
|
"Format for displaying the function in the mode line."
|
|
|
|
:group 'which-func
|
|
|
|
:type 'sexp)
|
|
|
|
;;;###autoload (put 'which-func-format 'risky-local-variable t)
|
|
|
|
|
2010-11-23 21:21:55 -05:00
|
|
|
(defvar which-func-imenu-joiner-function (lambda (x) (car (last x)))
|
2008-09-30 03:42:56 +00:00
|
|
|
"Function to join together multiple levels of imenu nomenclature.
|
|
|
|
Called with a single argument, a list of strings giving the names
|
|
|
|
of the menus we had to traverse to get to the item. Returns a
|
|
|
|
single string, the new name of the item.")
|
2008-09-30 03:41:35 +00:00
|
|
|
|
2003-05-30 23:31:15 +00:00
|
|
|
(defvar which-func-cleanup-function nil
|
|
|
|
"Function to transform a string before displaying it in the mode line.
|
|
|
|
The function is called with one argument, the string to display.
|
|
|
|
Its return value is displayed in the modeline.
|
|
|
|
If nil, no function is called. The default value is nil.
|
|
|
|
|
|
|
|
This feature can be useful if Imenu is set up to make more
|
|
|
|
detailed entries (e.g., containing the argument list of a function),
|
|
|
|
and you want to simplify them for the mode line
|
|
|
|
\(e.g., removing the parameter list to just have the function name.)")
|
|
|
|
|
|
|
|
;;; Code, nothing to customize below here
|
|
|
|
;;; -------------------------------------
|
|
|
|
;;;
|
|
|
|
(require 'imenu)
|
|
|
|
|
|
|
|
(defvar which-func-table (make-hash-table :test 'eq :weakness 'key))
|
|
|
|
|
|
|
|
(defconst which-func-current
|
|
|
|
'(:eval (gethash (selected-window) which-func-table which-func-unknown)))
|
|
|
|
;;;###autoload (put 'which-func-current 'risky-local-variable t)
|
|
|
|
|
|
|
|
(defvar which-func-mode nil
|
|
|
|
"Non-nil means display current function name in mode line.
|
|
|
|
This makes a difference only if `which-function-mode' is non-nil.")
|
|
|
|
(make-variable-buffer-local 'which-func-mode)
|
|
|
|
;;(put 'which-func-mode 'permanent-local t)
|
|
|
|
|
|
|
|
(add-hook 'find-file-hook 'which-func-ff-hook t)
|
|
|
|
|
|
|
|
(defun which-func-ff-hook ()
|
|
|
|
"File find hook for Which Function mode.
|
|
|
|
It creates the Imenu index for the buffer, if necessary."
|
|
|
|
(setq which-func-mode
|
|
|
|
(and which-function-mode
|
|
|
|
(or (eq which-func-modes t)
|
|
|
|
(member major-mode which-func-modes))))
|
|
|
|
|
2010-12-03 19:49:49 -05:00
|
|
|
(condition-case err
|
2003-05-30 23:31:15 +00:00
|
|
|
(if (and which-func-mode
|
|
|
|
(not (member major-mode which-func-non-auto-modes))
|
|
|
|
(or (null which-func-maxout)
|
|
|
|
(< buffer-saved-size which-func-maxout)
|
|
|
|
(= which-func-maxout 0)))
|
|
|
|
(setq imenu--index-alist
|
|
|
|
(save-excursion (funcall imenu-create-index-function))))
|
|
|
|
(error
|
2010-12-03 19:49:49 -05:00
|
|
|
(message "which-func-ff-hook error: %S" err)
|
2003-05-30 23:31:15 +00:00
|
|
|
(setq which-func-mode nil))))
|
|
|
|
|
|
|
|
(defun which-func-update ()
|
|
|
|
;; "Update the Which-Function mode display for all windows."
|
|
|
|
;; (walk-windows 'which-func-update-1 nil 'visible))
|
|
|
|
(which-func-update-1 (selected-window)))
|
|
|
|
|
|
|
|
(defun which-func-update-1 (window)
|
2004-08-16 22:46:26 +00:00
|
|
|
"Update the Which Function mode display for window WINDOW."
|
2003-05-30 23:31:15 +00:00
|
|
|
(with-selected-window window
|
|
|
|
(when which-func-mode
|
|
|
|
(condition-case info
|
|
|
|
(let ((current (which-function)))
|
|
|
|
(unless (equal current (gethash window which-func-table))
|
|
|
|
(puthash window current which-func-table)
|
|
|
|
(force-mode-line-update)))
|
|
|
|
(error
|
2005-05-29 08:31:54 +00:00
|
|
|
(setq which-func-mode nil)
|
2010-12-03 19:49:49 -05:00
|
|
|
(error "Error in which-func-update: %S" info))))))
|
2003-05-30 23:31:15 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defalias 'which-func-mode 'which-function-mode)
|
|
|
|
|
|
|
|
(defvar which-func-update-timer nil)
|
|
|
|
|
|
|
|
;; This is the name people would normally expect.
|
|
|
|
;;;###autoload
|
|
|
|
(define-minor-mode which-function-mode
|
|
|
|
"Toggle Which Function mode, globally.
|
|
|
|
When Which Function mode is enabled, the current function name is
|
|
|
|
continuously displayed in the mode line, in certain major modes.
|
|
|
|
|
2007-08-08 07:34:30 +00:00
|
|
|
With prefix ARG, turn Which Function mode on if arg is positive,
|
2003-05-30 23:31:15 +00:00
|
|
|
and off otherwise."
|
|
|
|
:global t :group 'which-func
|
2010-11-23 21:21:55 -05:00
|
|
|
(when (timerp which-func-update-timer)
|
|
|
|
(cancel-timer which-func-update-timer))
|
|
|
|
(setq which-func-update-timer nil)
|
2003-05-30 23:31:15 +00:00
|
|
|
(if which-function-mode
|
|
|
|
;;Turn it on
|
|
|
|
(progn
|
|
|
|
(setq which-func-update-timer
|
|
|
|
(run-with-idle-timer idle-update-delay t 'which-func-update))
|
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(setq which-func-mode
|
|
|
|
(or (eq which-func-modes t)
|
|
|
|
(member major-mode which-func-modes))))))
|
|
|
|
;; Turn it off
|
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(with-current-buffer buf (setq which-func-mode nil)))))
|
|
|
|
|
|
|
|
(defvar which-function-imenu-failed nil
|
|
|
|
"Locally t in a buffer if `imenu--make-index-alist' found nothing there.")
|
|
|
|
|
2003-09-30 12:53:26 +00:00
|
|
|
(defvar which-func-functions nil
|
|
|
|
"List of functions for `which-function' to call with no arguments.
|
|
|
|
It calls them sequentially, and if any returns non-nil,
|
|
|
|
`which-function' uses that name and stops looking for the name.")
|
|
|
|
|
2003-05-30 23:31:15 +00:00
|
|
|
(defun which-function ()
|
|
|
|
"Return current function name based on point.
|
2006-07-27 12:18:03 +00:00
|
|
|
Uses `which-func-functions', `imenu--index-alist'
|
2003-09-30 12:53:26 +00:00
|
|
|
or `add-log-current-defun-function'.
|
2003-05-30 23:31:15 +00:00
|
|
|
If no function name is found, return nil."
|
2004-12-05 16:58:13 +00:00
|
|
|
(let ((name
|
2006-07-27 12:18:03 +00:00
|
|
|
;; Try the `which-func-functions' functions first.
|
2004-12-05 16:58:13 +00:00
|
|
|
(run-hook-with-args-until-success 'which-func-functions)))
|
2003-09-30 12:53:26 +00:00
|
|
|
|
2003-05-30 23:31:15 +00:00
|
|
|
;; If Imenu is loaded, try to make an index alist with it.
|
2003-09-30 12:53:26 +00:00
|
|
|
(when (and (null name)
|
|
|
|
(boundp 'imenu--index-alist) (null imenu--index-alist)
|
2003-05-30 23:31:15 +00:00
|
|
|
(null which-function-imenu-failed))
|
2005-03-29 14:18:00 +00:00
|
|
|
(imenu--make-index-alist t)
|
2003-05-30 23:31:15 +00:00
|
|
|
(unless imenu--index-alist
|
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.
2010-12-10 15:00:25 -05:00
|
|
|
(set (make-local-variable 'which-function-imenu-failed) t)))
|
2003-05-30 23:31:15 +00:00
|
|
|
;; If we have an index alist, use it.
|
2003-09-30 12:53:26 +00:00
|
|
|
(when (and (null name)
|
|
|
|
(boundp 'imenu--index-alist) imenu--index-alist)
|
2003-05-30 23:31:15 +00:00
|
|
|
(let ((alist imenu--index-alist)
|
|
|
|
(minoffset (point-max))
|
2008-09-30 03:41:35 +00:00
|
|
|
offset pair mark imstack namestack)
|
|
|
|
;; Elements of alist are either ("name" . marker), or
|
|
|
|
;; ("submenu" ("name" . marker) ... ). The list can be
|
|
|
|
;; arbitrarily nested.
|
|
|
|
(while (or alist imstack)
|
2010-12-03 19:49:49 -05:00
|
|
|
(if (null alist)
|
|
|
|
(setq alist (car imstack)
|
|
|
|
namestack (cdr namestack)
|
|
|
|
imstack (cdr imstack))
|
|
|
|
|
|
|
|
(setq pair (car-safe alist)
|
|
|
|
alist (cdr-safe alist))
|
|
|
|
|
|
|
|
(cond
|
|
|
|
((atom pair)) ; Skip anything not a cons.
|
|
|
|
|
|
|
|
((imenu--subalist-p pair)
|
|
|
|
(setq imstack (cons alist imstack)
|
|
|
|
namestack (cons (car pair) namestack)
|
|
|
|
alist (cdr pair)))
|
|
|
|
|
|
|
|
((number-or-marker-p (setq mark (cdr pair)))
|
|
|
|
(when (and (>= (setq offset (- (point) mark)) 0)
|
|
|
|
(< offset minoffset)) ; Find the closest item.
|
|
|
|
(setq minoffset offset
|
|
|
|
name (if (null which-func-imenu-joiner-function)
|
|
|
|
(car pair)
|
|
|
|
(funcall
|
|
|
|
which-func-imenu-joiner-function
|
|
|
|
(reverse (cons (car pair) namestack))))))))))))
|
2008-09-30 03:41:35 +00:00
|
|
|
|
2003-05-30 23:31:15 +00:00
|
|
|
;; Try using add-log support.
|
|
|
|
(when (and (null name) (boundp 'add-log-current-defun-function)
|
|
|
|
add-log-current-defun-function)
|
|
|
|
(setq name (funcall add-log-current-defun-function)))
|
|
|
|
;; Filter the name if requested.
|
|
|
|
(when name
|
|
|
|
(if which-func-cleanup-function
|
|
|
|
(funcall which-func-cleanup-function name)
|
|
|
|
name))))
|
|
|
|
|
|
|
|
(provide 'which-func)
|
|
|
|
|
|
|
|
;;; which-func.el ends here
|