mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
(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
This commit is contained in:
parent
b86bbada37
commit
0012c1ec74
1 changed files with 16 additions and 2 deletions
|
@ -290,6 +290,15 @@ Currently-active file is at the head of the list.")
|
||||||
(defconst py-blank-or-comment-re "[ \t]*\\($\\|#\\)"
|
(defconst py-blank-or-comment-re "[ \t]*\\($\\|#\\)"
|
||||||
"Regexp matching blank or comment lines.")
|
"Regexp matching blank or comment lines.")
|
||||||
|
|
||||||
|
(defconst py-outdent-re
|
||||||
|
(concat "\\(" (mapconcat 'identity
|
||||||
|
'("else:"
|
||||||
|
"except\\s +.*:"
|
||||||
|
"finally:"
|
||||||
|
"elif\\s +.*:")
|
||||||
|
"\\|")
|
||||||
|
"\\)")
|
||||||
|
"Regexp matching clauses to be outdented one level.")
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -374,8 +383,8 @@ argument is provided, that many colons are inserted non-electrically."
|
||||||
(let (this-indent)
|
(let (this-indent)
|
||||||
(if (and (not arg)
|
(if (and (not arg)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(forward-word -1)
|
(back-to-indentation)
|
||||||
(looking-at "\\(else\\|except\\|finally\\elif\\):"))
|
(looking-at py-outdent-re))
|
||||||
(= (setq this-indent (py-compute-indentation))
|
(= (setq this-indent (py-compute-indentation))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(forward-line -1)
|
(forward-line -1)
|
||||||
|
@ -604,6 +613,11 @@ needed so that only a single column position is deleted."
|
||||||
(let* ((ci (current-indentation))
|
(let* ((ci (current-indentation))
|
||||||
(move-to-indentation-p (<= (current-column) ci))
|
(move-to-indentation-p (<= (current-column) ci))
|
||||||
(need (py-compute-indentation)))
|
(need (py-compute-indentation)))
|
||||||
|
;; watch for outdents
|
||||||
|
(if (save-excursion
|
||||||
|
(back-to-indentation)
|
||||||
|
(looking-at py-outdent-re))
|
||||||
|
(setq need (- need py-indent-offset)))
|
||||||
(if (/= ci need)
|
(if (/= ci need)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue