From: Yuan Fu Date: Sat, 4 Jan 2025 19:53:39 +0000 (-0800) Subject: Fix tsx-ts-mode syntax propertize function (bug#73978) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2f03a669b41f05d0012af86c94a3803561c36e36;p=emacs.git Fix tsx-ts-mode syntax propertize function (bug#73978) * 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) --- diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index 9b127c409ae..5b886b5da7f 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -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)))