mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Merge branch 'master' into funcalias
This commit is contained in:
commit
55143c1ee8
14 changed files with 230 additions and 118 deletions
12
.travis.yml
12
.travis.yml
|
@ -1,4 +1,7 @@
|
|||
language: python
|
||||
env:
|
||||
global:
|
||||
- secure: "pvQHCsdcIRjwNvsBrZxP8cZWEwug0+PLg1T8841ZLkMdCaO3YheqmxF1xGjAqty6hLppz6vX1LFEKmPjKurLL0/i+be6MhT8/ZikFpSan7TdNUqISxeFx31ls+QpuFKzCV7ZEx7C1ms8LPWEGmzMMN6bCtOBVtGznD9KKWZmLlA="
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
|
@ -35,7 +38,7 @@ install:
|
|||
- if [[ $BUILD_DOCS = true ]]; then
|
||||
python setup.py install;
|
||||
pip install -r requirements-docs.txt;
|
||||
pip install pygments prompt_toolkit ply psutil ipykernel matplotlib;
|
||||
pip install pygments prompt_toolkit ply psutil ipykernel matplotlib doctr;
|
||||
else
|
||||
pip install -r requirements-tests.txt;
|
||||
fi
|
||||
|
@ -45,6 +48,13 @@ script:
|
|||
- if [[ $BUILD_DOCS = true ]]; then
|
||||
cd docs;
|
||||
make html;
|
||||
cd ..;
|
||||
doctr deploy --deploy-repo xonsh/xonsh-docs --gh-pages-docs dev;
|
||||
git checkout $(git describe --tags `git rev-list --tags --max-count=1`);
|
||||
cd docs;
|
||||
make html;
|
||||
cd ..;
|
||||
doctr deploy --deploy-repo xonsh/xonsh-docs --gh-pages-docs .;
|
||||
else
|
||||
py.test --timeout=10;
|
||||
fi
|
||||
|
|
BIN
docs/_static/better_colors_windows.png
vendored
Normal file
BIN
docs/_static/better_colors_windows.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
38
docs/_static/console_colors.reg
vendored
38
docs/_static/console_colors.reg
vendored
|
@ -7,14 +7,14 @@ Windows Registry Editor Version 5.00
|
|||
; OLD MODIFY
|
||||
; NR cmd.exe HEX DWORD HEX DWORD
|
||||
; -- ------- ------ --------- ------- --------
|
||||
; 00 Black 000000 00000000 #323232 00323232
|
||||
; 00 Black 000000 00000000 #0A0A0A 000A0A0A
|
||||
; 01 Blue 000080 00800000 #4080D6 00D68040
|
||||
; 02 Green 008000 00008000 #00CD00 0000CD00
|
||||
; 03 Aqua 008080 00808000 #00CDCD 00CDCD00
|
||||
; 04 Red 800000 00000080 #CD0000 000000CD
|
||||
; 05 Purple 800080 00800080 #CD00CD 00CD00CD
|
||||
; 06 Yellow 808000 00008080 #CDCD00 0000CDCD
|
||||
; 07 White C0C0C0 00C0C0C0 #E5E5E5 00E5E5E5
|
||||
; 07 White C0C0C0 00C0C0C0 #C8C8C8 00C8C8C8
|
||||
; 08 Gray 808080 00808080 #7F7F7F 007F7F7F
|
||||
; 09 LightBlue 0000FF 00FF0000 #40A0FF 00FFA040
|
||||
; 10 LightGreen 00FF00 0000FF00 #00FF00 0000FF00
|
||||
|
@ -26,14 +26,14 @@ Windows Registry Editor Version 5.00
|
|||
|
||||
|
||||
[HKEY_CURRENT_USER\Console]
|
||||
"ColorTable00"=dword:00323232
|
||||
"ColorTable00"=dword:000A0A0A
|
||||
"ColorTable01"=dword:00D68040
|
||||
"ColorTable02"=dword:0000CD00
|
||||
"ColorTable03"=dword:00CDCD00
|
||||
"ColorTable04"=dword:000000CD
|
||||
"ColorTable05"=dword:00CD00CD
|
||||
"ColorTable06"=dword:0000CDCD
|
||||
"ColorTable07"=dword:00E5E5E5
|
||||
"ColorTable07"=dword:00C8C8C8
|
||||
"ColorTable08"=dword:007F7F7F
|
||||
"ColorTable09"=dword:00FFA040
|
||||
"ColorTable10"=dword:0000FF00
|
||||
|
@ -43,4 +43,32 @@ Windows Registry Editor Version 5.00
|
|||
"ColorTable14"=dword:0000FFFF
|
||||
"ColorTable15"=dword:00FFFFFF
|
||||
"ScreenColors"=dword:00000007
|
||||
"PopupColors"=dword: 000000f8
|
||||
"PopupColors" =dword:000000f8
|
||||
"FontFamily" =dword:00000036
|
||||
"FontSize" =dword:00100000
|
||||
"FontWeight" =dword:000002BC
|
||||
"FaceName" ="Consolas"
|
||||
|
||||
[HKEY_CURRENT_USER\Console\%SystemRoot%_cmd.exe]
|
||||
"ColorTable00"=dword:000A0A0A
|
||||
"ColorTable01"=dword:00D68040
|
||||
"ColorTable02"=dword:0000CD00
|
||||
"ColorTable03"=dword:00CDCD00
|
||||
"ColorTable04"=dword:000000CD
|
||||
"ColorTable05"=dword:00CD00CD
|
||||
"ColorTable06"=dword:0000CDCD
|
||||
"ColorTable07"=dword:00C8C8C8
|
||||
"ColorTable08"=dword:007F7F7F
|
||||
"ColorTable09"=dword:00FFA040
|
||||
"ColorTable10"=dword:0000FF00
|
||||
"ColorTable11"=dword:00FFFF00
|
||||
"ColorTable12"=dword:000000FF
|
||||
"ColorTable13"=dword:00FF00FF
|
||||
"ColorTable14"=dword:0000FFFF
|
||||
"ColorTable15"=dword:00FFFFFF
|
||||
"ScreenColors"=dword:00000007
|
||||
"PopupColors"=dword: 000000f8
|
||||
"FontFamily" =dword:00000036
|
||||
"FontSize" =dword:00100000
|
||||
"FontWeight" =dword:000002BC
|
||||
"FaceName" ="Consolas"
|
||||
|
|
BIN
docs/_static/intensify-colors-on-win-false.png
vendored
Normal file
BIN
docs/_static/intensify-colors-on-win-false.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
BIN
docs/_static/intensify-colors-on-win-true.png
vendored
Normal file
BIN
docs/_static/intensify-colors-on-win-true.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
|
@ -75,28 +75,48 @@ Usage
|
|||
|
||||
Color style
|
||||
--------------------------------
|
||||
The dark red and blue colors are complete unreadable in Windows' default
|
||||
terminal. To give new users the best experience Xonsh automatically
|
||||
replaces some of the dark colors with more readable alternatives (e.g. blue
|
||||
becomes cyan). The behaviour is controlled with the ``$INTENSIFY_COLORS_ON_WIN``
|
||||
The dark red and blue colors are completely unreadable in Windows' default
|
||||
terminal. To give new users, the best experience Xonsh automatically replaces
|
||||
some of the dark colors with more readable alternatives (e.g. blue becomes cyan).
|
||||
The behavior is controlled with the ``$INTENSIFY_COLORS_ON_WIN``
|
||||
environment variable.
|
||||
|
||||
It is possible to configure the Windows console with readable default colors.
|
||||
This following `console_colors.reg`_ registry file will configure the colors to
|
||||
more reable defaults.
|
||||
.. image:: _static/intensify-colors-win-false.png
|
||||
:width: 100 %
|
||||
:alt: intensify-colors-win-false
|
||||
:align: center
|
||||
|
||||
.. image:: _static/intensify-colors-win-true.png
|
||||
:width: 100 %
|
||||
:alt: intensify-colors-win-true
|
||||
:align: center
|
||||
|
||||
It is possible to configure the Windows console with readable default colors,
|
||||
but it is tedious to do manually. It can also be set through the windows registry,
|
||||
so to get good defaults you can download and run the registry file.
|
||||
|
||||
* `console_colors.reg`_
|
||||
|
||||
With better colors configured, ``$INTENSIFY_COLORS_ON_WIN`` should be set to
|
||||
``False``, and the default prompt can be changed to match how it looks on POSIX and Mac.
|
||||
You can do this by adding the following to the xonsh run control file ``.xonshrc``:
|
||||
|
||||
With better colors configured, ``$INTENSIFY_COLORS_ON_WIN`` can be disabled and
|
||||
the prompt can be changed to match how it looks on posix and mac. Add the
|
||||
follwing to the xonsh run control file ``.xonshrc``:
|
||||
|
||||
.. code-block:: xonshcon
|
||||
|
||||
>>> $INTENSIFY_COLORS_ON_WIN = False
|
||||
>>> $PROMPT = $PROMPT.replace('INTENSE_','').replace('CYAN','BLUE')
|
||||
$INTENSIFY_COLORS_ON_WIN = False
|
||||
$PROMPT = $PROMPT.replace('INTENSE_','').replace('CYAN','BLUE')
|
||||
|
||||
With everything setup the console will look like this:
|
||||
|
||||
.. image:: _static/better_colors_windows.png
|
||||
:width: 100 %
|
||||
:alt: better_colors_windows
|
||||
:align: center
|
||||
|
||||
|
||||
|
||||
.. _console_colors.reg: http://xon.sh/_static/xterm_colors.reg
|
||||
.. _console_colors.reg: http://xon.sh/_static/console_colors.reg
|
||||
|
||||
|
||||
Name space conflicts
|
||||
|
|
1
github_deploy_key.enc
Normal file
1
github_deploy_key.enc
Normal file
|
@ -0,0 +1 @@
|
|||
gAAAAABYCVeRMufeZzuB75i64JSZgVejwpGQJ6pEO4DwLwZidzRA2we3Xu02minO3Rt7mmQl5pKJOJJYQZ0zP6uCORSNTY27t8OX5NsZEueWgSwsBPg4tq8lzEcHyKqJjWKpThky5mm1La_Qjw4kBO407UwrGX7DuUIF9jbOphWRF9SbbG44mobT3LAttUE1t9jVRQ320fVE2hZvs-vONYFOu2HsMk29dJ08pIOxnqoTHuwylZn3YL-vEGi7XJFaXIDWCFbjvXzcdLbcUmhcYPkISKn9BZGzoID7uIEi4dJGq_ZoIdNVRp-XgyUxHjjYEA8EojvBOKJ4unMn5xt3IXajrlslGseQHnxO1hswIXNSMqr8IH_dzv1pUu4C7ssm8xGuyxWh9JEyTfpHkNGMau8urgVrdpyHypqENFQVDG4hU6f6CQeyoiOM1_hYBA7byN1FiP8ZhefHo5nIjcSF3rnKIOn7y_Wt2ye3soQXBP258yzB9WJvvpya-tW3QB48tXJHHg5US-F9hDHchJyzZS2nArBSYeKpB6yMWyC6vVQBY1BFqh4wrjTkEHrSx3qi5B-631418yI8rb2PalbAizWE2MGUgdo8nePMUa93RpSPELL_FkQsK9BRR8c8EpTvRcQJsmg7aKSzwkpNrTrO99v30DU94xIwNe4rFsq5ogZQiu4Rw-wFu7K6YBlNCfIbTSEgCAlcULAwxakvo1tNGTKbEpKZLLZ7jeeETyyKLb8YOEYxiMuID015iV9Ecbuk3AWHhsiFWU_qEltOzN6xkkX9CyvLeXVliFsGF6sEZOyYQUyXAoGwd_xkUMZafHy5L63WfnwX8FEl7SI4D7LlaRrKLh8du50HqR3s00_Zl7KzfIXBtu-BBgT1t8c3UEZpbhxPA8v6XaUlLSGyrQUhSe_GqVI9BVJ6toVRjNqT14j4Q_HHOElkPbzloh2Cas-mp9as3SyH15dTmLTvAPw4nuPv5g3vL04NyDBQQtMPhhcGS8pwQ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EkrZPHils7zwBZ5GzhyW2EGGZ3x-yHstqhJmKi-gthACbdoUMrCVO1G1iWtkA5TLLCnMdqiJRetlCD53DkBy9ld3Ez5vUZ2Mi4Ppx5ha66NPPZa__MQEASCy06bHABJq86NMHRzG6Y2ENvij8k=
|
16
news/alt_enter.rst
Normal file
16
news/alt_enter.rst
Normal file
|
@ -0,0 +1,16 @@
|
|||
**Added:**
|
||||
|
||||
* Alt+Enter will execute a multiline code block irrespective of cursor position
|
||||
|
||||
**Changed:**
|
||||
|
||||
* All custom prompt_toolkit key binding filters now declared with the
|
||||
``@Condition`` decorator
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:** None
|
||||
|
||||
**Security:** None
|
13
news/color_docs.rst
Normal file
13
news/color_docs.rst
Normal file
|
@ -0,0 +1,13 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:**
|
||||
|
||||
* Better documentation on how to get nice colors in Windows' default console
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:** None
|
||||
|
||||
**Security:** None
|
14
news/doctr.rst
Normal file
14
news/doctr.rst
Normal file
|
@ -0,0 +1,14 @@
|
|||
**Added:**
|
||||
|
||||
* Use `doctr <https://drdoctr.github.io/doctr/>`_ to deploy dev docs to github pages
|
||||
* Use `doctr <https://drdoctr.github.io/doctr/>`_ to deploy latest release docs to github pages
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:** None
|
||||
|
||||
**Security:** None
|
|
@ -915,19 +915,25 @@ def test_escape_windows_cmd_string(st, esc):
|
|||
assert esc == obs
|
||||
|
||||
|
||||
@pytest.mark.parametrize('st, esc', [
|
||||
('', '""'),
|
||||
('foo', 'foo'),
|
||||
@pytest.mark.parametrize('st, esc, forced', [
|
||||
('', '""', None),
|
||||
('foo', 'foo', '"foo"'),
|
||||
(r'arg1 "hallo, "world"" "\some\path with\spaces")',
|
||||
r'"arg1 \"hallo, \"world\"\" \"\some\path with\spaces\")"'),
|
||||
r'"arg1 \"hallo, \"world\"\" \"\some\path with\spaces\")"', None),
|
||||
(r'"argument"2" argument3 argument4',
|
||||
r'"\"argument\"2\" argument3 argument4"'),
|
||||
(r'"\foo\bar bar\foo\" arg',
|
||||
r'"\"\foo\bar bar\foo\\\" arg"')
|
||||
r'"\"argument\"2\" argument3 argument4"', None),
|
||||
(r'"\foo\bar bar\foo\" arg', r'"\"\foo\bar bar\foo\\\" arg"', None),
|
||||
(r'\\machine\dir\file.bat', r'\\machine\dir\file.bat', r'"\\machine\dir\file.bat"'),
|
||||
(r'"\\machine\dir space\file.bat"', r'"\"\\machine\dir space\file.bat\""', None)
|
||||
])
|
||||
def test_argvquote(st, esc):
|
||||
def test_argvquote(st, esc, forced):
|
||||
obs = argvquote(st)
|
||||
assert esc == obs
|
||||
|
||||
if forced is None:
|
||||
forced = esc
|
||||
obs = argvquote(st, force=True)
|
||||
assert forced == obs
|
||||
|
||||
|
||||
@pytest.mark.parametrize('inp', ['no string here', ''])
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
import builtins
|
||||
|
||||
from prompt_toolkit.enums import DEFAULT_BUFFER
|
||||
from prompt_toolkit.filters import (Condition, Filter, IsMultiline,
|
||||
HasSelection, EmacsInsertMode,
|
||||
ViInsertMode)
|
||||
from prompt_toolkit.filters import (Condition, IsMultiline, HasSelection,
|
||||
EmacsInsertMode, ViInsertMode)
|
||||
from prompt_toolkit.keys import Keys
|
||||
from xonsh.aliases import xonsh_exit
|
||||
from xonsh.tools import ON_WINDOWS, check_for_partial_string
|
||||
|
@ -15,10 +14,8 @@ DEDENT_TOKENS = frozenset(['raise', 'return', 'pass', 'break', 'continue'])
|
|||
|
||||
|
||||
def carriage_return(b, cli, *, autoindent=True):
|
||||
"""
|
||||
Preliminary parser to determine if 'Enter' key should send command to
|
||||
the xonsh parser for execution or should insert a newline for continued
|
||||
input.
|
||||
"""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
|
||||
|
@ -49,17 +46,14 @@ def carriage_return(b, cli, *, autoindent=True):
|
|||
doc.line_count > 1):
|
||||
b.newline(copy_margin=autoindent)
|
||||
b.delete_before_cursor(count=len(indent))
|
||||
elif (not doc.on_first_line and
|
||||
not current_line_blank):
|
||||
elif (not doc.on_first_line and not current_line_blank):
|
||||
b.newline(copy_margin=autoindent)
|
||||
elif (doc.char_before_cursor == '\\' and
|
||||
not (not builtins.__xonsh_env__.get('FORCE_POSIX_PATHS') and
|
||||
ON_WINDOWS)):
|
||||
b.newline(copy_margin=autoindent)
|
||||
elif (doc.find_next_word_beginning() is not None and
|
||||
(any(not _is_blank(i)
|
||||
for i
|
||||
in doc.lines_from_current[1:]))):
|
||||
(any(not _is_blank(i) for i in doc.lines_from_current[1:]))):
|
||||
b.newline(copy_margin=autoindent)
|
||||
elif not current_line_blank and not can_compile(doc.text):
|
||||
b.newline(copy_margin=autoindent)
|
||||
|
@ -69,68 +63,8 @@ def carriage_return(b, cli, *, autoindent=True):
|
|||
b.accept_action.validate_and_handle(cli, b)
|
||||
|
||||
|
||||
class TabShouldInsertIndentFilter(Filter):
|
||||
"""
|
||||
Filter that is intended to check if <Tab> should insert indent instead of
|
||||
starting autocompletion.
|
||||
It basically just checks if there are only whitespaces before the cursor -
|
||||
if so indent should be inserted, otherwise autocompletion.
|
||||
"""
|
||||
def __call__(self, cli):
|
||||
before_cursor = cli.current_buffer.document.current_line_before_cursor
|
||||
|
||||
return bool(before_cursor.isspace())
|
||||
|
||||
|
||||
class BeginningOfLine(Filter):
|
||||
"""
|
||||
Check if cursor is at beginning of a line other than the first line
|
||||
in a multiline document
|
||||
"""
|
||||
def __call__(self, cli):
|
||||
before_cursor = cli.current_buffer.document.current_line_before_cursor
|
||||
|
||||
return bool(len(before_cursor) == 0 and
|
||||
not cli.current_buffer.document.on_first_line)
|
||||
|
||||
|
||||
class EndOfLine(Filter):
|
||||
"""
|
||||
Check if cursor is at the end of a line other than the last line
|
||||
in a multiline document
|
||||
"""
|
||||
def __call__(self, cli):
|
||||
d = cli.current_buffer.document
|
||||
at_end = d.is_cursor_at_the_end_of_line
|
||||
last_line = d.is_cursor_at_the_end
|
||||
|
||||
return bool(at_end and not last_line)
|
||||
|
||||
|
||||
class ShouldConfirmCompletion(Filter):
|
||||
"""
|
||||
Check if completion needs confirmation
|
||||
"""
|
||||
def __call__(self, cli):
|
||||
return (builtins.__xonsh_env__.get('COMPLETIONS_CONFIRM') and
|
||||
cli.current_buffer.complete_state)
|
||||
|
||||
|
||||
# Copied from prompt-toolkit's key_binding/bindings/basic.py
|
||||
@Condition
|
||||
def ctrl_d_condition(cli):
|
||||
""" Ctrl-D binding is only active when the default buffer is selected
|
||||
and empty. """
|
||||
if builtins.__xonsh_env__.get("IGNOREEOF"):
|
||||
raise EOFError
|
||||
else:
|
||||
return (cli.current_buffer_name == DEFAULT_BUFFER and
|
||||
not cli.current_buffer.text)
|
||||
|
||||
|
||||
@Condition
|
||||
def autopair_condition(cli):
|
||||
return builtins.__xonsh_env__.get("XONSH_AUTOPAIR", False)
|
||||
def _is_blank(l):
|
||||
return len(l.strip()) == 0
|
||||
|
||||
|
||||
def can_compile(src):
|
||||
|
@ -148,6 +82,67 @@ def can_compile(src):
|
|||
return rtn
|
||||
|
||||
|
||||
@Condition
|
||||
def tab_insert_indent(cli):
|
||||
"""Check if <Tab> should insert indent instead of starting autocompletion.
|
||||
Checks if there are only whitespaces before the cursor - if so indent
|
||||
should be inserted, otherwise autocompletion.
|
||||
|
||||
"""
|
||||
before_cursor = cli.current_buffer.document.current_line_before_cursor
|
||||
|
||||
return bool(before_cursor.isspace())
|
||||
|
||||
|
||||
@Condition
|
||||
def beginning_of_line(cli):
|
||||
"""Check if cursor is at beginning of a line other than the first line in a
|
||||
multiline document
|
||||
"""
|
||||
before_cursor = cli.current_buffer.document.current_line_before_cursor
|
||||
|
||||
return bool(len(before_cursor) == 0 and
|
||||
not cli.current_buffer.document.on_first_line)
|
||||
|
||||
|
||||
@Condition
|
||||
def end_of_line(cli):
|
||||
"""Check if cursor is at the end of a line other than the last line in a
|
||||
multiline document
|
||||
"""
|
||||
d = cli.current_buffer.document
|
||||
at_end = d.is_cursor_at_the_end_of_line
|
||||
last_line = d.is_cursor_at_the_end
|
||||
|
||||
return bool(at_end and not last_line)
|
||||
|
||||
|
||||
@Condition
|
||||
def should_confirm_completion(cli):
|
||||
"""Check if completion needs confirmation"""
|
||||
return (builtins.__xonsh_env__.get('COMPLETIONS_CONFIRM') and
|
||||
cli.current_buffer.complete_state)
|
||||
|
||||
|
||||
# Copied from prompt-toolkit's key_binding/bindings/basic.py
|
||||
@Condition
|
||||
def ctrl_d_condition(cli):
|
||||
"""Ctrl-D binding is only active when the default buffer is selected and
|
||||
empty.
|
||||
"""
|
||||
if builtins.__xonsh_env__.get("IGNOREEOF"):
|
||||
raise EOFError
|
||||
else:
|
||||
return (cli.current_buffer_name == DEFAULT_BUFFER and
|
||||
not cli.current_buffer.text)
|
||||
|
||||
|
||||
@Condition
|
||||
def autopair_condition(cli):
|
||||
"""Check if XONSH_AUTOPAIR is set"""
|
||||
return builtins.__xonsh_env__.get("XONSH_AUTOPAIR", False)
|
||||
|
||||
|
||||
def load_xonsh_bindings(key_bindings_manager):
|
||||
"""
|
||||
Load custom key bindings.
|
||||
|
@ -156,8 +151,8 @@ def load_xonsh_bindings(key_bindings_manager):
|
|||
has_selection = HasSelection()
|
||||
insert_mode = ViInsertMode() | EmacsInsertMode()
|
||||
|
||||
@handle(Keys.Tab, filter=TabShouldInsertIndentFilter())
|
||||
def _(event):
|
||||
@handle(Keys.Tab, filter=tab_insert_indent)
|
||||
def insert_indent(event):
|
||||
"""
|
||||
If there are only whitespaces before current cursor position insert
|
||||
indent instead of autocompleting.
|
||||
|
@ -234,17 +229,23 @@ def load_xonsh_bindings(key_bindings_manager):
|
|||
b = event.cli.current_buffer
|
||||
carriage_return(b, event.cli)
|
||||
|
||||
@handle(Keys.ControlJ, filter=ShouldConfirmCompletion())
|
||||
@handle(Keys.ControlJ, filter=should_confirm_completion)
|
||||
def enter_confirm_completion(event):
|
||||
"""Ignore <enter> (confirm completion)"""
|
||||
event.current_buffer.complete_state = None
|
||||
|
||||
@handle(Keys.Escape, filter=ShouldConfirmCompletion())
|
||||
@handle(Keys.Escape, filter=should_confirm_completion)
|
||||
def esc_cancel_completion(event):
|
||||
"""Use <ESC> to cancel completion"""
|
||||
event.cli.current_buffer.cancel_completion()
|
||||
|
||||
@handle(Keys.Left, filter=BeginningOfLine())
|
||||
@handle(Keys.Escape, Keys.ControlJ)
|
||||
def execute_block_now(event):
|
||||
"""Execute a block of text irrespective of cursor position"""
|
||||
b = event.cli.current_buffer
|
||||
b.accept_action.validate_and_handle(event.cli, b)
|
||||
|
||||
@handle(Keys.Left, filter=beginning_of_line)
|
||||
def wrap_cursor_back(event):
|
||||
"""Move cursor to end of previous line unless at beginning of
|
||||
document
|
||||
|
@ -254,7 +255,7 @@ def load_xonsh_bindings(key_bindings_manager):
|
|||
relative_end_index = b.document.get_end_of_line_position()
|
||||
b.cursor_right(count=relative_end_index)
|
||||
|
||||
@handle(Keys.Right, filter=EndOfLine())
|
||||
@handle(Keys.Right, filter=end_of_line)
|
||||
def wrap_cursor_forward(event):
|
||||
"""Move cursor to beginning of next line unless at end of document"""
|
||||
b = event.cli.current_buffer
|
||||
|
@ -288,7 +289,3 @@ def load_xonsh_bindings(key_bindings_manager):
|
|||
else:
|
||||
event.cli.start_completion(insert_common_part=True,
|
||||
select_first=False)
|
||||
|
||||
|
||||
def _is_blank(l):
|
||||
return len(l.strip()) == 0
|
||||
|
|
|
@ -112,7 +112,7 @@ class Shell(object):
|
|||
names = builtins.__xonsh_config__.get('xontribs', ())
|
||||
for name in names:
|
||||
update_context(name, ctx=self.ctx)
|
||||
if hasattr(update_context, 'bad_imports'):
|
||||
if getattr(update_context, 'bad_imports', None):
|
||||
prompt_xontrib_install(update_context.bad_imports)
|
||||
del update_context.bad_imports
|
||||
# load run control files
|
||||
|
|
|
@ -747,16 +747,23 @@ def argvquote(arg, force=False):
|
|||
n_backslashes = 0
|
||||
cmdline = '"'
|
||||
for c in arg:
|
||||
if c == "\\":
|
||||
# first count the number of current backslashes
|
||||
n_backslashes += 1
|
||||
continue
|
||||
if c == '"':
|
||||
# Escape all backslashes and the following double quotation mark
|
||||
cmdline += (n_backslashes * 2 + 1) * '\\'
|
||||
else:
|
||||
# backslashes are not special here
|
||||
cmdline += n_backslashes * '\\'
|
||||
if c != '\\':
|
||||
cmdline += c
|
||||
n_backslashes = 0
|
||||
else:
|
||||
n_backslashes += 1
|
||||
return cmdline + n_backslashes * 2 * '\\' + '"'
|
||||
n_backslashes = 0
|
||||
cmdline += c
|
||||
# Escape all backslashes, but let the terminating
|
||||
# double quotation mark we add below be interpreted
|
||||
# as a metacharacter
|
||||
cmdline += + n_backslashes * 2 * '\\' + '"'
|
||||
return cmdline
|
||||
|
||||
|
||||
def on_main_thread():
|
||||
|
|
Loading…
Add table
Reference in a new issue