Subject: Re: bug#39972: 28.0.50; which-function no longer returning current Java method in Emacs 27

From: Alan Mackenzie <[email-masked]>
Date: Thu, 21 May 2020 17:42:11 +0000

Hello, Eli.

On Thu, May 21, 2020 at 19:15:42 +0300, Eli Zaretskii wrote:
> > From: Philipp Stephani <[email-masked]>
> > Date: Thu, 21 May 2020 17:56:16 +0200
> > Cc: [email-masked]

> > Do you think you could push these patches onto the release branch, as
> > this appears to be a regression?

> The fixes (especially the one for which-func) are too risky for the
> release branch.  Is it possible to come up with something simpler for
> emacs-27?

See below.

> What change(s) caused the regression, exactly?

class Foo {
    void bar() {
    // body      <============== Point is here.
    }
}

Traditionally, the function which-function (in which-func.el) has tried a
row of methods to find the current function, stopping after finding the
first non-null result.

Emacs 26's CC Mode's value of add-log-current-defun returned nil, after
which which-function tried querying the imenu structures, which worked
OK.

emacs-27's CC Mode's value of add-log-current-defun now returns the top
level function, "class Foo".  which-function no longers proceeds to the
imenu stuff.  "class Foo" is here the result returned by which-function.
This is not OK.

master's CC Mode's value of add-log-current-defun now returns "bar".

The remainder of the recent patch to which-function ensures that if
add-log-current-defun IS ACTUALLY CALLED and returns nil, this nil
becomes which-function's result.  There were previously problems where
add-log-current-defun had returned nil because point was outside any
function, yet imenu would later return a spurious function name.

> Is it possible to come up with something simpler for emacs-27?

I think the change (in master) to CC Mode's value of
add-log-current-defun could be put into emacs-27 on its own.  This should
be safe.

The patch which made this change (bug #39972) was:
5989432d15feb4439e759d2c0e28233ca22a7604
"CC Mode: Fix bug #39972, by fixing c-display-defun-name for nested
defuns"
Date:   Wed May 20 19:02:26 2020 +0000.

What do you say to putting this into emacs-27?

-- 
Alan Mackenzie (Nuremberg, Germany).