From: Yuan Fu <casouri@gmail.com>
To: Huan Nguyen <nguyenthieuhuan@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>, Eli Zaretskii <eliz@gnu.org>
Subject: Re: [PATCH] treesit.el: New function to describe font-lock rules
Date: Fri, 20 Oct 2023 21:11:01 -0700 [thread overview]
Message-ID: <A85E1D7E-320E-4B78-8677-061A05024B04@gmail.com> (raw)
In-Reply-To: <CALZcaFhB=oOFcO4arckFCMVbddkPb9xPQRAfUiDZp2_f=qd9fA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 348 bytes --]
(Adding emacs-devel back to CC)
> On Oct 18, 2023, at 1:32 AM, Huan Nguyen <nguyenthieuhuan@gmail.com> wrote:
>
> My copyright assignment process is done.
Great! I’ve pushed it to master. Eli, do we need a NEWS entry for this change? We are adding a new keyword for treesit-font-lock-rules. I attached the merged patch below.
Yuan
[-- Attachment #2: 0001-New-keyword-default-language-in-treesit-font-lock-ru.patch --]
[-- Type: application/octet-stream, Size: 3983 bytes --]
From 70c3bfdafa46a5389b25fab322ca2c2bb75f3583 Mon Sep 17 00:00:00 2001
From: Huan Nguyen <goafanxx@gmail.com>
Date: Sat, 7 Oct 2023 12:03:55 +0200
Subject: [PATCH] New keyword :default-language in `treesit-font-lock-rules'
function.
* lisp/treesit.el (treesit-font-lock-rules):
Keyword :default-language `LANGUAGE' will be chosen for every :feature.
Using :language will override the :default-language for the next :feature.
---
lisp/treesit.el | 44 +++++++++++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 17 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 402417c..31ebd50 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -922,12 +922,21 @@ treesit-font-lock-rules
;; that following queries will apply to.
current-language current-override
current-feature
+ ;; default-language will be chosen when current-language is not set
+ default-language
;; The list this function returns.
(result nil))
(while query-specs
(let ((token (pop query-specs)))
(pcase token
;; (1) Process keywords.
+ (:default-language
+ (let ((lang (pop query-specs)))
+ (when (or (not (symbolp lang)) (null lang))
+ (signal 'treesit-font-lock-error
+ `("Value of :default-language should be a symbol"
+ ,lang)))
+ (setq default-language lang)))
(:language
(let ((lang (pop query-specs)))
(when (or (not (symbolp lang)) (null lang))
@@ -955,23 +964,24 @@ treesit-font-lock-rules
(setq current-feature var)))
;; (2) Process query.
((pred treesit-query-p)
- (when (null current-language)
- (signal 'treesit-font-lock-error
- `("Language unspecified, use :language keyword to specify a language for this query" ,token)))
- (when (null current-feature)
- (signal 'treesit-font-lock-error
- `("Feature unspecified, use :feature keyword to specify the feature name for this query" ,token)))
- (if (treesit-compiled-query-p token)
- (push `(,current-language token) result)
- (push `(,(treesit-query-compile current-language token)
- t
- ,current-feature
- ,current-override)
- result))
- ;; Clears any configurations set for this query.
- (setq current-language nil
- current-override nil
- current-feature nil))
+ (let ((lang (or default-language current-language)))
+ (when (null lang)
+ (signal 'treesit-font-lock-error
+ `("Language unspecified, use :language keyword or :default-language to specify a language for this query" ,token)))
+ (when (null current-feature)
+ (signal 'treesit-font-lock-error
+ `("Feature unspecified, use :feature keyword to specify the feature name for this query" ,token)))
+ (if (treesit-compiled-query-p token)
+ (push `(,lang token) result)
+ (push `(,(treesit-query-compile lang token)
+ t
+ ,current-feature
+ ,current-override)
+ result))
+ ;; Clears any configurations set for this query.
+ (setq current-language nil
+ current-override nil
+ current-feature nil)))
(_ (signal 'treesit-font-lock-error
`("Unexpected value" ,token))))))
(nreverse result))))
--
2.41.0
next prev parent reply other threads:[~2023-10-21 4:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 13:32 [PATCH] treesit.el: New function to describe font-lock rules Huan Thieu Nguyen
2023-10-06 7:05 ` Yuan Fu
[not found] ` <1e5cd9da-7be2-486d-bbbb-7b50167e2916@gmail.com>
[not found] ` <35F71E15-AEAB-45FD-ACF3-50133A1766D8@gmail.com>
[not found] ` <2c196077-a1c7-4bfa-91b6-209ebf21b6fa@gmail.com>
[not found] ` <CB77885F-776A-4397-83E6-07835269FE50@gmail.com>
[not found] ` <91640cdb-d78a-4bd5-895c-9aacca3d4c97@gmail.com>
[not found] ` <E07BF33E-BD63-42F1-8B7E-FF110CE9642E@gmail.com>
[not found] ` <CALZcaFhB=oOFcO4arckFCMVbddkPb9xPQRAfUiDZp2_f=qd9fA@mail.gmail.com>
2023-10-21 4:11 ` Yuan Fu [this message]
2023-10-21 7:38 ` Eli Zaretskii
2023-10-21 8:17 ` Yuan Fu
2023-10-21 19:49 ` Yuan Fu
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=A85E1D7E-320E-4B78-8677-061A05024B04@gmail.com \
--to=casouri@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=nguyenthieuhuan@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).