From: Don Armstrong Date: Sun, 1 Jan 2023 19:07:08 +0000 (-0800) Subject: first stab at working with tree-sitter parsing X-Git-Url: https://git.donarmstrong.com/?p=lib.git;a=commitdiff_plain;h=60e6e57e4b2e788c659bf450caa9ca30d658b0ce first stab at working with tree-sitter parsing --- diff --git a/emacs_el/configuration/don-configuration.org b/emacs_el/configuration/don-configuration.org index 003a818..a00859a 100644 --- a/emacs_el/configuration/don-configuration.org +++ b/emacs_el/configuration/don-configuration.org @@ -112,6 +112,65 @@ (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook) #+END_SRC * Modules +** Tree sitter +#+BEGIN_SRC emacs-lisp +(use-package tree-sitter + :ensure t + :defer 1 + :config + (global-tree-sitter-mode) + ) +(use-package tree-sitter-langs + :ensure t + :defer 1 + :after tree-sitter + :config + (defun dla/python-function-at-point () + "Return a list of function arguments + +Borrowed from https://xenodium.com/emacs-generate-a-swift-initializer/ +" + (interactive) + (cl-assert (seq-contains local-minor-modes 'tree-sitter-mode) "tree-sitter-mode not enabled") + (let* ((node (tree-sitter-node-at-point 'function_definition) + ) + (args) + (arg) + (ret)) + (unless node + (error "Not in function")) + (mapc + (lambda (item) + (cond ((eq 'func_name + (car item)) + ; (when arg + ; (setq args (append args (list arg))) + ; ) + (setq arg (list (cons 'function (tsc-node-text + (cdr item)))))) + ((eq 'ident + (car item)) + (setq arg (map-insert arg 'ident (tsc-node-text + (cdr item))))) + ((eq 'ident_type + (car item)) + (setq arg (map-insert arg 'ident_type (tsc-node-text + (cdr item))))) + ((eq 'ret_type + (car item)) + (setq arg (map-insert arg 'ret_type (tsc-node-text + (cdr item))))) + )) + (tsc-query-captures + (tsc-make-query tree-sitter-language + "(function_definition (identifier) @func_name (parameters [(identifier) @ident (typed_parameter (identifier) @ident (type) @ident_type)]) (type)? @ret_type)") + (tree-sitter-node-at-point 'function_definition) nil)) + (when arg + (setq args (append args (list arg)))) + args)) + +) +#+END_SRC ** Spacemacs theme #+BEGIN_SRC emacs-lisp (use-package spacemacs-common