aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2023-02-04 04:16:55 +0200
committerDmitry Gutov2023-02-04 04:16:55 +0200
commit4c765d93ab3dd646c1b9722bdd5a91da525d06f2 (patch)
treed2ca71e020bc23987e30650ff878d70cdcac61d1
parentd99b5151f8c41d45084d10c49c86d6c228d5f730 (diff)
downloademacs-4c765d93ab3dd646c1b9722bdd5a91da525d06f2.tar.gz
emacs-4c765d93ab3dd646c1b9722bdd5a91da525d06f2.zip
Refine the previous change
* lisp/progmodes/ruby-ts-mode.el (ruby-ts--s-p-query): Fix a typo. (ruby-ts--syntax-propertize): Use pcase-exhaustive to avoid typos. Put the last s-t property after heredoc's end (apparently parse-partial-sexp likes that more). Move first s-t property on percent literals to the very beginning (to be refined later). Differentiate the %r{} literals from /.../ ones -- tree-sitter parses them exactly the same.
-rw-r--r--lisp/progmodes/ruby-ts-mode.el19
1 files changed, 13 insertions, 6 deletions
diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index 02cc1aad5e6..c0971193244 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -1026,7 +1026,7 @@ leading double colon is not added."
1026 ;; Backtick method redefinition. 1026 ;; Backtick method redefinition.
1027 ((operator "`" @backtick)) 1027 ((operator "`" @backtick))
1028 ;; TODO: Stop at interpolations. 1028 ;; TODO: Stop at interpolations.
1029 ((regex "/" @regex-slash)) 1029 ((regex "/" @regex_slash))
1030 ;; =begin...=end 1030 ;; =begin...=end
1031 ((comment) @comm 1031 ((comment) @comm
1032 (:match "\\`=" @comm)) 1032 (:match "\\`=" @comm))
@@ -1037,10 +1037,16 @@ leading double colon is not added."
1037(defun ruby-ts--syntax-propertize (beg end) 1037(defun ruby-ts--syntax-propertize (beg end)
1038 (let ((captures (treesit-query-capture 'ruby ruby-ts--s-p-query beg end))) 1038 (let ((captures (treesit-query-capture 'ruby ruby-ts--s-p-query beg end)))
1039 (pcase-dolist (`(,name . ,node) captures) 1039 (pcase-dolist (`(,name . ,node) captures)
1040 (pcase name 1040 (pcase-exhaustive name
1041 ('regex_slash 1041 ('regex_slash
1042 (put-text-property (treesit-node-start node) (treesit-node-end node) 1042 ;; N.B.: A regexp literal with modifiers actually includes them in
1043 'syntax-table (string-to-syntax "\"/"))) 1043 ;; the trailing "/" node.
1044 (put-text-property (treesit-node-start node) (1+ (treesit-node-start node))
1045 'syntax-table
1046 ;; Differentiate the %r{...} literals.
1047 (if (eq ?/ (char-after (treesit-node-start node)))
1048 (string-to-syntax "\"/")
1049 (string-to-syntax "|"))))
1044 ('ident 1050 ('ident
1045 (put-text-property (1- (treesit-node-end node)) (treesit-node-end node) 1051 (put-text-property (1- (treesit-node-end node)) (treesit-node-end node)
1046 'syntax-table (string-to-syntax "_"))) 1052 'syntax-table (string-to-syntax "_")))
@@ -1050,10 +1056,11 @@ leading double colon is not added."
1050 ('heredoc 1056 ('heredoc
1051 (put-text-property (treesit-node-start node) (1+ (treesit-node-start node)) 1057 (put-text-property (treesit-node-start node) (1+ (treesit-node-start node))
1052 'syntax-table (string-to-syntax "\"")) 1058 'syntax-table (string-to-syntax "\""))
1053 (put-text-property (1- (treesit-node-end node)) (treesit-node-end node) 1059 (put-text-property (treesit-node-end node) (1+ (treesit-node-end node))
1054 'syntax-table (string-to-syntax "\""))) 1060 'syntax-table (string-to-syntax "\"")))
1055 ('percent 1061 ('percent
1056 (put-text-property (1+ (treesit-node-start node)) (+ 2 (treesit-node-start node)) 1062 ;; TODO: Put the first one on the first paren in both %Q{} and %().
1063 (put-text-property (treesit-node-start node) (1+ (treesit-node-start node))
1057 'syntax-table (string-to-syntax "|")) 1064 'syntax-table (string-to-syntax "|"))
1058 (put-text-property (1- (treesit-node-end node)) (treesit-node-end node) 1065 (put-text-property (1- (treesit-node-end node)) (treesit-node-end node)
1059 'syntax-table (string-to-syntax "|"))) 1066 'syntax-table (string-to-syntax "|")))