aboutsummaryrefslogtreecommitdiffstats
path: root/oni-python
diff options
context:
space:
mode:
authorGravatar Tom Willemse2024-07-01 15:07:36 -0700
committerGravatar Tom Willemse2024-07-01 15:07:36 -0700
commit15181c50d13d4095bbd69ee574ab03d587ffe50e (patch)
tree6c966d8073d6881280b3cb893c4db8a26b606b00 /oni-python
parent75128ffcdfd55373d42b7152a06734c33530e6a4 (diff)
downloademacs-config-15181c50d13d4095bbd69ee574ab03d587ffe50e.tar.gz
emacs-config-15181c50d13d4095bbd69ee574ab03d587ffe50e.zip
[oni-python] Add treesit configuration
Diffstat (limited to 'oni-python')
-rw-r--r--oni-python/oni-python.el35
1 files 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 <tom@ryuslash.org>
;; 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