changeset 16272:b64d00e44e7b

(imenu--split-menu): Keep the rescan item at top level. Keep subalists at top level too. Name the split-off submenus from the first item in them. (imenu--generic-function): Avoid adding nil as elt of the result.
author Richard M. Stallman <rms@gnu.org>
date Sat, 21 Sep 1996 23:00:40 +0000
parents 00bece0cd6c2
children 14ff4afa06ec
files lisp/imenu.el
diffstat 1 files changed, 31 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/imenu.el	Sat Sep 21 22:32:10 1996 +0000
+++ b/lisp/imenu.el	Sat Sep 21 23:00:40 1996 +0000
@@ -406,25 +406,35 @@
 ;;; 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)
-  (if imenu-sort-function
-      (setq menulist
-	    (sort
-	     (let ((res nil)
-		   (oldlist menulist))
-	       ;; Copy list method from the cl package `copy-list'
-	       (while (consp oldlist) (push (pop oldlist) res))
-	       (prog1 (nreverse res) (setcdr res oldlist)))
-	     imenu-sort-function)))
-  (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)))
+  (let (keep-at-top tail)
+    (if (memq imenu--rescan-item menulist)
+	(setq keep-at-top (cons imenu--rescan-item nil)
+	      menulist (delq imenu--rescan-item menulist)))
+    (setq tail menulist)
+    (while tail
+      (if (imenu--subalist-p (car tail))
+	  (setq keep-at-top (cons (car tail) keep-at-top)
+		menulist (delq (car tail) menulist)))
+      (setq tail (cdr tail)))
+    (if imenu-sort-function
+	(setq menulist
+	      (sort
+	       (let ((res nil)
+		     (oldlist menulist))
+		 ;; Copy list method from the cl package `copy-list'
+		 (while (consp oldlist) (push (pop oldlist) res))
+		 (prog1 (nreverse res) (setcdr res oldlist)))
+	       imenu-sort-function)))
+    (if (> (length menulist) imenu-max-items)
+	(let ((count 0))
+	  (setq menulist
+		(mapcar
+		 (function
+		  (lambda (menu)
+		    (cons (format "From: %s" (caar menu)) menu)))
+		 (imenu--split menulist imenu-max-items)))))
+    (cons title
+	  (nconc (nreverse keep-at-top) menulist))))
 
 ;;; Split up each long alist that are nested within ALIST
 ;;; into nested alists.
@@ -675,7 +685,8 @@
 	   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))))
+      (nconc (delq main-element (delq 'dummy index-alist))
+	     (cdr main-element)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;