From d10056b2d12f6308b2c17a4ec735767cdda42558 Mon Sep 17 00:00:00 2001 From: "lin.sun" Date: Mon, 9 Jan 2023 19:33:42 -0800 Subject: [PATCH] fix(python/autoflake): deal with non-zero exit, and better docs Co-authored-by: Lucius Hu --- layers/+lang/python/funcs.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/layers/+lang/python/funcs.el b/layers/+lang/python/funcs.el index a059c193e..3194c79de 100644 --- a/layers/+lang/python/funcs.el +++ b/layers/+lang/python/funcs.el @@ -217,15 +217,16 @@ ROOT-DIR should be the path for the environemnt, `nil' for clean up" ;; from https://www.snip2code.com/Snippet/127022/Emacs-auto-remove-unused-import-statemen (defun spacemacs/python-remove-unused-imports () - "Use Autoflake to remove unused function" - "autoflake --remove-all-unused-imports -i unused_imports.py" + "Use Autoflake to remove unused imports. +Equivalent to: autoflake --remove-all-unused-imports --inplace " (interactive) (if (executable-find "autoflake") - (progn - (shell-command (format "autoflake --remove-all-unused-imports -i %s" - (shell-quote-argument (buffer-file-name)))) + (if (not (eql 0 + (shell-command (format "autoflake --remove-all-unused-imports --inplace %s" + (shell-quote-argument (buffer-file-name)))))) + (pop-to-buffer shell-command-buffer-name) (revert-buffer t t t)) - (message "Error: Cannot find autoflake executable."))) + (user-error "Cannot find autoflake executable"))) (defun spacemacs//pyenv-mode-set-local-version () "Set pyenv version from \".python-version\" by looking in parent directories."