diff --git a/extensions/python-mode/python-mode.lisp b/extensions/python-mode/python-mode.lisp index 2f1afbef6..d44bbb112 100644 --- a/extensions/python-mode/python-mode.lisp +++ b/extensions/python-mode/python-mode.lisp @@ -81,10 +81,25 @@ #| link : https://www.python.org/dev/peps/pep-0008/ |# (defun python-calc-indent (point) - (with-point ((point point)) - (let ((tab-width (variable-value 'tab-width :default point)) - (column (point-column point))) - (+ column (- tab-width (rem column tab-width)))))) + (with-point ((point point) (last-line-point point)) + (let* ((tab-width (variable-value 'tab-width :default point)) + (last-line-indent-column + (progn + (line-offset last-line-point -1) + (back-to-indentation last-line-point) + (point-column last-line-point))) + (column (point-column (back-to-indentation point))) + (next-indent-column (+ last-line-indent-column tab-width)) + (previous-indent-column + (max (- last-line-indent-column tab-width) 0))) + (cond + ((and (>= column last-line-indent-column) + (< column next-indent-column)) + next-indent-column) + ((>= column next-indent-column) + previous-indent-column) + (t + last-line-indent-column))))) (defun beginning-of-defun (point n) (loop :repeat n :do (search-backward-regexp point "^\\w")))