]> git.eshelyaron.com Git - emacs.git/commitdiff
Tweak various ts-mode's indent and fontification (bug#59931)
authorTheodor Thornhill <theo@thornhill.no>
Fri, 9 Dec 2022 21:36:03 +0000 (22:36 +0100)
committerYuan Fu <casouri@gmail.com>
Mon, 12 Dec 2022 23:08:54 +0000 (15:08 -0800)
* lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Add raw
string literal font-locking.
* lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules): Add
text_block indent rule.
(java-ts-mode--font-lock-settings): Add text_block font-locking.
* lisp/progmodes/js.el (js-ts-mode): Prefer top-level navigation.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Add comment feature.
(json-ts-mode): Use comment feature.
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-base-mode):
Prefer top-level navigation.

lisp/progmodes/c-ts-mode.el
lisp/progmodes/java-ts-mode.el
lisp/progmodes/js.el
lisp/progmodes/json-ts-mode.el
lisp/progmodes/typescript-ts-mode.el

index 824325d83e05004e9142a2cf611e207fe5266fb7..deba83641b2a4a6e456cae931d6180f517dd3c03 100644 (file)
@@ -251,7 +251,9 @@ MODE is either `c' or `cpp'."
    :language mode
    :feature 'string
    `((string_literal) @font-lock-string-face
-     (system_lib_string) @font-lock-string-face)
+     (system_lib_string) @font-lock-string-face
+     ,@(when (eq mode 'cpp)
+         '((raw_string_literal) @font-lock-string-face)))
 
    :language mode
    :feature 'literal
index 9155a7fff256954301cb15f3ae7800cf896b7cd3..ac591a08599a39c71d7271f80ee125b2ad23ad8d 100644 (file)
@@ -73,6 +73,7 @@
      ((node-is "]") parent-bol 0)
      ((and (parent-is "comment") comment-end) comment-start -1)
      ((parent-is "comment") comment-start-skip 0)
+     ((parent-is "text_block") no-indent)
      ((parent-is "class_body") parent-bol java-ts-mode-indent-offset)
      ((parent-is "interface_body") parent-bol java-ts-mode-indent-offset)
      ((parent-is "constructor_body") parent-bol java-ts-mode-indent-offset)
    :language 'java
    :override t
    :feature 'string
-   `((string_literal) @font-lock-string-face)
+   `((string_literal) @font-lock-string-face
+     (text_block) @font-lock-string-face)
    :language 'java
    :override t
    :feature 'literal
index f7318c481a2b66cfc5c9e7a332b154a8e6655133..1de0f3442f086f6d027566758cc4de5babf9c156 100644 (file)
@@ -3871,6 +3871,7 @@ Currently there are `js-mode' and `js-ts-mode'."
     ;; Indent.
     (setq-local treesit-simple-indent-rules js--treesit-indent-rules)
     ;; Navigation.
+    (setq-local treesit-defun-prefer-top-level t)
     (setq-local treesit-defun-type-regexp
                 (rx (or "class_declaration"
                         "method_definition"
index a118908a00cef5d204e344d9fb168dafa0889842..6fb982e37bd081b33edd658da7cc4f32d7362fd0 100644 (file)
@@ -74,6 +74,9 @@
 
 (defvar json-ts-mode--font-lock-settings
   (treesit-font-lock-rules
+   :language 'json
+   :feature 'comment
+   '((comment) @font-lock-comment-face)
    :language 'json
    :feature 'bracket
    '((["[" "]" "{" "}"]) @font-lock-bracket-face)
@@ -161,7 +164,7 @@ the subtrees."
   ;; Font-lock.
   (setq-local treesit-font-lock-settings json-ts-mode--font-lock-settings)
   (setq-local treesit-font-lock-feature-list
-              '((constant number pair string)
+              '((comment constant number pair string)
                 (escape-sequence)
                 (bracket delimiter error)))
 
index 8c4364ecc5b3eb7756812ec07b70fa2565e69e2c..e4d188971a06dfc226f498052d4d6882fd3dbbb1 100644 (file)
@@ -329,6 +329,8 @@ Argument LANGUAGE is either `typescript' or `tsx'."
                   (group (or (syntax comment-end)
                              (seq (+ "*") "/")))))
 
+  (setq-local treesit-defun-prefer-top-level t)
+
   ;; Electric
   (setq-local electric-indent-chars
               (append "{}():;," electric-indent-chars))