emacs-diffs
[Top][All Lists]
Advanced

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

emacs-29 8ec786349e1 1/2: Fix apostrophe handling in rust-ts-mode and go


From: Eli Zaretskii
Subject: emacs-29 8ec786349e1 1/2: Fix apostrophe handling in rust-ts-mode and go-ts-mode (Bug#63708)
Date: Sat, 3 Jun 2023 04:33:42 -0400 (EDT)

branch: emacs-29
commit 8ec786349e18068bff39b1387bc4a88d62265e34
Author: Йордан Миладинов <yordanm@pm.me>
Commit: Eli Zaretskii <eliz@gnu.org>

    Fix apostrophe handling in rust-ts-mode and go-ts-mode (Bug#63708)
    
    * lisp/progmodes/rust-ts-mode.el (rust-ts-mode--syntax-propertize):
    Treat apostrophes as strings if used to define character literals.
    Treat LT and GT as pairs if used to define type parameters (formerly
    they were treated as pairs only for type arguments).
    * lisp/progmodes/go-ts-mode.el (go-ts-mode--syntax-table): Treat
    apostrophes as strings if used to define rune literals.
    
    Copyright-paperwork-exempt: yes
---
 lisp/progmodes/go-ts-mode.el   |  1 +
 lisp/progmodes/rust-ts-mode.el | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index 4233b115f19..698c6424ea2 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -58,6 +58,7 @@
     (modify-syntax-entry ?<   "."      table)
     (modify-syntax-entry ?>   "."      table)
     (modify-syntax-entry ?\\  "\\"     table)
+    (modify-syntax-entry ?\'  "\""     table)
     (modify-syntax-entry ?/   ". 124b" table)
     (modify-syntax-entry ?*   ". 23"   table)
     (modify-syntax-entry ?\n  "> b"    table)
diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index be06acde3e3..360fcc89491 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -350,7 +350,10 @@ Return nil if there is no name or if NODE is not a defun 
node."
       (treesit-node-child-by-field-name node "name") t))))
 
 (defun rust-ts-mode--syntax-propertize (beg end)
-  "Apply syntax text property to template delimiters between BEG and END.
+  "Apply syntax properties to various special characters with
+contextual meaning between BEG and END.
+
+' should be treated as string when used for char literals.
 
 < and > are usually punctuation, e.g., as greater/less-than.  But
 when used for types, they should be considered pairs.
@@ -359,11 +362,18 @@ This function checks for < and > in the changed RANGES 
and apply
 appropriate text property to alter the syntax of template
 delimiters < and >'s."
   (goto-char beg)
+  (while (search-forward "'" end t)
+    (when (string-equal "char_literal"
+                        (treesit-node-type
+                         (treesit-node-at (match-beginning 0))))
+      (put-text-property (match-beginning 0) (match-end 0)
+                         'syntax-table (string-to-syntax "\""))))
+  (goto-char beg)
   (while (re-search-forward (rx (or "<" ">")) end t)
     (pcase (treesit-node-type
             (treesit-node-parent
              (treesit-node-at (match-beginning 0))))
-      ("type_arguments"
+      ((or "type_arguments" "type_parameters")
        (put-text-property (match-beginning 0)
                           (match-end 0)
                           'syntax-table



reply via email to

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