emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error in C++ mode with Emacs 27.0.90


From: Alan Mackenzie
Subject: Re: Error in C++ mode with Emacs 27.0.90
Date: Sat, 28 Mar 2020 20:10:57 +0000
User-agent: Mutt/1.10.1 (2018-07-13)

Hello again, Angelo.

On Sat, Mar 28, 2020 at 18:34:50 +0100, Angelo Graziosi wrote:

> > Il 28 marzo 2020 alle 16.19 Alan Mackenzie ha scritto:


> > The function where things go wrong is imenu-update-menubar, in the "else"
> > branch of the single `if' form in the function.

> > I hope to have time soon to look into this more thoroughly, assuming
> > nobody else does first.  ;-)

OK, the problem was imenu-update-menubar's handling of nested imenu
element lists.  (Somewhat simplified) the function was inadequately
recognising a nested list by testing the list's length being 1.  With
such a list, it then attempted to strip the enclosing (superfluous)
verbiage.

However when the list had a single elemental element, such as the
function "main", it threw an exception on attempting to strip the
non-existent enclosing level.

I think the following patch fixes the trouble.  Please try it out and
report on this list how well it works.  Thanks:



diff --git a/lisp/imenu.el b/lisp/imenu.el
index fb8b3de662..7d25c2bf91 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -911,11 +911,21 @@ imenu-update-menubar
         (setq index-alist (imenu--split-submenus index-alist))
        (let* ((menu (imenu--split-menu index-alist
                                         (buffer-name)))
-               (menu1 (imenu--create-keymap (car menu)
-                                           (cdr (if (< 1 (length (cdr menu)))
-                                                    menu
-                                                  (car (cdr menu))))
-                                           'imenu--menubar-select)))
+               (menu1 (imenu--create-keymap
+                       (car menu)
+                      (cdr
+                        (cond
+                         ((cddr menu)
+                          ;; (cdr menu) is a list of len > 1
+                          menu)
+                         ((and (consp (cdadr menu))
+                               ;; POSITION of a "Special element" is an atom:
+                               (consp (cadadr menu)))
+                          ;; Discard the enclosing level of the nested list.
+                          (cadr menu))
+                         (t             ; Non-nested list of length 1
+                          menu)))
+                      'imenu--menubar-select)))
          (setcdr imenu--menubar-keymap (cdr menu1)))))))
 
 (defun imenu--menubar-select (item)



> Thanks!

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]