Improve heuristic for Python walrus operator

* lisp/progmodes/python.el (python-base-mode): Improve heuristic for
Python walrus operator in 'electric-layout-mode'.
This commit is contained in:
Stefan Kangas 2024-12-16 21:48:45 +01:00
parent 5c1889c964
commit 02a1e3052b

View file

@ -7073,11 +7073,10 @@ implementations: `python-mode' and `python-ts-mode'."
`((?: . ,(lambda ()
(and (zerop (car (syntax-ppss)))
(python-info-statement-starts-block-p)
;; Heuristic: assume walrus operator :=
;; when colon is preceded by space.
;; Heuristic for walrus operator :=
(save-excursion
(goto-char (- (point) 2))
(looking-at (rx (not space) ":")))
(looking-at (rx (not space) ":" eol)))
'after)))))
;; Add """ ... """ pairing to electric-pair-mode.