From 15181c50d13d4095bbd69ee574ab03d587ffe50e Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 1 Jul 2024 15:07:36 -0700 Subject: [PATCH] [oni-python] Add treesit configuration --- oni-python/oni-python.el | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/oni-python/oni-python.el b/oni-python/oni-python.el index f737eeb..73bf001 100644 --- a/oni-python/oni-python.el +++ b/oni-python/oni-python.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2024.0313.112713 +;; Version: 2024.0621.092608 ;; Package-Requires: (oni-yasnippet oni-company oni-flycheck oni-hydra oni-lsp rainbow-delimiters reformatter) ;; This program is free software; you can redistribute it and/or modify @@ -41,6 +41,9 @@ (require 'whitespace) (require 'yasnippet) +;; Don't mind if treesit can't be loaded, maybe this Emacs doesn't have it. +(require 'treesit nil t) + (autoload 'hl-indent-mode "hl-indent-mode") (defconst oni-python-root @@ -73,6 +76,18 @@ for indentation." (setq-local whitespace-style '(face tabs)) (whitespace-mode)) +(defun oni-python--enable-hooks (hook) + (add-hook hook 'company-mode) + (add-hook hook 'display-fill-column-indicator-mode) + (add-hook hook 'electric-indent-local-mode) + (add-hook hook 'electric-pair-local-mode) + (add-hook hook 'flycheck-mode) + (add-hook hook 'lsp) + (add-hook hook 'oni-python-set-fill-column) + (add-hook hook 'oni-python-whitespace-mode) + (add-hook hook 'python-black-on-save-mode) + (add-hook hook 'rainbow-delimiters-mode)) + (reformatter-define python-black :program "black" :args `("--line-length" ,(number-to-string fill-column) "-") @@ -81,16 +96,14 @@ for indentation." (define-key python-mode-map (kbd "C-c r") 'python-refactor-hydra/body) -(add-hook 'python-mode-hook 'company-mode) -(add-hook 'python-mode-hook 'display-fill-column-indicator-mode) -(add-hook 'python-mode-hook 'electric-indent-local-mode) -(add-hook 'python-mode-hook 'electric-pair-local-mode) -(add-hook 'python-mode-hook 'flycheck-mode) -(add-hook 'python-mode-hook 'lsp) -(add-hook 'python-mode-hook 'oni-python-set-fill-column) -(add-hook 'python-mode-hook 'oni-python-whitespace-mode) -(add-hook 'python-mode-hook 'python-black-on-save-mode) -(add-hook 'python-mode-hook 'rainbow-delimiters-mode) +(oni-python--enable-hooks 'python-mode-hook) + +;;;###autoload +(when (and (functionp 'treesit-available-p) + (treesit-available-p) + (treesit-ready-p 'python)) + (add-to-list 'major-mode-remap-alist '(python-mode . python-ts-mode)) + (oni-python--enable-hooks 'python-ts-mode-hook)) (with-eval-after-load 'python (with-eval-after-load 'yasnippet