From c962bb3f9300740d6a64d7ebd61a678581142814 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Mon, 29 Jul 2024 11:45:01 +0100 Subject: [PATCH] Move python-check-command and python-flymake-command setting to hooks Set variables locally depending on what programs are available. Mostly helpful for checking if mypy is installed in given environment (since it's not globally), or for available programs on remote host --- init.el | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/init.el b/init.el index d44fa72..b3d8719 100644 --- a/init.el +++ b/init.el @@ -867,21 +867,17 @@ ("C-c c a" . eglot-code-actions) ("C-c c r" . eglot-rename)) :hook ((eglot-managed-mode . (lambda () (add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t))) - (nix-mode . (lambda () (if (and (project-current nil) - (executable-find "nil" t)) + (nix-mode . (lambda () (if (and (project-current nil) (executable-find "nil" t)) (eglot-ensure)))) (python-base-mode . (lambda () (if (and (project-current nil) (or (executable-find "pyright" t) (executable-find "pylsp" t))) (eglot-ensure)))) - (lua-mode . (lambda () (if (and (project-current nil) - (executable-find "lua-language-server" t)) + (lua-mode . (lambda () (if (and (project-current nil) (executable-find "lua-language-server" t)) (eglot-ensure)))) - ((rust-ts-mode rust-mode) . (lambda () (if (and (project-current nil) - (executable-find "rust-analyzer" t)) + ((rust-ts-mode rust-mode) . (lambda () (if (and (project-current nil) (executable-find "rust-analyzer" t)) (eglot-ensure)))) - ((js-base-mode typescript-ts-base-mode) . (lambda () (if (and (project-current nil) - (executable-find "typescript-language-server" t)) + ((js-base-mode typescript-ts-base-mode) . (lambda () (if (and (project-current nil) (executable-find "typescript-language-server" t)) (eglot-ensure)))) ) :custom @@ -1053,16 +1049,19 @@ Calls `project-remember-projects-under' for ~/Projects/" (display-fill-column-indicator-mode +1)) (use-package python - :hook ((python-base-mode . (lambda () (my/enable-fill-column 88)))) + :hook ((python-base-mode . (lambda () (my/enable-fill-column 88))) + (python-base-mode . (lambda () (setq-local + python-check-command (cond + ((executable-find "mypy" t) "mypy --check-untyped-defs --warn-unreachable --show-error-codes --ignore-missing-imports") + (t "pyflakes")) + python-flymake-command (cond + ((executable-find "ruff" t) '("ruff" "check" "--output-format=concise" "--stdin-filename=stdin" "-")) + ((executable-find "flake8" t) '("flake8" "--max-line-length" "88" "-")) + (t '("pyflakes"))))))) :custom (python-shell-interpreter "python3") - (python-shell-dedicated 'project) + (python-shell-dedicated nil) (python-indent-def-block-scale 1) - (python-check-command "mypy --check-untyped-defs --warn-unreachable --show-error-codes --ignore-missing-imports") - (python-flymake-command - (cond ((executable-find "ruff") '("ruff" "check" "--output-format=concise" "--stdin-filename=stdin" "-")) - ((executable-find "flake8") '("flake8" "--max-line-length" "88" "-")) - (t '("pyflakes")))) :config (setq python-ts-mode-hook python-mode-hook))