all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#60105: [PATCH] Add yaml-ts-mode
@ 2022-12-15 22:19 Randy Taylor
  2022-12-16  0:20 ` Stefan Kangas
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Randy Taylor @ 2022-12-15 22:19 UTC (permalink / raw)
  To: 60105; +Cc: casouri


[-- Attachment #1.1: Type: text/plain, Size: 31 bytes --]

X-Debbugs-CC: casouri@gmail.com

[-- Attachment #1.2: Type: text/html, Size: 606 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-yaml-ts-mode.patch --]
[-- Type: text/x-patch; name=0001-Add-yaml-ts-mode.patch, Size: 7915 bytes --]

From 13d3115e7217ebcc5d17a9557a4b8b0c5ae99215 Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Tue, 13 Dec 2022 09:41:01 -0500
Subject: [PATCH] Add yaml-ts-mode

* admin/notes/tree-sitter/build-module/batch.sh:
* admin/notes/tree-sitter/build-module/build.sh: Add yaml support.
* etc/NEWS: Mention it.
* lisp/textmodes/yaml-ts-mode.el: New major mode with
tree-sitter support.
* lisp/progmodes/eglot.el (eglot-server-programs): Add it.
---
 admin/notes/tree-sitter/build-module/batch.sh |   1 +
 admin/notes/tree-sitter/build-module/build.sh |   3 +
 etc/NEWS                                      |   5 +
 lisp/progmodes/eglot.el                       |   2 +-
 lisp/textmodes/yaml-ts-mode.el                | 151 ++++++++++++++++++
 5 files changed, 161 insertions(+), 1 deletion(-)
 create mode 100644 lisp/textmodes/yaml-ts-mode.el

diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh
index e7ef45cf57..40756c2203 100755
--- a/admin/notes/tree-sitter/build-module/batch.sh
+++ b/admin/notes/tree-sitter/build-module/batch.sh
@@ -17,6 +17,7 @@ languages=
     'toml'
     'tsx'
     'typescript'
+    'yaml'
 )
 
 for language in "${languages[@]}"
diff --git a/admin/notes/tree-sitter/build-module/build.sh b/admin/notes/tree-sitter/build-module/build.sh
index 4195ea58c3..895f5ed9e6 100755
--- a/admin/notes/tree-sitter/build-module/build.sh
+++ b/admin/notes/tree-sitter/build-module/build.sh
@@ -35,6 +35,9 @@ grammardir=
         sourcedir="tree-sitter-typescript/tsx/src"
         grammardir="tree-sitter-typescript/tsx"
         ;;
+    "yaml")
+        org="ikatyang"
+        ;;
 esac
 
 git clone "https://github.com/${org}/${repo}.git" \
diff --git a/etc/NEWS b/etc/NEWS
index 701e414fdb..8b4fb37585 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3081,6 +3081,11 @@ A major mode based on the tree-sitter library for editing files
 written in TOML, a format for writing configuration files.  It is
 auto-enabled for files with the ".toml" extension.
 
+*** New major mode 'yaml-ts-mode'.
+A major mode based on the tree-sitter library for editing files
+written in YAML.  It is auto-enabled for files with the ".yaml" or
+".yml" extensions.
+
 \f
 * Incompatible Lisp Changes in Emacs 29.1
 
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 9c5a361df7..4319623e64 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -224,7 +224,7 @@ eglot-server-programs
                                 ((tex-mode context-mode texinfo-mode bibtex-mode)
                                  . ,(eglot-alternatives '("digestif" "texlab")))
                                 (erlang-mode . ("erlang_ls" "--transport" "stdio"))
-                                (yaml-mode . ("yaml-language-server" "--stdio"))
+                                ((yaml-mode yaml-ts-mode) . ("yaml-language-server" "--stdio"))
                                 (nix-mode . ,(eglot-alternatives '("nil" "rnix-lsp")))
                                 (gdscript-mode . ("localhost" 6008))
                                 ((fortran-mode f90-mode) . ("fortls"))
diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el
new file mode 100644
index 0000000000..6ef6dabb3a
--- /dev/null
+++ b/lisp/textmodes/yaml-ts-mode.el
@@ -0,0 +1,151 @@
+;;; yaml-ts-mode.el --- tree-sitter support for YAML  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author     : Randy Taylor <dev@rjt.dev>
+;; Maintainer : Randy Taylor <dev@rjt.dev>
+;; Created    : December 2022
+;; Keywords   : yaml languages tree-sitter
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+
+;;; Code:
+
+(require 'treesit)
+
+(declare-function treesit-parser-create "treesit.c")
+
+(defvar yaml-ts-mode--syntax-table
+  (let ((table (make-syntax-table)))
+    (modify-syntax-entry ?#  "<"  table)
+    (modify-syntax-entry ?\n ">"  table)
+    (modify-syntax-entry ?&  "."  table)
+    (modify-syntax-entry ?*  "."  table)
+    (modify-syntax-entry ?\( "."  table)
+    (modify-syntax-entry ?\) "."  table)
+    (modify-syntax-entry ?\' "\"" table)
+    table)
+  "Syntax table for `yaml-ts-mode'.")
+
+(defvar yaml-ts-mode--font-lock-settings
+  (treesit-font-lock-rules
+   :language 'yaml
+   :feature 'bracket
+   '((["[" "]" "{" "}"]) @font-lock-bracket-face)
+
+   :language 'yaml
+   :feature 'comment
+   '((comment) @font-lock-comment-face)
+
+   :language 'yaml
+   :feature 'constant
+   '([(boolean_scalar)
+      (null_scalar)
+      (reserved_directive)
+      (tag_directive)
+      (yaml_directive)] @font-lock-constant-face)
+
+   :language 'yaml
+   :feature 'delimiter
+   '((["," ":" "-" ">" "?" "|"]) @font-lock-delimiter-face)
+
+   :language 'yaml
+   :feature 'misc-punctuation
+   '((["---" "..." "&" "*"]) @font-lock-misc-punctuation-face)
+
+   :language 'yaml
+   :feature 'number
+   '([(float_scalar) (integer_scalar)] @font-lock-number-face)
+
+   :language 'yaml
+   :feature 'type
+   '([(alias_name) (anchor_name) (tag)] @font-lock-type-face)
+
+   :language 'yaml
+   :feature 'string
+   :override t
+   '([(block_scalar)
+      (double_quote_scalar)
+      (single_quote_scalar)
+      (string_scalar)] @font-lock-string-face)
+
+   :language 'yaml
+   :feature 'escape-sequence
+   :override t
+   '((escape_sequence) @font-lock-escape-face)
+
+   :language 'yaml
+   :feature 'property
+   :override t
+   '((block_mapping_pair
+      key: (flow_node (plain_scalar (string_scalar) @font-lock-property-face)))
+     (block_mapping_pair
+      key: (flow_node
+            [(double_quote_scalar) (single_quote_scalar)] @font-lock-property-face))
+     (flow_mapping
+      (_ key: (flow_node (plain_scalar (string_scalar) @font-lock-property-face))))
+     (flow_mapping
+      (_ key:
+         (flow_node
+          [(double_quote_scalar) (single_quote_scalar)] @font-lock-property-face)))
+     (flow_sequence
+      (_ key: (flow_node (plain_scalar (string_scalar) @font-lock-property-face))))
+     (flow_sequence
+      (_ key:
+         (flow_node
+          [(double_quote_scalar) (single_quote_scalar)] @font-lock-property-face))))
+
+   :language 'yaml
+   :feature 'error
+   :override t
+   '((ERROR) @font-lock-warning-face))
+  "Tree-sitter font-lock settings for `yaml-ts-mode'.")
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode))
+
+;;;###autoload
+(define-derived-mode yaml-ts-mode text-mode "YAML"
+  "Major mode for editing YAML, powered by tree-sitter."
+  :group 'yaml
+  :syntax-table yaml-ts-mode--syntax-table
+
+  (when (treesit-ready-p 'yaml)
+    (treesit-parser-create 'yaml)
+
+    ;; Comments.
+    (setq-local comment-start "# ")
+    (setq-local comment-end "")
+
+    ;; Indentation.
+    (setq-local indent-tabs-mode nil)
+
+    ;; Font-lock.
+    (setq-local treesit-font-lock-settings yaml-ts-mode--font-lock-settings)
+    (setq-local treesit-font-lock-feature-list
+                '((comment)
+                  (string type)
+                  (constant escape-sequence number property)
+                  (bracket delimiter error misc-punctuation)))
+
+    (treesit-major-mode-setup)))
+
+(provide 'yaml-ts-mode)
+
+;;; yaml-ts-mode.el ends here
-- 
2.39.0


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

* bug#60105: [PATCH] Add yaml-ts-mode
  2022-12-15 22:19 bug#60105: [PATCH] Add yaml-ts-mode Randy Taylor
@ 2022-12-16  0:20 ` Stefan Kangas
  2022-12-16  2:01   ` Randy Taylor
  2022-12-16 22:55 ` Yuan Fu
  2023-01-02 18:52 ` Juri Linkov
  2 siblings, 1 reply; 10+ messages in thread
From: Stefan Kangas @ 2022-12-16  0:20 UTC (permalink / raw)
  To: Randy Taylor, 60105; +Cc: casouri

Randy Taylor <dev@rjt.dev> writes:

> diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> index 9c5a361df7..4319623e64 100644
> --- a/lisp/progmodes/eglot.el
> +++ b/lisp/progmodes/eglot.el
> @@ -224,7 +224,7 @@ eglot-server-programs
>                                  ((tex-mode context-mode texinfo-mode bibtex-mode)
>                                   . ,(eglot-alternatives '("digestif" "texlab")))
>                                  (erlang-mode . ("erlang_ls" "--transport" "stdio"))
> -                                (yaml-mode . ("yaml-language-server" "--stdio"))
> +                                ((yaml-mode yaml-ts-mode) . ("yaml-language-server" "--stdio"))

This is a nit, but I think it might make more sense to users if we put
the built-in mode first in the list.  After all, the one we ship with
Emacs is, or will be, the standard mode.





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

* bug#60105: [PATCH] Add yaml-ts-mode
  2022-12-16  0:20 ` Stefan Kangas
@ 2022-12-16  2:01   ` Randy Taylor
  0 siblings, 0 replies; 10+ messages in thread
From: Randy Taylor @ 2022-12-16  2:01 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: casouri, 60105

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

On Thursday, December 15th, 2022 at 19:20, Stefan Kangas <stefankangas@gmail.com> wrote:
> 
> Randy Taylor dev@rjt.dev writes:
> 
> > diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> > index 9c5a361df7..4319623e64 100644
> > --- a/lisp/progmodes/eglot.el
> > +++ b/lisp/progmodes/eglot.el
> > @@ -224,7 +224,7 @@ eglot-server-programs
> > ((tex-mode context-mode texinfo-mode bibtex-mode)
> > . ,(eglot-alternatives '("digestif" "texlab")))
> > (erlang-mode . ("erlang_ls" "--transport" "stdio"))
> > - (yaml-mode . ("yaml-language-server" "--stdio"))
> > + ((yaml-mode yaml-ts-mode) . ("yaml-language-server" "--stdio"))
> 
> 
> This is a nit, but I think it might make more sense to users if we put
> the built-in mode first in the list. After all, the one we ship with
> Emacs is, or will be, the standard mode.

Sounds good to me. I'll submit another patch tomorrow making that change for the rest of the modes we've added (unless someone beats me to it).

Attached is a new patch that applies cleanly against emacs-29 and has yaml-ts-mode come first for eglot.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-yaml-ts-mode-Bug-60105.patch --]
[-- Type: text/x-patch; name=0001-Add-yaml-ts-mode-Bug-60105.patch, Size: 7949 bytes --]

From 18e0fe1c1a676087e2a38b3ffd7445b509bbb9db Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Tue, 13 Dec 2022 09:41:01 -0500
Subject: [PATCH] Add yaml-ts-mode (Bug#60105)

* admin/notes/tree-sitter/build-module/batch.sh:
* admin/notes/tree-sitter/build-module/build.sh: Add yaml support.
* etc/NEWS: Mention it.
* lisp/textmodes/yaml-ts-mode.el: New major mode with
tree-sitter support.
* lisp/progmodes/eglot.el (eglot-server-programs): Add it.
---
 admin/notes/tree-sitter/build-module/batch.sh |   1 +
 admin/notes/tree-sitter/build-module/build.sh |   3 +
 etc/NEWS                                      |   5 +
 lisp/progmodes/eglot.el                       |   2 +-
 lisp/textmodes/yaml-ts-mode.el                | 151 ++++++++++++++++++
 5 files changed, 161 insertions(+), 1 deletion(-)
 create mode 100644 lisp/textmodes/yaml-ts-mode.el

diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh
index c50b9df37e..58272c7454 100755
--- a/admin/notes/tree-sitter/build-module/batch.sh
+++ b/admin/notes/tree-sitter/build-module/batch.sh
@@ -18,6 +18,7 @@ languages=
     'toml'
     'tsx'
     'typescript'
+    'yaml'
 )
 
 for language in "${languages[@]}"
diff --git a/admin/notes/tree-sitter/build-module/build.sh b/admin/notes/tree-sitter/build-module/build.sh
index b6c83ea9b9..f096294028 100755
--- a/admin/notes/tree-sitter/build-module/build.sh
+++ b/admin/notes/tree-sitter/build-module/build.sh
@@ -40,6 +40,9 @@ grammardir=
         sourcedir="tree-sitter-typescript/tsx/src"
         grammardir="tree-sitter-typescript/tsx"
         ;;
+    "yaml")
+        org="ikatyang"
+        ;;
 esac
 
 git clone "https://github.com/${org}/${repo}.git" \
diff --git a/etc/NEWS b/etc/NEWS
index dd11b3c271..93239e1a5f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3089,6 +3089,11 @@ the Go language.  It is auto-enabled for files with the ".go" extension.
 A major mode based on the tree-sitter library for editing "go.mod"
 files.  It is auto-enabled for files which are named "go.mod".
 
+*** New major mode 'yaml-ts-mode'.
+A major mode based on the tree-sitter library for editing files
+written in YAML.  It is auto-enabled for files with the ".yaml" or
+".yml" extensions.
+
 \f
 * Incompatible Lisp Changes in Emacs 29.1
 
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 02bb6bb665..161693a5a6 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -225,7 +225,7 @@ eglot-server-programs
                                 ((tex-mode context-mode texinfo-mode bibtex-mode)
                                  . ,(eglot-alternatives '("digestif" "texlab")))
                                 (erlang-mode . ("erlang_ls" "--transport" "stdio"))
-                                (yaml-mode . ("yaml-language-server" "--stdio"))
+                                ((yaml-ts-mode yaml-mode) . ("yaml-language-server" "--stdio"))
                                 (nix-mode . ,(eglot-alternatives '("nil" "rnix-lsp")))
                                 (gdscript-mode . ("localhost" 6008))
                                 ((fortran-mode f90-mode) . ("fortls"))
diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el
new file mode 100644
index 0000000000..6ef6dabb3a
--- /dev/null
+++ b/lisp/textmodes/yaml-ts-mode.el
@@ -0,0 +1,151 @@
+;;; yaml-ts-mode.el --- tree-sitter support for YAML  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author     : Randy Taylor <dev@rjt.dev>
+;; Maintainer : Randy Taylor <dev@rjt.dev>
+;; Created    : December 2022
+;; Keywords   : yaml languages tree-sitter
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+
+;;; Code:
+
+(require 'treesit)
+
+(declare-function treesit-parser-create "treesit.c")
+
+(defvar yaml-ts-mode--syntax-table
+  (let ((table (make-syntax-table)))
+    (modify-syntax-entry ?#  "<"  table)
+    (modify-syntax-entry ?\n ">"  table)
+    (modify-syntax-entry ?&  "."  table)
+    (modify-syntax-entry ?*  "."  table)
+    (modify-syntax-entry ?\( "."  table)
+    (modify-syntax-entry ?\) "."  table)
+    (modify-syntax-entry ?\' "\"" table)
+    table)
+  "Syntax table for `yaml-ts-mode'.")
+
+(defvar yaml-ts-mode--font-lock-settings
+  (treesit-font-lock-rules
+   :language 'yaml
+   :feature 'bracket
+   '((["[" "]" "{" "}"]) @font-lock-bracket-face)
+
+   :language 'yaml
+   :feature 'comment
+   '((comment) @font-lock-comment-face)
+
+   :language 'yaml
+   :feature 'constant
+   '([(boolean_scalar)
+      (null_scalar)
+      (reserved_directive)
+      (tag_directive)
+      (yaml_directive)] @font-lock-constant-face)
+
+   :language 'yaml
+   :feature 'delimiter
+   '((["," ":" "-" ">" "?" "|"]) @font-lock-delimiter-face)
+
+   :language 'yaml
+   :feature 'misc-punctuation
+   '((["---" "..." "&" "*"]) @font-lock-misc-punctuation-face)
+
+   :language 'yaml
+   :feature 'number
+   '([(float_scalar) (integer_scalar)] @font-lock-number-face)
+
+   :language 'yaml
+   :feature 'type
+   '([(alias_name) (anchor_name) (tag)] @font-lock-type-face)
+
+   :language 'yaml
+   :feature 'string
+   :override t
+   '([(block_scalar)
+      (double_quote_scalar)
+      (single_quote_scalar)
+      (string_scalar)] @font-lock-string-face)
+
+   :language 'yaml
+   :feature 'escape-sequence
+   :override t
+   '((escape_sequence) @font-lock-escape-face)
+
+   :language 'yaml
+   :feature 'property
+   :override t
+   '((block_mapping_pair
+      key: (flow_node (plain_scalar (string_scalar) @font-lock-property-face)))
+     (block_mapping_pair
+      key: (flow_node
+            [(double_quote_scalar) (single_quote_scalar)] @font-lock-property-face))
+     (flow_mapping
+      (_ key: (flow_node (plain_scalar (string_scalar) @font-lock-property-face))))
+     (flow_mapping
+      (_ key:
+         (flow_node
+          [(double_quote_scalar) (single_quote_scalar)] @font-lock-property-face)))
+     (flow_sequence
+      (_ key: (flow_node (plain_scalar (string_scalar) @font-lock-property-face))))
+     (flow_sequence
+      (_ key:
+         (flow_node
+          [(double_quote_scalar) (single_quote_scalar)] @font-lock-property-face))))
+
+   :language 'yaml
+   :feature 'error
+   :override t
+   '((ERROR) @font-lock-warning-face))
+  "Tree-sitter font-lock settings for `yaml-ts-mode'.")
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode))
+
+;;;###autoload
+(define-derived-mode yaml-ts-mode text-mode "YAML"
+  "Major mode for editing YAML, powered by tree-sitter."
+  :group 'yaml
+  :syntax-table yaml-ts-mode--syntax-table
+
+  (when (treesit-ready-p 'yaml)
+    (treesit-parser-create 'yaml)
+
+    ;; Comments.
+    (setq-local comment-start "# ")
+    (setq-local comment-end "")
+
+    ;; Indentation.
+    (setq-local indent-tabs-mode nil)
+
+    ;; Font-lock.
+    (setq-local treesit-font-lock-settings yaml-ts-mode--font-lock-settings)
+    (setq-local treesit-font-lock-feature-list
+                '((comment)
+                  (string type)
+                  (constant escape-sequence number property)
+                  (bracket delimiter error misc-punctuation)))
+
+    (treesit-major-mode-setup)))
+
+(provide 'yaml-ts-mode)
+
+;;; yaml-ts-mode.el ends here
-- 
2.39.0


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

* bug#60105: [PATCH] Add yaml-ts-mode
  2022-12-15 22:19 bug#60105: [PATCH] Add yaml-ts-mode Randy Taylor
  2022-12-16  0:20 ` Stefan Kangas
@ 2022-12-16 22:55 ` Yuan Fu
  2023-01-02 18:52 ` Juri Linkov
  2 siblings, 0 replies; 10+ messages in thread
From: Yuan Fu @ 2022-12-16 22:55 UTC (permalink / raw)
  To: Randy Taylor; +Cc: Stefan Kangas, 60105-done


Randy Taylor <dev@rjt.dev> writes:

> On Thursday, December 15th, 2022 at 19:20, Stefan Kangas <stefankangas@gmail.com> wrote:
>> 
>> Randy Taylor dev@rjt.dev writes:
>> 
>> > diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
>> > index 9c5a361df7..4319623e64 100644
>> > --- a/lisp/progmodes/eglot.el
>> > +++ b/lisp/progmodes/eglot.el
>> > @@ -224,7 +224,7 @@ eglot-server-programs
>> > ((tex-mode context-mode texinfo-mode bibtex-mode)
>> > . ,(eglot-alternatives '("digestif" "texlab")))
>> > (erlang-mode . ("erlang_ls" "--transport" "stdio"))
>> > - (yaml-mode . ("yaml-language-server" "--stdio"))
>> > + ((yaml-mode yaml-ts-mode) . ("yaml-language-server" "--stdio"))
>> 
>> 
>> This is a nit, but I think it might make more sense to users if we put
>> the built-in mode first in the list. After all, the one we ship with
>> Emacs is, or will be, the standard mode.
>
> Sounds good to me. I'll submit another patch tomorrow making that change for the rest of the modes we've added (unless someone beats me to it).
>
> Attached is a new patch that applies cleanly against emacs-29 and has yaml-ts-mode come first for eglot.
>

LGTM, I applied the patch, thanks!

Yuan





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

* bug#60105: [PATCH] Add yaml-ts-mode
  2022-12-15 22:19 bug#60105: [PATCH] Add yaml-ts-mode Randy Taylor
  2022-12-16  0:20 ` Stefan Kangas
  2022-12-16 22:55 ` Yuan Fu
@ 2023-01-02 18:52 ` Juri Linkov
  2023-01-02 21:58   ` Randy Taylor
  2 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2023-01-02 18:52 UTC (permalink / raw)
  To: Randy Taylor; +Cc: casouri, 60105

> +   :language 'yaml
> +   :feature 'string
> +   :override t
> +   '([(block_scalar)
> +      (double_quote_scalar)
> +      (single_quote_scalar)
> +      (string_scalar)] @font-lock-string-face)

Thanks, yaml-ts-mode works great.  One problem is that
with the above setting everything is (over)fontified in the buffer.
This is the only mode I have seen where 100% of text has
non-default colors making it so called "angry fruit salad".
In this regard yaml-mode is not better: it fontifies only text in quotes
that makes an unnecessary distinction between quoted and unquoted text.
I know it's possible to configure this in a hackish way:

  (with-eval-after-load 'yaml-ts-mode
    (setq yaml-ts-mode--font-lock-settings
          (seq-remove (lambda (e) (eq (nth 2 e) 'string))
                      yaml-ts-mode--font-lock-settings)))

But what I propose is to add a customizable option to enable/disable
font-lock-string-face on most text to lessen the color burden on users.





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

* bug#60105: [PATCH] Add yaml-ts-mode
  2023-01-02 18:52 ` Juri Linkov
@ 2023-01-02 21:58   ` Randy Taylor
  2023-01-03 18:21     ` Juri Linkov
  0 siblings, 1 reply; 10+ messages in thread
From: Randy Taylor @ 2023-01-02 21:58 UTC (permalink / raw)
  To: Juri Linkov; +Cc: casouri, 60105

On Monday, January 2nd, 2023 at 13:52, Juri Linkov <juri@linkov.net> wrote:
> 
> > + :language 'yaml
> 
> > + :feature 'string
> > + :override t
> > + '([(block_scalar)
> > + (double_quote_scalar)
> > + (single_quote_scalar)
> > + (string_scalar)] @font-lock-string-face)
> 
> 
> Thanks, yaml-ts-mode works great. One problem is that
> with the above setting everything is (over)fontified in the buffer.
> This is the only mode I have seen where 100% of text has
> non-default colors making it so called "angry fruit salad".
> In this regard yaml-mode is not better: it fontifies only text in quotes
> that makes an unnecessary distinction between quoted and unquoted text.
> I know it's possible to configure this in a hackish way:
> 
> (with-eval-after-load 'yaml-ts-mode
> (setq yaml-ts-mode--font-lock-settings
> (seq-remove (lambda (e) (eq (nth 2 e) 'string))
> yaml-ts-mode--font-lock-settings)))
> 
> But what I propose is to add a customizable option to enable/disable
> font-lock-string-face on most text to lessen the color burden on users.

I think using treesit-font-lock-recompute-features is the way to adjust which features you want, and is what is expected for cases like this (but Yuan would know best).

Alternatively, treesit-font-lock-level dictates which level of features should be included for highlighting. The default is level 3, and string is on level 2. We can move string to the 4th level, which may be an OK compromise?





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

* bug#60105: [PATCH] Add yaml-ts-mode
  2023-01-02 21:58   ` Randy Taylor
@ 2023-01-03 18:21     ` Juri Linkov
  2023-01-04 23:30       ` Dmitry Gutov
  0 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2023-01-03 18:21 UTC (permalink / raw)
  To: Randy Taylor; +Cc: casouri, 60105

>> But what I propose is to add a customizable option to enable/disable
>> font-lock-string-face on most text to lessen the color burden on users.
>
> I think using treesit-font-lock-recompute-features is the way to
> adjust which features you want, and is what is expected for cases like
> this (but Yuan would know best).

The reason why I proposed a new customizable option is because
ruby-ts-mode provides an option ruby-ts-highlight-predefined-constants
that enables some rules in ruby-ts--font-lock-settings.  But maybe
there is no way to avoid this fine-grained setting in ruby-ts-mode.

But you are right that (treesit-font-lock-recompute-features '() '(string))
is the right way to customize it.

> Alternatively, treesit-font-lock-level dictates which level of
> features should be included for highlighting. The default is level 3,
> and string is on level 2. We can move string to the 4th level, which
> may be an OK compromise?

It would be nice if you will decide to move 'string' to the 4th level
by default since the 4th level is intended for maximal fontification.





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

* bug#60105: [PATCH] Add yaml-ts-mode
  2023-01-03 18:21     ` Juri Linkov
@ 2023-01-04 23:30       ` Dmitry Gutov
  2023-01-05 18:09         ` Juri Linkov
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Gutov @ 2023-01-04 23:30 UTC (permalink / raw)
  To: Juri Linkov, Randy Taylor; +Cc: casouri, 60105

On 03/01/2023 20:21, Juri Linkov wrote:
> The reason why I proposed a new customizable option is because
> ruby-ts-mode provides an option ruby-ts-highlight-predefined-constants
> that enables some rules in ruby-ts--font-lock-settings.  But maybe
> there is no way to avoid this fine-grained setting in ruby-ts-mode.

But there is. What do you think about this change?

diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index 5c173ad24c7..93039c27511 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -87,11 +87,6 @@ ruby-ts
    :prefix "ruby-ts-"
    :group 'languages)

-(defcustom ruby-ts-highlight-predefined-constants t
-  "When non-nil, the pre-defined constants are highlighted.
-They will be highlighted the same way as the pre-defined variables."
-  :type 'boolean)
-
  (defvar ruby-ts--operators
    '("+" "-" "*" "/" "%" "**"
      "==" "!=" ">" "<" ">=" "<=" "<=>" "==="
@@ -202,9 +197,11 @@ ruby-ts--font-lock-settings

     :language language
     :feature 'builtin
-   `(((global_variable) @var (:match ,ruby-ts--predefined-variables 
@var)) @font-lock-builtin-face
-     ,@(when ruby-ts-highlight-predefined-constants
-         `(((constant) @var (:match ,ruby-ts--predefined-constants 
@var)) @font-lock-builtin-face)))
+   `(((global_variable) @var (:match ,ruby-ts--predefined-variables 
@var)) @font-lock-builtin-face)
+
+   :language language
+   :feature 'builtin-constant
+   `(((constant) @var (:match ,ruby-ts--predefined-constants @var)) 
@font-lock-builtin-face)

     :language language
     :feature 'keyword
@@ -932,7 +929,7 @@ ruby-ts-mode
    (setq-local treesit-font-lock-feature-list
                '(( comment method-definition )
                  ( keyword regexp string type)
-                ( builtin constant
+                ( builtin builtin-constant constant
                    delimiter escape-sequence global
                    instance
                    interpolation literal symbol variable)






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

* bug#60105: [PATCH] Add yaml-ts-mode
  2023-01-04 23:30       ` Dmitry Gutov
@ 2023-01-05 18:09         ` Juri Linkov
  2023-01-06  1:55           ` Dmitry Gutov
  0 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2023-01-05 18:09 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Randy Taylor, casouri, 60105

>> The reason why I proposed a new customizable option is because
>> ruby-ts-mode provides an option ruby-ts-highlight-predefined-constants
>> that enables some rules in ruby-ts--font-lock-settings.  But maybe
>> there is no way to avoid this fine-grained setting in ruby-ts-mode.
>
> But there is. What do you think about this change?
>
> @@ -202,9 +197,11 @@ ruby-ts--font-lock-settings
>
>     :language language
>     :feature 'builtin
> -   `(((global_variable) @var (:match ,ruby-ts--predefined-variables @var)) @font-lock-builtin-face
> -     ,@(when ruby-ts-highlight-predefined-constants
> -         `(((constant) @var (:match ,ruby-ts--predefined-constants @var))
>          @font-lock-builtin-face)))
> +   `(((global_variable) @var (:match ,ruby-ts--predefined-variables @var)) @font-lock-builtin-face)
> +
> +   :language language
> +   :feature 'builtin-constant
> +   `(((constant) @var (:match ,ruby-ts--predefined-constants @var)) @font-lock-builtin-face)

Look like this is a clear name.





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

* bug#60105: [PATCH] Add yaml-ts-mode
  2023-01-05 18:09         ` Juri Linkov
@ 2023-01-06  1:55           ` Dmitry Gutov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry Gutov @ 2023-01-06  1:55 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Randy Taylor, casouri, 60105

On 05/01/2023 20:09, Juri Linkov wrote:
>>> The reason why I proposed a new customizable option is because
>>> ruby-ts-mode provides an option ruby-ts-highlight-predefined-constants
>>> that enables some rules in ruby-ts--font-lock-settings.  But maybe
>>> there is no way to avoid this fine-grained setting in ruby-ts-mode.
>> But there is. What do you think about this change?
>>
>> @@ -202,9 +197,11 @@ ruby-ts--font-lock-settings
>>
>>      :language language
>>      :feature 'builtin
>> -   `(((global_variable) @var (:match ,ruby-ts--predefined-variables @var)) @font-lock-builtin-face
>> -     ,@(when ruby-ts-highlight-predefined-constants
>> -         `(((constant) @var (:match ,ruby-ts--predefined-constants @var))
>>           @font-lock-builtin-face)))
>> +   `(((global_variable) @var (:match ,ruby-ts--predefined-variables @var)) @font-lock-builtin-face)
>> +
>> +   :language language
>> +   :feature 'builtin-constant
>> +   `(((constant) @var (:match ,ruby-ts--predefined-constants @var)) @font-lock-builtin-face)
> Look like this is a clear name.

Very good. Pushed.





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

end of thread, other threads:[~2023-01-06  1:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-15 22:19 bug#60105: [PATCH] Add yaml-ts-mode Randy Taylor
2022-12-16  0:20 ` Stefan Kangas
2022-12-16  2:01   ` Randy Taylor
2022-12-16 22:55 ` Yuan Fu
2023-01-02 18:52 ` Juri Linkov
2023-01-02 21:58   ` Randy Taylor
2023-01-03 18:21     ` Juri Linkov
2023-01-04 23:30       ` Dmitry Gutov
2023-01-05 18:09         ` Juri Linkov
2023-01-06  1:55           ` Dmitry Gutov

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.