emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 ecdfd584a52: ruby-ts-mode: Fine-tune s-p-f on symbols (bug#6208


From: Dmitry Gutov
Subject: emacs-29 ecdfd584a52: ruby-ts-mode: Fine-tune s-p-f on symbols (bug#62086)
Date: Thu, 9 Mar 2023 16:51:02 -0500 (EST)

branch: emacs-29
commit ecdfd584a52f280c250b766011867059f9242057
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    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.
---
 lisp/progmodes/ruby-ts-mode.el            |  6 ++++--
 test/lisp/progmodes/ruby-ts-mode-tests.el | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]