unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Vladimir Kazanov <vekazanov@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: [ELPA] New package: ert-font-lock
Date: Sat, 18 Nov 2023 11:18:55 +0000	[thread overview]
Message-ID: <87v89zz4v4.fsf@posteo.net> (raw)
In-Reply-To: <CAAs=0-1O3hFoP0s_oCzYzBeFc24uyqTTrFMdf5D-AkAxDqV6Hw@mail.gmail.com> (Vladimir Kazanov's message of "Sat, 18 Nov 2023 10:43:20 +0000")

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

Vladimir Kazanov <vekazanov@gmail.com> writes:

> Hi all,
>
> I want to propose a new package to be included in ELPA. ert-font-lock
> (ERT Font Lock) is an extension to the standard ERT unit testing tool
> that makes it possible to write font-locking tests using a
> comment-based syntax. The syntax itself is based on the Tree-sitter
> unit testing system
> (https://tree-sitter.github.io/tree-sitter/syntax-highlighting#unit-testing).
>
> Find the package along with a test suite and a README here:
> https://github.com/vkazanov/ert-font-lock

Here are a few comments from reading over the source code:


[-- Attachment #2: Type: text/plain, Size: 3441 bytes --]

diff --git a/ert-font-lock.el b/ert-font-lock.el
index 7b8df01..6a6593f 100644
--- a/ert-font-lock.el
+++ b/ert-font-lock.el
@@ -6,7 +6,7 @@
 ;; Keywords: lisp, test
 ;; URL: https://github.com/vkazanov/ert-font-lock
 ;; Version: 0.1.0
-;; Package-Requires: ((emacs "29.1"))
+;; Package-Requires: ((emacs "28.1"))
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -61,7 +61,7 @@
   "Validate if MODE is a valid major mode."
   (unless (functionp mode)
     (user-error "Invalid major mode: %s. Please specify a valid major mode for
-syntax highlighting tests" mode)))
+ syntax highlighting tests" mode)))
 
 
 (defmacro ert-font-lock-deftest (name mode test-string &optional docstring)
@@ -69,6 +69,7 @@ syntax highlighting tests" mode)))
 TEST-STRING is the string to test, MODE is the major mode, and
 DOCSTRING is a docstring to use for the test."
   (declare (indent 2) (debug t) (doc-string 4))
+  ;; Or would it be possible to define a function that calls `ert-set-test'?
   `(ert-deftest ,name ()
      ,@(when docstring `(,docstring))
      (ert-font-lock--validate-major-mode ',mode)
@@ -79,7 +80,6 @@ DOCSTRING is a docstring to use for the test."
        (let ((tests (ert-font-lock--parse-comments)))
          (ert-font-lock--check-faces tests)))))
 
-
 (defmacro ert-font-lock-deftest-file (name mode file &optional docstring)
   "Define an ERT test NAME for font-lock syntax highlighting.
 FILE is the path to a file in ert resource dir with test cases,
@@ -91,23 +91,24 @@ the test."
      (ert-font-lock--validate-major-mode ',mode)
      (ert-font-lock-test-file (ert-resource-file ,file) ',mode)))
 
-
 (defun ert-font-lock--line-comment-p ()
   "Return t if the current line is a comment-only line."
+  (syntax-ppss)
   (save-excursion
     (beginning-of-line)
     (skip-syntax-forward " ")
-    ;; skip empty lines
-    (unless (eolp)
-      (or
-       ;; try the most convenient approach
-       (looking-at "\\s<")
-       ;; a bit smarter
-       (and comment-start (looking-at (regexp-quote comment-start)))
-       (and comment-start-skip (looking-at comment-start-skip))
-       ;; hardcoded
-       (and (derived-mode-p 'c-mode 'c++-mode 'java-mode)
-            (looking-at-p "//"))))))
+    (or
+     ;; skip empty lines
+     (eolp)
+     ;; try the most convenient approach
+     (looking-at "\\s<")
+     ;; a bit smarter
+     (and comment-start (looking-at (regexp-quote comment-start)))
+     (and comment-start-skip (looking-at comment-start-skip))
+     ;; hardcoded
+     (cond
+      ((derived-mode-p 'c-mode 'c++-mode 'java-mode)
+       (looking-at-p "//"))))))
 
 (defun ert-font-lock--goto-first-char ()
   "Move the point to the first character."
@@ -143,7 +144,7 @@ the test."
                                  (line-end-position) t)
 
           (unless (> linetocheck -1)
-            (user-error "Invalid test comment syntax at line %d. Expected a line to test before the comment line" curline))
+            (user-error "Invalid test comment syntax at line %d. Expected a line to test before the comment line" curline)) ;is this a user error?
 
           ;; construct a test
           (let* (;; either comment start char column (for arrows) or
@@ -243,5 +244,4 @@ The function is meant to be run from within an ERT test."
 
 
 (provide 'ert-font-lock)
-
 ;;; ert-font-lock.el ends here

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


> I am the sole author of the package, and did sign FSF papers some time
> ago so this should not be an issue.
>
> Comments, suggestions and critique are very welcome as the package is
> very new. I am open to ideas on the best places to publish the package
> if ELPA is not suitable for it.

ELPA shouls be fine.

> Some additional context.
>
> A while ago I created quakec-mode
> (https://github.com/vkazanov/quakec-mode). One of the most painful
> things about the mode is regex-based syntax highlighting. So I turned
> to creating a Tree-sitter grammar
> (https://github.com/vkazanov/tree-sitter-quakec) as well as a TS-based
> mode (https://github.com/vkazanov/quakec-ts-mode).
>
> While doing the syntax highlighting part proved to be much, much
> easier, I couldn't do work without relying on some kind of unit tests.
> Existing font-lock systems didn't feel convenient compared to the way
> Tree-sitter specifies parser tests so I replicated that.
>
> Thank you

  reply	other threads:[~2023-11-18 11:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-18 10:43 [ELPA] New package: ert-font-lock Vladimir Kazanov
2023-11-18 11:18 ` Philip Kaludercic [this message]
2023-11-18 12:07   ` Po Lu
2023-11-18 12:43     ` Eli Zaretskii
2023-11-18 13:14       ` Po Lu
2023-11-18 14:47         ` Philip Kaludercic
2023-11-18 16:23           ` Eli Zaretskii
2023-11-19  9:39           ` Vladimir Kazanov
2023-11-18 14:18       ` john muhl
2023-11-19 10:02         ` Vladimir Kazanov
2023-11-19 10:08       ` Vladimir Kazanov
2023-11-20 18:27         ` Vladimir Kazanov
2023-11-21  4:45           ` john muhl
2023-11-21  7:43             ` Vladimir Kazanov
2023-11-21 16:51               ` john muhl
2023-11-23 13:00                 ` Vladimir Kazanov

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=87v89zz4v4.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=emacs-devel@gnu.org \
    --cc=vekazanov@gmail.com \
    /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).