]> git.donarmstrong.com Git - lib.git/blobdiff - emacs_el/configuration/don-configuration.org
first stab at working with tree-sitter parsing
[lib.git] / emacs_el / configuration / don-configuration.org
index 5cf822e0d37573b15d97c60d55dc3020442da342..a00859a30e33b6a2cf4a23f4b631d3e1d7e374ab 100644 (file)
   (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
@@ -456,6 +515,19 @@ value, scrolling continues until there is no more output.
         company-minimum-prefix-length 1
         company-global-modes '(not)
         company-lighter-base "(C)")
+  (setq company-backends '(company-capf
+                           company-keywords
+                           company-semantic
+                           company-files
+                           company-etags
+                           company-elisp
+                           company-clang
+                           company-irony-c-headers
+                           company-irony
+                           company-jedi
+                           company-cmake
+                           company-ispell
+                           company-yasnippet))
   (global-company-mode 1)
   :bind (:map company-active-map
               ("C-n" . company-select-next)
@@ -467,24 +539,25 @@ value, scrolling continues until there is no more output.
 #+END_SRC
 *** C/C++
 #+BEGIN_SRC emacs-lisp
-  (use-package company-c-headers
-    :ensure t
-    :config (progn
-              (defun malb/ede-object-system-include-path ()
-                "Return the system include path for the current buffer."
-                (when ede-object
-                  (ede-system-include-path ede-object)))
-
-              (setq company-c-headers-path-system
-                    #'malb/ede-object-system-include-path)
+(use-package company-c-headers
+  :ensure t
+  :config (progn
+            (defun malb/ede-object-system-include-path ()
+              "Return the system include path for the current buffer."
+              (when ede-object
+                (ede-system-include-path ede-object)))
 
-              (add-to-list 'company-backends #'company-c-headers)))
+            (setq company-c-headers-path-system
+                  #'malb/ede-object-system-include-path)))
 #+END_SRC
 *** Python
 #+BEGIN_SRC emacs-lisp
-(use-package company-anaconda
+(use-package company-jedi
   :ensure t
-  :config (add-to-list 'company-backends #'company-anaconda))
+  :hook (python-mode  . 'jedi:setup)
+  :config
+  (setq jedi:complete-on-dot t)
+  )
 #+END_SRC
 *** Perl
 #+BEGIN_SRC emacs-lisp
@@ -520,6 +593,7 @@ value, scrolling continues until there is no more output.
               )
     )
 #+END_SRC
+**** Bibtex
 #+BEGIN_SRC emacs-lisp
   (use-package company-bibtex
     :ensure t
@@ -527,64 +601,64 @@ value, scrolling continues until there is no more output.
 #+END_SRC
 *** Shell
 
- #+BEGIN_SRC emacs-lisp
-   (use-package company-shell
-     :ensure t
-     :config (progn
-               (setq company-shell-modes '(sh-mode shell-mode))
-               (add-to-list 'company-backends 'company-shell)))
- #+END_SRC
+#+BEGIN_SRC emacs-lisp
+(use-package company-shell
+  :ensure t
+  :config (progn
+            (setq company-shell-modes '(sh-mode shell-mode))
+            (add-to-list 'company-backends 'company-shell)))
+#+END_SRC
 
 *** YaSnippet
 
- Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
+Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
 
- *Note:* Do this at the end of =company-mode= config.
+*Note:* Do this at the end of =company-mode= config.
 
- #+BEGIN_SRC emacs-lisp
-   (defvar malb/company-mode/enable-yas t
-     "Enable yasnippet for all backends.")
+#+BEGIN_SRC emacs-lisp
+(defvar malb/company-mode/enable-yas t
+  "Enable yasnippet for all backends.")
 
-   (defun malb/company-mode/backend-with-yas (backend)
-     (if (or (not malb/company-mode/enable-yas)
-             (and (listp backend)
-                  (member 'company-yasnippet backend)))
-         backend
-       (append (if (consp backend) backend (list backend))
-               '(:with company-yasnippet))))
+(defun malb/company-mode/backend-with-yas (backend)
+  (if (or (not malb/company-mode/enable-yas)
+          (and (listp backend)
+               (member 'company-yasnippet backend)))
+      backend
+    (append (if (consp backend) backend (list backend))
+            '(:with company-yasnippet))))
 
-   (setq company-backends
-         (mapcar #'malb/company-mode/backend-with-yas company-backends))
- #+END_SRC
+(setq company-backends
+      (mapcar #'malb/company-mode/backend-with-yas company-backends))
+#+END_SRC
 
 *** All the words
 
- Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
+Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
 
- #+BEGIN_SRC emacs-lisp
-   (defun malb/toggle-company-ispell ()
-     (interactive)
-     (cond
-      ((member '(company-ispell :with company-yasnippet) company-backends)
-       (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
-       (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
-       (message "company-ispell disabled"))
-      (t
-       (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
-       (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
-       (message "company-ispell enabled!"))))
-
-   (defun malb/company-ispell-setup ()
-     ;; @see https://github.com/company-mode/company-mode/issues/50
-     (when (boundp 'company-backends)
-       (make-local-variable 'company-backends)
-       (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
-       (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
-       ;; https://github.com/redguardtoo/emacs.d/issues/473
-       (if (and (boundp 'ispell-alternate-dictionary)
-                ispell-alternate-dictionary)
-           (setq company-ispell-dictionary ispell-alternate-dictionary))))
- #+END_SRC
+#+BEGIN_SRC emacs-lisp
+(defun malb/toggle-company-ispell ()
+  (interactive)
+  (cond
+   ((member '(company-ispell :with company-yasnippet) company-backends)
+    (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
+    (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
+    (message "company-ispell disabled"))
+   (t
+    (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
+    (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
+    (message "company-ispell enabled!"))))
+
+(defun malb/company-ispell-setup ()
+  ;; @see https://github.com/company-mode/company-mode/issues/50
+  (when (boundp 'company-backends)
+    (make-local-variable 'company-backends)
+    (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
+    (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
+    ;; https://github.com/redguardtoo/emacs.d/issues/473
+    (if (and (boundp 'ispell-alternate-dictionary)
+             ispell-alternate-dictionary)
+        (setq company-ispell-dictionary ispell-alternate-dictionary))))
+#+END_SRC
 
 *** Tab DWIM
 
@@ -793,6 +867,11 @@ Attempts to automatically identify the right indentation for a file
 
   ;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
   ;; (setq vertico-cycle t)
+  :config
+  (define-key vertico-map "\r" #'vertico-directory-enter)
+  (define-key vertico-map "\d" #'vertico-directory-delete-char)
+  (define-key vertico-map "\M-\d" #'vertico-directory-delete-word)
+  (add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy
   )
 
 ;; Persist history over Emacs restarts. Vertico sorts by history position.
@@ -1450,16 +1529,6 @@ From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colori
   (elpy-enable)
   )
 #+END_SRC
-# *** Jedi
-# #+BEGIN_SRC emacs-lisp
-#   (use-package company-jedi
-#     :ensure t
-#     :hook (python-mode . (add-to-list 'company-backends 'company-jedi))
-#     :hook (python-mode  . 'jedi:setup)
-#     :config
-#     (setq jedi:complete-on-dot t)
-#     )
-# #+END_SRC
 *** Black
 #+begin_src emacs-lisp :tangle yes
   (use-package python-black