From fae8b8bb6ba1c1e22d643edb583847738a49e520 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 24 Oct 2024 00:21:52 +0100 Subject: [PATCH] chore(treesit): add extra helper functions --- modules/text-editing/siren-treesit.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/text-editing/siren-treesit.el b/modules/text-editing/siren-treesit.el index 662d3df..242071a 100644 --- a/modules/text-editing/siren-treesit.el +++ b/modules/text-editing/siren-treesit.el @@ -26,6 +26,13 @@ "Add font-lock features to treesit." (add-to-list 'treesit-font-lock-feature-list features) t) + (defun siren-treesit-prepend-font-lock-settings (&rest query-specs) + "Replace existing features in font-lock settings, retaining feature order." + (setq-local + treesit-font-lock-settings + (append (apply 'treesit-font-lock-rules query-specs) + treesit-font-lock-settings))) + (defun siren-treesit-append-font-lock-settings (&rest query-specs) "Replace existing features in font-lock settings, retaining feature order." (setq-local @@ -33,7 +40,6 @@ (append treesit-font-lock-settings (apply 'treesit-font-lock-rules query-specs)))) - (defun siren-treesit-add-font-lock-settings (&rest query-specs) "Add features after existing ones in font-lock settings." (dolist (item (apply 'treesit-font-lock-rules query-specs)) @@ -59,6 +65,11 @@ treesit-font-lock-settings (apply 'treesit-font-lock-rules query-specs)))) + (defun siren-treesit-get-font-lock-rule (feature) + "Get the current treesit font-lock settings." + (cl-find-if (lambda (x) (eq (siren-treesit--feature x) feature)) + treesit-font-lock-settings)) + (defun siren-treesit--feature (compiled-query) "Get the feature from a compiled treesit query." (nth 2 compiled-query))