From 02e5cc293a93994bf52d5e0b911f2e4733c5bb20 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Fri, 4 Oct 2024 23:31:09 +0200 Subject: [PATCH] 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. (cherry picked from commit ee6e737fdf7a1bea3abec383a1bf0ae69ac8ca77) --- lisp/progmodes/python.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 566f7716a69..ece90b9f18f 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -7072,6 +7072,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. -- 2.39.2