Subject: bug#13576: 24.2.92; [PATCH] a bug in imenu--truncate-items

From: Leo Liu <[email-masked]>
Date: Tue, 29 Jan 2013 15:22:12 +0800

On 2013-01-29 10:25 +0800, Stefan Monnier wrote:
> Looks right, please install it in trunk,

I'll install something along these lines which also truncate the
car of a sub-alist.

diff --git a/lisp/imenu.el b/lisp/imenu.el
index 80dacf93..1d721659 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -555,16 +555,14 @@ (defun imenu--split-submenus (alist)
 
 (defun imenu--truncate-items (menulist)
   "Truncate all strings in MENULIST to `imenu-max-item-length'."
-  (mapcar (lambda (item)
-            (cond
-             ((consp (cdr item))
-              (imenu--truncate-items (cdr item)))
-             ;; truncate if necessary
-             ((and (numberp imenu-max-item-length)
-                   (> (length (car item)) imenu-max-item-length))
-              (setcar item (substring (car item) 0 imenu-max-item-length)))))
-	  menulist))
-
+  (mapc (lambda (item)
+	  ;; truncate if necessary
+	  (when (and (numberp imenu-max-item-length)
+		     (> (length (car item)) imenu-max-item-length))
+	    (setcar item (substring (car item) 0 imenu-max-item-length)))
+	  (when (imenu--subalist-p item)
+	    (imenu--truncate-items (cdr item))))
+	menulist))
 
 (defun imenu--make-index-alist (&optional noerror)
   "Create an index alist for the definitions in the current buffer.