Some improvements to py-isort config
- Rename variable - Wrap the save function to check condition variable at runtime - Add keybinding
This commit is contained in:
parent
a2d7461bb1
commit
d94d0d9f71
|
@ -231,6 +231,7 @@ function with a prefix argument, for example ~SPC u SPC m t a~.
|
|||
| Key Binding | Description |
|
||||
|-------------+--------------------------------------|
|
||||
| ~SPC m r i~ | remove unused imports with [[https://github.com/myint/autoflake][autoflake]] |
|
||||
| ~SPC m r I~ | sort imports with [[https://pypi.python.org/pypi/isort][isort]] |
|
||||
|
||||
** Live coding
|
||||
|
||||
|
|
|
@ -29,5 +29,5 @@
|
|||
|
||||
Possible values are `on-visit', `on-project-switch' or `nil'.")
|
||||
|
||||
(defvar python-enable-sort-imports-on-save nil
|
||||
(defvar python-sort-imports-on-save nil
|
||||
"If non-nil, automatically sort imports on save.")
|
||||
|
|
|
@ -161,3 +161,10 @@ to be called for each testrunner. "
|
|||
"tt" 'spacemacs/python-test-one
|
||||
"tM" 'spacemacs/python-test-pdb-module
|
||||
"tm" 'spacemacs/python-test-module))
|
||||
|
||||
(defun spacemacs//python-sort-imports ()
|
||||
;; py-isort-before-save checks the major mode as well, however we can prevent
|
||||
;; it from loading the package unnecessarily by doing our own check
|
||||
(when (and python-sort-imports-on-save
|
||||
(derived-mode-p 'python-mode))
|
||||
(py-isort-before-save)))
|
||||
|
|
|
@ -181,9 +181,12 @@
|
|||
|
||||
(defun python/init-py-isort ()
|
||||
(use-package py-isort
|
||||
:if python-enable-sort-imports-on-save
|
||||
:defer t
|
||||
:init (add-hook 'before-save-hook 'py-isort-before-save)))
|
||||
:init
|
||||
(progn
|
||||
(add-hook 'before-save-hook 'spacemacs//python-sort-imports)
|
||||
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
||||
"rI" 'py-isort-buffer))))
|
||||
|
||||
(defun python/init-pyenv-mode ()
|
||||
(use-package pyenv-mode
|
||||
|
|
Loading…
Reference in New Issue