Skip to content

Commit

Permalink
Merge pull request #1737 from funk443/main
Browse files Browse the repository at this point in the history
Implemented improved Python indent function.
  • Loading branch information
cxxxr authored Jan 6, 2025
2 parents d99ddc3 + 1027c00 commit f0b09a3
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions extensions/python-mode/python-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,36 @@

#| 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))
(last-line-end-with-delimiter-start-p
(progn
(line-end last-line-point)
(skip-whitespace-backward last-line-point t)
(when (> (point-charpos last-line-point) 0)
(character-offset last-line-point -1)
(member (character-at last-line-point)
'(#\: #\( #\[ #\{)
:test #'char=)))))
(cond
((or last-line-end-with-delimiter-start-p
(and (>= column last-line-indent-column)
(< column next-indent-column)
(not (zerop 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

0 comments on commit f0b09a3

Please sign in to comment.