Re: finding the overriding body for an overloadable function.

Stephen Leake <[email protected]> Fri, 14 Aug 2015 22:10:32 -0500
Newsgroups gmane.emacs.semantic
Message-ID <[email protected]>
Eric Ludlam <[email protected]> writes:

> 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.

What file is the elisp parser in?

> 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.

I found mode-local.el mode-local-augment-function-help, which has this
comment (in SourceForge CEDET):

;; NOTE TO SELF:
;; LIST ALL LOADED OVERRIDES FOR SYMBOL HERE

I'm guessing that's intended for help-fns-describe-function-functions?

>From mode-local--override, it appears that executing (fetch-overload
'semantic-parse-region) in an elisp buffer should return the overload.
But it returns nil; I guess that means execute the default. 

Ah; in a C buffer, (fetch-overload 'semantic-parse-region) returns
semantic-parse-region-c-mode.

I think for both *Help* and xref-find-definitions it would be ok to show
the definition for the current buffer (including when that's the
default); a single fetch-overload is sufficient for that.

Digging further, mode-local symbols are stored in
mode-local-symbol-table, which can be a buffer-local variable or a
property on the major mode symbol.

A global list of overrides would be nice, but I don't know how to get a
list of major modes. We could iterate thru all current buffers, but that
seems wasteful since it's not complete.

> 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.

Ah; the doc string for define-overloadable-function says that's
the default when there's no body and no mode-local override.

> 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.  

semantic-analyze-current-context does what I need. Excellent.

-- 
-- Stephe

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