aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el48
1 files changed, 19 insertions, 29 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4420faf3dfc..1c3f7466c8c 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -843,15 +843,6 @@ keyword
843 ;; Beginning of buffer. 843 ;; Beginning of buffer.
844 ((= (line-number-at-pos) 1) 844 ((= (line-number-at-pos) 1)
845 (cons :no-indent 0)) 845 (cons :no-indent 0))
846 ;; Comment continuation (maybe).
847 ((save-excursion
848 (when (and
849 (or
850 (python-info-current-line-comment-p)
851 (python-info-current-line-empty-p))
852 (forward-comment -1)
853 (python-info-current-line-comment-p))
854 (cons :after-comment (point)))))
855 ;; Inside a string. 846 ;; Inside a string.
856 ((let ((start (python-syntax-context 'string ppss))) 847 ((let ((start (python-syntax-context 'string ppss)))
857 (when start 848 (when start
@@ -963,28 +954,29 @@ keyword
963 ((let ((start (python-info-dedenter-statement-p))) 954 ((let ((start (python-info-dedenter-statement-p)))
964 (when start 955 (when start
965 (cons :at-dedenter-block-start start)))) 956 (cons :at-dedenter-block-start start))))
966 ;; After normal line. 957 ;; After normal line, comment or ender (default case).
967 ((let ((start (save-excursion 958 ((save-excursion
968 (back-to-indentation) 959 (back-to-indentation)
969 (skip-chars-backward " \t\n") 960 (skip-chars-backward " \t\n")
970 (python-nav-beginning-of-statement) 961 (python-nav-beginning-of-statement)
971 (point)))) 962 (cons
972 (when start 963 (cond ((python-info-current-line-comment-p)
973 (if (save-excursion 964 :after-comment)
974 (python-util-forward-comment -1) 965 ((save-excursion
975 (python-nav-beginning-of-statement) 966 (goto-char (line-end-position))
976 (looking-at (python-rx block-ender))) 967 (python-util-forward-comment -1)
977 (cons :after-block-end start) 968 (python-nav-beginning-of-statement)
978 (cons :after-line start))))) 969 (looking-at (python-rx block-ender)))
979 ;; Default case: do not indent. 970 :after-block-end)
980 (t (cons :no-indent 0)))))) 971 (t :after-line))
972 (point))))))))
981 973
982(defun python-indent--calculate-indentation () 974(defun python-indent--calculate-indentation ()
983 "Internal implementation of `python-indent-calculate-indentation'. 975 "Internal implementation of `python-indent-calculate-indentation'.
984May return an integer for the maximum possible indentation at 976May return an integer for the maximum possible indentation at
985current context or a list of integers. The latter case is only 977current context or a list of integers. The latter case is only
986happening for :at-dedenter-block-start context since the 978happening for :at-dedenter-block-start context since the
987possibilities can be narrowed to especific indentation points." 979possibilities can be narrowed to specific indentation points."
988 (save-restriction 980 (save-restriction
989 (widen) 981 (widen)
990 (save-excursion 982 (save-excursion
@@ -1075,7 +1067,7 @@ minimum."
1075(defun python-indent-line (&optional previous) 1067(defun python-indent-line (&optional previous)
1076 "Internal implementation of `python-indent-line-function'. 1068 "Internal implementation of `python-indent-line-function'.
1077Use the PREVIOUS level when argument is non-nil, otherwise indent 1069Use the PREVIOUS level when argument is non-nil, otherwise indent
1078to the maxium available level. When indentation is the minimum 1070to the maximum available level. When indentation is the minimum
1079possible and PREVIOUS is non-nil, cycle back to the maximum 1071possible and PREVIOUS is non-nil, cycle back to the maximum
1080level." 1072level."
1081 (let ((follow-indentation-p 1073 (let ((follow-indentation-p
@@ -1110,9 +1102,7 @@ indentation levels from right to left."
1110 (interactive "*") 1102 (interactive "*")
1111 (when (and (not (bolp)) 1103 (when (and (not (bolp))
1112 (not (python-syntax-comment-or-string-p)) 1104 (not (python-syntax-comment-or-string-p))
1113 (= (+ (line-beginning-position) 1105 (= (current-indentation) (current-column)))
1114 (current-indentation))
1115 (point)))
1116 (python-indent-line t) 1106 (python-indent-line t)
1117 t)) 1107 t))
1118 1108