all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#59931: 30.0.50; [PATCH] Tweak various ts-modes indent and font-lock
@ 2022-12-09 21:38 Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-12-12 22:22 ` Yuan Fu
  0 siblings, 1 reply; 2+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-12-09 21:38 UTC (permalink / raw)
  To: 59931; +Cc: casouri

[-- Attachment #1: Type: text/plain, Size: 76 bytes --]

Hi!

Yet some more tweaks - please apply when you find some time :-)

Theo


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Tweak-various-ts-modes-indent-and-font-lock.patch --]
[-- Type: text/x-diff, Size: 4373 bytes --]

From 88a9cc7d4e8407251976b07c9f03f32eabd3bfb7 Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Fri, 9 Dec 2022 22:36:03 +0100
Subject: [PATCH] Tweak various ts-modes indent and font-lock

* 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          | 4 +++-
 lisp/progmodes/java-ts-mode.el       | 4 +++-
 lisp/progmodes/js.el                 | 1 +
 lisp/progmodes/json-ts-mode.el       | 5 ++++-
 lisp/progmodes/typescript-ts-mode.el | 2 ++
 5 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 7b41718a74..5976e94512 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -251,7 +251,9 @@ c-ts-mode--font-lock-settings
    :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
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index 23e166ee4c..d3d658c8b8 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -73,6 +73,7 @@ java-ts-mode--indent-rules
      ((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)
@@ -162,7 +163,8 @@ java-ts-mode--font-lock-settings
    :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
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 45dfef372c..571938c8f0 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3868,6 +3868,7 @@ 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"
diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el
index a118908a00..6fb982e37b 100644
--- a/lisp/progmodes/json-ts-mode.el
+++ b/lisp/progmodes/json-ts-mode.el
@@ -74,6 +74,9 @@ json-ts--indent-rules
 
 (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 @@ json-ts-mode
   ;; 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)))
 
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 243f6146ae..1dec357e4e 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -328,6 +328,8 @@ typescript-ts-base-mode
                   (group (or (syntax comment-end)
                              (seq (+ "*") "/")))))
 
+  (setq-local treesit-defun-prefer-top-level t)
+
   ;; Electric
   (setq-local electric-indent-chars
               (append "{}():;," electric-indent-chars))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#59931: 30.0.50; [PATCH] Tweak various ts-modes indent and  font-lock
  2022-12-09 21:38 bug#59931: 30.0.50; [PATCH] Tweak various ts-modes indent and font-lock Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-12-12 22:22 ` Yuan Fu
  0 siblings, 0 replies; 2+ messages in thread
From: Yuan Fu @ 2022-12-12 22:22 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: 59931-done


Theodor Thornhill <theo@thornhill.no> writes:

> Hi!
>
> Yet some more tweaks - please apply when you find some time :-)
>
> Theo
>

Brilliant, thank you! I applied the patch.

Yuan





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-12 22:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-09 21:38 bug#59931: 30.0.50; [PATCH] Tweak various ts-modes indent and font-lock Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12 22:22 ` Yuan Fu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.