From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#43481: 27.1; cc-mode's c-context-line-break fails, inserting a new-line into the previous comment Date: Tue, 24 Nov 2020 15:02:46 +0000 Message-ID: <20201124150246.GA30574@ACM> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36021"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 43481@debbugs.gnu.org To: Campbell Barton Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 24 16:03:28 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 1khZqq-0009Gd-Fx for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Nov 2020 16:03:28 +0100 Original-Received: from localhost ([::1]:58098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khZqp-0003gA-HA for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Nov 2020 10:03:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khZqQ-0003fK-Oo for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2020 10:03:09 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49310) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1khZqQ-0001ML-FU for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2020 10:03:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1khZqQ-0004aw-Cf for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2020 10:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Nov 2020 15:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43481 X-GNU-PR-Package: emacs Original-Received: via spool by 43481-submit@debbugs.gnu.org id=B43481.160623017517647 (code B ref 43481); Tue, 24 Nov 2020 15:03:02 +0000 Original-Received: (at 43481) by debbugs.gnu.org; 24 Nov 2020 15:02:55 +0000 Original-Received: from localhost ([127.0.0.1]:60856 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1khZqJ-0004aZ-9g for submit@debbugs.gnu.org; Tue, 24 Nov 2020 10:02:55 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:58885 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1khZqH-0004aJ-2l for 43481@debbugs.gnu.org; Tue, 24 Nov 2020 10:02:53 -0500 Original-Received: (qmail 17187 invoked by uid 3782); 24 Nov 2020 15:02:46 -0000 Original-Received: from acm.muc.de (p4fe15a86.dip0.t-ipconnect.de [79.225.90.134]) by localhost.muc.de (tmda-ofmipd) with ESMTP; Tue, 24 Nov 2020 16:02:46 +0100 Original-Received: (qmail 30836 invoked by uid 1000); 24 Nov 2020 15:02:46 -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-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:194072 Archived-At: Hello, Campbell. Thank you indeed for taking the trouble to report this bug. On Fri, Sep 18, 2020 at 09:38:16 +1000, Campbell Barton wrote: > Running 'c-context-line-break' sometimes adds the line break to the > previous comment, this seems to depend on the internal state > since it doesn't happen every time. Yes. The internal state it depends on is a cache for things like c-literal-limits (as you point out below). To make the bug show itself, first type a space in the "A" comment somewhere (which clears the cache entries for any points after the place of the change), then move point into the B comment and type M-j. > Tested in 27.1, and current master, this has been an issue for some > years IIRC. > Take this example C file: > ---- BEGIN `example.c` > /* > * A > */ > /* > * B > */ > ---- END > - Move the cursor the end-of-line above 'A'. > - M-x, c-context-line-break > ---- `example.c` (with newline above 'A', as expected). > /* > * > * A > */ > /* > * B > */ > ---- END [ .... ] > ---- > I looked into the bug and this is caused by 'c-literal-limits' > returning an invalid range (where the beginning is correct, but the > end is the end of the previous comment, instead of the end of the > current comment). Thank you very much indeed for taking the debugging so far. That was exceptionally helpful. What was happening was CC Mode read a cache entry, and because there was no entry for the "B" comment, got that for the "A" comment. It later wrongly used the END element of that cache entry, without testing properly that it was valid. > Printing 'c-literal-limits' before calling 'c-context-line-break' > shows this error, temporarily advising 'c-literal-limits' to return > the beginning/end of the comment is a workaround which > gives the 'EXPECTED RESULT'. Yes. > In GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22, > cairo version 1.17.3) > of 2020-08-29 built on juergen > Windowing system distributor 'The X.Org Foundation', version > 11.0.12009000 > System Description: Arch Linux [ .... ] Would you please try the following patch in CC Mode. After applying it, you need byte compile only cc-engine.el (which is in emacs/lisp/progmodes/). In the unlikely event you would like any help with the patching or byte compilation, feel free to send me private email. Having applied it, please test out the problem in your real code, and confirm that the bug is, in fact, fixed, or alternatively tell us that there are still glitches with it. Thanks! diff -r 4cdd79795247 cc-engine.el --- a/cc-engine.el Sun Nov 15 10:19:11 2020 +0000 +++ b/cc-engine.el Tue Nov 24 14:53:07 2020 +0000 @@ -3152,7 +3152,7 @@ ((nth 7 s) 'c++) (t 'c))) (setq start (nth 8 s)) - (unless end + (unless (and end (>= end here)) (setq s1 (parse-partial-sexp here (point-max) nil ; TARGETDEPTH nil ; STOPBEFORE -- Alan Mackenzie (Nuremberg, Germany).