python: Better support := in electric-layout-mode

* lisp/progmodes/python.el (python-base-mode): Use heuristic to better
support the Python walrus operator := in electric-layout-rules.
This commit is contained in:
Stefan Kangas 2024-10-04 23:31:09 +02:00
parent e9727982cf
commit ee6e737fdf

View file

@ -7090,6 +7090,11 @@ 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.
(save-excursion
(goto-char (- (point) 2))
(looking-at (rx (not space) ":")))
'after)))))
;; Add """ ... """ pairing to electric-pair-mode.