feat(tree-sitter): conditionally enable ts-hl-mode
Based on the new variable `+tree-sitter-hl-enabled-modes` This allows for people to use tree sitters tools without having to use it for highlighting. Useful because some modes (such as web-mode and its derivatives) do a better job than the tree sitter alternative in this respect.
This commit is contained in:
parent
4f23a02877
commit
8e68cd5ffd
2 changed files with 26 additions and 3 deletions
|
@ -2,8 +2,21 @@
|
||||||
|
|
||||||
;;;###autodef (fset 'tree-sitter! #'ignore)
|
;;;###autodef (fset 'tree-sitter! #'ignore)
|
||||||
(defun tree-sitter! ()
|
(defun tree-sitter! ()
|
||||||
(interactive)
|
"Dispatch to turn on tree sitter.
|
||||||
(turn-on-tree-sitter-mode))
|
|
||||||
|
Used as a hook function which turns on `tree-sitter-mode'
|
||||||
|
and selectively turn on `tree-sitter-hl-mode'.
|
||||||
|
according to `+tree-sitter-hl-enabled-modes'"
|
||||||
|
(turn-on-tree-sitter-mode)
|
||||||
|
;; conditionally enable `tree-sitter-hl-mode'
|
||||||
|
(let ((mode (bound-and-true-p tree-sitter-hl-mode)))
|
||||||
|
(when-let (mode (if (pcase +tree-sitter-hl-enabled-modes
|
||||||
|
(`(not . ,modes) (not (memq major-mode modes)))
|
||||||
|
((and `(,_ . ,_) modes) (memq major-mode modes))
|
||||||
|
(bool bool))
|
||||||
|
(unless mode +1)
|
||||||
|
(if mode -1)))
|
||||||
|
(tree-sitter-hl-mode mode))))
|
||||||
|
|
||||||
;; HACK: Remove and refactor when `use-package' eager macro expansion is solved or `use-package!' is removed
|
;; HACK: Remove and refactor when `use-package' eager macro expansion is solved or `use-package!' is removed
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
;;; tools/tree-sitter/config.el -*- lexical-binding: t; -*-
|
;;; tools/tree-sitter/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(defvar +tree-sitter-hl-enabled-modes '(not web-mode typescript-tsx-mode)
|
||||||
|
"A list of major modes which should be highlighted by tree-sitter.
|
||||||
|
|
||||||
|
If this list begins with `not', then it negates the list.
|
||||||
|
If it is t, it is enabled in all modes.
|
||||||
|
If nil, it is disabled in all modes")
|
||||||
|
|
||||||
|
;;
|
||||||
|
;;; Packages
|
||||||
|
|
||||||
(use-package! tree-sitter
|
(use-package! tree-sitter
|
||||||
:hook (tree-sitter-after-on . tree-sitter-hl-mode)
|
:defer t
|
||||||
:config
|
:config
|
||||||
(require 'tree-sitter-langs)
|
(require 'tree-sitter-langs)
|
||||||
;; This makes every node a link to a section of code
|
;; This makes every node a link to a section of code
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue