From f88bfa5bacb6edba7ebceafbb264169a01cd5157 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Tue, 21 Jan 2025 18:34:54 +0300 Subject: [PATCH] python-mode: add 'exit' and 'quit' to the list of block-enders '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 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 6f0435efd47..3a1d64d8251 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -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 -- 2.39.5