changeset 14726:35e1cfdd29a4

(imenu--menubar-select): No longer interactive. (imenu-create-submenu-name): Function deleted. (imenu-example--create-lisp-index): Don't use it. (imenu--generic-function): Don't use imenu-create-submenu-name. (imenu-submenu-name-format): Variable deleted. (imenu--split-menu): Use TITLE as the head of the new list. Don't split if everything fits in one level. (imenu--split-submenus): New function. (imenu-update-menubar): Use imenu--split-submenus. (imenu--mouse-menu): Use imenu--split-submenus.
author Richard M. Stallman <rms@gnu.org>
date Fri, 01 Mar 1996 18:09:57 +0000
parents eeffb8e882b4
children 78cb76d091af
files lisp/imenu.el
diffstat 1 files changed, 35 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/imenu.el	Fri Mar 01 17:09:00 1996 +0000
+++ b/lisp/imenu.el	Fri Mar 01 18:09:57 1996 +0000
@@ -98,7 +98,7 @@
 \(NAME . POSITION).  Look at `imenu--sort-by-name' for an example.")
 
 (defvar imenu-max-items 25
-  "*Maximum number of elements in an index mouse-menu.")
+  "*Maximum number of elements in an mouse menu for Imenu.")
 
 (defvar imenu-scanning-message "Scanning buffer for index (%3d%%)"
   "*Progress message during the index scanning of the buffer.
@@ -117,9 +117,6 @@
 Used for making mouse-menu titles and for flattening nested indexes
 with name concatenation.")
 
-(defvar imenu-submenu-name-format "%s"
-  "*The format for making a submenu name.")
-
 ;;;###autoload
 (defvar imenu-generic-expression nil
   "The regex pattern to use for creating a buffer index.
@@ -282,13 +279,13 @@
 		       index-unknown-alist)))))))
     (imenu-progress-message prev-pos 100)
     (and index-var-alist
-	 (push (cons (imenu-create-submenu-name "Variables") index-var-alist)
+	 (push (cons "Variables" index-var-alist)
 	       index-alist))
     (and index-type-alist
- 	 (push (cons (imenu-create-submenu-name "Types") index-type-alist)
+ 	 (push (cons "Types" index-type-alist)
   	       index-alist))
     (and index-unknown-alist
-	 (push (cons (imenu-create-submenu-name "Syntax-unknown") index-unknown-alist)
+	 (push (cons "Syntax-unknown" index-unknown-alist)
 	       index-alist))
     index-alist))
 
@@ -372,14 +369,6 @@
 	(/ (1- pos) (max (/ total 100) 1))
       (/ (* 100 (1- pos)) (max total 1)))))
 
-;;;
-;;; Function for supporting general looking submenu names.
-;;; Uses `imenu-submenu-name-format' for creating the name.
-;;; NAME is the base of the new submenu name.
-;;;
-(defun imenu-create-submenu-name (name)
-   (format imenu-submenu-name-format name))
-
 ;; Split LIST into sublists of max length N.
 ;; Example (imenu--split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8))
 (defun imenu--split (list n)
@@ -401,16 +390,30 @@
 	 (push (nreverse sublist) result))
     (nreverse result)))
 
-;;;
-;;; Split a menu in to several menus.
-;;;
+;;; Split the alist MENULIST into a nested alist, if it is long enough.
+;;; In any case, add TITLE to the front of the alist.
 (defun imenu--split-menu (menulist title)
-  (cons "Index menu"
-	(mapcar
-	 (function
-	  (lambda (menu)
-	    (cons (format "(%s)" title) menu)))
-	 (imenu--split menulist imenu-max-items))))
+  (if (> (length menulist) imenu-max-items)
+      (let ((count 0))
+	(cons title
+	      (mapcar
+	       (function
+		(lambda (menu)
+		  (cons (format "(%s-%d)" title (setq count (1+ count)))
+			menu)))
+	       (imenu--split menulist imenu-max-items))))
+    (cons title menulist)))
+
+;;; Split up each long alist that are nested within ALIST
+;;; into nested alists.
+(defun imenu--split-submenus (alist)
+  (mapcar (function (lambda (elt)
+		      (if (and (consp elt)
+			       (stringp (car elt))
+			       (listp (cdr elt)))
+			  (imenu--split-menu (cdr elt) (car elt))
+			elt)))
+	  alist))
 
 ;;;
 ;;; Find all items in this buffer that should be in the index.
@@ -629,18 +632,14 @@
 			  (push 
 			   (cons (buffer-substring-no-properties beg end) beg)
 			   (cdr 
-			    (or (if (not (stringp menu-title)) index-alist) 
-				(assoc 
-				 (imenu-create-submenu-name menu-title) 
-				 index-alist)
+			    (or (assoc menu-title index-alist)
 				(car (push 
-				      (cons 
-				       (imenu-create-submenu-name menu-title) 
-				       '()) 
+				      (cons menu-title '()) 
 				      index-alist))))))))))
-	    patterns))))
-      (imenu-progress-message prev-pos 100 t)
-      (delete 'dummy index-alist)))
+	   patterns))))
+    (imenu-progress-message prev-pos 100 t)
+    (let ((main-element (assq nil index-alist)))
+      (nconc (delq main-element (delq 'dummy index-alist)) main-element))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;
@@ -696,6 +695,7 @@
 INDEX-ALIST is the buffer index and EVENT is a mouse event.
 
 Returns t for rescan and otherwise a position number."
+  (setq index-alist (imenu--split-submenus index-alist))
   (let* ((menu 	(imenu--split-menu
 		 (if imenu-sort-function
 		     (sort
@@ -810,6 +810,7 @@
 	 (or (equal index-alist imenu--last-menubar-index-alist)
 	     (let (menu menu1 old)
 	       (setq imenu--last-menubar-index-alist index-alist)
+	       (setq index-alist (imenu--split-submenus index-alist))
 	       (setq menu (imenu--split-menu
 			   (if imenu-sort-function
 			       (sort
@@ -832,7 +833,6 @@
 
 (defun imenu--menubar-select (item)
   "Use Imenu to select the function or variable named in this menu item."
-  (interactive)
   (imenu item))
 
 ;;;###autoload