changeset 17229:b48a8dd2d8ce

(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.
author Richard M. Stallman <rms@gnu.org>
date Sat, 22 Mar 1997 23:42:48 +0000
parents b64f5f132d96
children 1c853c91aaf0
files lisp/imenu.el
diffstat 1 files changed, 56 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/imenu.el	Sat Mar 22 07:36:21 1997 +0000
+++ b/lisp/imenu.el	Sat Mar 22 23:42:48 1997 +0000
@@ -98,7 +98,7 @@
 (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 @@
 `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 @@
 		       (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 @@
 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 @@
 
 (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 @@
   (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)