* toml-ts-mode: first draft @ 2022-12-11 13:28 Jostein Kjønigsen 2022-12-11 17:09 ` Juri Linkov 0 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-11 13:28 UTC (permalink / raw) To: Ergus via Emacs development discussions., Yuan Fu, Theodor Thornhill, Eli Zaretskii [-- Attachment #1.1: Type: text/html, Size: 1968 bytes --] [-- Attachment #1.2: 0003-Introduce-support-for-TOML-config-format.patch --] [-- Type: application/octet-stream, Size: 5735 bytes --] From 0cf13cd41ad1a73e3fab3ce87699b2d27e1b5564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <jostein@kjonigsen.net> Date: Sun, 11 Dec 2022 13:05:29 +0100 Subject: [PATCH 3/3] Introduce support for TOML config-format This commit introduces support for the semi-popular TOML config-format[1] through a new major-mode: toml-ts-mode. I've read through the full spec[2], and from what I can see this major-mode should provide correct syntax-highligting for every sort of config-declaration which adheres to the specification. Besides that it also adds support for basic tree-sitter based navigation. For the time being toml-ts-mode does NOT support imenu navigation, but this is clearly something which can be added later. [1] https://toml.io/en/ [2] https://toml.io/en/v1.0.0 --- admin/notes/tree-sitter/build-module/batch.sh | 1 + lisp/progmodes/toml-ts-mode.el | 115 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 lisp/progmodes/toml-ts-mode.el diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh index d45f37f4b64..73914125a8b 100755 --- a/admin/notes/tree-sitter/build-module/batch.sh +++ b/admin/notes/tree-sitter/build-module/batch.sh @@ -13,6 +13,7 @@ languages= 'rust' 'typescript' 'tsx' + 'toml' ) for language in "${languages[@]}" diff --git a/lisp/progmodes/toml-ts-mode.el b/lisp/progmodes/toml-ts-mode.el new file mode 100644 index 00000000000..dcc2ba6e472 --- /dev/null +++ b/lisp/progmodes/toml-ts-mode.el @@ -0,0 +1,115 @@ +;;; toml-ts-mode.el --- tree-sitter support for TOML -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; Author : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Maintainer : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Created : December 2022 +;; Keywords : toml 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") +(declare-function treesit-induce-sparse-tree "treesit.c") +(declare-function treesit-node-start "treesit.c") +(declare-function treesit-node-child-by-field-name "treesit.c") + +(defvar toml-ts-mode--font-lock-settings + (treesit-font-lock-rules + :language 'toml + :feature 'constant + '((boolean) @font-lock-constant-face) + :language 'toml + :feature 'delimiter + '((["="]) @font-lock-delimiter-face) + :language 'toml + :feature 'number + '((integer) @font-lock-number-face + (float) @font-lock-number-face + (local_date) @font-lock-number-face + (local_date_time) @font-lock-number-face + (local_time) @font-lock-number-face) + :language 'toml + :feature 'string + '((string) @font-lock-string-face) + :language 'toml + :feature 'escape-sequence + :override t + '((escape_sequence) @font-lock-escape-face) + :language 'toml + :feature 'pair + :override t ; Needed for overriding string face on keys. + '((comment) @font-lock-comment-face + (bare_key) @font-lock-property-face + (quoted_key) @font-lock-property-face + (table ("[" @font-lock-bracket-face + (_) @font-lock-type-face + "]" @font-lock-bracket-face)) + (table_array_element ("[[" @font-lock-bracket-face + (_) @font-lock-type-face + "]]" @font-lock-bracket-face)) + (table (quoted_key) @font-lock-type-face) + (table (dotted_key (quoted_key)) @font-lock-type-face)) + :language 'toml + :feature 'error + :override t + '((ERROR) @font-lock-warning-face)) + "Font-lock settings for TOML.") + +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-ts-mode)) + +;;;###autoload +(define-derived-mode toml-ts-mode prog-mode "TOML" + "Major mode for editing TOML, powered by tree-sitter." + :group 'toml-mode + + (unless (treesit-ready-p 'toml) + (error "Tree-sitter for TOML isn't avilable")) + + (treesit-parser-create 'toml) + + ;; Comments + (setq-local comment-start "# ") + (setq-local commend-end "") + + ;; Navigation. + (setq-local treesit-defun-type-regexp + (rx (or "table" "table_array_element"))) + + ;; Font-lock. + (setq-local treesit-font-lock-settings toml-ts-mode--font-lock-settings) + (setq-local treesit-font-lock-feature-list + '((constant number pair string) + (escape-sequence) + (delimiter error))) + + ;; Imenu. + ;; (setq-local imenu-create-index-function #'toml-ts-mode--imenu) + ;; (setq-local which-func-functions nil) ;; Piggyback on imenu + + (treesit-major-mode-setup)) + +(provide 'toml-ts-mode) + +;;; toml-ts-mode.el ends here -- 2.37.2 [-- Attachment #1.3: Type: text/html, Size: 141 bytes --] ^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 13:28 toml-ts-mode: first draft Jostein Kjønigsen @ 2022-12-11 17:09 ` Juri Linkov 2022-12-11 17:23 ` Jostein Kjønigsen 2022-12-11 17:40 ` Eli Zaretskii 0 siblings, 2 replies; 36+ messages in thread From: Juri Linkov @ 2022-12-11 17:09 UTC (permalink / raw) To: Jostein Kjønigsen Cc: Ergus via Emacs development discussions., Yuan Fu, Theodor Thornhill, Eli Zaretskii > lisp/progmodes/toml-ts-mode.el Why not lisp/textmodes/toml-ts-mode.el? ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 17:09 ` Juri Linkov @ 2022-12-11 17:23 ` Jostein Kjønigsen 2022-12-11 17:40 ` Eli Zaretskii 1 sibling, 0 replies; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-11 17:23 UTC (permalink / raw) To: Juri Linkov Cc: Ergus via Emacs development discussions., Yuan Fu, Theodor Thornhill, Eli Zaretskii [-- Attachment #1.1: Type: text/html, Size: 3555 bytes --] [-- Attachment #1.2: favicon.ico --] [-- Type: image/x-icon, Size: 3290 bytes --] ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 17:09 ` Juri Linkov 2022-12-11 17:23 ` Jostein Kjønigsen @ 2022-12-11 17:40 ` Eli Zaretskii 2022-12-11 18:19 ` Stefan Kangas 2022-12-11 19:56 ` Jostein Kjønigsen 1 sibling, 2 replies; 36+ messages in thread From: Eli Zaretskii @ 2022-12-11 17:40 UTC (permalink / raw) To: Juri Linkov; +Cc: jostein, emacs-devel, casouri, theo > From: Juri Linkov <juri@linkov.net> > Cc: "Ergus via Emacs development discussions." <emacs-devel@gnu.org>, Yuan > Fu <casouri@gmail.com>, Theodor Thornhill <theo@thornhill.no>, Eli > Zaretskii <eliz@gnu.org> > Date: Sun, 11 Dec 2022 19:09:46 +0200 > > > lisp/progmodes/toml-ts-mode.el > > Why not lisp/textmodes/toml-ts-mode.el? I agree: conf-mode is in textmodes, so this new mode should be there as well. ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 17:40 ` Eli Zaretskii @ 2022-12-11 18:19 ` Stefan Kangas 2022-12-11 18:23 ` Eli Zaretskii 2022-12-12 17:04 ` Juri Linkov 2022-12-11 19:56 ` Jostein Kjønigsen 1 sibling, 2 replies; 36+ messages in thread From: Stefan Kangas @ 2022-12-11 18:19 UTC (permalink / raw) To: Eli Zaretskii, Juri Linkov; +Cc: jostein, emacs-devel, casouri, theo Eli Zaretskii <eliz@gnu.org> writes: >> Why not lisp/textmodes/toml-ts-mode.el? > > I agree: conf-mode is in textmodes, so this new mode should be there > as well. Should json-ts-mode.el be moved to textmodes as well? ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 18:19 ` Stefan Kangas @ 2022-12-11 18:23 ` Eli Zaretskii 2022-12-11 21:43 ` Stefan Kangas 2022-12-12 17:04 ` Juri Linkov 1 sibling, 1 reply; 36+ messages in thread From: Eli Zaretskii @ 2022-12-11 18:23 UTC (permalink / raw) To: Stefan Kangas; +Cc: juri, jostein, emacs-devel, casouri, theo > From: Stefan Kangas <stefankangas@gmail.com> > Date: Sun, 11 Dec 2022 10:19:34 -0800 > Cc: jostein@secure.kjonigsen.net, emacs-devel@gnu.org, casouri@gmail.com, > theo@thornhill.no > > Eli Zaretskii <eliz@gnu.org> writes: > > >> Why not lisp/textmodes/toml-ts-mode.el? > > > > I agree: conf-mode is in textmodes, so this new mode should be there > > as well. > > Should json-ts-mode.el be moved to textmodes as well? I don't see why. JSON is a programming feature, not text for human consumption. ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 18:23 ` Eli Zaretskii @ 2022-12-11 21:43 ` Stefan Kangas 2022-12-12 3:28 ` Eli Zaretskii 0 siblings, 1 reply; 36+ messages in thread From: Stefan Kangas @ 2022-12-11 21:43 UTC (permalink / raw) To: Eli Zaretskii; +Cc: juri, jostein, emacs-devel, casouri, theo Eli Zaretskii <eliz@gnu.org> writes: > > Should json-ts-mode.el be moved to textmodes as well? > > I don't see why. JSON is a programming feature, not text for human > consumption. They are all just formats for structured data, just like XML. You can write JSON files intended for human consumption (if by that you mean "meant to be edited by a human"), and you can use YAML/TOML to share data between programs. That's just an aspect of how the format is used in a given application, and is not inherent to the format itself. Just to give one example, Hugo supports configuration written in either one of YAML, TOML or JSON: https://gohugo.io/getting-started/configuration/#configuration-file ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 21:43 ` Stefan Kangas @ 2022-12-12 3:28 ` Eli Zaretskii 0 siblings, 0 replies; 36+ messages in thread From: Eli Zaretskii @ 2022-12-12 3:28 UTC (permalink / raw) To: Stefan Kangas; +Cc: juri, jostein, emacs-devel, casouri, theo > From: Stefan Kangas <stefankangas@gmail.com> > Date: Sun, 11 Dec 2022 22:43:50 +0100 > Cc: juri@linkov.net, jostein@secure.kjonigsen.net, emacs-devel@gnu.org, > casouri@gmail.com, theo@thornhill.no > > Eli Zaretskii <eliz@gnu.org> writes: > > > > Should json-ts-mode.el be moved to textmodes as well? > > > > I don't see why. JSON is a programming feature, not text for human > > consumption. > > They are all just formats for structured data, just like XML. You can > write JSON files intended for human consumption (if by that you mean > "meant to be edited by a human"), and you can use YAML/TOML to share > data between programs. That's just an aspect of how the format is > used in a given application, and is not inherent to the format itself. > > Just to give one example, Hugo supports configuration written in > either one of YAML, TOML or JSON: > https://gohugo.io/getting-started/configuration/#configuration-file That's not enough of a reason to move json-ts-mode from its current place. ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 18:19 ` Stefan Kangas 2022-12-11 18:23 ` Eli Zaretskii @ 2022-12-12 17:04 ` Juri Linkov 1 sibling, 0 replies; 36+ messages in thread From: Juri Linkov @ 2022-12-12 17:04 UTC (permalink / raw) To: Stefan Kangas; +Cc: Eli Zaretskii, jostein, emacs-devel, casouri, theo >>> Why not lisp/textmodes/toml-ts-mode.el? >> >> I agree: conf-mode is in textmodes, so this new mode should be there >> as well. > > Should json-ts-mode.el be moved to textmodes as well? The only problem with this reasoning is that json is based on js mode. json is data representation that uses the same syntax as js. So separating json from js would be like separating lisp-data-mode from lisp-mode that use the same syntax for data and programs. ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 17:40 ` Eli Zaretskii 2022-12-11 18:19 ` Stefan Kangas @ 2022-12-11 19:56 ` Jostein Kjønigsen 2022-12-11 20:07 ` Eli Zaretskii 2022-12-11 23:01 ` Yuan Fu 1 sibling, 2 replies; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-11 19:56 UTC (permalink / raw) To: Eli Zaretskii, Juri Linkov; +Cc: emacs-devel, casouri, theo [-- Attachment #1: Type: text/plain, Size: 676 bytes --] On 11.12.2022 18:40, Eli Zaretskii wrote: >> From: Juri Linkov <juri@linkov.net> >> Cc: "Ergus via Emacs development discussions." <emacs-devel@gnu.org>, Yuan >> Fu <casouri@gmail.com>, Theodor Thornhill <theo@thornhill.no>, Eli >> Zaretskii <eliz@gnu.org> >> Date: Sun, 11 Dec 2022 19:09:46 +0200 >> >>> lisp/progmodes/toml-ts-mode.el >> Why not lisp/textmodes/toml-ts-mode.el? > I agree: conf-mode is in textmodes, so this new mode should be there > as well. That's an easy change. Attached is a new patch which moves the code-file to lisp/textmodes/ and also makes it derive from text-mode instead. Are there any other changes I need to implement? -- Jostein [-- Attachment #2: 0003-Introduce-support-for-TOML-config-format.patch --] [-- Type: text/x-patch, Size: 5573 bytes --] From 5966f687aea8004fa4522514ed803e62e9e08af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <jostein@kjonigsen.net> Date: Sun, 11 Dec 2022 13:05:29 +0100 Subject: [PATCH 3/3] Introduce support for TOML config-format This commit introduces support for the semi-popular TOML config-format[1] through a new major-mode: toml-ts-mode. I've read through the full spec[2], and from what I can see this major-mode should provide correct syntax-highligting for every sort of config-declaration which adheres to the specification. Besides that it also adds support for basic tree-sitter based navigation. For the time being toml-ts-mode does NOT support imenu navigation, but this is clearly something which can be added later. [1] https://toml.io/en/ [2] https://toml.io/en/v1.0.0 --- admin/notes/tree-sitter/build-module/batch.sh | 1 + lisp/textmodes/toml-ts-mode.el | 115 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 lisp/textmodes/toml-ts-mode.el diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh index d45f37f4b64..73914125a8b 100755 --- a/admin/notes/tree-sitter/build-module/batch.sh +++ b/admin/notes/tree-sitter/build-module/batch.sh @@ -13,6 +13,7 @@ languages= 'rust' 'typescript' 'tsx' + 'toml' ) for language in "${languages[@]}" diff --git a/lisp/textmodes/toml-ts-mode.el b/lisp/textmodes/toml-ts-mode.el new file mode 100644 index 00000000000..99717972bb5 --- /dev/null +++ b/lisp/textmodes/toml-ts-mode.el @@ -0,0 +1,115 @@ +;;; toml-ts-mode.el --- tree-sitter support for TOML -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; Author : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Maintainer : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Created : December 2022 +;; Keywords : toml 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") +(declare-function treesit-induce-sparse-tree "treesit.c") +(declare-function treesit-node-start "treesit.c") +(declare-function treesit-node-child-by-field-name "treesit.c") + +(defvar toml-ts-mode--font-lock-settings + (treesit-font-lock-rules + :language 'toml + :feature 'constant + '((boolean) @font-lock-constant-face) + :language 'toml + :feature 'delimiter + '((["="]) @font-lock-delimiter-face) + :language 'toml + :feature 'number + '((integer) @font-lock-number-face + (float) @font-lock-number-face + (local_date) @font-lock-number-face + (local_date_time) @font-lock-number-face + (local_time) @font-lock-number-face) + :language 'toml + :feature 'string + '((string) @font-lock-string-face) + :language 'toml + :feature 'escape-sequence + :override t + '((escape_sequence) @font-lock-escape-face) + :language 'toml + :feature 'pair + :override t ; Needed for overriding string face on keys. + '((comment) @font-lock-comment-face + (bare_key) @font-lock-property-face + (quoted_key) @font-lock-property-face + (table ("[" @font-lock-bracket-face + (_) @font-lock-type-face + "]" @font-lock-bracket-face)) + (table_array_element ("[[" @font-lock-bracket-face + (_) @font-lock-type-face + "]]" @font-lock-bracket-face)) + (table (quoted_key) @font-lock-type-face) + (table (dotted_key (quoted_key)) @font-lock-type-face)) + :language 'toml + :feature 'error + :override t + '((ERROR) @font-lock-warning-face)) + "Font-lock settings for TOML.") + +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-ts-mode)) + +;;;###autoload +(define-derived-mode toml-ts-mode text-mode "TOML" + "Major mode for editing TOML, powered by tree-sitter." + :group 'toml-mode + + (unless (treesit-ready-p 'toml) + (error "Tree-sitter for TOML isn't avilable")) + + (treesit-parser-create 'toml) + + ;; Comments + (setq-local comment-start "# ") + (setq-local commend-end "") + + ;; Navigation. + (setq-local treesit-defun-type-regexp + (rx (or "table" "table_array_element"))) + + ;; Font-lock. + (setq-local treesit-font-lock-settings toml-ts-mode--font-lock-settings) + (setq-local treesit-font-lock-feature-list + '((constant number pair string) + (escape-sequence) + (delimiter error))) + + ;; Imenu. + ;; (setq-local imenu-create-index-function #'toml-ts-mode--imenu) + ;; (setq-local which-func-functions nil) ;; Piggyback on imenu + + (treesit-major-mode-setup)) + +(provide 'toml-ts-mode) + +;;; toml-ts-mode.el ends here -- 2.37.2 ^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 19:56 ` Jostein Kjønigsen @ 2022-12-11 20:07 ` Eli Zaretskii 2022-12-11 20:31 ` Jostein Kjønigsen 2022-12-11 23:01 ` Yuan Fu 1 sibling, 1 reply; 36+ messages in thread From: Eli Zaretskii @ 2022-12-11 20:07 UTC (permalink / raw) To: jostein; +Cc: juri, emacs-devel, casouri, theo > Date: Sun, 11 Dec 2022 20:56:33 +0100 > Cc: emacs-devel@gnu.org, casouri@gmail.com, theo@thornhill.no > From: Jostein Kjønigsen <jostein@secure.kjonigsen.net> > > >> Why not lisp/textmodes/toml-ts-mode.el? > > I agree: conf-mode is in textmodes, so this new mode should be there > > as well. > > That's an easy change. > > Attached is a new patch which moves the code-file to lisp/textmodes/ and > also makes it derive from text-mode instead. > > Are there any other changes I need to implement? How about imenu support? conf-mode does offer it. Thanks. ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 20:07 ` Eli Zaretskii @ 2022-12-11 20:31 ` Jostein Kjønigsen 2022-12-11 20:38 ` Eli Zaretskii 0 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-11 20:31 UTC (permalink / raw) To: Eli Zaretskii, jostein; +Cc: juri, emacs-devel, casouri, theo On 11.12.2022 21:07, Eli Zaretskii wrote: > How about imenu support? conf-mode does offer it. > Thanks. There's no imenu support yet, but I agree it would be nice to have, and it absolutely is my plan to add it. That said, my idea was to make sure everyone was happy with the code I already had for this, before moving on to expanding it to include other stuff. If that's all the feedback so far, I can take a stab at implementing it. Just to have a clear sense of priorities, is imenu-support considered a "must have" for merging, or just a "nice to have"? And are there any chance to get this included in the emacs-29 branch if merged? -- Jostein ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 20:31 ` Jostein Kjønigsen @ 2022-12-11 20:38 ` Eli Zaretskii 2022-12-11 20:49 ` Jostein Kjønigsen 0 siblings, 1 reply; 36+ messages in thread From: Eli Zaretskii @ 2022-12-11 20:38 UTC (permalink / raw) To: jostein; +Cc: juri, emacs-devel, casouri, theo > Date: Sun, 11 Dec 2022 21:31:30 +0100 > Cc: juri@linkov.net, emacs-devel@gnu.org, casouri@gmail.com, theo@thornhill.no > From: Jostein Kjønigsen <jostein@secure.kjonigsen.net> > > Just to have a clear sense of priorities, is imenu-support considered a > "must have" for merging, or just a "nice to have"? It's nice to have. > And are there any chance to get this included in the emacs-29 branch > if merged? That's the intent, yes. ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 20:38 ` Eli Zaretskii @ 2022-12-11 20:49 ` Jostein Kjønigsen 0 siblings, 0 replies; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-11 20:49 UTC (permalink / raw) To: Eli Zaretskii, jostein; +Cc: juri, emacs-devel, casouri, theo On 11.12.2022 21:38, Eli Zaretskii wrote: >> Just to have a clear sense of priorities, is imenu-support considered a >> "must have" for merging, or just a "nice to have"? > It's nice to have. The TOML parse tree is a little different from the other parse-trees I've seen so might take a few days. I'll see what I can get done. > That's the intent, yes. Thanks!That's great to hear! -- Jostein ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 19:56 ` Jostein Kjønigsen 2022-12-11 20:07 ` Eli Zaretskii @ 2022-12-11 23:01 ` Yuan Fu 2022-12-12 13:10 ` Jostein Kjønigsen ` (2 more replies) 1 sibling, 3 replies; 36+ messages in thread From: Yuan Fu @ 2022-12-11 23:01 UTC (permalink / raw) To: jostein; +Cc: Eli Zaretskii, Juri Linkov, emacs-devel, theo > On Dec 11, 2022, at 11:56 AM, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: > > On 11.12.2022 18:40, Eli Zaretskii wrote: >>> From: Juri Linkov <juri@linkov.net> >>> Cc: "Ergus via Emacs development discussions." <emacs-devel@gnu.org>, Yuan >>> Fu <casouri@gmail.com>, Theodor Thornhill <theo@thornhill.no>, Eli >>> Zaretskii <eliz@gnu.org> >>> Date: Sun, 11 Dec 2022 19:09:46 +0200 >>> >>>> lisp/progmodes/toml-ts-mode.el >>> Why not lisp/textmodes/toml-ts-mode.el? >> I agree: conf-mode is in textmodes, so this new mode should be there >> as well. > > That's an easy change. > > Attached is a new patch which moves the code-file to lisp/textmodes/ and also makes it derive from text-mode instead. > > Are there any other changes I need to implement? Looks great! + (unless (treesit-ready-p 'toml) + (error "Tree-sitter for TOML isn't avilable”)) Treesit-ready-p already raises a warning when something goes wrong. So you want to either pass the QUIET argument or let it do the barking ;-) Yuan ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 23:01 ` Yuan Fu @ 2022-12-12 13:10 ` Jostein Kjønigsen 2022-12-12 13:53 ` Theodor Thornhill 2022-12-12 20:41 ` Jostein Kjønigsen 2022-12-13 10:45 ` toml-ts-mode: first draft Rudolf Schlatte 2 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-12 13:10 UTC (permalink / raw) To: Yuan Fu, jostein; +Cc: Eli Zaretskii, Juri Linkov, emacs-devel, theo On 12.12.2022 00:01, Yuan Fu wrote: > Looks great! Thanks! > + (unless (treesit-ready-p 'toml) > + (error "Tree-sitter for TOML isn't avilable”)) > > Treesit-ready-p already raises a warning when something goes wrong. So you want to either pass the QUIET argument or let it do the barking ;-) > > Yuan Sure, I can fix that. I notice though that this is not applied consistently in the other tree-sitter based major-modes. From json-ts-mode.el: > (unless (treesit-ready-p 'json) > (error "Tree-sitter for JSON isn't available")) From csharp-mode.el: > (unless (treesit-ready-p 'c-sharp) > (error "Tree-sitter for C# isn't available")) From typescript-ts-mode.el: > (when (treesit-ready-p 'tsx) > (treesit-parser-create 'tsx) From python.el: > (when (treesit-ready-p 'python) > (treesit-parser-create 'python) I see in the (treesit-ready-p) it clearly throws when language is missing. So from what I can tell all of the "established" forms are doing too much: * checking return-value (not required because of throwing) * creating errors Could you recommend 1 specific form, and I'll try to stick to that, at least for toml-ts-mode (and then we can clean up those other modes later on). -- Jostein ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-12 13:10 ` Jostein Kjønigsen @ 2022-12-12 13:53 ` Theodor Thornhill 0 siblings, 0 replies; 36+ messages in thread From: Theodor Thornhill @ 2022-12-12 13:53 UTC (permalink / raw) To: Jostein Kjønigsen, Yuan Fu, jostein Cc: Eli Zaretskii, Juri Linkov, emacs-devel Jostein Kjønigsen <jostein@secure.kjonigsen.net> writes: > On 12.12.2022 00:01, Yuan Fu wrote: >> Looks great! > Thanks! >> + (unless (treesit-ready-p 'toml) >> + (error "Tree-sitter for TOML isn't avilable”)) >> >> Treesit-ready-p already raises a warning when something goes wrong. So you want to either pass the QUIET argument or let it do the barking ;-) >> >> Yuan > > Sure, I can fix that. > > I notice though that this is not applied consistently in the other > tree-sitter based major-modes. > > From json-ts-mode.el: > > > (unless (treesit-ready-p 'json) > > (error "Tree-sitter for JSON isn't available")) > > From csharp-mode.el: > > > (unless (treesit-ready-p 'c-sharp) > > (error "Tree-sitter for C# isn't available")) > > From typescript-ts-mode.el: > > > (when (treesit-ready-p 'tsx) > > (treesit-parser-create 'tsx) > > From python.el: > > > (when (treesit-ready-p 'python) > > (treesit-parser-create 'python) > > I see in the (treesit-ready-p) it clearly throws when language is missing. > > So from what I can tell all of the "established" forms are doing too much: > > * checking return-value (not required because of throwing) > * creating errors IIRC I had some issues with that form some time in the past. I think we should abstract this away completely and let treesit-major-mode-setup do it, by doing something like: ``` (treesit-major-mode-setup 'java) ``` and inside of that function do the (when (treesit-ready-p lang) (treesit-parser-create lang) ....) Then this could be removed from all modes: (unless (treesit-ready-p 'java) (error "Tree-sitter for Java isn't available")) (treesit-parser-create 'java) Most init is just setq-locals anyway. Is there a reason we cannot do that? Theo ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 23:01 ` Yuan Fu 2022-12-12 13:10 ` Jostein Kjønigsen @ 2022-12-12 20:41 ` Jostein Kjønigsen 2022-12-12 21:17 ` Randy Taylor 2022-12-13 10:45 ` toml-ts-mode: first draft Rudolf Schlatte 2 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-12 20:41 UTC (permalink / raw) To: Yuan Fu, Eli Zaretskii, Juri Linkov; +Cc: emacs-devel, theo [-- Attachment #1.1: Type: text/plain, Size: 1499 bytes --] On 12.12.2022 00:01, Yuan Fu wrote: > Looks great! > > + (unless (treesit-ready-p 'toml) > + (error "Tree-sitter for TOML isn't avilable”)) > > Treesit-ready-p already raises a warning when something goes wrong. So you want to either pass the QUIET argument or let it do the barking ;-) > > Yuan Hey everyone. A quick update. I've updated the code to follow the above-mentioned (when (treesit-ready-p ...)) convention. Bigger news perhaps is that I've also updated it to support imenu. The imenu-implementation is limited to tables/sections/array-elements only, and has no accessor for direct values. That said it still works pretty good and the code should be fully understandable. Said simply, the patch attached to this email contains all fixes and features requested by everyone so far. I consider it more than good enough for everyday use at this point. I'm obviously biased, but I have to say this version fares quite favourable when doing an objective comparison to toml-mode as found in MELPA: * better and more consistent fontification * better support for various quoting formats * better support for dotted values * better support for inline tables * it highlights syntax-errors * it actually has imenu support (limited to headers/tables only, now direct value access) Pretty much every obvious bug I see in the MELPA-version is fixed in this one. So... Any other requests I should look into before we start considering merging this? :) -- Jostein [-- Attachment #1.2: Type: text/html, Size: 2084 bytes --] [-- Attachment #2: 0002-Introduce-support-for-TOML-config-format.patch --] [-- Type: text/x-patch, Size: 6935 bytes --] From f073159d6cc19aafda2cc18debe0e1b890bee715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <jostein@kjonigsen.net> Date: Sun, 11 Dec 2022 13:05:29 +0100 Subject: [PATCH 2/5] Introduce support for TOML config-format This commit introduces support for the semi-popular TOML config-format[1] through a new major-mode: toml-ts-mode. I've read through the full spec[2], and from what I can see this major-mode should provide correct syntax-highligting for every sort of config-declaration which adheres to the specification. Besides that it also adds support for imenu and basic tree-sitter based navigation. [1] https://toml.io/en/ [2] https://toml.io/en/v1.0.0 --- admin/notes/tree-sitter/build-module/batch.sh | 1 + lisp/textmodes/toml-ts-mode.el | 152 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 lisp/textmodes/toml-ts-mode.el diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh index 6dce000caa6..e955bb6bcf5 100755 --- a/admin/notes/tree-sitter/build-module/batch.sh +++ b/admin/notes/tree-sitter/build-module/batch.sh @@ -14,6 +14,7 @@ languages= 'rust' 'typescript' 'tsx' + 'toml' ) for language in "${languages[@]}" diff --git a/lisp/textmodes/toml-ts-mode.el b/lisp/textmodes/toml-ts-mode.el new file mode 100644 index 00000000000..322f63a3170 --- /dev/null +++ b/lisp/textmodes/toml-ts-mode.el @@ -0,0 +1,152 @@ +;;; toml-ts-mode.el --- tree-sitter support for TOML -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; Author : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Maintainer : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Created : December 2022 +;; Keywords : toml 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") +(declare-function treesit-induce-sparse-tree "treesit.c") +(declare-function treesit-node-start "treesit.c") +(declare-function treesit-node-child-by-field-name "treesit.c") + +(defvar toml-ts-mode--font-lock-settings + (treesit-font-lock-rules + :language 'toml + :feature 'constant + '((boolean) @font-lock-constant-face) + :language 'toml + :feature 'delimiter + '((["="]) @font-lock-delimiter-face) + :language 'toml + :feature 'number + '((integer) @font-lock-number-face + (float) @font-lock-number-face + (local_date) @font-lock-number-face + (local_date_time) @font-lock-number-face + (local_time) @font-lock-number-face) + :language 'toml + :feature 'string + '((string) @font-lock-string-face) + :language 'toml + :feature 'escape-sequence + :override t + '((escape_sequence) @font-lock-escape-face) + :language 'toml + :feature 'pair + :override t ; Needed for overriding string face on keys. + '((comment) @font-lock-comment-face + (bare_key) @font-lock-property-face + (quoted_key) @font-lock-property-face + (table ("[" @font-lock-bracket-face + (_) @font-lock-type-face + "]" @font-lock-bracket-face)) + (table_array_element ("[[" @font-lock-bracket-face + (_) @font-lock-type-face + "]]" @font-lock-bracket-face)) + (table (quoted_key) @font-lock-type-face) + (table (dotted_key (quoted_key)) @font-lock-type-face)) + :language 'toml + :feature 'error + :override t + '((ERROR) @font-lock-warning-face)) + "Font-lock settings for TOML.") + +(defun toml-ts-mode--get-table-name (node) + "Obtains the header-name for the associated tree-sitter `NODE'." + (if node + (treesit-node-text + (car (cdr (treesit-node-children node)))) + "Root table")) + +(defun toml-ts-mode--imenu-1 (node) + "Helper for `toml-ts-mode--imenu'. +Find string representation for NODE and set marker, then recurse +the subtrees." + (let* ((ts-node (car node)) + (subtrees (mapcan #'toml-ts-mode--imenu-1 (cdr node))) + (name (toml-ts-mode--get-table-name ts-node)) + (marker (when ts-node + (set-marker (make-marker) + (treesit-node-start ts-node))))) + (cond + ((null ts-node) subtrees) + (subtrees + `((,name ,(cons name marker) ,@subtrees))) + (t + `((,name . ,marker)))))) + +(defun toml-ts-mode--imenu () + "Return Imenu alist for the current buffer." + (let* ((node (treesit-buffer-root-node)) + (table-tree (treesit-induce-sparse-tree + node "^table$" nil 1000)) + (table-array-tree (treesit-induce-sparse-tree + node "^table_array_element$" nil 1000)) + (table-index (toml-ts-mode--imenu-1 table-tree)) + (table-array-index (toml-ts-mode--imenu-1 table-array-tree))) + ;;(setq global-toml-node (treesit-buffer-root-node)) + (append + (when table-index `(("Headers" . ,table-index))) + (when table-array-index `(("Arrays" . ,table-array-index)))))) + + +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-ts-mode)) + +;;;###autoload +(define-derived-mode toml-ts-mode text-mode "TOML" + "Major mode for editing TOML, powered by tree-sitter." + :group 'toml-mode + + (when (treesit-ready-p 'toml) + (treesit-parser-create 'toml) + + ;; Comments + (setq-local comment-start "# ") + (setq-local commend-end "") + + ;; Navigation. + (setq-local treesit-defun-type-regexp + (rx (or "table" "table_array_element"))) + + ;; Font-lock. + (setq-local treesit-font-lock-settings toml-ts-mode--font-lock-settings) + (setq-local treesit-font-lock-feature-list + '((constant number pair string) + (escape-sequence) + (delimiter error))) + + ;; Imenu. + (setq-local imenu-create-index-function #'toml-ts-mode--imenu) + (setq-local which-func-functions nil) ;; Piggyback on imenu + + (treesit-major-mode-setup))) + +(provide 'toml-ts-mode) + +;;; toml-ts-mode.el ends here -- 2.37.2 ^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-12 20:41 ` Jostein Kjønigsen @ 2022-12-12 21:17 ` Randy Taylor 2022-12-13 20:43 ` Jostein Kjønigsen 0 siblings, 1 reply; 36+ messages in thread From: Randy Taylor @ 2022-12-12 21:17 UTC (permalink / raw) To: jostein; +Cc: Yuan Fu, Eli Zaretskii, Juri Linkov, emacs-devel, theo [-- Attachment #1: Type: text/plain, Size: 1560 bytes --] On Monday, December 12th, 2022 at 15:41, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: > On 12.12.2022 00:01, Yuan Fu wrote: > >> Looks great! >> >> + (unless (treesit-ready-p 'toml) >> + (error "Tree-sitter for TOML isn't avilable”)) >> >> Treesit-ready-p already raises a warning when something goes wrong. So you want to either pass the QUIET argument or let it do the barking ;-) >> >> Yuan > > So... Any other requests I should look into before we start considering merging this? :) > > -- > > Jostein Looks good! A few silly nits: - It would be nice to keep batch.sh alphabetized (so maybe move typescript while you're there). - Most modes put a newline between features in their font-lock rules definition. I think we should stick to that. - I think comment should be moved out of pair to its own feature. - For features like 'number, I like to group them (e.g. [(int) (float]), then you only need to specify @font-lock-number-face once. - ;;(setq global-toml-node (treesit-buffer-root-node)) seems like this was leftover debugging to be removed? - treesit-font-lock-feature-list should have 4 levels, and delimiter and error should probably go in the 4th one (side note, we should all figure out the "final" list of general features and which levels they belong to). The first level should maybe just be comment on its own, the rest looks good to me.- Indentation support for multi-line arrays would be nice (and maybe even follow the indentation of the previous line if that's not too hard and doesn't cause everything to blow up?) [-- Attachment #2: Type: text/html, Size: 2436 bytes --] ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-12 21:17 ` Randy Taylor @ 2022-12-13 20:43 ` Jostein Kjønigsen 2022-12-13 22:37 ` Randy Taylor 0 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-13 20:43 UTC (permalink / raw) To: Randy Taylor; +Cc: Yuan Fu, Eli Zaretskii, Juri Linkov, emacs-devel, theo [-- Attachment #1.1: Type: text/plain, Size: 2076 bytes --] On 12.12.2022 22:17, Randy Taylor wrote: > Looks good! A few silly nits: Thanks for the constructive feedback! > - It would be nice to keep batch.sh alphabetized (so maybe move > typescript while you're there). Did this. I saw bash was missing, so I added that too. It's unrelated to TOML, but I hope it can pass :) > - Most modes put a newline between features in their font-lock rules > definition. I think we should stick to that. Done > - I think comment should be moved out of pair to its own feature. Done > - For features like 'number, I like to group them (e.g. [(int) > (float]), then you only need to specify @font-lock-number-face once. Done > - ;;(setq global-toml-node (treesit-buffer-root-node)) seems like this > was leftover debugging to be removed? Oops. Fixed. > - treesit-font-lock-feature-list should have 4 levels, and delimiter > and error should probably go in the 4th one (side note, we should all > figure out the "final" list of general features and which levels they > belong to). The first level should maybe just be comment on its own, > the rest looks good to me. Done. > - Indentation support for multi-line arrays would be nice (and maybe > even follow the indentation of the previous line if that's not too > hard and doesn't cause everything to blow up?) I was fine with all this until you started mentioning indentation... :D I gave it a try though, and what we have provides a customizable indentation-level, which is applied to multiline strings and array-values. (Indentation was never my "forte" if you like, and I haven't figured out an obvious way to make it follow previous line's indentation though.) If it's OK for you, for now I would like to leave the indentation-ambitions at the point which is implemented. Aaand... With that said... That should (to the best of my knowledge) address everything you requested, and IMO that makes it a nice upgrade from last patch. Attached is a patch with all changes combined up until now. Anything else you (or anyone else) think should be fixed up? -- Jostein [-- Attachment #1.2: Type: text/html, Size: 5948 bytes --] [-- Attachment #2: 0005-Introduce-support-for-TOML-config-format.patch --] [-- Type: text/x-patch, Size: 7863 bytes --] From bfb5cc253faf9ed9f7c9256df035200debaf931c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <jostein@kjonigsen.net> Date: Sun, 11 Dec 2022 13:05:29 +0100 Subject: [PATCH 5/5] Introduce support for TOML config-format This commit introduces support for the semi-popular TOML config-format[1] through a new major-mode: toml-ts-mode. I've read through the full spec[2], and from what I can see this major-mode should provide correct syntax-highligting for every sort of config-declaration which adheres to the specification. Besides that it also adds support for imenu and basic tree-sitter based navigation. [1] https://toml.io/en/ [2] https://toml.io/en/v1.0.0 --- admin/notes/tree-sitter/build-module/batch.sh | 4 +- lisp/textmodes/toml-ts-mode.el | 188 ++++++++++++++++++ 2 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 lisp/textmodes/toml-ts-mode.el diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh index 6dce000caa6..2b8367fe6db 100755 --- a/admin/notes/tree-sitter/build-module/batch.sh +++ b/admin/notes/tree-sitter/build-module/batch.sh @@ -1,6 +1,7 @@ #!/bin/bash languages=( + 'bash' 'c' 'cpp' 'css' @@ -12,8 +13,9 @@ languages= 'json' 'python' 'rust' - 'typescript' + 'toml' 'tsx' + 'typescript' ) for language in "${languages[@]}" diff --git a/lisp/textmodes/toml-ts-mode.el b/lisp/textmodes/toml-ts-mode.el new file mode 100644 index 00000000000..c0a6fe9c0b0 --- /dev/null +++ b/lisp/textmodes/toml-ts-mode.el @@ -0,0 +1,188 @@ +;;; toml-ts-mode.el --- tree-sitter support for TOML -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; Author : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Maintainer : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Created : December 2022 +;; Keywords : toml 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") +(declare-function treesit-induce-sparse-tree "treesit.c") +(declare-function treesit-node-start "treesit.c") +(declare-function treesit-node-child-by-field-name "treesit.c") + +(defcustom toml-ts-mode-indent-offset 2 + "Number of spaces for each indentation step in `toml-ts-mode'." + :version "29.1" + :type 'integer + :safe 'integerp + :group 'toml) + +(defvar toml-ts-mode--syntax-table + (let ((table (make-syntax-table))) + (modify-syntax-entry ?_ "_" table) + (modify-syntax-entry ?\\ "\\" table) + (modify-syntax-entry ?= "." table) + (modify-syntax-entry ?\' "\"" table) + (modify-syntax-entry ?# "<" table) + (modify-syntax-entry ?\n "> b" table) + (modify-syntax-entry ?\^m "> b" table) + table) + "Syntax table for `toml-ts-mode'.") + +(defvar toml-ts--indent-rules + `((toml + ((node-is "]") parent-bol 0) + ((parent-is "string") parent-bol toml-ts-mode-indent-offset) + ((parent-is "array") parent-bol toml-ts-mode-indent-offset)))) + +(defvar toml-ts-mode--font-lock-settings + (treesit-font-lock-rules + :language 'toml + :feature 'comment + '((comment) @font-lock-comment-face) + + :language 'toml + :feature 'constant + '((boolean) @font-lock-constant-face) + + :language 'toml + :feature 'delimiter + '((["="]) @font-lock-delimiter-face) + + :language 'toml + :feature 'number + '([(integer) (float) (local_date) (local_date_time) (local_time)] + @font-lock-number-face) + + :language 'toml + :feature 'string + '((string) @font-lock-string-face) + + :language 'toml + :feature 'escape-sequence + :override t + '((escape_sequence) @font-lock-escape-face) + + :language 'toml + :feature 'pair + :override t ; Needed for overriding string face on keys. + '((bare_key) @font-lock-property-face + (quoted_key) @font-lock-property-face + (table ("[" @font-lock-bracket-face + (_) @font-lock-type-face + "]" @font-lock-bracket-face)) + (table_array_element ("[[" @font-lock-bracket-face + (_) @font-lock-type-face + "]]" @font-lock-bracket-face)) + (table (quoted_key) @font-lock-type-face) + (table (dotted_key (quoted_key)) @font-lock-type-face)) + + :language 'toml + :feature 'error + :override t + '((ERROR) @font-lock-warning-face)) + "Font-lock settings for TOML.") + +(defun toml-ts-mode--get-table-name (node) + "Obtains the header-name for the associated tree-sitter `NODE'." + (if node + (treesit-node-text + (car (cdr (treesit-node-children node)))) + "Root table")) + +(defun toml-ts-mode--imenu-1 (node) + "Helper for `toml-ts-mode--imenu'. +Find string representation for NODE and set marker, then recurse +the subtrees." + (let* ((ts-node (car node)) + (subtrees (mapcan #'toml-ts-mode--imenu-1 (cdr node))) + (name (toml-ts-mode--get-table-name ts-node)) + (marker (when ts-node + (set-marker (make-marker) + (treesit-node-start ts-node))))) + (cond + ((null ts-node) subtrees) + (subtrees + `((,name ,(cons name marker) ,@subtrees))) + (t + `((,name . ,marker)))))) + +(defun toml-ts-mode--imenu () + "Return Imenu alist for the current buffer." + (let* ((node (treesit-buffer-root-node)) + (table-tree (treesit-induce-sparse-tree + node "^table$" nil 1000)) + (table-array-tree (treesit-induce-sparse-tree + node "^table_array_element$" nil 1000)) + (table-index (toml-ts-mode--imenu-1 table-tree)) + (table-array-index (toml-ts-mode--imenu-1 table-array-tree))) + (append + (when table-index `(("Headers" . ,table-index))) + (when table-array-index `(("Arrays" . ,table-array-index)))))) + + +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-ts-mode)) + +;;;###autoload +(define-derived-mode toml-ts-mode text-mode "TOML" + "Major mode for editing TOML, powered by tree-sitter." + :group 'toml-mode + :syntax-table toml-ts-mode--syntax-table + + (when (treesit-ready-p 'toml) + (treesit-parser-create 'toml) + + ;; Comments + (setq-local comment-start "# ") + (setq-local commend-end "") + + ;; Indent. + (setq-local treesit-simple-indent-rules toml-ts--indent-rules) + + ;; Navigation. + (setq-local treesit-defun-type-regexp + (rx (or "table" "table_array_element"))) + + ;; Font-lock. + (setq-local treesit-font-lock-settings toml-ts-mode--font-lock-settings) + (setq-local treesit-font-lock-feature-list + '((comment) + (constant number pair string) + (escape-sequence) + (delimiter error))) + (setq-local treesit-font-lock-level 4) + + ;; Imenu. + (setq-local imenu-create-index-function #'toml-ts-mode--imenu) + (setq-local which-func-functions nil) ;; Piggyback on imenu + + (treesit-major-mode-setup))) + +(provide 'toml-ts-mode) + +;;; toml-ts-mode.el ends here -- 2.37.2 ^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-13 20:43 ` Jostein Kjønigsen @ 2022-12-13 22:37 ` Randy Taylor 2022-12-14 8:40 ` Jostein Kjønigsen 0 siblings, 1 reply; 36+ messages in thread From: Randy Taylor @ 2022-12-13 22:37 UTC (permalink / raw) To: jostein; +Cc: Yuan Fu, Eli Zaretskii, Juri Linkov, emacs-devel, theo [-- Attachment #1: Type: text/plain, Size: 2645 bytes --] On Tuesday, December 13th, 2022 at 15:43, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: > On 12.12.2022 22:17, Randy Taylor wrote: > >> Looks good! A few silly nits: > > Thanks for the constructive feedback! > >> - It would be nice to keep batch.sh alphabetized (so maybe move typescript while you're there). > > Did this. I saw bash was missing, so I added that too. It's unrelated to TOML, but I hope it can pass :) > >> - Most modes put a newline between features in their font-lock rules definition. I think we should stick to that. > > Done > >> - I think comment should be moved out of pair to its own feature. > > Done > >> - For features like 'number, I like to group them (e.g. [(int) (float]), then you only need to specify @font-lock-number-face once. > > Done > >> - ;;(setq global-toml-node (treesit-buffer-root-node)) seems like this was leftover debugging to be removed? > > Oops. Fixed. > >> - treesit-font-lock-feature-list should have 4 levels, and delimiter and error should probably go in the 4th one (side note, we should all figure out the "final" list of general features and which levels they belong to). The first level should maybe just be comment on its own, the rest looks good to me. > > Done. > >> - Indentation support for multi-line arrays would be nice (and maybe even follow the indentation of the previous line if that's not too hard and doesn't cause everything to blow up?) > > I was fine with all this until you started mentioning indentation... :D > > I gave it a try though, and what we have provides a customizable indentation-level, which is applied to multiline strings and array-values. (Indentation was never my "forte" if you like, and I haven't figured out an obvious way to make it follow previous line's indentation though.) > > If it's OK for you, for now I would like to leave the indentation-ambitions at the point which is implemented. > > Aaand... > > With that said... That should (to the best of my knowledge) address everything you requested, and IMO that makes it a nice upgrade from last patch. > > Attached is a patch with all changes combined up until now. > > Anything else you (or anyone else) think should be fixed up? > > -- > > Jostein Looks good! Just a few final comments: - It would be nice to separate bracket out to its own bracket feature if it's not too much of a hassle. Is it not matchable just with (["[" "]"]) on its own? - (setq-local treesit-font-lock-level 4) should probably be removed since I don't think modes shouldn't be setting that. - Should toml-ts--indent-rules be named toml-ts-mode--indent-rules to be consistent with everything else? > [-- Attachment #2: Type: text/html, Size: 6023 bytes --] ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-13 22:37 ` Randy Taylor @ 2022-12-14 8:40 ` Jostein Kjønigsen 2022-12-14 13:24 ` Randy Taylor 0 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-14 8:40 UTC (permalink / raw) To: Randy Taylor; +Cc: Yuan Fu, Eli Zaretskii, Juri Linkov, emacs-devel, theo [-- Attachment #1.1: Type: text/plain, Size: 914 bytes --] On 13.12.2022 23:37, Randy Taylor wrote: > > Looks good! > > Just a few final comments: > > - It would be nice to separate bracket out to its own bracket feature > if it's not too much of a hassle. Is it not matchable just with (["[" > "]"]) on its own? > It's actually a problem about matching the bare_key, or dotted_key in the table-header. Without having those brackets there, that selector does not get applied. > - (setq-local treesit-font-lock-level 4) should probably be removed > since I don't think modes shouldn't be setting that. > Ok. Fixed. And I'll just need to figure out how to force level 4 on my system globally then. I don't find level 3 particularly pleasing :) > - Should toml-ts--indent-rules be named toml-ts-mode--indent-rules to > be consistent with everything else? > Nice catch. Fixed. Attached is a new revision. Final revision? Is this good for merging now? :) -- Jostein [-- Attachment #1.2: Type: text/html, Size: 2545 bytes --] [-- Attachment #2: 0005-Introduce-support-for-TOML-config-format.patch --] [-- Type: text/x-patch, Size: 7829 bytes --] From 757326f6cd7c09ea46085860ea6a66b86cf2be09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <jostein@kjonigsen.net> Date: Sun, 11 Dec 2022 13:05:29 +0100 Subject: [PATCH 5/5] Introduce support for TOML config-format This commit introduces support for the semi-popular TOML config-format[1] through a new major-mode: toml-ts-mode. I've read through the full spec[2], and from what I can see this major-mode should provide correct syntax-highligting for every sort of config-declaration which adheres to the specification. Besides that it also adds support for imenu and basic tree-sitter based navigation. [1] https://toml.io/en/ [2] https://toml.io/en/v1.0.0 --- admin/notes/tree-sitter/build-module/batch.sh | 4 +- lisp/textmodes/toml-ts-mode.el | 187 ++++++++++++++++++ 2 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 lisp/textmodes/toml-ts-mode.el diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh index 6dce000caa6..2b8367fe6db 100755 --- a/admin/notes/tree-sitter/build-module/batch.sh +++ b/admin/notes/tree-sitter/build-module/batch.sh @@ -1,6 +1,7 @@ #!/bin/bash languages=( + 'bash' 'c' 'cpp' 'css' @@ -12,8 +13,9 @@ languages= 'json' 'python' 'rust' - 'typescript' + 'toml' 'tsx' + 'typescript' ) for language in "${languages[@]}" diff --git a/lisp/textmodes/toml-ts-mode.el b/lisp/textmodes/toml-ts-mode.el new file mode 100644 index 00000000000..26a3eb69d8d --- /dev/null +++ b/lisp/textmodes/toml-ts-mode.el @@ -0,0 +1,187 @@ +;;; toml-ts-mode.el --- tree-sitter support for TOML -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; Author : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Maintainer : Jostein Kjønigsen <jostein@kjonigsen.net> +;; Created : December 2022 +;; Keywords : toml 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") +(declare-function treesit-induce-sparse-tree "treesit.c") +(declare-function treesit-node-start "treesit.c") +(declare-function treesit-node-child-by-field-name "treesit.c") + +(defcustom toml-ts-mode-indent-offset 2 + "Number of spaces for each indentation step in `toml-ts-mode'." + :version "29.1" + :type 'integer + :safe 'integerp + :group 'toml) + +(defvar toml-ts-mode--syntax-table + (let ((table (make-syntax-table))) + (modify-syntax-entry ?_ "_" table) + (modify-syntax-entry ?\\ "\\" table) + (modify-syntax-entry ?= "." table) + (modify-syntax-entry ?\' "\"" table) + (modify-syntax-entry ?# "<" table) + (modify-syntax-entry ?\n "> b" table) + (modify-syntax-entry ?\^m "> b" table) + table) + "Syntax table for `toml-ts-mode'.") + +(defvar toml-ts-mode--indent-rules + `((toml + ((node-is "]") parent-bol 0) + ((parent-is "string") parent-bol toml-ts-mode-indent-offset) + ((parent-is "array") parent-bol toml-ts-mode-indent-offset)))) + +(defvar toml-ts-mode--font-lock-settings + (treesit-font-lock-rules + :language 'toml + :feature 'comment + '((comment) @font-lock-comment-face) + + :language 'toml + :feature 'constant + '((boolean) @font-lock-constant-face) + + :language 'toml + :feature 'delimiter + '((["="]) @font-lock-delimiter-face) + + :language 'toml + :feature 'number + '([(integer) (float) (local_date) (local_date_time) (local_time)] + @font-lock-number-face) + + :language 'toml + :feature 'string + '((string) @font-lock-string-face) + + :language 'toml + :feature 'escape-sequence + :override t + '((escape_sequence) @font-lock-escape-face) + + :language 'toml + :feature 'pair + :override t ; Needed for overriding string face on keys. + '((bare_key) @font-lock-property-face + (quoted_key) @font-lock-property-face + (table ("[" @font-lock-bracket-face + (_) @font-lock-type-face + "]" @font-lock-bracket-face)) + (table_array_element ("[[" @font-lock-bracket-face + (_) @font-lock-type-face + "]]" @font-lock-bracket-face)) + (table (quoted_key) @font-lock-type-face) + (table (dotted_key (quoted_key)) @font-lock-type-face)) + + :language 'toml + :feature 'error + :override t + '((ERROR) @font-lock-warning-face)) + "Font-lock settings for TOML.") + +(defun toml-ts-mode--get-table-name (node) + "Obtains the header-name for the associated tree-sitter `NODE'." + (if node + (treesit-node-text + (car (cdr (treesit-node-children node)))) + "Root table")) + +(defun toml-ts-mode--imenu-1 (node) + "Helper for `toml-ts-mode--imenu'. +Find string representation for NODE and set marker, then recurse +the subtrees." + (let* ((ts-node (car node)) + (subtrees (mapcan #'toml-ts-mode--imenu-1 (cdr node))) + (name (toml-ts-mode--get-table-name ts-node)) + (marker (when ts-node + (set-marker (make-marker) + (treesit-node-start ts-node))))) + (cond + ((null ts-node) subtrees) + (subtrees + `((,name ,(cons name marker) ,@subtrees))) + (t + `((,name . ,marker)))))) + +(defun toml-ts-mode--imenu () + "Return Imenu alist for the current buffer." + (let* ((node (treesit-buffer-root-node)) + (table-tree (treesit-induce-sparse-tree + node "^table$" nil 1000)) + (table-array-tree (treesit-induce-sparse-tree + node "^table_array_element$" nil 1000)) + (table-index (toml-ts-mode--imenu-1 table-tree)) + (table-array-index (toml-ts-mode--imenu-1 table-array-tree))) + (append + (when table-index `(("Headers" . ,table-index))) + (when table-array-index `(("Arrays" . ,table-array-index)))))) + + +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-ts-mode)) + +;;;###autoload +(define-derived-mode toml-ts-mode text-mode "TOML" + "Major mode for editing TOML, powered by tree-sitter." + :group 'toml-mode + :syntax-table toml-ts-mode--syntax-table + + (when (treesit-ready-p 'toml) + (treesit-parser-create 'toml) + + ;; Comments + (setq-local comment-start "# ") + (setq-local commend-end "") + + ;; Indent. + (setq-local treesit-simple-indent-rules toml-ts-mode--indent-rules) + + ;; Navigation. + (setq-local treesit-defun-type-regexp + (rx (or "table" "table_array_element"))) + + ;; Font-lock. + (setq-local treesit-font-lock-settings toml-ts-mode--font-lock-settings) + (setq-local treesit-font-lock-feature-list + '((comment) + (constant number pair string) + (escape-sequence) + (delimiter error))) + + ;; Imenu. + (setq-local imenu-create-index-function #'toml-ts-mode--imenu) + (setq-local which-func-functions nil) ;; Piggyback on imenu + + (treesit-major-mode-setup))) + +(provide 'toml-ts-mode) + +;;; toml-ts-mode.el ends here -- 2.37.2 ^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-14 8:40 ` Jostein Kjønigsen @ 2022-12-14 13:24 ` Randy Taylor 2022-12-14 18:53 ` toml-ts-mode (code-review done) Jostein Kjønigsen 0 siblings, 1 reply; 36+ messages in thread From: Randy Taylor @ 2022-12-14 13:24 UTC (permalink / raw) To: jostein; +Cc: Yuan Fu, Eli Zaretskii, Juri Linkov, emacs-devel, theo [-- Attachment #1: Type: text/plain, Size: 1114 bytes --] On Wednesday, December 14th, 2022 at 03:40, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: > On 13.12.2022 23:37, Randy Taylor wrote: > >> Looks good! >> >> Just a few final comments: >> >> - It would be nice to separate bracket out to its own bracket feature if it's not too much of a hassle. Is it not matchable just with (["[" "]"]) on its own? > > It's actually a problem about matching the bare_key, or dotted_key in the table-header. Without having those brackets there, that selector does not get applied. > >> - (setq-local treesit-font-lock-level 4) should probably be removed since I don't think modes shouldn't be setting that. > > Ok. Fixed. > > And I'll just need to figure out how to force level 4 on my system globally then. I don't find level 3 particularly pleasing :) I just (setq-default treesit-font-lock-level 4) in my config. >> - Should toml-ts--indent-rules be named toml-ts-mode--indent-rules to be consistent with everything else? > > Nice catch. Fixed. > > Attached is a new revision. Final revision? Is this good for merging now? :) > > -- > > Jostein Looks good to me! > [-- Attachment #2: Type: text/html, Size: 2857 bytes --] ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-14 13:24 ` Randy Taylor @ 2022-12-14 18:53 ` Jostein Kjønigsen 2022-12-14 19:02 ` Theodor Thornhill 0 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-14 18:53 UTC (permalink / raw) To: Randy Taylor, jostein Cc: Yuan Fu, Eli Zaretskii, Juri Linkov, emacs-devel, theo [-- Attachment #1: Type: text/plain, Size: 576 bytes --] On 14.12.2022 14:24, Randy Taylor wrote: > > On Wednesday, December 14th, 2022 at 03:40, Jostein Kjønigsen > <jostein@secure.kjonigsen.net> wrote: > Nice catch. Fixed. >> >> Attached is a new revision. Final revision? Is this good for merging >> now? :) >> >> -- >> >> Jostein >> > Looks good to me! > Great! Thanks for So what's the next move from here on? Are there any other things which needs to be completed before this can be merged? I'm asking since this is my first full "original" submissions, which isn't a patch to an existing package/module. :) -- Jostein [-- Attachment #2: Type: text/html, Size: 1688 bytes --] ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-14 18:53 ` toml-ts-mode (code-review done) Jostein Kjønigsen @ 2022-12-14 19:02 ` Theodor Thornhill 2022-12-14 20:37 ` Yuan Fu 0 siblings, 1 reply; 36+ messages in thread From: Theodor Thornhill @ 2022-12-14 19:02 UTC (permalink / raw) To: jostein, Jostein Kjønigsen, Randy Taylor Cc: Yuan Fu, Eli Zaretskii, Juri Linkov, emacs-devel On 14 December 2022 19:53:25 CET, "Jostein Kjønigsen" <jostein@secure.kjonigsen.net> wrote: >On 14.12.2022 14:24, Randy Taylor wrote: >> >> On Wednesday, December 14th, 2022 at 03:40, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: >> Nice catch. Fixed. >>> >>> Attached is a new revision. Final revision? Is this good for merging now? :) >>> >>> -- >>> >>> Jostein >>> >> Looks good to me! >> >Great! Thanks for > >So what's the next move from here on? Are there any other things which needs to be completed before this can be merged? > >I'm asking since this is my first full "original" submissions, which isn't a patch to an existing package/module. :) > >-- >Jostein Imo it's only missing a push :) Theo ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-14 19:02 ` Theodor Thornhill @ 2022-12-14 20:37 ` Yuan Fu 2022-12-14 22:02 ` Jostein Kjønigsen 0 siblings, 1 reply; 36+ messages in thread From: Yuan Fu @ 2022-12-14 20:37 UTC (permalink / raw) To: Theodor Thornhill Cc: jostein, Jostein Kjønigsen, Randy Taylor, Eli Zaretskii, Juri Linkov, emacs-devel > On Dec 14, 2022, at 11:02 AM, Theodor Thornhill <theo@thornhill.no> wrote: > > > > On 14 December 2022 19:53:25 CET, "Jostein Kjønigsen" <jostein@secure.kjonigsen.net> wrote: >> On 14.12.2022 14:24, Randy Taylor wrote: >>> >>> On Wednesday, December 14th, 2022 at 03:40, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: >>> Nice catch. Fixed. >>>> >>>> Attached is a new revision. Final revision? Is this good for merging now? :) >>>> >>>> -- >>>> >>>> Jostein >>>> >>> Looks good to me! >>> >> Great! Thanks for >> >> So what's the next move from here on? Are there any other things which needs to be completed before this can be merged? >> >> I'm asking since this is my first full "original" submissions, which isn't a patch to an existing package/module. :) >> >> -- >> Jostein > > Imo it's only missing a push :) > > Theo I applied and pushed it. Great work, folks! Yuan ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-14 20:37 ` Yuan Fu @ 2022-12-14 22:02 ` Jostein Kjønigsen 2022-12-15 2:24 ` Randy Taylor 0 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-14 22:02 UTC (permalink / raw) To: Yuan Fu; +Cc: emacs-devel Awesome. Thanks! — Jostein Kjønigsen https://jostein.kjønigsen.net > On 14 Dec 2022, at 21:37, Yuan Fu <casouri@gmail.com> wrote: > > > >> On Dec 14, 2022, at 11:02 AM, Theodor Thornhill <theo@thornhill.no> wrote: >> >> >> >>> On 14 December 2022 19:53:25 CET, "Jostein Kjønigsen" <jostein@secure.kjonigsen.net> wrote: >>> On 14.12.2022 14:24, Randy Taylor wrote: >>>> >>>> On Wednesday, December 14th, 2022 at 03:40, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: >>>> Nice catch. Fixed. >>>>> >>>>> Attached is a new revision. Final revision? Is this good for merging now? :) >>>>> >>>>> -- >>>>> >>>>> Jostein >>>>> >>>> Looks good to me! >>>> >>> Great! Thanks for >>> >>> So what's the next move from here on? Are there any other things which needs to be completed before this can be merged? >>> >>> I'm asking since this is my first full "original" submissions, which isn't a patch to an existing package/module. :) >>> >>> -- >>> Jostein >> >> Imo it's only missing a push :) >> >> Theo > > I applied and pushed it. Great work, folks! > > Yuan ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-14 22:02 ` Jostein Kjønigsen @ 2022-12-15 2:24 ` Randy Taylor 2022-12-15 12:52 ` Jostein Kjønigsen 0 siblings, 1 reply; 36+ messages in thread From: Randy Taylor @ 2022-12-15 2:24 UTC (permalink / raw) To: Jostein Kjønigsen; +Cc: Yuan Fu, emacs-devel On Wednesday, December 14th, 2022 at 17:02, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: > > Awesome. Thanks! I think a NEWS entry is missing for it. ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-15 2:24 ` Randy Taylor @ 2022-12-15 12:52 ` Jostein Kjønigsen 2022-12-15 13:22 ` Theodor Thornhill 0 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-15 12:52 UTC (permalink / raw) To: Randy Taylor; +Cc: Yuan Fu, emacs-devel [-- Attachment #1: Type: text/plain, Size: 300 bytes --] On 15.12.2022 03:24, Randy Taylor wrote: > On Wednesday, December 14th, 2022 at 17:02, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: >> Awesome. Thanks! > I think a NEWS entry is missing for it. > I guess you're right. Here's a patch for that, if anyone wants to commit it :) -- Jostein [-- Attachment #2: 0002-Update-news-add-toml-ts-mode.patch --] [-- Type: text/x-patch, Size: 837 bytes --] From d1de3483f5a3e26de134b6498c3792d5a1b9626a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <jostein@kjonigsen.net> Date: Thu, 15 Dec 2022 13:47:41 +0100 Subject: [PATCH 2/2] Update news, add toml-ts-mode. etc/NEWS: add new toml-ts-mode to news file too. --- etc/NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 662c3125e07..a9dd3e8e2ec 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -3068,6 +3068,10 @@ A major mode based on the tree-sitter library for editing CMake files. It includes support for font-locking, indentation, Imenu, and which-func. +** New major mode toml-ts-mode'. +A major mode based on the tree-sitter library for editing TOML files. +It includes support for font-locking, indentation and Imenu. + \f * Incompatible Lisp Changes in Emacs 29.1 -- 2.34.1 ^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-15 12:52 ` Jostein Kjønigsen @ 2022-12-15 13:22 ` Theodor Thornhill 2022-12-15 13:45 ` Jostein Kjønigsen 0 siblings, 1 reply; 36+ messages in thread From: Theodor Thornhill @ 2022-12-15 13:22 UTC (permalink / raw) To: Jostein Kjønigsen, Randy Taylor; +Cc: Yuan Fu, emacs-devel Jostein Kjønigsen <jostein@secure.kjonigsen.net> writes: > On 15.12.2022 03:24, Randy Taylor wrote: >> On Wednesday, December 14th, 2022 at 17:02, Jostein Kjønigsen <jostein@secure.kjonigsen.net> wrote: >>> Awesome. Thanks! >> I think a NEWS entry is missing for it. >> > I guess you're right. > > Here's a patch for that, if anyone wants to commit it :) > > -- > Jostein > From d1de3483f5a3e26de134b6498c3792d5a1b9626a Mon Sep 17 00:00:00 2001 > From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <jostein@kjonigsen.net> > Date: Thu, 15 Dec 2022 13:47:41 +0100 > Subject: [PATCH 2/2] Update news, add toml-ts-mode. > > etc/NEWS: add new toml-ts-mode to news file too. > --- > etc/NEWS | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/etc/NEWS b/etc/NEWS > index 662c3125e07..a9dd3e8e2ec 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -3068,6 +3068,10 @@ A major mode based on the tree-sitter library for editing CMake files. > It includes support for font-locking, indentation, Imenu, and > which-func. > > +** New major mode toml-ts-mode'. > +A major mode based on the tree-sitter library for editing TOML files. > +It includes support for font-locking, indentation and Imenu. > + Small typo, 'toml-ts-mode' :-) Theo ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-15 13:22 ` Theodor Thornhill @ 2022-12-15 13:45 ` Jostein Kjønigsen 2022-12-15 14:22 ` Eli Zaretskii 0 siblings, 1 reply; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-15 13:45 UTC (permalink / raw) To: Theodor Thornhill, Randy Taylor; +Cc: Yuan Fu, emacs-devel [-- Attachment #1: Type: text/plain, Size: 97 bytes --] > Small typo, 'toml-ts-mode' :-) > Theo You're right. Good catch! New patch here. -- Jostein [-- Attachment #2: 0002-Update-news-add-toml-ts-mode.patch --] [-- Type: text/x-patch, Size: 838 bytes --] From 3e768c4269bc5acfc05acd259504da1143c0aae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <jostein@kjonigsen.net> Date: Thu, 15 Dec 2022 13:47:41 +0100 Subject: [PATCH 2/2] Update news, add toml-ts-mode. etc/NEWS: add new toml-ts-mode to news file too. --- etc/NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 662c3125e07..2350d34d17b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -3068,6 +3068,10 @@ A major mode based on the tree-sitter library for editing CMake files. It includes support for font-locking, indentation, Imenu, and which-func. +** New major mode 'toml-ts-mode'. +A major mode based on the tree-sitter library for editing TOML files. +It includes support for font-locking, indentation and Imenu. + \f * Incompatible Lisp Changes in Emacs 29.1 -- 2.34.1 ^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-15 13:45 ` Jostein Kjønigsen @ 2022-12-15 14:22 ` Eli Zaretskii 2022-12-15 14:28 ` Jostein Kjønigsen 0 siblings, 1 reply; 36+ messages in thread From: Eli Zaretskii @ 2022-12-15 14:22 UTC (permalink / raw) To: Jostein Kjønigsen; +Cc: theo, dev, casouri, emacs-devel > Date: Thu, 15 Dec 2022 14:45:42 +0100 > Cc: Yuan Fu <casouri@gmail.com>, emacs-devel <emacs-devel@gnu.org> > From: Jostein Kjønigsen <jostein@secure.kjonigsen.net> > > > Small typo, 'toml-ts-mode' :-) > > Theo > > You're right. Good catch! > > New patch here. When did you last look at NEWS on the release branch? ;-) ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode (code-review done) 2022-12-15 14:22 ` Eli Zaretskii @ 2022-12-15 14:28 ` Jostein Kjønigsen 0 siblings, 0 replies; 36+ messages in thread From: Jostein Kjønigsen @ 2022-12-15 14:28 UTC (permalink / raw) To: Eli Zaretskii; +Cc: theo, dev, casouri, emacs-devel Date: Thu, 15 Dec 2022 14:45:42 +0100 >> You're right. Good catch! >> New patch here. > When did you last look at NEWS on the release branch? ;-) Clearly not recently enough. Thanks for filling in the blanks! Consider this case-closed then :) -- Jostein ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-11 23:01 ` Yuan Fu 2022-12-12 13:10 ` Jostein Kjønigsen 2022-12-12 20:41 ` Jostein Kjønigsen @ 2022-12-13 10:45 ` Rudolf Schlatte 2022-12-13 13:20 ` Eli Zaretskii 2 siblings, 1 reply; 36+ messages in thread From: Rudolf Schlatte @ 2022-12-13 10:45 UTC (permalink / raw) To: emacs-devel Yuan Fu <casouri@gmail.com> writes: > > + (unless (treesit-ready-p 'toml) > + (error "Tree-sitter for TOML isn't avilable”)) > > Treesit-ready-p already raises a warning when something goes wrong. So > you want to either pass the QUIET argument or let it do the barking > ;-) I'd expect predicates (functions ending -p) to return T or NIL only and not have side effects. A function with the described behavior (check for availability and raise an error if not) could be named something like `tree-sitter-ensure-language'. Please ignore this mail if necessary; this small stylistic thing has been sitting with me for days now and I needed to get it off my chest :-) Rudi ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-13 10:45 ` toml-ts-mode: first draft Rudolf Schlatte @ 2022-12-13 13:20 ` Eli Zaretskii 2022-12-13 14:22 ` Rudi Schlatte 0 siblings, 1 reply; 36+ messages in thread From: Eli Zaretskii @ 2022-12-13 13:20 UTC (permalink / raw) To: Rudolf Schlatte; +Cc: emacs-devel > From: Rudolf Schlatte <rudi@constantly.at> > Date: Tue, 13 Dec 2022 11:45:42 +0100 > > Yuan Fu <casouri@gmail.com> writes: > > > > > + (unless (treesit-ready-p 'toml) > > + (error "Tree-sitter for TOML isn't avilable”)) > > > > Treesit-ready-p already raises a warning when something goes wrong. So > > you want to either pass the QUIET argument or let it do the barking > > ;-) > > I'd expect predicates (functions ending -p) to return T or NIL only and > not have side effects. Did you read the doc string of this function? I think it explains why this predicate can sometimes emit a warning and sometimes not. It has more than one modus operandi. ^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: toml-ts-mode: first draft 2022-12-13 13:20 ` Eli Zaretskii @ 2022-12-13 14:22 ` Rudi Schlatte 0 siblings, 0 replies; 36+ messages in thread From: Rudi Schlatte @ 2022-12-13 14:22 UTC (permalink / raw) To: Eli Zaretskii; +Cc: emacs-devel > On 13 Dec 2022, at 14:20, Eli Zaretskii <eliz@gnu.org> wrote: > >> From: Rudolf Schlatte <rudi@constantly.at> >> Date: Tue, 13 Dec 2022 11:45:42 +0100 >> >> Yuan Fu <casouri@gmail.com> writes: >> >>> >>> + (unless (treesit-ready-p 'toml) >>> + (error "Tree-sitter for TOML isn't avilable”)) >>> >>> Treesit-ready-p already raises a warning when something goes wrong. So >>> you want to either pass the QUIET argument or let it do the barking >>> ;-) >> >> I'd expect predicates (functions ending -p) to return T or NIL only and >> not have side effects. > > Did you read the doc string of this function? I think it explains why > this predicate can sometimes emit a warning and sometimes not. It has > more than one modus operandi. [Attention conservation notice: this is only nitpicking about a function name; please do feel free to not answer this message] The current docstring (as in the end of this mail) tells me that this predicate takes a second argument and has various side effects, and I can see how all these behaviors are useful. But it seems the authors of a number of tree sitter-using modes did something like (unless (treesit-ready-p ‘my-language) (warn “Didn’t find tree-sitter”)) which tells me that the authors expected treesit-ready-p to behave like other predicate functions, i.e., return NIL or T without side effects. I theorize that this will be a recurring issue, and that using a function name not ending in `-p’ (e.g., (treesit-ensure-ready ‘my-language ‘message)) would remove this millimeter-high barrier. But again: nitpicking, please ignore freely :) Rudi "Check whether tree-sitter is ready to be used for MODE and LANGUAGE. LANGUAGE is the language symbol to check for availability. It can also be a list of language symbols. If tree-sitter is not ready, emit a warning and return nil. If the user has chosen to activate tree-sitter for LANGUAGE and tree-sitter is ready, return non-nil. If QUIET is t, don't emit a warning in either case; if quiet is `message', display a message instead of emitting a warning.” ^ permalink raw reply [flat|nested] 36+ messages in thread
end of thread, other threads:[~2022-12-15 14:28 UTC | newest] Thread overview: 36+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-12-11 13:28 toml-ts-mode: first draft Jostein Kjønigsen 2022-12-11 17:09 ` Juri Linkov 2022-12-11 17:23 ` Jostein Kjønigsen 2022-12-11 17:40 ` Eli Zaretskii 2022-12-11 18:19 ` Stefan Kangas 2022-12-11 18:23 ` Eli Zaretskii 2022-12-11 21:43 ` Stefan Kangas 2022-12-12 3:28 ` Eli Zaretskii 2022-12-12 17:04 ` Juri Linkov 2022-12-11 19:56 ` Jostein Kjønigsen 2022-12-11 20:07 ` Eli Zaretskii 2022-12-11 20:31 ` Jostein Kjønigsen 2022-12-11 20:38 ` Eli Zaretskii 2022-12-11 20:49 ` Jostein Kjønigsen 2022-12-11 23:01 ` Yuan Fu 2022-12-12 13:10 ` Jostein Kjønigsen 2022-12-12 13:53 ` Theodor Thornhill 2022-12-12 20:41 ` Jostein Kjønigsen 2022-12-12 21:17 ` Randy Taylor 2022-12-13 20:43 ` Jostein Kjønigsen 2022-12-13 22:37 ` Randy Taylor 2022-12-14 8:40 ` Jostein Kjønigsen 2022-12-14 13:24 ` Randy Taylor 2022-12-14 18:53 ` toml-ts-mode (code-review done) Jostein Kjønigsen 2022-12-14 19:02 ` Theodor Thornhill 2022-12-14 20:37 ` Yuan Fu 2022-12-14 22:02 ` Jostein Kjønigsen 2022-12-15 2:24 ` Randy Taylor 2022-12-15 12:52 ` Jostein Kjønigsen 2022-12-15 13:22 ` Theodor Thornhill 2022-12-15 13:45 ` Jostein Kjønigsen 2022-12-15 14:22 ` Eli Zaretskii 2022-12-15 14:28 ` Jostein Kjønigsen 2022-12-13 10:45 ` toml-ts-mode: first draft Rudolf Schlatte 2022-12-13 13:20 ` Eli Zaretskii 2022-12-13 14:22 ` Rudi Schlatte
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).