To change tabs to spaces and fill in comments at the same time, you can use this command:
(defun my-format-python-text ()
"untabify and wrap python comments"
(interactive)
(untabify (point-min) (point-max))
(goto-char (point-min))
(while (re-search-forward comment-start nil t)
(call-interactively 'fill-paragraph)
(forward-line 1)))
What you can bind to a key of your choice, presumably like this:
(eval-after-load "python"
'(progn
(define-key python-mode-map (kbd "RET") 'newline-and-indent)
(define-key python-mode-map (kbd "<f4>") 'my-format-python-text)))
RET .
, :
C-x h ;; mark-whole-buffer
M-x untabify ;; tabs->spaces
, , .emacs:
(setq fill-column 79)
(setq-default tab-width 4)
, 8, , (8 ). , 4 'python-mode-hook. .