From: Stefan Kangas Date: Fri, 4 Oct 2024 21:31:09 +0000 (+0200) Subject: python: Better support := in electric-layout-mode X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=02e5cc293a93994bf52d5e0b911f2e4733c5bb20;p=emacs.git 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) --- 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.