Last active
June 17, 2022 11:16
Revisions
-
kracekumar revised this gist
Aug 17, 2014 . 1 changed file with 27 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,27 +1,35 @@ ;;; auto-remove.el --- Auto remove unused functions in python ;;; Commentary: ;; Uses external tool autoflake to remove unused imports from a Python file. ;;; Code: (defcustom python-autoflake-path (executable-find "autoflake") "Autoflake executable path. Allows working with a virtualenv without actually adding support for it." :group 'python :type 'string) (defun python-remove-unused-imports () "Use Autoflake to remove unused function. $ autoflake --remove-all-unused-imports -i unused_imports.py" (interactive) (when (eq major-mode 'python-mode) (shell-command (format "%s --remove-all-unused-imports -i %s" python-autoflake-path (shell-quote-argument (buffer-file-name)))) (revert-buffer t t t)) nil) (eval-after-load 'python '(if python-autoflake-path (add-hook 'before-save-hook 'python-remove-unused-imports) (message "Unable to find autoflake. Configure `python-autoflake-path`"))) (provide 'auto-remove) ;;; auto-remove.el ends here -
kracekumar revised this gist
Aug 17, 2014 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,7 @@ for it." (error "Unable to find autoflake. Configure `python-autoflake-path`")) ;; Run python-remove-unused-imports before save ; As jaseemabid pointed out this gets called on all buffers ;(add-hook 'python-mode-hook ; (lambda () ; (add-hook 'before-save-hook 'python-remove-unused-imports))) -
kracekumar revised this gist
Aug 17, 2014 . 1 changed file with 20 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,26 @@ ;; Auto remove unused functions in python (defcustom python-autoflake-path (executable-find "autoflake") "Autoflake executable path. Allows working with a virtualenv without actually adding support for it." :group 'python :type 'string) (defun python-remove-unused-imports() "Use Autoflake to remove unused function" "autoflake --remove-all-unused-imports -i unused_imports.py" (interactive) (shell-command (format "%s --remove-all-unused-imports -i %s" python-autoflake-path (shell-quote-argument (buffer-file-name)))) (revert-buffer t t t)) (unless python-autoflake-path (error "Unable to find autoflake. Configure `python-autoflake-path`")) ;; Run python-remove-unused-imports before save (add-hook 'python-mode-hook (lambda () (add-hook 'before-save-hook 'python-remove-unused-imports))) -
kracekumar created this gist
Aug 16, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ ;; Auto remove unused functions in python (defun python-remove-unused-imports() "Use Autoflake to remove unused function" "autoflake --remove-all-unused-imports -i unused_imports.py" (interactive) (shell-command (format "autoflake --remove-all-unused-imports -i %s" (shell-quote-argument (buffer-file-name))) ) (revert-buffer t t t) )