[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 1c3ca3bb649 1/6: Fix <> syntax in rust-ts-mode
From: |
Yuan Fu |
Subject: |
emacs-29 1c3ca3bb649 1/6: Fix <> syntax in rust-ts-mode |
Date: |
Sun, 29 Jan 2023 03:13:07 -0500 (EST) |
branch: emacs-29
commit 1c3ca3bb649b7e812a84b4a559463462d4357080
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Fix <> syntax in rust-ts-mode
Similar to bug#60351, the angle brackets in rust-ts-mode are not
recognized as pairs when they should be. This change copies the
function used by c++-ts-mode and adapts it to rust-ts-mode.
* lisp/progmodes/rust-ts-mode.el:
(rust-ts-mode--syntax-propertize): New function.
(rust-ts-mode): Set up syntax-propertize-function.
---
lisp/progmodes/rust-ts-mode.el | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index 3a6cb61b719..2812e39c101 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -275,6 +275,28 @@ Return nil if there is no name or if NODE is not a defun
node."
(treesit-node-text
(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.
+
+< and > are usually punctuation, e.g., as greater/less-than. But
+when used for types, they should be considered pairs.
+
+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 (re-search-forward (rx (or "<" ">")) end t)
+ (pcase (treesit-node-type
+ (treesit-node-parent
+ (treesit-node-at (match-beginning 0))))
+ ("type_arguments"
+ (put-text-property (match-beginning 0)
+ (match-end 0)
+ 'syntax-table
+ (pcase (char-before)
+ (?< '(4 . ?>))
+ (?> '(5 . ?<))))))))
+
;;;###autoload
(define-derived-mode rust-ts-mode prog-mode "Rust"
"Major mode for editing Rust, powered by tree-sitter."
@@ -284,6 +306,10 @@ Return nil if there is no name or if NODE is not a defun
node."
(when (treesit-ready-p 'rust)
(treesit-parser-create 'rust)
+ ;; Syntax.
+ (setq-local syntax-propertize-function
+ #'rust-ts-mode--syntax-propertize)
+
;; Comments.
(c-ts-common-comment-setup)
- emacs-29 updated (56e8607dc99 -> 1970726e26a), Yuan Fu, 2023/01/29
- emacs-29 4b1714571c8 3/6: ; Fix byte-compile warnings in c-ts-mode.el, Yuan Fu, 2023/01/29
- emacs-29 1970726e26a 6/6: Use treesit-subtree-stat to determine treesit--font-lock-fast-mode, Yuan Fu, 2023/01/29
- emacs-29 f50cb7d7c4b 2/6: ; Improve docstring of c-ts-mode--indent-style-setter, Yuan Fu, 2023/01/29
- emacs-29 a3003492ace 4/6: Move c-ts-mode--statement-offset to c-ts-common.el, Yuan Fu, 2023/01/29
- emacs-29 1c3ca3bb649 1/6: Fix <> syntax in rust-ts-mode,
Yuan Fu <=
- emacs-29 382e018856a 5/6: Add treesit-subtree-stat, Yuan Fu, 2023/01/29