Re: finding the overriding body for an overloadable function.

Eric Ludlam <[email protected]> Fri, 14 Aug 2015 20:29:25 -0400
Newsgroups gmane.emacs.semantic
Message-ID <[email protected]>
On 08/14/2015 04:49 PM, Stephen Leake wrote:
> I'm trying to understand how Semantic parses an elisp buffer. In
> particular, I want it to parse the code near point, to tell me whether
> the identifier at point is a variable or a function or something else.
> Currently, it seems to only parse the top level forms, skipping over
> their bodies.

Different parsers use different tactics.  The elisp one is a bit 
different in that is uses the parser infrastructure to find lists, and 
then uses the Emacs built-in 'read' to convert.  That's why you don't 
see it parsing functions bodies.  That bit is a bunch of custom stuff.

Other languages often introduce new %start and %scopestart tokens that 
are good starting points.  The scopestart tokens are used by the local 
context parsing system.   See semantic/ctxt.el.

> I tried looking in the Semantic manuals, but I didn't see anything
> relevant. So I'm taking my usual approach of tracing the code with
> edebug.
>
> However, I'm stumped by '(define-overloadable-function
> semantic-parse-region'
>
> I can't get edubug to step into that, and I can't figure out what
> mode-local-* function to call to get the actual body for elisp mode.

Mode local will dispatch to the correct mode specific implementation 
when the mode-local function is called.

The way things should work is if you use describe-function on an 
overloaded function, it should list all the mode specific 
implementations.  I just tried it and that appears to be broken, so I'll 
have to look into why that happened.

The pattern I think you bumped into is that there is 
`define-overloadable-function' with no body.  That does some setup. 
Just beneath you will see semantic-parse-region-default.  That's the 
function that is called by default if the mode doesn't implement it.

> So I have no idea what code is actually parsing the elisp buffer.
> Something is; it returns a list of tags (not containing the info I
> need).
>
> Once I do figure out how to find overriding bodies, perhaps I can add it
> to the list produced by xref-find-definitions in Emacs master; that
> would be useful.

If you just want to know the symbol under point, you can either use 
semantic-ctxt-current-symbol for just the raw symbol, or you can use 
semantic-analyze-current-context, which will give you lots of useful 
data.  The last is also interactive (for debugging purposes) so you can 
just run it in different situations to see what the result is.

Eric


------------------------------------------------------------------------------