diff options
author | Dmitry Gutov <dgutov@yandex.ru> | 2023-02-04 04:16:55 +0200 |
---|---|---|
committer | Dmitry Gutov <dgutov@yandex.ru> | 2023-02-04 04:16:55 +0200 |
commit | 4c765d93ab3dd646c1b9722bdd5a91da525d06f2 (patch) | |
tree | d2ca71e020bc23987e30650ff878d70cdcac61d1 | |
parent | d99b5151f8c41d45084d10c49c86d6c228d5f730 (diff) | |
download | emacs-4c765d93ab3dd646c1b9722bdd5a91da525d06f2.tar.gz emacs-4c765d93ab3dd646c1b9722bdd5a91da525d06f2.tar.bz2 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.el | 19 |
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." ;; Backtick method redefinition. ((operator "`" @backtick)) ;; TODO: Stop at interpolations. - ((regex "/" @regex-slash)) + ((regex "/" @regex_slash)) ;; =begin...=end ((comment) @comm (:match "\\`=" @comm)) @@ -1037,10 +1037,16 @@ leading double colon is not added." (defun ruby-ts--syntax-propertize (beg end) (let ((captures (treesit-query-capture 'ruby ruby-ts--s-p-query beg end))) (pcase-dolist (`(,name . ,node) captures) - (pcase name + (pcase-exhaustive name ('regex_slash - (put-text-property (treesit-node-start node) (treesit-node-end node) - 'syntax-table (string-to-syntax "\"/"))) + ;; N.B.: A regexp literal with modifiers actually includes them in + ;; the trailing "/" node. + (put-text-property (treesit-node-start node) (1+ (treesit-node-start node)) + 'syntax-table + ;; Differentiate the %r{...} literals. + (if (eq ?/ (char-after (treesit-node-start node))) + (string-to-syntax "\"/") + (string-to-syntax "|")))) ('ident (put-text-property (1- (treesit-node-end node)) (treesit-node-end node) 'syntax-table (string-to-syntax "_"))) @@ -1050,10 +1056,11 @@ leading double colon is not added." ('heredoc (put-text-property (treesit-node-start node) (1+ (treesit-node-start node)) 'syntax-table (string-to-syntax "\"")) - (put-text-property (1- (treesit-node-end node)) (treesit-node-end node) + (put-text-property (treesit-node-end node) (1+ (treesit-node-end node)) 'syntax-table (string-to-syntax "\""))) ('percent - (put-text-property (1+ (treesit-node-start node)) (+ 2 (treesit-node-start node)) + ;; TODO: Put the first one on the first paren in both %Q{} and %(). + (put-text-property (treesit-node-start node) (1+ (treesit-node-start node)) 'syntax-table (string-to-syntax "|")) (put-text-property (1- (treesit-node-end node)) (treesit-node-end node) 'syntax-table (string-to-syntax "|"))) |