From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Campbell Barton 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: Thu, 26 Nov 2020 15:58:20 +1100 Message-ID: <73c01ad8-4546-c059-1b5d-6edc4aca1d14@gmail.com> References: <20201124150246.GA30574@ACM> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25190"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 Cc: 43481@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 26 05:59:13 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 1ki9N9-0006OL-85 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Nov 2020 05:59:11 +0100 Original-Received: from localhost ([::1]:40354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ki9N8-00012a-5S for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 25 Nov 2020 23:59:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki9N0-00012E-L4 for bug-gnu-emacs@gnu.org; Wed, 25 Nov 2020 23:59:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ki9N0-0005T8-Du for bug-gnu-emacs@gnu.org; Wed, 25 Nov 2020 23:59:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ki9N0-00080e-9t for bug-gnu-emacs@gnu.org; Wed, 25 Nov 2020 23:59:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Campbell Barton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Nov 2020 04:59: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.160636671230749 (code B ref 43481); Thu, 26 Nov 2020 04:59:02 +0000 Original-Received: (at 43481) by debbugs.gnu.org; 26 Nov 2020 04:58:32 +0000 Original-Received: from localhost ([127.0.0.1]:38153 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ki9MW-0007zt-AB for submit@debbugs.gnu.org; Wed, 25 Nov 2020 23:58:32 -0500 Original-Received: from mail-pf1-f171.google.com ([209.85.210.171]:39552) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ki9MU-0007zg-Ek for 43481@debbugs.gnu.org; Wed, 25 Nov 2020 23:58:31 -0500 Original-Received: by mail-pf1-f171.google.com with SMTP id x24so552255pfn.6 for <43481@debbugs.gnu.org>; Wed, 25 Nov 2020 20:58:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=CliY0dAYQS7Op9ugqMIzt3XFa4uUrVUmPZAZL7BmVuY=; b=q3VOUUNY1jNIf5TAgU5DeIcv/hGkb+GlcilnefLNnH7V+5Lez/PZSYTa/zQFSjKliM g7kouLV7HHpwDmx/xZhLUjCeJlelyFlL9gADV0cdPJthpBHFnp81rmnIuWdjqrN3j/JQ t+VIzy5FSurEgcemEGPB/eMxRT8tmNi2cTgrkRVWVdofcnJkiDzStfbqUdCtcca2UKLA mJuIgV/ZaZ7X67W6Uiyeb6S7XosRvN4IxjMzU15bVqJJvkSBisr62R6oxiTv9wtUF6IW fjn6ZqSIC04xFbFQCu7JVpeBtITzc/VY5vx4jWRkR82YNIqFPMxhPGAGVtpL1Itg2x3S 80Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=CliY0dAYQS7Op9ugqMIzt3XFa4uUrVUmPZAZL7BmVuY=; b=pjcUN6MolSgQLXSOKqDk7nlU/+zau5DHkhtIVdPU6vAfGP1yueW/jaFdDxq9cajWtq mxeANI/aOluPvgmEsTXIvjOU8FHVdeW0CgcBCin20PwUHt54vJ/43XM2ByeU6bhbR+Tu U9/ALYy0eyeyaU7BimF51VklMvmgjbIxhXqXSeg+MTbJU/GZycSacUGXAjzKOCCjv5yo Vqu+lH4dnB23r1Jg4ONfnxazYpp0BEpGeZT/rIzygxGBcer9I6FMraxcDTQ5kureDbdJ ArzwOc5baMUv3nBt+1b5LOlGrNzSAMO5GwCKKNPbEup4HcHda5akrIXEmFom3bOEHbGw GCHg== X-Gm-Message-State: AOAM533Y71OUzFE78x5fmMbLmBys1wYJRvUcDeAkEn0SfWpyHF7nj7Qo yFm3mEOvT44Yndkb5ntkTmyIHd28zCE= X-Google-Smtp-Source: ABdhPJy8RAsAgEbJne0D3BGRVGYT7WFfQbyiFwQbfF+WFecnBj9yOrXhedfziSrZlDkV1FFx7QsltA== X-Received: by 2002:a62:864a:0:b029:197:ad58:4184 with SMTP id x71-20020a62864a0000b0290197ad584184mr1180381pfd.55.1606366704307; Wed, 25 Nov 2020 20:58:24 -0800 (PST) Original-Received: from ?IPv6:2402:b801:2844:2100::1? ([2402:b801:2844:2100::1]) by smtp.gmail.com with ESMTPSA id a22sm3299426pfn.29.2020.11.25.20.58.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Nov 2020 20:58:23 -0800 (PST) In-Reply-To: <20201124150246.GA30574@ACM> Content-Language: en-US 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:194260 Archived-At: Hi Alan, thanks for fixing this, Tested this both with `emacs -Q` and my personal (evil) config. When your fix is applied, in both cases this works as expected. On 11/25/20 2:02 AM, Alan Mackenzie wrote: > 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 > >