mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-30 17:10:51 -08:00
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.
This commit is contained in:
parent
d9a0e78197
commit
87f83f1c17
1 changed files with 23 additions and 18 deletions
|
|
@ -670,24 +670,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)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue