emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: two imenu entries for same function in C-mode


From: David Hunter
Subject: Re: two imenu entries for same function in C-mode
Date: Wed, 20 Apr 2005 00:25:46 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)

martin rudalics wrote:
The beg/start dichotomy might also explain why INDEX-POSITION
occasionally gets me to a rather strange place: `java-mode', for
example, seems to prefer a position two characters before the end of the
keyword preceding the listed identifier - something like "vo-!-id" or
"Stri-!-ng".  If there's no such keyword the first suitable character
string is used and I might find myself in a preceding comment.
`cperl-mode', on the other hand, puts me at the _end_ of the identifier
listed by imenu.

I didn't see why at first, but it makes sense after some investigation.  imenu uses 
`re-search-backward' to find identifiers.  The java-mode regex 
(`cc-imenu-java-generic-expression') matches a typespec using 
"[a-zA-Z_][\]\[.a-zA-Z0-9_]+", which makes sense when you're searching 
forwards.  But since a backwards re-search stops at the first match CLOSEST to point, 
that `+' operator effectively becomes non-greedy.  In this case, the last two characters 
of anything typespec-ish will match that regex -- even if that thing is at the end of a 
preceding single-line comment.

Regardless, Richard's fix does The Right Thing (TM), and you'll always find 
yourself at the start of the line containing the identifier.

(On a related note, any regex junkies want to take a crack at the c-mode regex(es)?  Some 
of those "identifiers" found in abbrev.c are buried in comments.)

-Dave





reply via email to

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