all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] treesit.el: New function to describe font-lock rules
@ 2023-10-03 13:32 Huan Thieu Nguyen
  2023-10-06  7:05 ` Yuan Fu
  0 siblings, 1 reply; 6+ messages in thread
From: Huan Thieu Nguyen @ 2023-10-03 13:32 UTC (permalink / raw)
  To: emacs-devel

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

Hello emacs maintainers,

I think most major modes don't need to use multiple tree-sitter 
grammars, so I made a function called `treesit-font-lock-simple-rules' 
which saves the user from typing `:language` for every query-spec.

I have not added an announcement in the news file yet.

Best Regards

Nguyen Thieu Huan

[-- Attachment #2: 0001-Add-treesit-font-lock-simple-rules-function.patch --]
[-- Type: text/x-patch, Size: 1316 bytes --]

From 390870496073d3cc9fb6a85413b21338d0f9ecdb Mon Sep 17 00:00:00 2001
From: Huan Nguyen <goafanxx@gmail.com>
Date: Tue, 3 Oct 2023 15:17:55 +0200
Subject: [PATCH] Add `treesit-font-lock-simple-rules' function.

* lisp/treesit.el (treesit-font-lock-simple-rules):
Add a function which saves the user from typing :language for every
query-spec.
---
 lisp/treesit.el | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index a9761db..3bcca9d 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -837,6 +837,17 @@ treesit-font-lock-rules
                        `("Unexpected value" ,token))))))
       (nreverse result))))
 
+(defun treesit-font-lock-simple-rules (language &rest rules)
+  "Wrapper around `treesit-font-lock-rules'.
+It saves the user from typing :language `LANGUAGE' for every `RULES'."
+  (apply #'treesit-font-lock-rules
+         (seq-reduce
+   (lambda (query-specs keyword)
+     (if (eq :feature keyword)
+	 (append query-specs `(:language ,language ,keyword))
+       (append query-specs `(,keyword))))
+   rules '())))
+
 ;; `font-lock-fontify-region-function' has the LOUDLY argument, but
 ;; `jit-lock-functions' doesn't pass that argument.  So even if we set
 ;; `font-lock-verbose' to t, if jit-lock is enabled (and it's almost
-- 
2.41.0


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

end of thread, other threads:[~2023-10-21 19:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2023-10-21  7:38                   ` Eli Zaretskii
2023-10-21  8:17                     ` Yuan Fu
2023-10-21 19:49                       ` Yuan Fu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.