]> git.eshelyaron.com Git - emacs.git/commitdiff
python-mode: add 'exit' and 'quit' to the list of block-enders
authorKonstantin Kharlamov <Hi-Angel@yandex.ru>
Tue, 21 Jan 2025 15:34:54 +0000 (18:34 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 25 Jan 2025 17:49:03 +0000 (18:49 +0100)
'exit()' and 'quit()' end the current codeflow, there can't be
any code past it, similarly to 'return', 'continue', etc.  So
when calculating indentation for the line next to 'exit()',
'os.exit()', 'os._exit()', 'sys.exit()' and 'quit()', decrease
the indentation level.
* /lisp/progmodes/python.el (python-rx): Add 'exit()', 'os.exit()',
'os._exit()', 'sys.exit()', 'quit' to the list of block-enders.
(Bug#75729)

(cherry picked from commit 0514619b2c944ae17fbf649496595c5e866ff785)

lisp/progmodes/python.el

index 6f0435efd470e07f307d9505ffdfbc7604a52bd5..3a1d64d82515bb29b47d7c7743592ac197bcbd1a 100644 (file)
@@ -434,10 +434,17 @@ This variant of `rx' supports common Python named REGEXPS."
             (dedenter          (seq symbol-start
                                     (or "elif" "else" "except" "finally" "case")
                                     symbol-end))
-            (block-ender       (seq symbol-start
-                                    (or
-                                     "break" "continue" "pass" "raise" "return")
-                                    symbol-end))
+            (block-ender       (seq
+                                symbol-start
+                                (or
+                                 (seq (or
+                                       "break" "continue" "pass" "raise" "return")
+                                  symbol-end)
+                                 (seq
+                                  (or
+                                   (seq (? (or (seq "os." (? ?_)) "sys.")) "exit")
+                                   "quit")
+                                  (* space) "("))))
             (decorator         (seq line-start (* space) ?@ (any letter ?_)
                                     (* (any word ?_))))
             (defun             (seq symbol-start