aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier2013-11-28 21:03:39 -0500
committerStefan Monnier2013-11-28 21:03:39 -0500
commitbd15d9d1ad961157afa3a16bc1ceb11be64e46f1 (patch)
tree08f18f4c7617387e9d6006d7eb808e24f4abcdb6 /lisp
parent7cdf484be3f4408b2bdf58db5bd4ae896cf262e5 (diff)
downloademacs-bd15d9d1ad961157afa3a16bc1ceb11be64e46f1.tar.gz
emacs-bd15d9d1ad961157afa3a16bc1ceb11be64e46f1.zip
* lisp/progmodes/python.el (python-mode-map): Remove binding for ":".
(python-indent-electric-colon): Remove command. (python-indent-post-self-insert-function): Integrate the previous code of python-indent-electric-colon. Make it conditional on electric-indent-mode. (python-mode): Add ?: to electric-indent-chars. Move python-indent-post-self-insert-function to the end of post-self-insert-hook.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/progmodes/python.el79
2 files changed, 48 insertions, 42 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c617a10ff22..6e1e8d17fee 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12013-11-29 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * progmodes/python.el (python-mode-map): Remove binding for ":".
4 (python-indent-electric-colon): Remove command.
5 (python-indent-post-self-insert-function): Integrate the previous code
6 of python-indent-electric-colon. Make it conditional on
7 electric-indent-mode.
8 (python-mode): Add ?: to electric-indent-chars.
9 Move python-indent-post-self-insert-function to the end of
10 post-self-insert-hook.
11
12013-11-28 Stefan Monnier <monnier@iro.umontreal.ca> 122013-11-28 Stefan Monnier <monnier@iro.umontreal.ca>
2 13
3 * doc-view.el (doc-view-goto-page): Update mode-line. 14 * doc-view.el (doc-view-goto-page): Update mode-line.
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 458f0f16fb6..3e0708cd3c2 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -40,9 +40,9 @@
40 40
41;; Indentation: Automatic indentation with indentation cycling is 41;; Indentation: Automatic indentation with indentation cycling is
42;; provided, it allows you to navigate different available levels of 42;; provided, it allows you to navigate different available levels of
43;; indentation by hitting <tab> several times. Also when inserting a 43;; indentation by hitting <tab> several times. Also electric-indent-mode
44;; colon the `python-indent-electric-colon' command is invoked and 44;; is supported such that when inserting a colon the current line is
45;; causes the current line to be dedented automatically if needed. 45;; dedented automatically if needed.
46 46
47;; Movement: `beginning-of-defun' and `end-of-defun' functions are 47;; Movement: `beginning-of-defun' and `end-of-defun' functions are
48;; properly implemented. There are also specialized 48;; properly implemented. There are also specialized
@@ -248,7 +248,6 @@
248 (define-key map (kbd "<backtab>") 'python-indent-dedent-line) 248 (define-key map (kbd "<backtab>") 'python-indent-dedent-line)
249 (define-key map "\C-c<" 'python-indent-shift-left) 249 (define-key map "\C-c<" 'python-indent-shift-left)
250 (define-key map "\C-c>" 'python-indent-shift-right) 250 (define-key map "\C-c>" 'python-indent-shift-right)
251 (define-key map ":" 'python-indent-electric-colon)
252 ;; Skeletons 251 ;; Skeletons
253 (define-key map "\C-c\C-tc" 'python-skeleton-class) 252 (define-key map "\C-c\C-tc" 'python-skeleton-class)
254 (define-key map "\C-c\C-td" 'python-skeleton-def) 253 (define-key map "\C-c\C-td" 'python-skeleton-def)
@@ -1058,48 +1057,43 @@ the lines in which START and END lie."
1058 (list (region-beginning) (region-end) current-prefix-arg) 1057 (list (region-beginning) (region-end) current-prefix-arg)
1059 (list (line-beginning-position) (line-end-position) current-prefix-arg))) 1058 (list (line-beginning-position) (line-end-position) current-prefix-arg)))
1060 (let ((deactivate-mark nil)) 1059 (let ((deactivate-mark nil))
1061 (if count 1060 (setq count (if count (prefix-numeric-value count)
1062 (setq count (prefix-numeric-value count)) 1061 python-indent-offset))
1063 (setq count python-indent-offset))
1064 (indent-rigidly start end count))) 1062 (indent-rigidly start end count)))
1065 1063
1066(defun python-indent-electric-colon (arg)
1067 "Insert a colon and maybe de-indent the current line.
1068With numeric ARG, just insert that many colons. With
1069\\[universal-argument], just insert a single colon."
1070 (interactive "*P")
1071 (self-insert-command (if (not (integerp arg)) 1 arg))
1072 (when (and (not arg)
1073 (eolp)
1074 (not (equal ?: (char-after (- (point-marker) 2))))
1075 (not (python-syntax-comment-or-string-p)))
1076 (let ((indentation (current-indentation))
1077 (calculated-indentation (python-indent-calculate-indentation)))
1078 (python-info-closing-block-message)
1079 (when (> indentation calculated-indentation)
1080 (save-excursion
1081 (indent-line-to calculated-indentation)
1082 (when (not (python-info-closing-block-message))
1083 (indent-line-to indentation)))))))
1084(put 'python-indent-electric-colon 'delete-selection t)
1085
1086(defun python-indent-post-self-insert-function () 1064(defun python-indent-post-self-insert-function ()
1087 "Adjust closing paren line indentation after a char is added. 1065 "Adjust indentation after insertion of some characters.
1088This function is intended to be added to the 1066This function is intended to be added to the
1089`post-self-insert-hook.' If a line renders a paren alone, after 1067`post-self-insert-hook.' If a line renders a paren alone, after
1090adding a char before it, the line will be re-indented 1068adding a char before it, the line will be re-indented
1091automatically if needed." 1069automatically if needed."
1092 (when (and (eq (char-before) last-command-event) 1070 (when (and electric-indent-mode
1093 (not (bolp)) 1071 (eq (char-before) last-command-event))
1094 (memq (char-after) '(?\) ?\] ?\}))) 1072 (cond
1095 (save-excursion 1073 ((and (not (bolp))
1096 (goto-char (line-beginning-position)) 1074 (memq (char-after) '(?\) ?\] ?\})))
1097 ;; If after going to the beginning of line the point 1075 (save-excursion
1098 ;; is still inside a paren it's ok to do the trick 1076 (goto-char (line-beginning-position))
1099 (when (python-syntax-context 'paren) 1077 ;; If after going to the beginning of line the point
1100 (let ((indentation (python-indent-calculate-indentation))) 1078 ;; is still inside a paren it's ok to do the trick
1101 (when (< (current-indentation) indentation) 1079 (when (python-syntax-context 'paren)
1102 (indent-line-to indentation))))))) 1080 (let ((indentation (python-indent-calculate-indentation)))
1081 (when (< (current-indentation) indentation)
1082 (indent-line-to indentation))))))
1083 ((and (eq ?: last-command-event)
1084 (memq ?: electric-indent-chars)
1085 (not current-prefix-arg)
1086 (eolp)
1087 (not (equal ?: (char-before (1- (point)))))
1088 (not (python-syntax-comment-or-string-p)))
1089 (let ((indentation (current-indentation))
1090 (calculated-indentation (python-indent-calculate-indentation)))
1091 (python-info-closing-block-message)
1092 (when (> indentation calculated-indentation)
1093 (save-excursion
1094 (indent-line-to calculated-indentation)
1095 (when (not (python-info-closing-block-message))
1096 (indent-line-to indentation)))))))))
1103 1097
1104 1098
1105;;; Navigation 1099;;; Navigation
@@ -3619,6 +3613,7 @@ list is returned as is."
3619 (set (make-local-variable 'indent-region-function) #'python-indent-region) 3613 (set (make-local-variable 'indent-region-function) #'python-indent-region)
3620 ;; Because indentation is not redundant, we cannot safely reindent code. 3614 ;; Because indentation is not redundant, we cannot safely reindent code.
3621 (setq-local electric-indent-inhibit t) 3615 (setq-local electric-indent-inhibit t)
3616 (setq-local electric-indent-chars (cons ?: electric-indent-chars))
3622 3617
3623 ;; Add """ ... """ pairing to electric-pair-mode. 3618 ;; Add """ ... """ pairing to electric-pair-mode.
3624 (add-hook 'post-self-insert-hook 3619 (add-hook 'post-self-insert-hook
@@ -3626,7 +3621,7 @@ list is returned as is."
3626 3621
3627 (set (make-local-variable 'paragraph-start) "\\s-*$") 3622 (set (make-local-variable 'paragraph-start) "\\s-*$")
3628 (set (make-local-variable 'fill-paragraph-function) 3623 (set (make-local-variable 'fill-paragraph-function)
3629 'python-fill-paragraph) 3624 #'python-fill-paragraph)
3630 3625
3631 (set (make-local-variable 'beginning-of-defun-function) 3626 (set (make-local-variable 'beginning-of-defun-function)
3632 #'python-nav-beginning-of-defun) 3627 #'python-nav-beginning-of-defun)
@@ -3634,10 +3629,10 @@ list is returned as is."
3634 #'python-nav-end-of-defun) 3629 #'python-nav-end-of-defun)
3635 3630
3636 (add-hook 'completion-at-point-functions 3631 (add-hook 'completion-at-point-functions
3637 'python-completion-complete-at-point nil 'local) 3632 #'python-completion-complete-at-point nil 'local)
3638 3633
3639 (add-hook 'post-self-insert-hook 3634 (add-hook 'post-self-insert-hook
3640 'python-indent-post-self-insert-function nil 'local) 3635 #'python-indent-post-self-insert-function 'append 'local)
3641 3636
3642 (set (make-local-variable 'imenu-create-index-function) 3637 (set (make-local-variable 'imenu-create-index-function)
3643 #'python-imenu-create-index) 3638 #'python-imenu-create-index)