diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 56c80c8264b..7576bae9f95 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -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.