Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0012c1e

Browse files
committed
(py-outdent-re): new constant
(py-electric-colon): use py-outdent-re instead of hardcoding (py-indent-line): look for py-outdent-re and outdent a level accordingly
1 parent b86bbad commit 0012c1e

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Misc/python-mode.el

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,15 @@ Currently-active file is at the head of the list.")
290290
(defconst py-blank-or-comment-re "[ \t]*\\($\\|#\\)"
291291
"Regexp matching blank or comment lines.")
292292

293+
(defconst py-outdent-re
294+
(concat "\\(" (mapconcat 'identity
295+
'("else:"
296+
"except\\s +.*:"
297+
"finally:"
298+
"elif\\s +.*:")
299+
"\\|")
300+
"\\)")
301+
"Regexp matching clauses to be outdented one level.")
293302

294303

295304
;;;###autoload
@@ -374,8 +383,8 @@ argument is provided, that many colons are inserted non-electrically."
374383
(let (this-indent)
375384
(if (and (not arg)
376385
(save-excursion
377-
(forward-word -1)
378-
(looking-at "\\(else\\|except\\|finally\\elif\\):"))
386+
(back-to-indentation)
387+
(looking-at py-outdent-re))
379388
(= (setq this-indent (py-compute-indentation))
380389
(save-excursion
381390
(forward-line -1)
@@ -604,6 +613,11 @@ needed so that only a single column position is deleted."
604613
(let* ((ci (current-indentation))
605614
(move-to-indentation-p (<= (current-column) ci))
606615
(need (py-compute-indentation)))
616+
;; watch for outdents
617+
(if (save-excursion
618+
(back-to-indentation)
619+
(looking-at py-outdent-re))
620+
(setq need (- need py-indent-offset)))
607621
(if (/= ci need)
608622
(save-excursion
609623
(beginning-of-line)

0 commit comments

Comments
 (0)