all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#3153: 23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included)
@ 2009-04-28 19:26 ` Geert Kloosterman
  2009-04-28 21:40   ` bug#3153: marked as done (23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included)) Emacs bug Tracking System
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Kloosterman @ 2009-04-28 19:26 UTC (permalink / raw)
  To: emacs-pretest-bug

[-- Attachment #1: Type: text/plain, Size: 1495 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: whichfunc-testcase.cpp --]
[-- Type: text/x-c++src, Size: 754 bytes --]

/*
  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;
}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: which-func.patch --]
[-- Type: text/x-diff, Size: 1322 bytes --]

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)

[-- Attachment #4: Type: text/plain, Size: 34 bytes --]



Best regards,
Geert Kloosterman

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#3153: marked as done (23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included))
  2009-04-28 19:26 ` bug#3153: 23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included) Geert Kloosterman
@ 2009-04-28 21:40   ` Emacs bug Tracking System
  0 siblings, 0 replies; 2+ messages in thread
From: Emacs bug Tracking System @ 2009-04-28 21:40 UTC (permalink / raw)
  To: Chong Yidong

[-- Attachment #1: Type: text/plain, Size: 958 bytes --]


Your message dated Tue, 28 Apr 2009 17:31:13 -0400
with message-id <87ws94pise.fsf@cyd.mit.edu>
and subject line Re: 23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included)
has caused the Emacs bug report #3153,
regarding 23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included)
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@emacsbugs.donarmstrong.com
immediately.)


-- 
3153: http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=3153
Emacs Bug Tracking System
Contact owner@emacsbugs.donarmstrong.com with problems

[-- Attachment #2: Type: message/rfc822, Size: 6860 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 1495 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.1.2: whichfunc-testcase.cpp --]
[-- Type: text/x-c++src, Size: 754 bytes --]

/*
  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;
}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.1.3: which-func.patch --]
[-- Type: text/x-diff, Size: 1322 bytes --]

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)

[-- Attachment #2.1.4: Type: text/plain, Size: 34 bytes --]



Best regards,
Geert Kloosterman

[-- Attachment #3: Type: message/rfc822, Size: 1294 bytes --]

From: Chong Yidong <cyd@stupidchicken.com>
To: Geert Kloosterman <g.j.kloosterman@gmail.com>
Cc: 3153-done@emacsbugs.donarmstrong.com
Subject: Re: 23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included)
Date: Tue, 28 Apr 2009 17:31:13 -0400
Message-ID: <87ws94pise.fsf@cyd.mit.edu>

> When a C/C++ file contains mixed struct/function definitions,
> which-func-mode gets confused.

Thanks for analyzing this problem, and fixing it.  I've committed your
patch.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-04-28 21:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87ws94pise.fsf@cyd.mit.edu>
2009-04-28 19:26 ` bug#3153: 23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included) Geert Kloosterman
2009-04-28 21:40   ` bug#3153: marked as done (23.0.60; which-func-mode (C++) confused when mixing structs/functions (patch included)) Emacs bug Tracking System

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.