GNU bug report logs - #9199
Imenu does not work any more with C/C++ mode

Previous Next

Packages: cc-mode, emacs;

Reported by: Angelo Graziosi <angelo.graziosi <at> alice.it>

Date: Fri, 29 Jul 2011 21:05:01 UTC

Severity: important

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 9199 in the body.
You can then email your comments to 9199 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#9199; Package emacs. (Fri, 29 Jul 2011 21:05:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Angelo Graziosi <angelo.graziosi <at> alice.it>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 29 Jul 2011 21:05:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Angelo Graziosi <angelo.graziosi <at> alice.it>
To: bug-emacs <bug-gnu-emacs <at> gnu.org>
Subject: Imenu does not work any more with C/C++ mode
Date: Fri, 29 Jul 2011 23:04:38 +0200
$ cat init.el
(add-hook 'c-mode-hook
          '(lambda()
             (imenu-add-to-menubar "Functions")
             )
          )


$ cat test.c
int main(){}
void foo1(){}
void foo2(){}
void foo2(){}

$ emacs test.c &

Now click on 'Functions' in the menu bar, the result is as in

https://lists.gnu.org/archive/html/emacs-devel/2011-07/jpgDDUvliLSqM.jpg

the drop-down menu is very very compressed. The same occurs with c-mode 
--> c++-mode.

If I remove init.el completely and

$ emacs test.c &
M-x imenu-add-to-menubar <RET>
Functions <RET>

Now clicking on Functions works as expected!

If in the above init.el file I change c-mode with f90, fortran, sh... it 
works right.

The last trunk I can test and with which it works with C/C++, is rev. 
104859 (july 1 or 2).


Ciao,
  Angelo.




Severity set to 'important' from 'normal' Request was from Stefan Monnier <monnier <at> iro.umontreal.ca> to control <at> debbugs.gnu.org. (Thu, 15 Mar 2012 01:36:01 GMT) Full text and rfc822 format available.

Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Thu, 15 Mar 2012 02:10:01 GMT) Full text and rfc822 format available.

Notification sent to Angelo Graziosi <angelo.graziosi <at> alice.it>:
bug acknowledged by developer. (Thu, 15 Mar 2012 02:10:02 GMT) Full text and rfc822 format available.

Message #12 received at 9199-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Angelo Graziosi <angelo.graziosi <at> alice.it>
Cc: 9199-done <at> debbugs.gnu.org
Subject: Re: bug#9199: Imenu does not work any more with C/C++ mode
Date: Wed, 14 Mar 2012 21:39:07 -0400
> $ cat init.el
> (add-hook 'c-mode-hook
>           '(lambda()
>              (imenu-add-to-menubar "Functions")
>              )
>           )

Running for the Useless Use of Quote Award? ;-)

> $ cat test.c
> int main(){}
> void foo1(){}
> void foo2(){}
> void foo2(){}
> $ emacs test.c &
> Now click on 'Functions' in the menu bar, the result is as in

Hmm... indeed.

> If I remove init.el completely and
> $ emacs test.c &
> M-x imenu-add-to-menubar <RET>
> Functions <RET>
> Now clicking on Functions works as expected!

Yup: the reason why this (and other major modes) works is that the bug
only manifests itself if you call imenu-add-to-menubar more than once
(and it so happens that c-mode-hook is run twice for some reason).

I believe this is fixed in the trunk now thanks the the patch below,


        Stefan


=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-03-13 23:27:56 +0000
+++ lisp/ChangeLog	2012-03-15 01:37:45 +0000
@@ -1,3 +1,9 @@
+2012-03-15  Stefan Monnier  <monnier <at> iro.umontreal.ca>
+
+	* imenu.el: Fix multiple inheritance breakage (bug#9199).
+	(imenu-add-to-menubar): Don't add a redundant index.
+	(imenu-update-menubar): Handle a dynamically composed keymap.
+
 2012-03-13  Katsumi Yamaoka  <yamaoka <at> jpl.org>
 
 	* mail/sendmail.el (mail-encode-header):

=== modified file 'lisp/imenu.el'
--- lisp/imenu.el	2012-01-19 07:21:25 +0000
+++ lisp/imenu.el	2012-03-15 01:32:35 +0000
@@ -963,13 +963,14 @@
 	  imenu-generic-expression
 	  (not (eq imenu-create-index-function
 		   'imenu-default-create-index-function)))
+      (unless (keymapp (lookup-key (current-local-map) [menu-bar index]))
       (let ((newmap (make-sparse-keymap)))
 	(set-keymap-parent newmap (current-local-map))
 	(setq imenu--last-menubar-index-alist nil)
 	(define-key newmap [menu-bar index]
 	  `(menu-item ,name ,(make-sparse-keymap "Imenu")))
 	(use-local-map newmap)
-	(add-hook 'menu-bar-update-hook 'imenu-update-menubar))
+	  (add-hook 'menu-bar-update-hook 'imenu-update-menubar)))
     (error "The mode `%s' does not support Imenu"
            (format-mode-line mode-name))))
 
@@ -1008,6 +1009,9 @@
 						   (car (cdr menu))))
 					    'imenu--menubar-select))
 	  (setq old (lookup-key (current-local-map) [menu-bar index]))
+	  ;; This should never happen, but in some odd cases, potentially,
+	  ;; lookup-key may return a dynamically composed keymap.
+	  (if (keymapp (cadr old)) (setq old (cadr old)))
 	  (setcdr old (cdr menu1)))))))
 
 (defun imenu--menubar-select (item)





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 12 Apr 2012 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 69 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.