;; Beginning of buffer.
((= (line-number-at-pos) 1)
(cons :no-indent 0))
- ;; Comment continuation (maybe).
- ((save-excursion
- (when (and
- (or
- (python-info-current-line-comment-p)
- (python-info-current-line-empty-p))
- (forward-comment -1)
- (python-info-current-line-comment-p))
- (cons :after-comment (point)))))
;; Inside a string.
((let ((start (python-syntax-context 'string ppss)))
(when start
((let ((start (python-info-dedenter-statement-p)))
(when start
(cons :at-dedenter-block-start start))))
- ;; After normal line.
- ((let ((start (save-excursion
- (back-to-indentation)
- (skip-chars-backward " \t\n")
- (python-nav-beginning-of-statement)
- (point))))
- (when start
- (if (save-excursion
- (python-util-forward-comment -1)
- (python-nav-beginning-of-statement)
- (looking-at (python-rx block-ender)))
- (cons :after-block-end start)
- (cons :after-line start)))))
- ;; Default case: do not indent.
- (t (cons :no-indent 0))))))
+ ;; After normal line, comment or ender (default case).
+ ((save-excursion
+ (back-to-indentation)
+ (skip-chars-backward " \t\n")
+ (python-nav-beginning-of-statement)
+ (cons
+ (cond ((python-info-current-line-comment-p)
+ :after-comment)
+ ((save-excursion
+ (goto-char (line-end-position))
+ (python-util-forward-comment -1)
+ (python-nav-beginning-of-statement)
+ (looking-at (python-rx block-ender)))
+ :after-block-end)
+ (t :after-line))
+ (point))))))))
(defun python-indent--calculate-indentation ()
"Internal implementation of `python-indent-calculate-indentation'.
May return an integer for the maximum possible indentation at
current context or a list of integers. The latter case is only
happening for :at-dedenter-block-start context since the
-possibilities can be narrowed to especific indentation points."
+possibilities can be narrowed to specific indentation points."
(save-restriction
(widen)
(save-excursion
(defun python-indent-line (&optional previous)
"Internal implementation of `python-indent-line-function'.
Use the PREVIOUS level when argument is non-nil, otherwise indent
-to the maxium available level. When indentation is the minimum
+to the maximum available level. When indentation is the minimum
possible and PREVIOUS is non-nil, cycle back to the maximum
level."
(let ((follow-indentation-p
(interactive "*")
(when (and (not (bolp))
(not (python-syntax-comment-or-string-p))
- (= (+ (line-beginning-position)
- (current-indentation))
- (point)))
+ (= (current-indentation) (current-column)))
(python-indent-line t)
t))