mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-03 11:33:37 +00:00
(imenu, imenu--flatten-index-alist): Add marker support.
(imenu--cleanup): New function. (imenu-example--name-and-position): Now uses markers. (imenu-add-to-menubar): New function to add an entry to the menubar for the buffer's current local keymap.
This commit is contained in:
parent
f150bd2b3e
commit
5d3b0f182f
@ -5,7 +5,7 @@
|
|||||||
;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se>
|
;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se>
|
||||||
;; Lars Lindberg <lli@sypro.cap.se>
|
;; Lars Lindberg <lli@sypro.cap.se>
|
||||||
;; Created: 8 Feb 1994
|
;; Created: 8 Feb 1994
|
||||||
;; Version: 1.7
|
;; Version: 1.11
|
||||||
;; Keywords: tools
|
;; Keywords: tools
|
||||||
;;
|
;;
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
@ -43,6 +43,15 @@
|
|||||||
;; supplied.
|
;; supplied.
|
||||||
|
|
||||||
;;; Change Log:
|
;;; Change Log:
|
||||||
|
;; v1.11 Jul 26 1994 Ake Stenhoff
|
||||||
|
;; Fixed bugs in 'imenu-add-to-menubar'.
|
||||||
|
;; v1.10 Jul 21 1994 Ake Stenhoff
|
||||||
|
;; Added support for markers.
|
||||||
|
;; Changed the examples to use
|
||||||
|
;; markers.
|
||||||
|
;; Thanks [alon].
|
||||||
|
;; v1.9 Jun 14 1994 Ake Stenhoff
|
||||||
|
;; Added 'imenu-add-to-menubar'.
|
||||||
;; v1.7 Apr 12 1994 Ake Stenhoff
|
;; v1.7 Apr 12 1994 Ake Stenhoff
|
||||||
;; Changed doc strings refering to symbols.
|
;; Changed doc strings refering to symbols.
|
||||||
;; Require 'cl' when compiling only.
|
;; Require 'cl' when compiling only.
|
||||||
@ -77,7 +86,7 @@
|
|||||||
;;; Thanks goes to
|
;;; Thanks goes to
|
||||||
;; [simon] - Simon Leinen simon@lia.di.epfl.ch
|
;; [simon] - Simon Leinen simon@lia.di.epfl.ch
|
||||||
;; [dean] - Dean Andrews ada@unison.com
|
;; [dean] - Dean Andrews ada@unison.com
|
||||||
;;
|
;; [alon] - Alon Albert al@mercury.co.il
|
||||||
|
|
||||||
;;; Code
|
;;; Code
|
||||||
(eval-when-compile (require 'cl))
|
(eval-when-compile (require 'cl))
|
||||||
@ -287,7 +296,25 @@ This function is called after the function pointed out by
|
|||||||
(error "No items suitable for an index found in this buffer."))
|
(error "No items suitable for an index found in this buffer."))
|
||||||
;; Add a rescan option to the index.
|
;; Add a rescan option to the index.
|
||||||
(cons imenu--rescan-item imenu--index-alist))
|
(cons imenu--rescan-item imenu--index-alist))
|
||||||
|
;;;
|
||||||
|
;;; Find all markers in alist and makes
|
||||||
|
;;; them point nowhere.
|
||||||
|
;;;
|
||||||
|
(defun imenu--cleanup (&optional alist)
|
||||||
|
;; Sets the markers in imenu--index-alist
|
||||||
|
;; point nowhere.
|
||||||
|
;; if alist is provided use that list.
|
||||||
|
(and imenu--index-alist
|
||||||
|
(mapc
|
||||||
|
(function
|
||||||
|
(lambda (item)
|
||||||
|
(cond
|
||||||
|
((markerp (cdr item))
|
||||||
|
(set-marker (cdr item) nil))
|
||||||
|
((listp (cdr item))
|
||||||
|
(imenu--cleanup (cdr item))))))
|
||||||
|
(if alist alist imenu--index-alist))
|
||||||
|
t))
|
||||||
(defun imenu-default-create-index-function ()
|
(defun imenu-default-create-index-function ()
|
||||||
"*Wrapper for index searching functions.
|
"*Wrapper for index searching functions.
|
||||||
|
|
||||||
@ -350,7 +377,7 @@ Their results are gathered into an index alist."
|
|||||||
(concat prefix imenu-level-separator name)
|
(concat prefix imenu-level-separator name)
|
||||||
name))))
|
name))))
|
||||||
(cond
|
(cond
|
||||||
((numberp pos)
|
((or (markerp pos) (numberp pos))
|
||||||
(list (cons new-prefix pos)))
|
(list (cons new-prefix pos)))
|
||||||
(t
|
(t
|
||||||
(imenu--flatten-index-alist pos new-prefix))))))
|
(imenu--flatten-index-alist pos new-prefix))))))
|
||||||
@ -468,9 +495,20 @@ The returned value is on the form (INDEX-NAME . INDEX-POSITION)."
|
|||||||
(imenu--mouse-menu index-alist last-nonmenu-event)
|
(imenu--mouse-menu index-alist last-nonmenu-event)
|
||||||
(imenu--completion-buffer index-alist prompt)))
|
(imenu--completion-buffer index-alist prompt)))
|
||||||
(and (eq result t)
|
(and (eq result t)
|
||||||
|
(imenu--cleanup)
|
||||||
(setq imenu--index-alist nil)))
|
(setq imenu--index-alist nil)))
|
||||||
result))
|
result))
|
||||||
|
|
||||||
|
(defun imenu-add-to-menubar (name)
|
||||||
|
"Adds an \"imenu\" entry to the menubar for the
|
||||||
|
current local keymap.
|
||||||
|
NAME is the string naming the menu to be added.
|
||||||
|
See 'imenu' for more information."
|
||||||
|
(interactive "sMenu name: ")
|
||||||
|
(and window-system
|
||||||
|
(define-key (current-local-map) [menu-bar index]
|
||||||
|
(cons name 'imenu))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun imenu ()
|
(defun imenu ()
|
||||||
"Jump to a place in the buffer chosen using a buffer menu or mouse menu.
|
"Jump to a place in the buffer chosen using a buffer menu or mouse menu.
|
||||||
@ -480,7 +518,12 @@ See `imenu-choose-buffer-index' for more information."
|
|||||||
(and index-item
|
(and index-item
|
||||||
(progn
|
(progn
|
||||||
(push-mark)
|
(push-mark)
|
||||||
(goto-char (cdr index-item))))))
|
(cond
|
||||||
|
((markerp (cdr index-item))
|
||||||
|
(goto-char (marker-position (cdr index-item))))
|
||||||
|
(t
|
||||||
|
(goto-char (cdr index-item))))))))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;;
|
;;;;
|
||||||
@ -495,9 +538,11 @@ See `imenu-choose-buffer-index' for more information."
|
|||||||
(save-excursion
|
(save-excursion
|
||||||
(forward-sexp -1)
|
(forward-sexp -1)
|
||||||
(let ((beg (point))
|
(let ((beg (point))
|
||||||
(end (progn (forward-sexp) (point))))
|
(end (progn (forward-sexp) (point)))
|
||||||
|
(marker (make-marker)))
|
||||||
|
(set-marker marker beg)
|
||||||
(cons (buffer-substring beg end)
|
(cons (buffer-substring beg end)
|
||||||
beg))))
|
marker))))
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; Lisp
|
;;; Lisp
|
||||||
|
Loading…
Reference in New Issue
Block a user