summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1997-03-22 23:42:48 +0000
committerRichard M. Stallman <rms@gnu.org>1997-03-22 23:42:48 +0000
commitb1e486dab98cd428b82704fbe90519f06b8c6103 (patch)
tree1b4aca165617103471f5bdc9be725335b9c97238
parent7e5d3b9da1695ca6645e9541a40ac2c280b78a5d (diff)
downloademacs-b1e486dab98cd428b82704fbe90519f06b8c6103.tar.gz
(imenu-scanning-message): Support for bigger numbers.
(imenu--generic-function): Fixed probably a typo: named appeared twice in an item. Put function after name and beg in a special item because a normal item has name and beg (for orthogonality). (imenu-add-to-menubar): First test to see if the mode supports imenu. (imenu--menubar-select): Use the defined variable imenu-rescan-item. (imenu-default-goto-function): New subroutine, broken out of `imenu'. (imenu-default-goto-function): New variable. (imenu): Made it use the above function, via that variable.
-rw-r--r--lisp/imenu.el92
1 files changed, 56 insertions, 36 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el
index 1ddd70dcfd2..ea22884cfb0 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -98,7 +98,7 @@ element should come before the second. The arguments are cons cells;
(defvar imenu-max-items 25
"*Maximum number of elements in an mouse menu for Imenu.")
-(defvar imenu-scanning-message "Scanning buffer for index...%2d%%"
+(defvar imenu-scanning-message "Scanning buffer for index (%3d%%)"
"*Progress message during the index scanning of the buffer.
If non-nil, user gets a message during the scanning of the buffer.
@@ -191,6 +191,12 @@ This function is called after the function pointed out by
`imenu-prev-index-position-function'.")
(make-variable-buffer-local 'imenu-extract-index-name-function)
+(defvar imenu-default-goto-function 'imenu-default-goto-function
+ "The default function called when selecting an Imenu item.
+The function in this variable is called when selecting a normal index-item.")
+(make-variable-buffer-local 'imenu-default-goto-function)
+
+
(defun imenu--subalist-p (item)
(and (consp (cdr item)) (listp (cadr item))
(not (eq (caadr item) 'lambda))))
@@ -685,7 +691,7 @@ pattern.
(let ((name
(buffer-substring-no-properties beg end)))
(if function
- (nconc (list name function name beg)
+ (nconc (list name beg function)
rest)
(cons name beg)))
(cdr
@@ -838,15 +844,19 @@ The returned value is of the form (INDEX-NAME . INDEX-POSITION)."
NAME is a string used to name the menu bar item.
See the command `imenu' for more information."
(interactive "sImenu menu item name: ")
- (let ((newmap (make-sparse-keymap))
- (menu-bar (lookup-key (current-local-map) [menu-bar])))
- (define-key newmap [menu-bar]
- (append (make-sparse-keymap) menu-bar))
- (define-key newmap [menu-bar index]
- (cons name (nconc (make-sparse-keymap "Imenu")
- (make-sparse-keymap))))
- (use-local-map (append newmap (current-local-map))))
- (add-hook 'menu-bar-update-hook 'imenu-update-menubar))
+ (if (or (and (fboundp imenu-prev-index-position-function)
+ (fboundp imenu-extract-index-name-function))
+ (and imenu-generic-expression))
+ (let ((newmap (make-sparse-keymap))
+ (menu-bar (lookup-key (current-local-map) [menu-bar])))
+ (define-key newmap [menu-bar]
+ (append (make-sparse-keymap) menu-bar))
+ (define-key newmap [menu-bar index]
+ (cons name (nconc (make-sparse-keymap "Imenu")
+ (make-sparse-keymap))))
+ (use-local-map (append newmap (current-local-map)))
+ (add-hook 'menu-bar-update-hook 'imenu-update-menubar))
+ (error "The mode `%s' does not support Imenu" mode-name)))
(defvar imenu-buffer-menubar nil)
@@ -872,13 +882,39 @@ See the command `imenu' for more information."
(defun imenu--menubar-select (item)
"Use Imenu to select the function or variable named in this menu item."
- (if (equal item '("*Rescan*" . -99))
+ (if (equal item imenu--rescan-item)
(progn
(imenu--cleanup)
(setq imenu--index-alist nil)
(imenu-update-menubar))
(imenu item)))
+(defun imenu-default-goto-function (name position &optional rest)
+"This function is used for moving the point at POSITION.
+The NAME and REST parameters are not used, they are here just to make
+this function have the same interface as a function placed in a special
+index-item"
+ (cond
+ ((markerp position)
+ (if (or (< (marker-position position) (point-min))
+ (> (marker-position position) (point-max)))
+ ;; widen if outside narrowing
+ (widen))
+ (goto-char (marker-position position)))
+;;; ;this never happens!
+;;; ((imenu--subalist-p index-item)
+;;; (if (or (< (cdr index-item) (point-min))
+;;; (> (cdr index-item) (point-max)))
+;;; ;; widen if outside narrowing
+;;; (widen))
+;;; (goto-char (cdr index-item)))
+ (t
+ (if (or (< (cdr index-item) (point-min))
+ (> (cdr index-item) (point-max)))
+ ;; widen if outside narrowing
+ (widen))
+ (goto-char (cdr index-item)))))
+
;;;###autoload
(defun imenu (index-item)
"Jump to a place in the buffer chosen using a buffer menu or mouse menu.
@@ -890,30 +926,14 @@ See `imenu-choose-buffer-index' for more information."
(and index-item
(progn
(push-mark)
- (cond
- ((markerp (cdr index-item))
- (if (or (< (marker-position (cdr index-item)) (point-min))
- (> (marker-position (cdr index-item)) (point-max)))
- ;; widen if outside narrowing
- (widen))
- (goto-char (marker-position (cdr index-item))))
- ((imenu--subalist-p index-item)
- (if (or (< (cdr index-item) (point-min))
- (> (cdr index-item) (point-max)))
- ;; widen if outside narrowing
- (widen))
- (goto-char (cdr index-item)))
- ((integerp (cdr index-item))
- (if (or (< (cdr index-item) (point-min))
- (> (cdr index-item) (point-max)))
- ;; widen if outside narrowing
- (widen))
- (goto-char (cdr index-item)))
- (t
- ;; A special item with a function.
- (let ((function (cadr index-item))
- (rest (cddr index-item)))
- (apply function (car index-item) rest)))))))
+ (let* ((is-special-item (listp (cdr index-item)))
+ (function
+ (if is-special-item
+ (caddr index-item) imenu-default-goto-function))
+ (position (if is-special-item
+ (cadr index-item) (cdr index-item)))
+ (rest (if is-special-item (cddr index-item))))
+ (apply function (car index-item) position rest)))))
(provide 'imenu)