1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-23 18:47:57 +00:00
emacs/lisp/progmodes/which-func.el

366 lines
13 KiB
EmacsLisp
Raw Normal View History

2003-05-30 23:31:15 +00:00
;;; which-func.el --- print current function in mode line
2013-01-01 09:11:05 +00:00
;; Copyright (C) 1994, 1997-1998, 2001-2013 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.
;; 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
;; 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
;; 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
Remove incorrect uses of "modeline". * ansi-color.el (ansi-color-faces-vector): Change default faces. * cus-edit.el (mode-line): * dframe.el (dframe-mouse-hscroll): * emacs-lisp/re-builder.el: * emacs-lisp/easy-mmode.el (define-minor-mode): * frame.el (set-frame-name): * help.el (lookup-minor-mode-from-indicator): * net/rcirc.el (rcirc-activity-string, rcirc-short-buffer-name): * progmodes/cc-cmds.el (c-toggle-auto-newline) (c-toggle-hungry-state): * progmodes/antlr-mode.el (antlr-language-alist): * progmodes/idlw-shell.el (idlwave-shell-electric-stop-line-face): * progmodes/vhdl-mode.el (vhdl-mode): * progmodes/which-func.el (which-func, which-func-cleanup-function): * term/ns-win.el (ns-face-at-pos): * term/sup-mouse.el (sup-mouse-report): * textmodes/flyspell.el (flyspell-mode-line-string): * textmodes/ispell.el (ispell-highlight-face): * textmodes/reftex-global.el: * vc/vc-arch.el (vc-arch-mode-line-string): * vc/vc-cvs.el (vc-cvs-mode-line-string): * vc/vc-git.el (vc-git-mode-line-string): * vc/vc-hooks.el (vc-display-status) (vc-default-mode-line-string): * vc/vc-mtn.el (vc-mtn-mode-line-string): Doc fixes. * dired.el (dired-sort-set-mode-line): Rename from dired-sort-set-modeline. All callers changed. * foldout.el (foldout-mode-line-string): Rename from foldout-modeline-string. All callers changed. (foldout-update-mode-line): Rename from foldout-update-modeline. * strokes.el (strokes-lighter): Rename from strokes-modeline-string. * subr.el (redraw-modeline): Make into obsolete alias. * calendar/timeclock.el (timeclock-mode-line-display): Rename from timeclock-modeline-display. Make old name an alias. (timeclock-update-mode-line): Likewise. All callers changed. (timeclock-mode-line-display): No need to check before using add-hook. (timeclock-relative, timeclock-day-over-hook) (timeclock-use-elapsed, timeclock-mode-string) (timeclock-mode-line-display): Doc fix, "modeline" -> "mode line". * emulation/crisp.el (crisp-mode-mode-line-string): Rename from crisp-mode-modeline-string. * erc-track.el (erc-track, erc-track-faces-priority-list) (erc-track-faces-normal-list, erc-track-find-face) (erc-track-modified-channels): Fix modeline -> mode line in docs. * eshell/esh-mode.el (eshell-status-in-mode-line): Rename from eshell-status-in-modeline. * org-clock.el (org-clock-string-limit) (org-clock-modeline-total, org-clock-task-overrun-text) (org-clock-mode-line-entry): Doc fix, "modeline" -> "mode line". * play/solitaire.el (solitaire-build-mode-line): Rename from solitaire-build-modeline. All callers changed. * play/zone.el (zone-hiding-mode-line): Rename from zone-hiding-modeline. All callers changed. (zone): Remove unusued `modeline-hidden-level' property. * progmodes/xscheme.el (xscheme-mode-line-initialize): Rename from xscheme-modeline-initialize. All callers changed. * textmodes/sgml-mode.el (html-face-tag-alist) (html-tag-face-alist): Use mode-line face instead of obsolete alias modeline. Fixes: debbugs:10329
2012-06-02 10:56:09 +00:00
"Display the current function name in the mode line."
2003-05-30 23:31:15 +00:00
:group 'tools
:version "20.3")
(defcustom which-func-modes t
;; '(emacs-lisp-mode c-mode c++-mode objc-mode perl-mode cperl-mode python-mode
;; 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
:version "24.3" ; explicit list -> t
2003-05-30 23:31:15 +00:00
: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)
(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.")
(defface which-func
;; 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."
:group 'which-func)
(defcustom which-func-format
`("["
(:propertize which-func-current
local-map ,which-func-keymap
face which-func
mouse-face mode-line-highlight
help-echo "mouse-1: go to beginning\n\
mouse-2: toggle rest visibility\n\
mouse-3: go to end")
"]")
2003-05-30 23:31:15 +00:00
"Format for displaying the function in the mode line."
:version "24.2" ; added mouse-face; 24point2 is correct
2003-05-30 23:31:15 +00:00
:group 'which-func
:type 'sexp)
;;;###autoload (put 'which-func-format 'risky-local-variable t)
(defvar which-func-imenu-joiner-function (lambda (x) (car (last x)))
"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.")
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.
Remove incorrect uses of "modeline". * ansi-color.el (ansi-color-faces-vector): Change default faces. * cus-edit.el (mode-line): * dframe.el (dframe-mouse-hscroll): * emacs-lisp/re-builder.el: * emacs-lisp/easy-mmode.el (define-minor-mode): * frame.el (set-frame-name): * help.el (lookup-minor-mode-from-indicator): * net/rcirc.el (rcirc-activity-string, rcirc-short-buffer-name): * progmodes/cc-cmds.el (c-toggle-auto-newline) (c-toggle-hungry-state): * progmodes/antlr-mode.el (antlr-language-alist): * progmodes/idlw-shell.el (idlwave-shell-electric-stop-line-face): * progmodes/vhdl-mode.el (vhdl-mode): * progmodes/which-func.el (which-func, which-func-cleanup-function): * term/ns-win.el (ns-face-at-pos): * term/sup-mouse.el (sup-mouse-report): * textmodes/flyspell.el (flyspell-mode-line-string): * textmodes/ispell.el (ispell-highlight-face): * textmodes/reftex-global.el: * vc/vc-arch.el (vc-arch-mode-line-string): * vc/vc-cvs.el (vc-cvs-mode-line-string): * vc/vc-git.el (vc-git-mode-line-string): * vc/vc-hooks.el (vc-display-status) (vc-default-mode-line-string): * vc/vc-mtn.el (vc-mtn-mode-line-string): Doc fixes. * dired.el (dired-sort-set-mode-line): Rename from dired-sort-set-modeline. All callers changed. * foldout.el (foldout-mode-line-string): Rename from foldout-modeline-string. All callers changed. (foldout-update-mode-line): Rename from foldout-update-modeline. * strokes.el (strokes-lighter): Rename from strokes-modeline-string. * subr.el (redraw-modeline): Make into obsolete alias. * calendar/timeclock.el (timeclock-mode-line-display): Rename from timeclock-modeline-display. Make old name an alias. (timeclock-update-mode-line): Likewise. All callers changed. (timeclock-mode-line-display): No need to check before using add-hook. (timeclock-relative, timeclock-day-over-hook) (timeclock-use-elapsed, timeclock-mode-string) (timeclock-mode-line-display): Doc fix, "modeline" -> "mode line". * emulation/crisp.el (crisp-mode-mode-line-string): Rename from crisp-mode-modeline-string. * erc-track.el (erc-track, erc-track-faces-priority-list) (erc-track-faces-normal-list, erc-track-find-face) (erc-track-modified-channels): Fix modeline -> mode line in docs. * eshell/esh-mode.el (eshell-status-in-mode-line): Rename from eshell-status-in-modeline. * org-clock.el (org-clock-string-limit) (org-clock-modeline-total, org-clock-task-overrun-text) (org-clock-mode-line-entry): Doc fix, "modeline" -> "mode line". * play/solitaire.el (solitaire-build-mode-line): Rename from solitaire-build-modeline. All callers changed. * play/zone.el (zone-hiding-mode-line): Rename from zone-hiding-modeline. All callers changed. (zone): Remove unusued `modeline-hidden-level' property. * progmodes/xscheme.el (xscheme-mode-line-initialize): Rename from xscheme-modeline-initialize. All callers changed. * textmodes/sgml-mode.el (html-face-tag-alist) (html-tag-face-alist): Use mode-line face instead of obsolete alias modeline. Fixes: debbugs:10329
2012-06-02 10:56:09 +00:00
Its return value is displayed in the mode line.
2003-05-30 23:31:15 +00:00
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 (replace-regexp-in-string
"%" "%%"
(or (gethash (selected-window) which-func-table)
which-func-unknown))))
2003-05-30 23:31:15 +00:00
;;;###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))))
(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
(unless (equal err
'(user-error "This buffer cannot use `imenu-default-create-index-function'"))
(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
(setq which-func-mode nil)
(error "Error in which-func-update: %S" info))))))
2003-05-30 23:31:15 +00:00
;;;###autoload
Use declare forms, where possible, to mark obsolete functions. * lisp/allout.el (allout-passphrase-hint-string): Likewise. (allout-init): Use a declare form to mark obsolete. * lisp/calendar/calendar.el (calendar-version): * lisp/calendar/icalendar.el (icalendar-extract-ical-from-buffer) (icalendar-convert-diary-to-ical): * lisp/cus-edit.el (custom-mode): * lisp/ansi-color.el (ansi-color-unfontify-region): * lisp/international/latin1-disp.el (latin1-char-displayable-p): * lisp/progmodes/cwarn.el (turn-on-cwarn-mode): * lisp/progmodes/which-func.el (which-func-update-1): Use define-obsolete-function-alias. * lisp/bookmark.el (bookmark-jump-noselect): Use a declare form to mark this function obsolete. * lisp/calendar/cal-x.el (calendar-two-frame-setup) (calendar-only-one-frame-setup, calendar-one-frame-setup): * lisp/calendar/calendar.el (american-calendar, european-calendar) (calendar-for-loop): * lisp/comint.el (comint-dynamic-simple-complete) (comint-dynamic-complete-as-filename, comint-unquote-filename): * lisp/desktop.el (desktop-load-default): * lisp/dired-x.el (dired-omit-here-always) (dired-hack-local-variables, dired-default-directory): * lisp/emacs-lisp/derived.el (derived-mode-class): * lisp/emacs-lisp/timer.el (timer-set-time-with-usecs): * lisp/emacs-lock.el (toggle-emacs-lock): * lisp/epa.el (epa-display-verify-result): * lisp/epg.el (epg-sign-keys, epg-start-sign-keys) (epg-passphrase-callback-function): * lisp/eshell/esh-util.el (eshell-for): * lisp/eshell/eshell.el (eshell-remove-from-window-buffer-names) (eshell-add-to-window-buffer-names): * lisp/files.el (locate-file-completion): * lisp/imenu.el (imenu-example--create-c-index) (imenu-example--create-lisp-index) (imenu-example--lisp-extract-index-name) (imenu-example--name-and-position): * lisp/international/mule-cmds.el (princ-list): * lisp/international/mule-diag.el (decode-codepage-char): * lisp/international/mule-util.el (detect-coding-with-priority): * lisp/iswitchb.el (iswitchb-read-buffer): * lisp/mail/mailalias.el (mail-complete): * lisp/mail/sendmail.el (mail-sent-via): * lisp/mouse.el (mouse-popup-menubar-stuff, mouse-popup-menubar) (mouse-major-mode-menu): * lisp/password-cache.el (password-read-and-add): * lisp/pcomplete.el (pcomplete-parse-comint-arguments): * lisp/progmodes/sh-script.el (sh-maybe-here-document): * lisp/replace.el (query-replace-regexp-eval): * lisp/savehist.el (savehist-load): * lisp/simple.el (choose-completion-delete-max-match): * lisp/term.el (term-dynamic-simple-complete): * lisp/vc/ediff-init.el (ediff-check-version): * lisp/vc/ediff-wind.el (ediff-choose-window-setup-function-automatically): * lisp/vc/vc.el (vc-diff-switches-list): * lisp/view.el (view-return-to-alist-update): Likewise. * lisp/iswitchb.el (iswitchb-read-buffer): Move code of iswitchb-define-mode-map here, and delete that obsolete function. * lisp/subr.el (eval-next-after-load, makehash, insert-string) (assoc-ignore-representation, assoc-ignore-case): Use declare to mark obsolete. (mode-line-inverse-video): Variable deleted. * lisp/emacs-lisp/byte-run.el (make-obsolete): Doc fix; emphasize that this applies to functions. * lisp/erc/erc.el (erc-send-command): Use define-obsolete-function-alias. * lisp/international/mule-util.el (string-to-sequence): Remove. * lisp/net/newst-backend.el (newsticker-cache-filename): * lisp/net/newst-treeview.el (newsticker-groups-filename): Fix incorrect obsolescence declaration. * lisp/net/snmp-mode.el (snmp-font-lock-keywords-3): Don't use obsolete font-lock-reference-face. * lisp/url/url-parse.el (url-recreate-url-attributes): * lisp/url/url-util.el (url-generate-unique-filename): Use declare to mark obsolete. * src/xdisp.c (mode_line_inverse_video): Delete obsolete variable.
2012-09-25 04:13:02 +00:00
(define-obsolete-function-alias 'which-func-mode 'which-function-mode "24.1")
2003-05-30 23:31:15 +00:00
(defvar which-func-update-timer nil)
;; This is the name people would normally expect.
;;;###autoload
(define-minor-mode which-function-mode
Fix more minor mode docstrings. * lisp/emulation/cua-base.el (cua-mode): * lisp/mail/footnote.el (footnote-mode): * lisp/mail/mailabbrev.el (mail-abbrevs-mode): * lisp/net/xesam.el (xesam-minor-mode): * lisp/progmodes/bug-reference.el (bug-reference-mode): * lisp/progmodes/cap-words.el (capitalized-words-mode): * lisp/progmodes/compile.el (compilation-minor-mode) (compilation-shell-minor-mode): * lisp/progmodes/gud.el (gud-tooltip-mode): * lisp/progmodes/hideif.el (hide-ifdef-mode): * lisp/progmodes/idlw-shell.el (idlwave-shell-electric-debug-mode): * lisp/progmodes/subword.el (subword-mode): * lisp/progmodes/vhdl-mode.el (vhdl-electric-mode, vhdl-stutter-mode): * lisp/progmodes/which-func.el (which-function-mode): * lisp/term/tvi970.el (tvi970-set-keypad-mode): * lisp/term/vt100.el (vt100-wide-mode): * lisp/textmodes/flyspell.el (flyspell-mode): * lisp/textmodes/ispell.el (ispell-minor-mode): * lisp/textmodes/nroff-mode.el (nroff-electric-mode): * lisp/textmodes/paragraphs.el (use-hard-newlines): * lisp/textmodes/refill.el (refill-mode): * lisp/textmodes/reftex.el (reftex-mode): * lisp/textmodes/rst.el (rst-minor-mode): * lisp/textmodes/sgml-mode.el (html-autoview-mode) (sgml-electric-tag-pair-mode): * lisp/textmodes/tex-mode.el (latex-electric-env-pair-mode): * lisp/vc/diff-mode.el (diff-auto-refine-mode, diff-minor-mode): * lisp/emulation/crisp.el (crisp-mode): * lisp/emacs-lisp/eldoc.el (eldoc-mode): * lisp/emacs-lisp/checkdoc.el (checkdoc-minor-mode): Doc fixes for new minor mode behavior. * lisp/erc/erc-fill.el (erc-fill-mode): * lisp/erc/erc-track.el (erc-track-minor-mode): Doc fix. * lisp/erc/erc.el (define-erc-module): Fix autogenerated docstring to reflect Emacs 24 minor mode changes. * lisp/gnus/gnus-cite.el (gnus-message-citation-mode): Doc fix (in Emacs 24, calling a minor mode from Lisp with nil arg enables it, so we have to make the working a bit ambiguous here).
2011-10-20 00:26:14 +00:00
"Toggle mode line display of current function (Which Function mode).
With a prefix argument ARG, enable Which Function mode if ARG is
positive, and disable it otherwise. If called from Lisp, enable
the mode if ARG is omitted or nil.
Which Function mode is a global minor mode. When enabled, the
current function name is continuously displayed in the mode line,
in certain major modes."
2003-05-30 23:31:15 +00:00
:global t :group 'which-func
(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.")
(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.
Uses `which-func-functions', `imenu--index-alist'
or `add-log-current-defun'.
2003-05-30 23:31:15 +00:00
If no function name is found, return nil."
(let ((name
;; Try the `which-func-functions' functions first.
(run-hook-with-args-until-success 'which-func-functions)))
2003-05-30 23:31:15 +00:00
;; If Imenu is loaded, try to make an index alist with it.
(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))
(ignore-errors (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 20:00:25 +00: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.
(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))
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)
(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)))
((or (number-or-marker-p (setq mark (cdr pair)))
(and (overlayp mark)
(setq mark (overlay-start mark))))
(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))))))))))))
2003-05-30 23:31:15 +00:00
;; Try using add-log support.
(when (null name)
(setq name (add-log-current-defun)))
2003-05-30 23:31:15 +00:00
;; Filter the name if requested.
(when name
(if which-func-cleanup-function
(funcall which-func-cleanup-function name)
name))))
;;; Integration with other packages
(defvar ediff-window-A)
(defvar ediff-window-B)
(defvar ediff-window-C)
(defun which-func-update-ediff-windows ()
"Update Which-Function mode display for Ediff windows.
This function is meant to be called from `ediff-select-hook'."
(when (eq major-mode 'ediff-mode)
(when ediff-window-A
(which-func-update-1 ediff-window-A))
(when ediff-window-B
(which-func-update-1 ediff-window-B))
(when ediff-window-C
(which-func-update-1 ediff-window-C))))
(add-hook 'ediff-select-hook 'which-func-update-ediff-windows)
2003-05-30 23:31:15 +00:00
(provide 'which-func)
;;; which-func.el ends here