From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#39972: 28.0.50; which-function no longer returning current Java method in Emacs 27 Date: Sun, 19 Apr 2020 14:03:25 +0000 Message-ID: <20200419140325.GA22514@ACM> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="12757"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 39972@debbugs.gnu.org To: Philipp Stephani Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 19 16:05:41 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jQAZp-0003CK-23 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Apr 2020 16:05:41 +0200 Original-Received: from localhost ([::1]:42094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQAZo-000259-4T for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Apr 2020 10:05:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37110) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQAYV-0000Zg-8Q for bug-gnu-emacs@gnu.org; Sun, 19 Apr 2020 10:04:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQAYK-0005cd-0z for bug-gnu-emacs@gnu.org; Sun, 19 Apr 2020 10:04:19 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34102) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQAYD-0005V6-Rv for bug-gnu-emacs@gnu.org; Sun, 19 Apr 2020 10:04:07 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jQAYD-00012U-MD for bug-gnu-emacs@gnu.org; Sun, 19 Apr 2020 10:04:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 19 Apr 2020 14:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39972 X-GNU-PR-Package: emacs Original-Received: via spool by 39972-submit@debbugs.gnu.org id=B39972.15873050143958 (code B ref 39972); Sun, 19 Apr 2020 14:04:01 +0000 Original-Received: (at 39972) by debbugs.gnu.org; 19 Apr 2020 14:03:34 +0000 Original-Received: from localhost ([127.0.0.1]:45648 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQAXi-00011g-0Z for submit@debbugs.gnu.org; Sun, 19 Apr 2020 10:03:34 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:34549 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1jQAXg-00011W-1E for 39972@debbugs.gnu.org; Sun, 19 Apr 2020 10:03:29 -0400 Original-Received: (qmail 54419 invoked by uid 3782); 19 Apr 2020 14:03:26 -0000 Original-Received: from acm.muc.de (p4FE151BB.dip0.t-ipconnect.de [79.225.81.187]) by localhost.muc.de (tmda-ofmipd) with ESMTP; Sun, 19 Apr 2020 16:03:25 +0200 Original-Received: (qmail 22744 invoked by uid 1000); 19 Apr 2020 14:03:25 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:178638 Archived-At: Hello, Philipp. On Sat, Mar 07, 2020 at 14:07:42 +0100, Philipp Stephani wrote: > Assume there's a file /tmp/Foo.java: > $ cat /tmp/Foo.java > class Foo { > void bar() { > // body > } > } > Emacs 26: > $ emacs -Q -batch -l which-func /tmp/Foo.java -eval '(progn (search-forward "// body") (print (which-function)))' > "bar" > Emacs 27 pretest: > $ emacs -Q -batch -l which-func /tmp/Foo.java -eval '(progn (search-forward "// body") (print (which-function)))' > "class Foo" > That is, Emacs 27 now prints the clas name instead of the method name. > I think the Emacs 26 behavior is preferrable. Yes, indeed. Just in passing, lisp/progmodes/which-func.el could do with a serious amount of tender loving care. I reported a bug about it this morning, and enclose a rough workaround fix to another one in this post. > In GNU Emacs 28.0.50 (build 10, x86_64-pc-linux-gnu, GTK+ Version 3.24.12, cairo version 1.16.0) > of 2020-02-25 > Repository revision: 03c07c88d90b5747456b9d286bace2dd4a713aac > Repository branch: master > Windowing system distributor 'The X.Org Foundation', version 11.0.12004000 > System Description: Debian GNU/Linux rodete CC Mode's support for "name of function at point" is somewhat bedraggled, too. It gets mixed up with c-defun-tactic, the option which instructs CC Mode to use the current function within the next enclosing class, etc., rather than the top level thing. CC Mode's support includes two different functionalities: one intended for interactive display (triggered by C-c C-z), the other intended for add-change-log-entry-other-window (C-x 4 a). I can't actually see why the second of these is different from the first. However, which-function has been using this second of these. A rough patch to CC Mode is as follows: diff -r 2c9f4cff0753 cc-mode.el --- a/cc-mode.el Fri Apr 03 20:04:29 2020 +0000 +++ b/cc-mode.el Sun Apr 19 13:37:22 2020 +0000 @@ -778,7 +778,8 @@ (make-local-variable 'add-log-current-defun-function) (setq add-log-current-defun-function (lambda () - (or (c-cpp-define-name) (c-defun-name))))) + (or (c-cpp-define-name) + (car (c-defun-name-and-limits nil)))))) (let ((rfn (assq mode c-require-final-newline))) (when rfn However, there is a problem in which-function, where when one puts point after the final } in your test file, it reports "bar" on the mode line. It really should indicate "no function" or, at a pinch, "class Foo". The problem here is in `which-function', where it keeps trying different methods until it finds one which returns non-nil. The last of these methods is a search of the imode list, which contains only "bar". Here is a very rough workaround, which might form the basis of a proper fix at some stage. diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el index 1cee552b0c..9be629dafd 100644 --- a/lisp/progmodes/which-func.el +++ b/lisp/progmodes/which-func.el @@ -282,6 +282,11 @@ which-function (when (null name) (setq name (add-log-current-defun))) ;; If Imenu is loaded, try to make an index alist with it. +;;;; NEW STOUGH, 2020-04-19 + ;; If `add-log-current-defun' ran and gave nil, accept this. + (when (and (null name) + (null add-log-current-defun-function)) +;;;; END OF NEW STOUGH (when (and (null name) (boundp 'imenu--index-alist) (or (null imenu--index-alist) @@ -328,6 +333,9 @@ which-function (funcall which-func-imenu-joiner-function (reverse (cons (car pair) namestack)))))))))))) +;;;; NEW STOUGH, 2020-04-19 + ) +;;;; END OF NEW STOUGH ;; Filter the name if requested. (when name (if which-func-cleanup-function -- Alan Mackenzie (Nuremberg, Germany).