unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: emacs-devel@gnu.org
Cc: Yuan Fu <casouri@gmail.com>
Subject: Code quality of some -ts-mode major modes
Date: Fri, 17 Mar 2023 10:08:52 +0000	[thread overview]
Message-ID: <87fsa3g05n.fsf@posteo.net> (raw)

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


Hi, I took a look at some of the new tree-sitter major modes and was
surprised at what I saw.  Without meaning to belittle anyone, there were
some basic "stylistic mistakes" that I wouldn't have expected to have
gotten merged.  I didn't look up the exact chronology, but it seems like
there has been a lot of uncritical copying between these files.

Take `yaml-ts-mode' for example.  I attach a diff with a few changes
that I would have expected to have been made before the file was merged:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff, Size: 2642 bytes --]

diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el
index dfa8d22fb34..43e8868fc44 100644
--- a/lisp/textmodes/yaml-ts-mode.el
+++ b/lisp/textmodes/yaml-ts-mode.el
@@ -2,10 +2,10 @@
 
 ;; Copyright (C) 2022-2023 Free Software Foundation, Inc.
 
-;; Author     : Randy Taylor <dev@rjt.dev>
-;; Maintainer : Randy Taylor <dev@rjt.dev>
-;; Created    : December 2022
-;; Keywords   : yaml languages tree-sitter
+;; Author: Randy Taylor <dev@rjt.dev>
+;; Maintainer: Randy Taylor <dev@rjt.dev>
+;; Created: December 2022
+;; Keywords: languages
 
 ;; This file is part of GNU Emacs.
 
@@ -23,15 +23,18 @@
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
 ;;; Commentary:
-;;
+
+;; This file provides basic YAML syntax highlighting using Tree
+;; Sitter.  To use the `yaml-ts-mode' major mode you will have to make
+;; sure that you have installed the appropriate grammar.
 
 ;;; Code:
 
 (require 'treesit)
 
-(declare-function treesit-parser-create "treesit.c")
+;; (declare-function treesit-parser-create "treesit.c") ;doesn't appear necessary
 
-(defvar yaml-ts-mode--syntax-table
+(defvar yaml-ts-mode-syntax-table
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?#  "<"  table)
     (modify-syntax-entry ?\n ">"  table)
@@ -59,7 +62,8 @@ yaml-ts-mode--font-lock-settings
       (null_scalar)
       (reserved_directive)
       (tag_directive)
-      (yaml_directive)] @font-lock-constant-face)
+      (yaml_directive)]
+     @font-lock-constant-face)
 
    :language 'yaml
    :feature 'delimiter
@@ -83,7 +87,8 @@ yaml-ts-mode--font-lock-settings
    '([(block_scalar)
       (double_quote_scalar)
       (single_quote_scalar)
-      (string_scalar)] @font-lock-string-face)
+      (string_scalar)]
+     @font-lock-string-face)
 
    :language 'yaml
    :feature 'escape-sequence
@@ -120,10 +125,9 @@ yaml-ts-mode--font-lock-settings
 ;;;###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
+  ;; :group 'yaml ;; no such customisation group was defined?
 
-  (when (treesit-ready-p 'yaml)
+  (when (treesit-ready-p 'yaml)         ;why not raise an `user-error'?
     (treesit-parser-create 'yaml)
 
     ;; Comments.
@@ -143,9 +147,8 @@ yaml-ts-mode
 
     (treesit-major-mode-setup)))
 
-(if (treesit-ready-p 'yaml)
-    (add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode)))
+(when (treesit-ready-p 'yaml)
+  (add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode)))
 
 (provide 'yaml-ts-mode)
-
 ;;; yaml-ts-mode.el ends here

[-- Attachment #3: Type: text/plain, Size: 764 bytes --]


In particular: The lack of a commentary section or any
indication/pointer on how to install the grammar which is the necessary
prequisite for the mode to have any effect to begin with (my
understanding is that Emacs will not ship with these files, nor are any
distributions working on providing them, right?).  I considered
mentioning the new command `treesit-install-language-grammar', but that
seems pointless as long as `treesit-language-source-alist' is empty by
default.

My question: Would there be any objection from those involves with
tree-sitter against me making changes like the ones I gave above?
Maintaining some basic style in the core seems desirable to me, as we
have seen that these files often serve as a template for creating new
major modes.

             reply	other threads:[~2023-03-17 10:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-17 10:08 Philip Kaludercic [this message]
2023-03-17 10:29 ` Code quality of some -ts-mode major modes Ruijie Yu via Emacs development discussions.
2023-03-17 11:52   ` Eli Zaretskii
2023-03-17 12:37   ` Philip Kaludercic
2023-03-17 13:54     ` Eli Zaretskii
2023-03-17 15:20       ` Philip Kaludercic
2023-03-17 15:31         ` Eli Zaretskii
2023-03-17 15:49           ` Philip Kaludercic
2023-03-17 16:35             ` Eli Zaretskii
2023-03-17 16:53               ` Philip Kaludercic
2023-03-17 21:45       ` Dmitry Gutov
2023-03-18  5:59         ` Eli Zaretskii
2023-03-17 11:46 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fsa3g05n.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).