Skip to content

Commit

Permalink
emacs29.1: treesit
Browse files Browse the repository at this point in the history
  • Loading branch information
junjiemars committed Aug 12, 2023
1 parent 1507373 commit 293282c
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions config/on-treesit-autoload.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,43 @@
(when-feature-treesit%

(defun toggle-treesit! ()
"Toggle \\=`treesit\\='."
"Toggle \\=`treesit\\=' on or off."
(interactive)
(if major-mode-remap-alist
(let ((ms major-mode-remap-alist))
(while (car ms)
(setq auto-mode-alist
(remove-if* (lambda (x) (eq (cdar ms) x))
auto-mode-alist
:key #'cdr))
(setq ms (cdr ms)))
(setq major-mode-remap-alist nil
treesit-language-source-alist nil)
(message "treesit off"))
(let ((ss (treesit*-settings)) (rr nil) (mm nil)
(aa (copy-sequence auto-mode-alist)))
(dolist* (x ss)
(let ((l1 (plist-get x :lang))
(m1 (plist-get x :mode))
(u1 (plist-get x :url))
(r1 (plist-get x :map)))
(when u1 (push! (list l1 u1) rr t))
(push! (cons m1 r1) mm t)
(dolist* (y auto-mode-alist)
(when (eq (cdr y) m1)
(push! (cons (car y) r1) aa)))))
(setq treesit-language-source-alist rr
major-mode-remap-alist mm
auto-mode-alist aa)
(message "treesit on")))))
(let ((on (catch 'rc
(let ((ss (treesit*-settings)))
(dolist* (x ss)
(when (some* (lambda (a)
(eq (plist-get x :map) (cdr a)))
major-mode-remap-alist)
(throw 'rc t)))))))
(if on
(let ((ts (treesit*-settings)))
(dolist* (x ts)
(setq auto-mode-alist
(remove-if* (lambda (a) (eq (plist-get x :map) a))
auto-mode-alist
:key #'cdr)
major-mode-remap-alist
(remove-if* (lambda (a) (eq (plist-get x :map) a))
major-mode-remap-alist
:key #'cdr)))
(setq treesit-language-source-alist nil)
(message "treesit off"))
(let ((ts (treesit*-settings))
(aa (copy-sequence auto-mode-alist)))
(dolist* (x ts)
(let ((l1 (plist-get x :lang))
(m1 (plist-get x :mode))
(u1 (plist-get x :url))
(r1 (plist-get x :map)))
(when u1
(push! (list l1 u1) treesit-language-source-alist t))
(push! (cons m1 r1) major-mode-remap-alist t)
(dolist* (y auto-mode-alist)
(when (eq (cdr y) m1)
(push! (cons (car y) r1) aa)))))
(setq auto-mode-alist aa)
(message "treesit on"))))))


(when-feature-treesit%
Expand Down

0 comments on commit 293282c

Please sign in to comment.