Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented improved Python indent function. #1736

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions extensions/python-mode/python-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down
Loading