emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 49151316306 1/3: Merge from savannah/emacs-30


From: Po Lu
Subject: master 49151316306 1/3: Merge from savannah/emacs-30
Date: Sat, 3 Aug 2024 04:58:14 -0400 (EDT)

branch: master
commit 4915131630646a5fc9e3d0caee5c6d6e456c884a
Merge: 15afa72460b ef5466c2675
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Merge from savannah/emacs-30
    
    ef5466c2675 Avoid aborts when buffer is modified during its redisplay
    cb421286d2e Fix c++-ts-mode indentation for templace (bug#72263)
---
 lisp/progmodes/c-ts-mode.el                        |  3 ++-
 src/xdisp.c                                        | 22 ++++++++++++++---
 .../lisp/progmodes/c-ts-mode-resources/indent.erts | 28 ++++++++++++++++++++++
 3 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index abc5f19c849..7f23b30a88a 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -466,7 +466,8 @@ MODE is either `c' or `cpp'."
            ,@(when (eq mode 'cpp)
                '(((node-is "access_specifier") parent-bol 0)
                  ;; Indent the body of namespace definitions.
-                 ((parent-is "declaration_list") parent-bol 
c-ts-mode-indent-offset)))
+                 ((parent-is "declaration_list") parent-bol 
c-ts-mode-indent-offset)
+                 ((parent-is "template_declaration") parent-bol 0)))
 
 
            ;; int[5] a = { 0, 0, 0, 0 };
diff --git a/src/xdisp.c b/src/xdisp.c
index 491ce9cc970..6f29f159d16 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -20007,6 +20007,7 @@ redisplay_window (Lisp_Object window, bool 
just_this_one_p)
   int frame_line_height, margin;
   bool use_desired_matrix;
   void *itdata = NULL;
+  modiff_count lchars_modiff = CHARS_MODIFF, ochars_modiff = lchars_modiff;
 
   SET_TEXT_POS (lpoint, PT, PT_BYTE);
   opoint = lpoint;
@@ -20100,6 +20101,7 @@ redisplay_window (Lisp_Object window, bool 
just_this_one_p)
   end_unchanged = END_UNCHANGED;
 
   SET_TEXT_POS (opoint, PT, PT_BYTE);
+  ochars_modiff = CHARS_MODIFF;
 
   specbind (Qinhibit_point_motion_hooks, Qt);
 
@@ -21132,14 +21134,28 @@ redisplay_window (Lisp_Object window, bool 
just_this_one_p)
     TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE);
   else if (CHARPOS (opoint) > ZV)
     TEMP_SET_PT_BOTH (Z, Z_BYTE);
-  else
+  else if (ochars_modiff == CHARS_MODIFF)
     TEMP_SET_PT_BOTH (CHARPOS (opoint), BYTEPOS (opoint));
-
+  else
+    {
+      /* If the buffer was modified while we were redisplaying it, we
+         cannot trust the correspondence between character and byte
+         positions.  This can happen, for example, if we are
+         redisplaying *Messages* and some Lisp, perhaps invoked by
+         display_mode_lines, signals an error which caused something
+         added/deleted to/from the buffer text.  */
+      TEMP_SET_PT_BOTH (CHARPOS (opoint), CHAR_TO_BYTE (CHARPOS (opoint)));
+    }
   set_buffer_internal_1 (old);
   /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
      shorter.  This can be caused by log truncation in *Messages*.  */
   if (CHARPOS (lpoint) <= ZV)
-    TEMP_SET_PT_BOTH (CHARPOS (lpoint), BYTEPOS (lpoint));
+    {
+      if (lchars_modiff == CHARS_MODIFF)
+       TEMP_SET_PT_BOTH (CHARPOS (lpoint), BYTEPOS (lpoint));
+      else
+       TEMP_SET_PT_BOTH (CHARPOS (lpoint), CHAR_TO_BYTE (CHARPOS (lpoint)));
+    }
 
   unbind_to (count, Qnil);
 }
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts 
b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 24b244c1611..599173832b5 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -458,6 +458,34 @@ namespace test {
 }
 =-=-=
 
+Name: Namespace and template (bug#72263)
+
+=-=
+namespace A {
+
+T myfunction1(const char *fname)
+{
+}
+
+template <class T>
+T myfunction2(const char *fname)
+{
+}
+}
+=-=
+namespace A {
+
+  T myfunction1(const char *fname)
+  {
+  }
+
+  template <class T>
+  T myfunction2(const char *fname)
+  {
+  }
+}
+=-=-=
+
 Code:
   (lambda ()
     (c-ts-mode)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]