From 2310cbe20da0f0ade13f36e8b23b542ccd0ec9b6 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Sat, 25 Feb 2023 00:44:25 -0800 Subject: [PATCH] Revamp the lsp/python stuff and use tree sitter for syntax highlighting. --- elisp/custom.el | 2 +- elisp/keybinds.el | 4 +++ elisp/modes/default-modes.el | 52 +++++++++++++++++++++++-------------- elisp/modes/python-mode-settings.el | 20 +++++--------- 4 files changed, 44 insertions(+), 34 deletions(-) diff --git a/elisp/custom.el b/elisp/custom.el index c52f21d..af57729 100644 --- a/elisp/custom.el +++ b/elisp/custom.el @@ -4,7 +4,7 @@ ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(package-selected-packages - '(color-identifiers-mode centaur-tabs lsp-pyright magit doom-modeline flycheck-indicator nord-theme powerline rainbow-delimiters python-pytest json-mode company-jedi jedi hl-defined counsel rainbow-identifiers exwm-config all-the-icons-ibuffer slime ivy zerodark-theme zerodark neotree all-the-icons paredit flycheck aggressive-indent aggressive-indent-mode lsp-python-ms py-autopep8 pyenv-mode elpy lsp-ui use-package))) + '(company-lsp color-identifiers-mode centaur-tabs lsp-pyright magit doom-modeline flycheck-indicator nord-theme powerline rainbow-delimiters python-pytest json-mode company-jedi jedi hl-defined counsel rainbow-identifiers exwm-config all-the-icons-ibuffer slime ivy zerodark-theme zerodark neotree all-the-icons paredit flycheck aggressive-indent aggressive-indent-mode lsp-python-ms py-autopep8 pyenv-mode elpy lsp-ui use-package))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. diff --git a/elisp/keybinds.el b/elisp/keybinds.el index 25f90b4..c031747 100644 --- a/elisp/keybinds.el +++ b/elisp/keybinds.el @@ -12,3 +12,7 @@ ;; Force C-x C-b to ibuffer (global-set-key (kbd "C-x C-b") 'ibuffer) + +;; Use projectile find file to help +;; with larger projects. +(global-set-key (kbd "C-x f") 'projectile--find-file) diff --git a/elisp/modes/default-modes.el b/elisp/modes/default-modes.el index b20b893..96d2509 100644 --- a/elisp/modes/default-modes.el +++ b/elisp/modes/default-modes.el @@ -1,27 +1,10 @@ ;; Default mode definitions. -;;; Code: -;; Easier to identify identifiers -(use-package color-identifiers-mode - :ensure t - :init (add-hook 'after-init-hook 'global-color-identifiers-mode) - :config - (setq color-identifiers:recoloring-delay 1)) - ;; Flycheck is enabled globally. (use-package flycheck :ensure t :hook ((after-init . global-flycheck-mode))) -;; Company is enabled globally. -(use-package company - :ensure t - :hook ((after-init . global-company-mode)) - :config ;; backend setting must be done only after load. - (push 'company-files company-backends) - (push 'company-keywords company-backends) - (push 'company-capf company-backends)) - (use-package projectile :ensure t :bind-keymap @@ -29,12 +12,41 @@ (use-package lsp-mode :ensure t - :hook ((python-mode . lsp-deferred)) - :commands (lsp lsp-deferred)) + :hook ((python-mode . lsp-deferred) + (ruby-mode . lsp-deferred) + (c-mode . lsp-deferred) + (c++-mode . lsp-deferred))) (use-package lsp-ui :ensure t - :hook (lsp-mode . lsp-ui-mode)) + :after lsp + :hook ((lsp-mode . lsp-ui-mode)) + :config + (setq lsp-ui-doc-enable t) + (setq lsp-ui-doc-show-with-cursor t) + (setq lsp-ui-doc-show-with-mouse t)) + +;; Way better syntax highlighting for many languages +;; Emacs 29 supports this natively. +(if (version<= emacs-version "29") + (progn + (use-package tree-sitter + :ensure t + :init + (global-tree-sitter-mode) + :hook ((tree-sitter-after-on . tree-sitter-hl-mode))) + (use-package tree-sitter-langs + :ensure t)) + ) + +;; Company is enabled globally. +(use-package company + :ensure t + :hook ((after-init . global-company-mode)) + :config ;; backend setting must be done only after load. + (push 'company-files company-backends) + (push 'company-keywords company-backends) + (push 'company-capf company-backends)) (with-eval-after-load 'magit-mode (add-hook 'after-save-hook 'magit-after-save-refresh-status t)) diff --git a/elisp/modes/python-mode-settings.el b/elisp/modes/python-mode-settings.el index 92b0a81..148f9b2 100644 --- a/elisp/modes/python-mode-settings.el +++ b/elisp/modes/python-mode-settings.el @@ -4,8 +4,8 @@ ;;; ;;; ;;; - For each project you will need to install flake8/autopep8 into the virtualenv -;;; - For each project you will need to install jedi into the virtualenv ;;; - To set your pyenv use M-x pyenv-mode and select your local virtualenv + ;; thx rakan.me (defun pyenv-activate-current-project () "Automatically activates pyenv version if .python-version file exists." @@ -19,20 +19,13 @@ (pyenv-mode-set pyenv-current-version) (message (concat "Setting virtualenv to " pyenv-current-version)))))))) -;; For Python enable Elpy. -(use-package elpy - :ensure t - :defer t - :init - (advice-add 'python-mode :before 'elpy-enable)) - - ;; Enable pyenv integration. (if (executable-find "pyenv") (use-package pyenv-mode :ensure t :config (pyenv-mode))) + ;; Disable elpy default virtualenv (use the pyenv one) (setq elpy-rpc-virtualenv-path 'current) @@ -40,12 +33,13 @@ (use-package py-autopep8 :ensure t) -(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save) +(add-hook 'elpy-mode-hook 'py-autopep8-mode) ;; Enable flake8 - requires flake8 in your path so use pyenv/global pip install (add-hook 'python-mode-hook '(lambda () - (setq flycheck-python-flake8-executable "flake8") - (flycheck-select-checker 'python-flake8) - (flycheck-mode t))) + (setq flycheck-python-flake8-executable "flake8") + (flycheck-select-checker 'python-flake8) + (flycheck-mode t))) + ;; Activate pyenv automatically if a .python-version is supplied (if (executable-find "pyenv") (add-hook 'python-mode-hook 'pyenv-activate-current-project))