From 475d0bad256fdfbc31bf5d2f1e52a17798320d6f Mon Sep 17 00:00:00 2001 From: Vedang Manerikar <ved.manerikar@gmail.com> Date: Mon, 18 Nov 2024 22:10:43 +0530 Subject: [PATCH] Experiment with a Python setup - Virtualenvs should be detected and should work out of the box - Eglot should be started as soon as a project file is launched --- unravel-emacs.org | 30 +++++++++++++++++++++++++++--- unravel-modules/unravel-langs.el | 25 +++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/unravel-emacs.org b/unravel-emacs.org index 1ddde81..e344822 100644 --- a/unravel-emacs.org +++ b/unravel-emacs.org @@ -4292,8 +4292,6 @@ of packaging. I use it whenever I work on my numerous Emacs packages. (setq flymake-wrap-around nil) (setq flymake-mode-line-format '("" flymake-mode-line-exception flymake-mode-line-counters)) - ;; NOTE 2023-07-03: `prot-modeline.el' actually defines the counters - ;; itself and ignores this. (setq flymake-mode-line-counter-format '("" flymake-mode-line-error-counter flymake-mode-line-warning-counter @@ -4640,7 +4638,33 @@ Prot is the developer of this package. The built-in Python mode for Emacs goes a long way. We build minimal tooling around this mode, specifically to support ~eglot~ and Python's virtualenv system. -Anytime you create a virtualenv, you should run the following command: =pip3 install ruff +Anytime you create a virtualenv, you should run the following command: =pip3 install ruff python-lsp-server python-lsp-ruff= + +#+begin_src emacs-lisp :tangle "unravel-modules/unravel-langs.el" + ;;;; Configuration for Python Programming + + (use-package python + :ensure nil + :hook + ((python-ts-mode . eglot-ensure) + (python-mode . eglot-ensure)) + :config + (setq python-shell-dedicated 'project)) + + (use-package pyvenv + :ensure t + :commands (pyvenv-create pyvenv-workon pyvenv-activate pyvenv-deactivate) + :config + (setenv "WORKON_HOME" "~/.cache/venvs/") + (pyvenv-tracking-mode 1)) + + (use-package auto-virtualenv + :ensure t + :config + (setq auto-virtualenv-verbose t) + (auto-virtualenv-setup)) +#+end_src + ** Finally, we provide the =unravel-langs.el= module #+begin_src emacs-lisp :tangle "unravel-modules/unravel-langs.el" diff --git a/unravel-modules/unravel-langs.el b/unravel-modules/unravel-langs.el index 4bdee1c..e171f8f 100644 --- a/unravel-modules/unravel-langs.el +++ b/unravel-modules/unravel-langs.el @@ -90,8 +90,6 @@ (setq flymake-wrap-around nil) (setq flymake-mode-line-format '("" flymake-mode-line-exception flymake-mode-line-counters)) - ;; NOTE 2023-07-03: `prot-modeline.el' actually defines the counters - ;; itself and ignores this. (setq flymake-mode-line-counter-format '("" flymake-mode-line-error-counter flymake-mode-line-warning-counter @@ -344,4 +342,27 @@ Perform the comparison with `string<'." ("M-?" . nil)) ; `xref-find-references` uses it. :hook ((lisp-data-mode lisp-mode clojure-mode clojure-ts-mode cider-repl-mode inferior-emacs-lisp-mode) . paredit-mode)) +;;;; Configuration for Python Programming + +(use-package python + :ensure nil + :hook + ((python-ts-mode . eglot-ensure) + (python-mode . eglot-ensure)) + :config + (setq python-shell-dedicated 'project)) + +(use-package pyvenv + :ensure t + :commands (pyvenv-create pyvenv-workon pyvenv-activate pyvenv-deactivate) + :config + (setenv "WORKON_HOME" "~/.cache/venvs/") + (pyvenv-tracking-mode 1)) + +(use-package auto-virtualenv + :ensure t + :config + (setq auto-virtualenv-verbose t) + (auto-virtualenv-setup)) + (provide 'unravel-langs)