Browse Source

restructured python mode, integrated pet.

master
Marc 2 weeks ago
parent
commit
d7dc9b77d8
1 changed files with 32 additions and 9 deletions
  1. 41
      config.org

41
config.org

@ -1701,6 +1701,9 @@ at least pandas couldnt be resolved in pyright
#+end_src #+end_src
** LSP-Mode ** LSP-Mode
see https://github.com/emacs-lsp/lsp-pyright
for pything pip install basedpyright
see also https://github.com/DetachHead/basedpyright
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun corfu-lsp-setup () (defun corfu-lsp-setup ()
(setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults)) (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
@ -1725,9 +1728,11 @@ at least pandas couldnt be resolved in pyright
:after (python lsp-mode) :after (python lsp-mode)
:custom :custom
(lsp-pyright-multi-root nil) (lsp-pyright-multi-root nil)
(lsp-pyright-langserver-command "basedpyright")
:hook :hook
(python-mode-hook . (lambda ()
(require 'lsp-pyright) (lsp))))
(python-mode . (lambda ()
(require 'lsp-pyright)
(lsp))))
#+end_src #+end_src
** flymake ** flymake
python in venv: pip install pyflake (or ruff?) python in venv: pip install pyflake (or ruff?)
@ -1948,13 +1953,10 @@ npm install -g prettier
Preparations: Preparations:
- create env: - create env:
m-x shell m-x shell
python3 -m venv ./.env
python3 -m venv ./.venv
- Install language server in *each* projects venv - Install language server in *each* projects venv
source ./.env/bin/activate source ./.env/bin/activate
pip install pyright
- in project root:
touch .project.el
echo "((nil . (pyvenv-activate . "/path/to/project/.env")))" >> .dir-locals.el
pip install basedpyright
für andere language servers für andere language servers
https://github.com/emacs-lsp/lsp-mode#install-language-server https://github.com/emacs-lsp/lsp-mode#install-language-server
@ -1983,7 +1985,7 @@ Preparations:
:hook :hook
(python-mode . pyvenv-mode) (python-mode . pyvenv-mode)
:custom :custom
(pyvenv-default-virtual-env-name ".env")
(pyvenv-default-virtual-env-name ".venv")
(pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))) (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]"))))
@ -1996,10 +1998,31 @@ Preparations:
TODO python mode hook: TODO python mode hook:
- activate venv
- activate eglot with proper ls - activate eglot with proper ls
- activate tree-sitter? - activate tree-sitter?
- have some fallback if activations fail - have some fallback if activations fail
** python pet
see https://github.com/wyuenho/emacs-pet
It uses pyvenv to activate the venv. Somehow it doesn't do it on its own. Maybe a misunderstanding on my side.
#+begin_src emacs-lisp
(use-package pet
:ensure t
:config
(add-hook 'python-base-mode-hook 'pet-mode -10)
(add-hook 'pet-mode-hook
(lambda ()
(when python-shell-virtualenv-root
(pyvenv-activate python-shell-virtualenv-root))))
(add-hook 'python-mode-hook
(lambda ()
(setq-local python-shell-interpreter (pet-executable-find "python")
python-shell-virtualenv-root (pet-virtualenv-root))
(flymake-mode)
(lsp)
(setq-local dap-python-executable python-shell-interpreter))))
#+end_src
* beancount * beancount
** Installation ** Installation

Loading…
Cancel
Save