[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#3153: 23.0.60; which-func-mode (C++) confused when mixing structs/fu
From: |
Geert Kloosterman |
Subject: |
bug#3153: 23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included) |
Date: |
Tue, 28 Apr 2009 21:26:28 +0200 |
In GNU Emacs 23.0.60.1 (i686-pc-linux-gnu, GTK+ Version 2.12.0)
of 2008-11-26 on geert-laptop
Windowing system distributor `The X.Org Foundation', version 11.0.10300000
When a C/C++ file contains mixed struct/function definitions,
which-func-mode gets confused.
To reproduce (see also the comments in the test case file):
1. open the test case file whichfunc-testcase.cpp
2. make sure which-func-mode is enabled (M-x which-func-mode)
3. put the point within the funcA() definition
4. the modeline shows "structA", not the expected "funcA"
In the following I'll describe the problem in somewhat more detail.
In `which-function()' it is assumed that the entries from
`imenu--index-alist' are ordered by buffer possition. `which-function()'
does a linear search through the items, and as soon as a buffer position
is encountered greater than point, the search stops. However, when
submenu's are present in `imenu--index-alist', the items are not
necessarily ordered by buffer position anymore:
For the testcase the imenu--index-alist variable looks like this:
(("Class"
("structA" . #<marker at 2 in whichfunc-testcase.cpp>)
("structB" . #<marker at 63 in whichfunc-testcase.cpp>))
("funcA" . #<marker at 34 in whichfunc-testcase.cpp>)
("funcB" . #<marker at 96 in whichfunc-testcase.cpp>))
The attached patch ensures the linear search through `menu--index-alist
does not end prematurely, and all items are taken into account. This
fixes the problem.
/*
test case for which-func-mode
(GJK 2009-04-28)
Tested against the following revision:
Repository revision: 1.26
/cvsroot/emacs/emacs/lisp/progmodes/which-func.el,v
The imenu--index-alist variable looks like this:
(("Class"
("structA" . #<marker at 2 in whichfunc-testcase.cpp>)
("structB" . #<marker at 63 in whichfunc-testcase.cpp>))
("funcA" . #<marker at 34 in whichfunc-testcase.cpp>)
("funcB" . #<marker at 96 in whichfunc-testcase.cpp>))
Because of the submenu, the overall items are not in order.
*/
struct structA
{
int i;
};
void funcA()
{ // here the modeline will still show "structA"
dummy;
}
struct structB
{
int i;
};
void funcB()
{
dummy;
}
Index: which-func.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/which-func.el,v
retrieving revision 1.26
diff -c -r1.26 which-func.el
*** which-func.el 5 Jan 2009 03:23:54 -0000 1.26
--- which-func.el 28 Apr 2009 19:13:57 -0000
***************
*** 310,319 ****
(setq minoffset offset
name (funcall
which-func-imenu-joiner-function
! (reverse (cons (car pair)
namestack)))))
! ;; Entries in order, so can skip all those after
point.
! (setq alist nil
! imstack nil)))))
(setq alist (car imstack)
namestack (cdr namestack)
--- 310,317 ----
(setq minoffset offset
name (funcall
which-func-imenu-joiner-function
! (reverse (cons (car pair)
! namestack)))))))))
(setq alist (car imstack)
namestack (cdr namestack)
Best regards,
Geert Kloosterman
- bug#3153: 23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included),
Geert Kloosterman <=