unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: 40658@debbugs.gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#40658: Fforward-comment: Incorrect recognition of end of comment in C++
Date: Thu, 16 Apr 2020 12:44:26 +0000	[thread overview]
Message-ID: <20200416124426.GA5328@ACM> (raw)

Hello, Emacs.

C++ comments can be continued onto the next line by an escaped NL.  This
is configured in Emacs with the variable comment-end-can-be-escaped.

However, Fforward_comment (in the backward direction) doesn't take this
into account.  A BOL following an escaped NL cannot be at the end of a
C++ line comment:

    // C++ comment first line \
    Second line of comment
    ^
    |
  point

Point here is in the middle of a comment.

It is therefore wrong in Fforward_comment not to check
comment-end-can-be-escaped when immediately after an Sendcomment.  This
can be fixed thusly:


diff --git a/src/syntax.c b/src/syntax.c
index e24b98da32..ff125b137c 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -2572,8 +2572,9 @@ between them, return t; otherwise return nil.  */)
 	    }
 	  else if (code == Sendcomment)
 	    {
-	      found = back_comment (from, from_byte, stop, comnested, comstyle,
-				    &out_charpos, &out_bytepos);
+              found = (!quoted || !Vcomment_end_can_be_escaped)
+                && back_comment (from, from_byte, stop, comnested, comstyle,
+                                 &out_charpos, &out_bytepos);
 	      if (!found)
 		{
 		  if (c == '\n')


This should clearly go into the master branch.  I think it should also go
into the emacs-27 release branch, since it is relevant for a nasty bug,
bug #40052.  There, scrolling in a C++ include file, which consists of a
#define macro ~2,400 lines long is deadly slow.  With the above fix in
place, scrolling is over 4 times as fast, although still too slow.

-- 
Alan Mackenzie (Nuremberg, Germany).





             reply	other threads:[~2020-04-16 12:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16 12:44 Alan Mackenzie [this message]
2020-04-16 13:35 ` bug#40658: Fforward-comment: Incorrect recognition of end of comment in C++ Eli Zaretskii
2020-04-16 17:29   ` Alan Mackenzie
2020-04-16 18:01     ` Stefan Monnier
     [not found] ` <handler.40658.B.158704107627532.ack@debbugs.gnu.org>
2020-04-16 17:31   ` bug#40658: (Fforward-comment: Incorrect recognition of end of comment in C++) Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200416124426.GA5328@ACM \
    --to=acm@muc.de \
    --cc=40658@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).