Add an autoflake command
This commit is contained in:
parent
9207a8d212
commit
dd068c7923
@ -2512,6 +2512,28 @@ Run black on the current buffer:
|
|||||||
:hook ((python-mode . sphinx-doc-mode)))
|
:hook ((python-mode . sphinx-doc-mode)))
|
||||||
#+END_SRC
|
#+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
|
* Hy
|
||||||
Python but Lispy!
|
Python but Lispy!
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user