From 650a90b81230ce50bb7ac3811827ab4072258a10 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 8 May 2024 10:59:18 -0400 Subject: [PATCH] Make origami-treesit a proper minor mode --- emacs/.emacs.d/config/init-treesit.el | 1 + .../origami-treesit/origami-treesit.el | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/emacs/.emacs.d/config/init-treesit.el b/emacs/.emacs.d/config/init-treesit.el index 9ac7de4..f2afa43 100644 --- a/emacs/.emacs.d/config/init-treesit.el +++ b/emacs/.emacs.d/config/init-treesit.el @@ -114,6 +114,7 @@ :ensure nil :load-path "packages/origami-treesit" :after origami + :hook (origami-mode . origami-treesit-mode) :custom (origami-treesit-level 4)) diff --git a/emacs/.emacs.d/packages/origami-treesit/origami-treesit.el b/emacs/.emacs.d/packages/origami-treesit/origami-treesit.el index 1787278..39bbdb3 100644 --- a/emacs/.emacs.d/packages/origami-treesit/origami-treesit.el +++ b/emacs/.emacs.d/packages/origami-treesit/origami-treesit.el @@ -199,11 +199,25 @@ (child-nodes (list value))) (list start end offset child-nodes))))))) -(with-eval-after-load 'origami - (add-to-list 'origami-parser-alist '(yaml-ts-mode . origami-yaml-treesit-parser)) - (add-to-list 'origami-parser-alist '(yaml-mode . origami-yaml-treesit-parser)) - (add-to-list 'origami-parser-alist '(ruby-ts-mode . origami-ruby-treesit-parser)) - (add-to-list 'origami-parser-alist '(ruby-mode . origami-ruby-treesit-parser))) +(defvar origami-treesit-parser-alist + '((yaml-ts-mode . origami-yaml-treesit-parser) + (yaml-mode . origami-yaml-treesit-parser) + (ruby-ts-mode . origami-ruby-treesit-parser) + (ruby-mode . origami-ruby-treesit-parser)) + "Alist mapping major-mode to origami-treesit parser function.") + +;;;###autoload +(define-minor-mode origami-treesit-mode + "Minor mode for folding code using tree-sitter." + :group 'origami + :lighter nil + :init-value nil + (if origami-treesit-mode + (setq-local origami-parser-alist + (append origami-treesit-parser-alist origami-parser-alist)) + (setq-local origami-parser-alist + (-difference origami-parser-alist origami-treesit-parser-alist)))) + (provide 'origami-treesit) ;;; origami-treesit.el ends here