-
Notifications
You must be signed in to change notification settings - Fork 0
/
python.el
executable file
·35 lines (32 loc) · 1.22 KB
/
python.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(add-hook 'python-mode-hook
(lambda ()
(define-key python-mode-map "\C-m"
'python-reindent-then-newline-and-indent)
(add-hook 'local-write-file-hooks
'(lambda()
(save-excursion
(untabify (point-min) (point-max))
(delete-trailing-whitespace))))
(set (make-local-variable 'tab-width) 4)
(set (make-local-variable 'indent-tabs-mode) 'nil)))
(defun python-reindent-then-newline-and-indent ()
"Reindents the current line then creates an indented newline."
(interactive "*")
(newline)
(save-excursion
(end-of-line 0)
(indent-according-to-mode)
(delete-region (point) (progn (skip-chars-backward " \t") (point))))
(when (python-previous-line-is-comment)
(insert "# "))
(indent-according-to-mode))
(defun python-previous-line-is-comment ()
"Returns `t' if the previous line is a Python comment."
(save-excursion
(forward-line -1)
(python-line-is-comment)))
(defun python-line-is-comment ()
"Returns `t' if the current line is a Python comment."
(save-excursion
(beginning-of-line)
(search-forward "#" (point-at-eol) t)))