]> git.eshelyaron.com Git - emacs.git/commitdiff
Support electric-layout-mode in python-base-mode
authorStefan Kangas <stefankangas@gmail.com>
Sat, 21 Sep 2024 02:41:46 +0000 (04:41 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 23 Sep 2024 10:45:26 +0000 (12:45 +0200)
* lisp/progmodes/python.el (python-base-mode): Add support for
'electric-layout-mode'.

(cherry picked from commit dfecd6037d5ebe5778c40ff7b38bfcbaa3ef779e)

lisp/progmodes/python.el

index a46ac806eddcb0de0e53d15be21d888403473400..76c9cbb77a754560a282229285caed68eb44bb1d 100644 (file)
@@ -7070,6 +7070,11 @@ implementations: `python-mode' and `python-ts-mode'."
   (setq-local electric-indent-inhibit t)
   (setq-local electric-indent-chars
               (cons ?: electric-indent-chars))
+  (setq-local electric-layout-rules
+              `((?: . ,(lambda ()
+                         (and (zerop (car (syntax-ppss)))
+                              (python-info-statement-starts-block-p)
+                              'after)))))
 
   ;; Add """ ... """ pairing to electric-pair-mode.
   (add-hook 'post-self-insert-hook