unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: "John C. Ruttenberg" <ruttenberg@reservoir.com>
Cc: acm@muc.de, 48837@debbugs.gnu.org
Subject: bug#48837: Interaction between completion-moide and cc-mode new in 27.2
Date: Sun, 20 Jun 2021 18:43:33 +0000	[thread overview]
Message-ID: <YM+MVRHDU3+kGZFN@ACM> (raw)
In-Reply-To: <CAPx0gTjCLqqNb+So+hc7s_NWRx7Z_HEfto=KW1XZA5AC_kuZ=A@mail.gmail.com>

Hello, John.

Thanks for taking the trouble to report this bug, and thanks even more
for cutting the test case down to an easy to work with minimum.

On Fri, Jun 04, 2021 at 16:13:47 -0400, John C. Ruttenberg wrote:
> This bug occurs in 27.2 but not in 26.3

> In a clean emacs "emacs -q --no-site-file":
> 1. Enable dynamic completion "(dynamic-completion-mode)"
> 2. Open a c++ source file
> 3. Text should be:

> foo() {
>   std::cerr <
>   int i = static_cast<unsigned>(z);
> }

>    4. Position the cursor directly after the "<" and type "< " (two
> characters "<" " "
>    5. I get this error message: "Scan error: containing expression ends
> prematurely, 22, 22"

The cause of this was that the "<" had wrongly been marked as an opening
angle bracket.  A backward `scan-sexps' Lisp instruction bumped into
this barrier of an angle bracket and gave the error.

The solution is to correct the reason for the spurious marking.  That
was that "static_cast" (along with three other newish ..._cast keywords)
weren't being properly handled.  This should be corrected in the
supplied patch (which actually fixes a bit more).

Would you please apply the following patch then byte-compile CC Mode in
its entirety (as a Lisp macro has been changed).  CC Mode is in
..../emacs/lisp/progmodes/cc-*.el

Then please load the new CC Mode into your Emacs 27.2, test it on your
real source code, and either confirm that the bug is fixed, or tell me
where it is still going wrong.  If you want any help with the patching
or byte compiling, feel free to send me private email.  Thanks!



diff -r 92a4592886a1 cc-engine.el
--- a/cc-engine.el	Sun Apr 25 17:26:38 2021 +0000
+++ b/cc-engine.el	Sun Jun 20 18:23:16 2021 +0000
@@ -6965,8 +6965,10 @@
 	(c-go-list-forward))
       (when (equal (c-get-char-property (1- (point)) 'syntax-table)
 		   c->-as-paren-syntax) ; should always be true.
-	(c-unmark-<->-as-paren (1- (point))))
-      (c-unmark-<->-as-paren pos))))
+	(c-unmark-<->-as-paren (1- (point)))
+	(c-truncate-lit-pos-cache (1- (point))))
+      (c-unmark-<->-as-paren pos)
+      (c-truncate-lit-pos-cache pos))))
 
 (defun c-clear->-pair-props (&optional pos)
   ;; POS (default point) is at a > character.  If it is marked with
@@ -6982,8 +6984,10 @@
 	(c-go-up-list-backward))
       (when (equal (c-get-char-property (point) 'syntax-table)
 			c-<-as-paren-syntax) ; should always be true.
-	(c-unmark-<->-as-paren (point)))
-      (c-unmark-<->-as-paren pos))))
+	(c-unmark-<->-as-paren (point))
+	(c-truncate-lit-pos-cache (point)))
+      (c-unmark-<->-as-paren pos)
+      (c-truncate-lit-pos-cache pos))))
 
 (defun c-clear-<>-pair-props (&optional pos)
   ;; POS (default point) is at a < or > character.  If it has an
@@ -7016,7 +7020,8 @@
 		 (equal (c-get-char-property (1- (point)) 'syntax-table)
 			c->-as-paren-syntax)) ; should always be true.
 	(c-unmark-<->-as-paren (1- (point)))
-	(c-unmark-<->-as-paren pos))
+	(c-unmark-<->-as-paren pos)
+	(c-truncate-lit-pos-cache pos))
       t)))
 
 (defun c-clear->-pair-props-if-match-before (lim &optional pos)
@@ -7037,6 +7042,7 @@
 		 (equal (c-get-char-property (point) 'syntax-table)
 			c-<-as-paren-syntax)) ; should always be true.
 	(c-unmark-<->-as-paren (point))
+	(c-truncate-lit-pos-cache (point))
 	(c-unmark-<->-as-paren pos))
       t)))
 
@@ -8078,13 +8084,14 @@
 	;; bracket arglist.  It's propagated through the return value
 	;; on successful completion.
 	(c-record-found-types c-record-found-types)
+	(syntax-table-prop-on-< (c-get-char-property (point) 'syntax-table))
 	;; List that collects the positions after the argument
 	;; separating ',' in the arglist.
 	arg-start-pos)
     ;; If the '<' has paren open syntax then we've marked it as an angle
     ;; bracket arglist before, so skip to the end.
     (if (and (not c-parse-and-markup-<>-arglists)
-	     (c-get-char-property (point) 'syntax-table))
+	     syntax-table-prop-on-<)
 
 	(progn
 	  (forward-char)
@@ -8167,8 +8174,20 @@
 			(c-put-c-type-property (1- (car arg-start-pos))
 					       'c-<>-arg-sep)
 			(setq arg-start-pos (cdr arg-start-pos)))
+		      (when (and (not syntax-table-prop-on-<)
+				 (c-get-char-property (1- (point))
+						      'syntax-table))
+			;; Clear the now spuriously matching < of its
+			;; syntax-table property.  This could happen on
+			;; inserting "_cast" into "static <" with C-y.
+			(save-excursion
+			  (and (c-go-list-backward)
+			       (eq (char-after) ?<)
+			       (c-truncate-lit-pos-cache (point))
+			       (c-unmark-<->-as-paren (point)))))
 		      (c-mark-<-as-paren start)
-		      (c-mark->-as-paren (1- (point))))
+		      (c-mark->-as-paren (1- (point)))
+		      (c-truncate-lit-pos-cache start))
 		    (setq res t)
 		    nil))		; Exit the loop.
 
diff -r 92a4592886a1 cc-langs.el
--- a/cc-langs.el	Sun Apr 25 17:26:38 2021 +0000
+++ b/cc-langs.el	Sun Jun 20 18:23:16 2021 +0000
@@ -2730,7 +2730,8 @@
 `c-recognize-<>-arglists' for details.  That language constant is
 assumed to be set if this isn't nil."
   t    nil
-  c++  '("template")
+  c++  '("template" "const_cast" "dynamic_cast" "reinterpret_cast"
+	 "static_cast")
   idl  '("fixed" "string" "wstring"))
 
 (c-lang-defconst c-<>-sexp-kwds


> In GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20)
>  of 2021-06-02 built on catb
> Windowing system distributor 'AT&T Laboratories Cambridge', version
> 11.0.3332
> System Description: Ubuntu 20.04.2 LTS

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).





  reply	other threads:[~2021-06-20 18:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04 20:13 bug#48837: Interaction between completion-moide and cc-mode new in 27.2 John C. Ruttenberg
2021-06-20 18:43 ` Alan Mackenzie [this message]
     [not found]   ` <CAPx0gTiJJJKsyjuo2He_B81CMrnBjXg8+WwTXw1TndjacjNGkg@mail.gmail.com>
     [not found]     ` <YNeIjEIVlKFHcHHD@ACM>
     [not found]       ` <CAPx0gTh-567hARAfNhUDyuB7=tWWGSR1+hDxWjEU31JZ_-_CDA@mail.gmail.com>
2021-06-27 13:36         ` Alan Mackenzie
2021-06-27 13:58           ` John C. Ruttenberg

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=YM+MVRHDU3+kGZFN@ACM \
    --to=acm@muc.de \
    --cc=48837@debbugs.gnu.org \
    --cc=ruttenberg@reservoir.com \
    /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).