mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
added auto dedenting for certain tokens
This commit is contained in:
parent
8772d5832a
commit
c83a7d44fe
1 changed files with 8 additions and 0 deletions
|
@ -88,6 +88,9 @@ def _insert_text_func(s, readline):
|
|||
return inserter
|
||||
|
||||
|
||||
DEDENT_TOKENS = frozenset(['raise', 'return', 'pass', 'break', 'continue'])
|
||||
|
||||
|
||||
class ReadlineShell(BaseShell, Cmd):
|
||||
"""The readline based xonsh shell."""
|
||||
|
||||
|
@ -133,6 +136,11 @@ class ReadlineShell(BaseShell, Cmd):
|
|||
ind += builtins.__xonsh_env__.get('INDENT', '')
|
||||
readline.set_pre_input_hook(_insert_text_func(ind, readline))
|
||||
self._current_indent = ind
|
||||
elif line.split(maxsplit=1)[0] in DEDENT_TOKENS:
|
||||
env = builtins.__xonsh_env__
|
||||
ind = self._current_indent[:-len(env.get('INDENT', ''))]
|
||||
readline.set_pre_input_hook(_insert_text_func(ind, readline))
|
||||
self._current_indent = ind
|
||||
else:
|
||||
ind = line[:len(line) - len(line.lstrip())]
|
||||
if ind != self._current_indent:
|
||||
|
|
Loading…
Add table
Reference in a new issue