From eb8c7a1d75181d1f2cd7b979e5df558b680ea128 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 16 Oct 2024 20:55:54 +0200 Subject: Integrate with ‘electric-indent-mode’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsp-ts-mode.el | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'gsp-ts-mode.el') diff --git a/gsp-ts-mode.el b/gsp-ts-mode.el index 8650452..91967cf 100644 --- a/gsp-ts-mode.el +++ b/gsp-ts-mode.el @@ -98,6 +98,20 @@ These settings are assigned directly to `treesit-simple-indent-rules'. See the documentation for `treesit-simple-indent-rules' and `treesit-simple-indent-presets' for more information.") + +;;; Integration with ‘electric-indent-mode’ + +(defun gsp-ts-mode-electric-should-try-indent (char) + "Electric indentation hook for `gsp-ts-mode'. +This function is a hook for `electric-indent-functions' to trigger +automatic indentation as you type. + +See the documentation for `electric-indent-mode' and +`electric-indent-functions' for more information." + ;; The documentation for ‘electric-indent-functions’ specifies that + ;; this should return ‘t’ and not some arbitrary non-nil value. + (and (= char ?\}) t)) + ;;; Major Mode Setup @@ -123,7 +137,12 @@ See the documentation for `treesit-simple-indent-rules' and (unless (treesit-ready-p 'gsp) (error "Tree-Sitter for GSP isn’t available")) (treesit-parser-create 'gsp) - (gsp-ts--setup)) + (gsp-ts--setup) + + (with-eval-after-load 'electric + (add-hook 'electric-indent-functions + #'gsp-ts-mode-electric-should-try-indent + nil :local))) (provide 'gsp-ts-mode) ;;; gsp-ts-mode.el ends here -- cgit v1.2.3