I don’t know how you call autopep8, but this particular shell already works with the region or marks the current function: https://gist.github.com/whirm/6122031
Keep the point wherever you save your elisp personal code, for example ~/elisp/autopep8.el.
In .emacsmake sure that your catalog is in lisp load path, loads the file and override key binding:
(add-to-list 'load-path "~/elisp") ; or wherever you saved the elisp file
(require 'autopep8)
(define-key evil-normal-state-map "gq" 'autopep8)
The default version in gist is for formatting the current function if no areas are active. By default, for the entire buffer, rewrite the autopep8 function to a file as follows:
(defun autopep8 (begin end)
"Beautify a region of python using autopep8"
(interactive
(if mark-active
(list (region-beginning) (region-end))
(list (point-min) (point-max))))
(save-excursion
(shell-command-on-region begin end
(concat "python "
autopep8-path
autopep8-args)
nil t))))
, autopep8 Emacs. autopep8 Emacs , , , , , , , . C-h f autopep8, .
, autopep8 , , .
(define-key evil-normal-state-map "gq" 'autopep8-x)
(defun autopep8-x (begin end)
"Wraps autopep8 from ??? to format the region or the whole buffer."
(interactive
(if mark-active
(list (region-beginning) (region-end))
(list (point-min) (point-max))))
(autopep8 begin end)) ; assuming an existing autopep8 function taking
; region arguments but not defaulting to the
; whole buffer itself
.emacs .