From 327d359fd36d1711511e91adc97bc96c330596ca Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 22 Dec 2019 23:00:26 -0500 Subject: [PATCH] lang/python: silence errors when python isn't present --- modules/lang/python/config.el | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/lang/python/config.el b/modules/lang/python/config.el index d8d72f6a7..461f3d8db 100644 --- a/modules/lang/python/config.el +++ b/modules/lang/python/config.el @@ -95,12 +95,13 @@ called.") (add-hook! 'python-mode-local-vars-hook (defun +python-init-anaconda-mode-maybe-h () - "Enable `anaconda-mode' if `lsp-mode' isn't." + "Enable `anaconda-mode' if `lsp-mode' is absent and +`python-shell-interpreter' is present." (unless (or (bound-and-true-p lsp-mode) - (bound-and-true-p lsp--buffer-deferred)) + (bound-and-true-p lsp--buffer-deferred) + (not (executable-find python-shell-interpreter))) (anaconda-mode +1)))) :config - (add-hook 'anaconda-mode-hook #'anaconda-eldoc-mode) (set-company-backend! 'anaconda-mode '(company-anaconda)) (set-lookup-handlers! 'anaconda-mode :definition #'anaconda-mode-find-definitions @@ -108,6 +109,8 @@ called.") :documentation #'anaconda-mode-show-doc) (set-popup-rule! "^\\*anaconda-mode" :select nil) + (add-hook 'anaconda-mode-hook #'anaconda-eldoc-mode) + (defun +python-auto-kill-anaconda-processes-h () "Kill anaconda processes if this buffer is the last python buffer." (when (and (eq major-mode 'python-mode) @@ -286,11 +289,20 @@ called.") (after! python (setq lsp-python-ms-python-executable-cmd python-shell-interpreter)) + ;; HACK If you don't have python installed, then opening python buffers with + ;; this on causes a "wrong number of arguments: nil 0" error, because of + ;; careless usage of `cl-destructuring-bind'. This silences that error, + ;; since we may still want to write some python on a system without + ;; python installed! + (defadvice! +python--silence-errors-a (orig-fn &rest args) + :around #'lsp-python-ms--extra-init-params + (ignore-errors (apply orig-fn args))) + ;; HACK lsp-python-ms shouldn't install itself if it isn't present. This - ;; circumvents LSP falling back to pyls when lsp-python-ms is absent. - ;; Installing the server should be a deliberate act; either 'M-x - ;; lsp-python-ms-setup' or setting `lsp-python-ms-executable' to an existing - ;; install will do. + ;; circumvents LSP falling back to pyls when lsp-python-ms is absent. + ;; Installing the server should be a deliberate act; either 'M-x + ;; lsp-python-ms-setup' or setting `lsp-python-ms-executable' to an + ;; existing install will do. (defadvice! +python--dont-auto-install-server-a () :override #'lsp-python-ms--command-string lsp-python-ms-executable))