From: Dmitry Gutov Date: Thu, 9 Mar 2023 21:49:39 +0000 (+0200) Subject: ruby-ts-mode: Fine-tune s-p-f on symbols (bug#62086) X-Git-Tag: emacs-29.0.90~208 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ecdfd584a52f280c250b766011867059f9242057;p=emacs.git ruby-ts-mode: Fine-tune s-p-f on symbols (bug#62086) * lisp/progmodes/ruby-ts-mode.el (ruby-ts--s-p-query): Don't match ':' in symbol node text. Or '_', I suppose. (ruby-ts--syntax-propertize): Make sure to only put the '_' syntax on punctuation syntax characters, and not on the whole symbol (to e.g. have symbols like :foo? include text recognized as word). * test/lisp/progmodes/ruby-ts-mode-tests.el (ruby-ts-syntax-propertize-symbol): New test. --- diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index 750642420e3..da2a0a6c852 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." (:match "\\`?[#\"'`:?]" @char)) ;; Symbols like :+, :<=> or :foo=. ((simple_symbol) @symbol - (:match "[[:punct:]]" @symbol)) + (:match "\\s." @symbol)) ;; Method calls with name ending with ? or !. ((call method: (identifier) @ident) (:match "[?!]\\'" @ident)) @@ -1058,7 +1058,9 @@ leading double colon is not added." (put-text-property (1- (treesit-node-end node)) (treesit-node-end node) 'syntax-table (string-to-syntax "_"))) ('symbol - (put-text-property (1+ (treesit-node-start node)) (treesit-node-end node) + (goto-char (treesit-node-end node)) + (skip-syntax-backward "." (treesit-node-start node)) + (put-text-property (point) (treesit-node-end node) 'syntax-table (string-to-syntax "_"))) ('heredoc (put-text-property (treesit-node-start node) (1+ (treesit-node-start node)) diff --git a/test/lisp/progmodes/ruby-ts-mode-tests.el b/test/lisp/progmodes/ruby-ts-mode-tests.el index c99e1a43063..0e258275f97 100644 --- a/test/lisp/progmodes/ruby-ts-mode-tests.el +++ b/test/lisp/progmodes/ruby-ts-mode-tests.el @@ -258,6 +258,21 @@ The whitespace before and including \"|\" on each line is removed." (delete-char 1) (should (string= (ruby-ts-add-log-current-function) "M::C#foo")))) +(ert-deftest ruby-ts-syntax-propertize-symbol () + (pcase-dolist (`(,str . ,expected) + '((":abc" . ":abc") + (":foo?" . #(":foo?" 4 5 (syntax-table (3)))) + (":<=>" . #(":<=>" 1 4 (syntax-table (3)))))) + (ruby-ts-with-temp-buffer str + (syntax-propertize (point-max)) + (let ((text (buffer-string))) + (remove-text-properties 0 (1- (point-max)) + '(fontified) + text) + (should (equal-including-properties + text + expected)))))) + (defmacro ruby-ts-resource-file (file) `(when-let ((testfile ,(or (macroexp-file-name) buffer-file-name)))