]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix tsx-ts-mode syntax propertize function (bug#73978)
authorYuan Fu <casouri@gmail.com>
Sat, 4 Jan 2025 19:53:39 +0000 (11:53 -0800)
committerEshel Yaron <me@eshelyaron.com>
Sat, 4 Jan 2025 21:00:11 +0000 (22:00 +0100)
* lisp/progmodes/typescript-ts-mode.el:
(tsx-ts--syntax-propertize-captures): Apply punctuation syntax
on balanced pairs, instead of using string syntax.

(cherry picked from commit 87f83f1c1771ad3ca4d84bf2fc7a337e241952be)

lisp/progmodes/typescript-ts-mode.el

index 9b127c409aed172d32ff2a20c9b8a0fe17ac5ecd..5b886b5da7f848367d6fb9b9432af081e78ec599 100644 (file)
@@ -668,24 +668,29 @@ at least 3 (which is the default value)."
 
 (defun tsx-ts--syntax-propertize-captures (captures)
   (pcase-dolist (`(,name . ,node) captures)
-    (let* ((ns (treesit-node-start node))
-           (ne (treesit-node-end node))
-           (syntax (pcase-exhaustive name
-                     ('regexp
-                      (cl-decf ns)
-                      (cl-incf ne)
-                      (string-to-syntax "\"/"))
-                     ('jsx
-                      (string-to-syntax "|")))))
-      ;; The string syntax require at least two characters (one for
-      ;; opening fence and one for closing fence).  So if the string has
-      ;; only one character, we apply the whitespace syntax.  The string
-      ;; has to be in a non-code syntax, lest the string could contain
-      ;; parent or brackets and messes up syntax-ppss.
-      (if (eq ne (1+ ns))
-          (put-text-property ns ne 'syntax-table "-")
-        (put-text-property ns (1+ ns) 'syntax-table syntax)
-        (put-text-property (1- ne) ne 'syntax-table syntax)))))
+    (let ((ns (treesit-node-start node))
+          (ne (treesit-node-end node)))
+      (pcase-exhaustive name
+        ('regexp
+         (let ((syntax (string-to-syntax "\"/")))
+           (cl-decf ns)
+           (cl-incf ne)
+           (put-text-property ns (1+ ns) 'syntax-table syntax)
+           (put-text-property (1- ne) ne 'syntax-table syntax)))
+        ;; We put punctuation syntax on all the balanced pair
+        ;; characters so they don't mess up syntax-ppss.  We can't put
+        ;; string syntax on the whole thing because a) it doesn't work
+        ;; if the text is one character long, and b) it interferes
+        ;; forward/backward-sexp.
+        ('jsx
+         (save-excursion
+           (goto-char ns)
+           (while (re-search-forward (rx (or "{" "}" "[" "]"
+                                             "(" ")" "<" ">"))
+                                     ne t)
+             (put-text-property
+              (match-beginning 0) (match-end 0)
+              'syntax-table (string-to-syntax ".")))))))))
 
 (if (treesit-ready-p 'tsx)
     (add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode)))