mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
rearrange docstrings and minor pep8 tweaks
This commit is contained in:
parent
36b2bba5f1
commit
4a00e47df4
1 changed files with 21 additions and 22 deletions
|
@ -9,14 +9,28 @@ env = builtins.__xonsh_env__
|
||||||
indent_ = env.get('INDENT')
|
indent_ = env.get('INDENT')
|
||||||
DEDENT_TOKENS = frozenset(['raise', 'return', 'pass', 'break', 'continue'])
|
DEDENT_TOKENS = frozenset(['raise', 'return', 'pass', 'break', 'continue'])
|
||||||
|
|
||||||
|
|
||||||
def carriage_return(b, cli):
|
def carriage_return(b, cli):
|
||||||
|
"""
|
||||||
|
Preliminary parser to determine if 'Enter' key should send command to
|
||||||
|
the xonsh parser for execution or should insert a newline for continued
|
||||||
|
input.
|
||||||
|
|
||||||
|
Current 'triggers' for inserting a newline are:
|
||||||
|
- Not on first line of buffer and line is non-empty
|
||||||
|
- Previous character is a colon (covers if, for, etc...)
|
||||||
|
- User is in an open paren-block
|
||||||
|
- Line ends with backslash
|
||||||
|
- Any text exists below cursor position (relevant when editing previous
|
||||||
|
multiline blocks)
|
||||||
|
"""
|
||||||
|
|
||||||
at_end_of_line = _is_blank(b.document.current_line_after_cursor)
|
at_end_of_line = _is_blank(b.document.current_line_after_cursor)
|
||||||
current_line_blank = _is_blank(b.document.current_line)
|
current_line_blank = _is_blank(b.document.current_line)
|
||||||
|
|
||||||
# indent after a colon
|
# indent after a colon
|
||||||
if (b.document.current_line_before_cursor.strip().endswith(':')
|
if (b.document.current_line_before_cursor.strip().endswith(':') and
|
||||||
and at_end_of_line):
|
at_end_of_line):
|
||||||
b.newline()
|
b.newline()
|
||||||
b.insert_text(indent_, fire_event=False)
|
b.insert_text(indent_, fire_event=False)
|
||||||
# if current line isn't blank, check dedent tokens
|
# if current line isn't blank, check dedent tokens
|
||||||
|
@ -31,14 +45,15 @@ def carriage_return(b, cli):
|
||||||
b.newline()
|
b.newline()
|
||||||
elif (b.document.find_next_word_beginning() is not None and
|
elif (b.document.find_next_word_beginning() is not None and
|
||||||
(any(not _is_blank(i)
|
(any(not _is_blank(i)
|
||||||
for i
|
for i
|
||||||
in b.document.lines_from_current[1:]))):
|
in b.document.lines_from_current[1:]))):
|
||||||
b.newline(copy_margin=True)
|
b.newline(copy_margin=True)
|
||||||
elif not current_line_blank and not can_compile(b.document.text):
|
elif not current_line_blank and not can_compile(b.document.text):
|
||||||
b.newline()
|
b.newline()
|
||||||
else:
|
else:
|
||||||
b.accept_action.validate_and_handle(cli, b)
|
b.accept_action.validate_and_handle(cli, b)
|
||||||
|
|
||||||
|
|
||||||
class TabShouldInsertIndentFilter(Filter):
|
class TabShouldInsertIndentFilter(Filter):
|
||||||
"""
|
"""
|
||||||
Filter that is intended to check if <Tab> should insert indent instead of
|
Filter that is intended to check if <Tab> should insert indent instead of
|
||||||
|
@ -70,7 +85,6 @@ def load_xonsh_bindings(key_bindings_manager):
|
||||||
"""
|
"""
|
||||||
handle = key_bindings_manager.registry.add_binding
|
handle = key_bindings_manager.registry.add_binding
|
||||||
|
|
||||||
|
|
||||||
@handle(Keys.Tab, filter=TabShouldInsertIndentFilter())
|
@handle(Keys.Tab, filter=TabShouldInsertIndentFilter())
|
||||||
def _(event):
|
def _(event):
|
||||||
"""
|
"""
|
||||||
|
@ -81,27 +95,12 @@ def load_xonsh_bindings(key_bindings_manager):
|
||||||
|
|
||||||
@handle(Keys.BackTab)
|
@handle(Keys.BackTab)
|
||||||
def insert_literal_tab(event):
|
def insert_literal_tab(event):
|
||||||
"""
|
""" Insert literal tab on Shift+Tab instead of autocompleting """
|
||||||
Insert literal tab on Shift+Tab instead of autocompleting
|
|
||||||
"""
|
|
||||||
event.cli.current_buffer.insert_text(env.get('INDENT'))
|
event.cli.current_buffer.insert_text(env.get('INDENT'))
|
||||||
|
|
||||||
@handle(Keys.ControlJ, filter=IsMultiline())
|
@handle(Keys.ControlJ, filter=IsMultiline())
|
||||||
def multiline_carriage_return(event):
|
def multiline_carriage_return(event):
|
||||||
"""
|
""" Wrapper around carriage_return multiline parser """
|
||||||
Preliminary parser to determine if 'Enter' key should send command to
|
|
||||||
the xonsh parser for execution or should insert a newline for continued
|
|
||||||
input.
|
|
||||||
|
|
||||||
Current 'triggers' for inserting a newline are:
|
|
||||||
- Not on first line of buffer and line is non-empty
|
|
||||||
- Previous character is a colon (covers if, for, etc...)
|
|
||||||
- User is in an open paren-block
|
|
||||||
- Line ends with backslash
|
|
||||||
- Any text exists below cursor position (relevant when editing previous
|
|
||||||
multiline blocks)
|
|
||||||
"""
|
|
||||||
|
|
||||||
b = event.cli.current_buffer
|
b = event.cli.current_buffer
|
||||||
carriage_return(b, event.cli)
|
carriage_return(b, event.cli)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue