From dd068c79230810215e5721b5c4f9d7f0db85adfa Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 13 Feb 2020 11:39:33 -0500 Subject: [PATCH] Add an autoflake command --- emacs/init.org | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/emacs/init.org b/emacs/init.org index 60e2a06..65104a7 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -2512,6 +2512,28 @@ Run black on the current buffer: :hook ((python-mode . sphinx-doc-mode))) #+END_SRC +** Autoflake +[[https://pypi.org/project/autoflake/][Autoflake]] is a tool that removes unused imports and variables from Python code: +#+BEGIN_SRC emacs-lisp + (defvar autoflake-args '() + "Arguments to pass to the autoflake command. + + See URL `https://pypi.org/project/autoflake' for options.") + + (defun autoflake (arg) + (interactive "P") + (let ((autoflake-cmd (or (executable-find "autoflake") + (error "Autoflake executable not found"))) + (file (cond + ((or arg (not buffer-file-name)) + (read-file-name "Run autoflake on file: ")) + (buffer-file-name buffer-file-name) + (:else (error "Invalid file for autoflake"))))) + (apply #'call-process autoflake-cmd nil nil nil + (append autoflake-args (list "--in-place" file))))) +#+END_SRC + + * Hy Python but Lispy!