Add an autoflake command

This commit is contained in:
Jeremy Dormitzer 2020-02-13 11:39:33 -05:00
parent 9207a8d212
commit dd068c7923

View File

@ -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!