From fdb47be7d73652142eb15ae978d5cb63313d346a Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 19 Dec 2020 21:39:17 +0100 Subject: feat(emacs-tree-sitter-move): load more than one tree sitter grammar Change-Id: I43b8ddb180c056f1b8c650ccc915ec41bae83960 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2262 Reviewed-by: Profpatsch Tested-by: BuildkiteCI --- users/Profpatsch/emacs-tree-sitter-move/tmp.el | 30 ++++++++++++++++------ .../emacs-tree-sitter-move/tree-sitter-move.el | 1 + 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'users/Profpatsch') diff --git a/users/Profpatsch/emacs-tree-sitter-move/tmp.el b/users/Profpatsch/emacs-tree-sitter-move/tmp.el index f7a8437096fb..88d13fa45b81 100644 --- a/users/Profpatsch/emacs-tree-sitter-move/tmp.el +++ b/users/Profpatsch/emacs-tree-sitter-move/tmp.el @@ -1,14 +1,28 @@ -(tree-sitter-load - 'python - (format "%s/bin/python" - (getenv "TREE_SITTER_GRAMMAR_DIR"))) +(defun tree-sitter-load-from-grammar-dir (grammar-dir sym lang-name) + (tree-sitter-load + sym + (format "%s/bin/%s" + (getenv grammar-dir) + lang-name))) + +(defun tree-sitter-init-tmp-langs (alist) + (mapcar + (lambda (lang) + (pcase-let ((`(,name ,sym ,mode) lang)) + (tree-sitter-load-from-grammar-dir "TREE_SITTER_GRAMMAR_DIR" sym name) + (cons mode sym))) + alist)) -(setq tree-sitter-major-mode-language-alist - '((python-mode . python))) +(setq tree-sitter-major-mode-language-alist + (tree-sitter-init-tmp-langs + '(("python" python python-mode) + ("json" json js-mode) + ("bash" bash sh-mode) + ))) (define-key evil-normal-state-map (kbd "C-.") #'tree-sitter-move-reset) (define-key evil-normal-state-map (kbd "C-") #'tree-sitter-move-right) (define-key evil-normal-state-map (kbd "C-") #'tree-sitter-move-left) -(define-key evil-normal-state-map (kbd "C-") 'tree-sitter-move-up) -(define-key evil-normal-state-map (kbd "C-") 'tree-sitter-move-down) +(define-key evil-normal-state-map (kbd "C-") #'tree-sitter-move-up) +(define-key evil-normal-state-map (kbd "C-") #'tree-sitter-move-down) diff --git a/users/Profpatsch/emacs-tree-sitter-move/tree-sitter-move.el b/users/Profpatsch/emacs-tree-sitter-move/tree-sitter-move.el index c23e401f0a23..ddccb58c8948 100644 --- a/users/Profpatsch/emacs-tree-sitter-move/tree-sitter-move.el +++ b/users/Profpatsch/emacs-tree-sitter-move/tree-sitter-move.el @@ -15,6 +15,7 @@ (defun tree-sitter-move--setup () ;; TODO (progn + ;; TODO: if tree-sitter-mode fails to load, display a better error (tree-sitter-mode t) (setq tree-sitter-move--cursor (tsc-root-node tree-sitter-tree)) (add-variable-watcher -- cgit 1.4.1