We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add 'edit and execute command` function
bash and zsh (and I'm sure others) have an edit and execute command that is invoked with Ctrl-e + Ctrl-x which opens the current contents of the command prompt in the system editor.  Edits made to the command are then run on save and quit.  

It could be this functionality is already baked in and I'm missing it?  In any case, it's especially handy for longer commands -- and given xonsh's multi-line input capabilities this seems like a good fit.

Thoughts?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `xonsh/prompt_toolkit_shell.py`
Content:
```
1 """The prompt_toolkit based xonsh shell"""
2 import os
3 import builtins
4 from warnings import warn
5 
6 from prompt_toolkit.shortcuts import get_input
7 from prompt_toolkit.key_binding.manager import KeyBindingManager
8 from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
9 from pygments.token import Token
10 from pygments.style import Style
11 
12 from xonsh.base_shell import BaseShell
13 from xonsh.tools import format_prompt_for_prompt_toolkit
14 from xonsh.prompt_toolkit_completer import PromptToolkitCompleter
15 from xonsh.prompt_toolkit_history import LimitedFileHistory
16 from xonsh.prompt_toolkit_key_bindings import load_xonsh_bindings
17 
18 
19 def setup_history():
20     """Creates history object."""
21     env = builtins.__xonsh_env__
22     hfile = env.get('XONSH_HISTORY_FILE')
23     history = LimitedFileHistory()
24     try:
25         history.read_history_file(hfile)
26     except PermissionError:
27         warn('do not have read permissions for ' + hfile, RuntimeWarning)
28     return history
29 
30 
31 def teardown_history(history):
32     """Tears down the history object."""
33     env = builtins.__xonsh_env__
34     hsize = env.get('XONSH_HISTORY_SIZE')[0]
35     hfile = env.get('XONSH_HISTORY_FILE')
36     try:
37         history.save_history_to_file(hfile, hsize)
38     except PermissionError:
39         warn('do not have write permissions for ' + hfile, RuntimeWarning)
40 
41 
42 class PromptToolkitShell(BaseShell):
43     """The xonsh shell."""
44 
45     def __init__(self, **kwargs):
46         super().__init__(**kwargs)
47         self.history = setup_history()
48         self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)
49         self.key_bindings_manager = KeyBindingManager(
50             enable_auto_suggest_bindings=True,
51             enable_search=True, enable_abort_and_exit_bindings=True)
52         load_xonsh_bindings(self.key_bindings_manager)
53 
54     def __del__(self):
55         if self.history is not None:
56             teardown_history(self.history)
57 
58     def cmdloop(self, intro=None):
59         """Enters a loop that reads and execute input from user."""
60         if intro:
61             print(intro)
62         _auto_suggest = AutoSuggestFromHistory()
63         while not builtins.__xonsh_exit__:
64             try:
65                 token_func, style_cls = self._get_prompt_tokens_and_style()
66                 mouse_support = builtins.__xonsh_env__.get('MOUSE_SUPPORT')
67                 if builtins.__xonsh_env__.get('AUTO_SUGGEST'):
68                     auto_suggest = _auto_suggest
69                 else:
70                     auto_suggest = None
71                 completions_display = builtins.__xonsh_env__.get('COMPLETIONS_DISPLAY')
72                 multicolumn = (completions_display == 'multi')
73                 completer = None if completions_display == 'none' else self.pt_completer
74                 line = get_input(
75                     mouse_support=mouse_support,
76                     auto_suggest=auto_suggest,
77                     get_prompt_tokens=token_func,
78                     style=style_cls,
79                     completer=completer,
80                     history=self.history,
81                     key_bindings_registry=self.key_bindings_manager.registry,
82                     display_completions_in_columns=multicolumn)
83                 if not line:
84                     self.emptyline()
85                 else:
86                     line = self.precmd(line)
87                     self.default(line)
88             except KeyboardInterrupt:
89                 self.reset_buffer()
90             except EOFError:
91                 break
92 
93     def _get_prompt_tokens_and_style(self):
94         """Returns function to pass as prompt to prompt_toolkit."""
95         token_names, cstyles, strings = format_prompt_for_prompt_toolkit(self.prompt)
96         tokens = [getattr(Token, n) for n in token_names]
97 
98         def get_tokens(cli):
99             return list(zip(tokens, strings))
100 
101         class CustomStyle(Style):
102             styles = {
103                 Token.Menu.Completions.Completion.Current: 'bg:#00aaaa #000000',
104                 Token.Menu.Completions.Completion: 'bg:#008888 #ffffff',
105                 Token.Menu.Completions.ProgressButton: 'bg:#003333',
106                 Token.Menu.Completions.ProgressBar: 'bg:#00aaaa',
107                 Token.AutoSuggestion: '#666666',
108                 Token.Aborted: '#888888',
109             }
110             # update with the prompt styles
111             styles.update({t: s for (t, s) in zip(tokens, cstyles)})
112             # Update with with any user styles
113             userstyle = builtins.__xonsh_env__.get('PROMPT_TOOLKIT_STYLES')
114             if userstyle is not None:
115                 styles.update(userstyle)
116 
117         return get_tokens, CustomStyle
118
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/xonsh/prompt_toolkit_shell.py b/xonsh/prompt_toolkit_shell.py
--- a/xonsh/prompt_toolkit_shell.py
+++ b/xonsh/prompt_toolkit_shell.py
@@ -48,6 +48,7 @@
         self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)
         self.key_bindings_manager = KeyBindingManager(
             enable_auto_suggest_bindings=True,
+            enable_open_in_editor=True,
             enable_search=True, enable_abort_and_exit_bindings=True)
         load_xonsh_bindings(self.key_bindings_manager)

{"golden_diff": "diff --git a/xonsh/prompt_toolkit_shell.py b/xonsh/prompt_toolkit_shell.py\n--- a/xonsh/prompt_toolkit_shell.py\n+++ b/xonsh/prompt_toolkit_shell.py\n@@ -48,6 +48,7 @@\n         self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)\n         self.key_bindings_manager = KeyBindingManager(\n             enable_auto_suggest_bindings=True,\n+            enable_open_in_editor=True,\n             enable_search=True, enable_abort_and_exit_bindings=True)\n         load_xonsh_bindings(self.key_bindings_manager)\n", "issue": "Add 'edit and execute command` function\nbash and zsh (and I'm sure others) have an edit and execute command that is invoked with Ctrl-e + Ctrl-x which opens the current contents of the command prompt in the system editor.  Edits made to the command are then run on save and quit.  \n\nIt could be this functionality is already baked in and I'm missing it?  In any case, it's especially handy for longer commands -- and given xonsh's multi-line input capabilities this seems like a good fit.\n\nThoughts?\n\n", "before_files": [{"content": "\"\"\"The prompt_toolkit based xonsh shell\"\"\"\nimport os\nimport builtins\nfrom warnings import warn\n\nfrom prompt_toolkit.shortcuts import get_input\nfrom prompt_toolkit.key_binding.manager import KeyBindingManager\nfrom prompt_toolkit.auto_suggest import AutoSuggestFromHistory\nfrom pygments.token import Token\nfrom pygments.style import Style\n\nfrom xonsh.base_shell import BaseShell\nfrom xonsh.tools import format_prompt_for_prompt_toolkit\nfrom xonsh.prompt_toolkit_completer import PromptToolkitCompleter\nfrom xonsh.prompt_toolkit_history import LimitedFileHistory\nfrom xonsh.prompt_toolkit_key_bindings import load_xonsh_bindings\n\n\ndef setup_history():\n    \"\"\"Creates history object.\"\"\"\n    env = builtins.__xonsh_env__\n    hfile = env.get('XONSH_HISTORY_FILE')\n    history = LimitedFileHistory()\n    try:\n        history.read_history_file(hfile)\n    except PermissionError:\n        warn('do not have read permissions for ' + hfile, RuntimeWarning)\n    return history\n\n\ndef teardown_history(history):\n    \"\"\"Tears down the history object.\"\"\"\n    env = builtins.__xonsh_env__\n    hsize = env.get('XONSH_HISTORY_SIZE')[0]\n    hfile = env.get('XONSH_HISTORY_FILE')\n    try:\n        history.save_history_to_file(hfile, hsize)\n    except PermissionError:\n        warn('do not have write permissions for ' + hfile, RuntimeWarning)\n\n\nclass PromptToolkitShell(BaseShell):\n    \"\"\"The xonsh shell.\"\"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.history = setup_history()\n        self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)\n        self.key_bindings_manager = KeyBindingManager(\n            enable_auto_suggest_bindings=True,\n            enable_search=True, enable_abort_and_exit_bindings=True)\n        load_xonsh_bindings(self.key_bindings_manager)\n\n    def __del__(self):\n        if self.history is not None:\n            teardown_history(self.history)\n\n    def cmdloop(self, intro=None):\n        \"\"\"Enters a loop that reads and execute input from user.\"\"\"\n        if intro:\n            print(intro)\n        _auto_suggest = AutoSuggestFromHistory()\n        while not builtins.__xonsh_exit__:\n            try:\n                token_func, style_cls = self._get_prompt_tokens_and_style()\n                mouse_support = builtins.__xonsh_env__.get('MOUSE_SUPPORT')\n                if builtins.__xonsh_env__.get('AUTO_SUGGEST'):\n                    auto_suggest = _auto_suggest\n                else:\n                    auto_suggest = None\n                completions_display = builtins.__xonsh_env__.get('COMPLETIONS_DISPLAY')\n                multicolumn = (completions_display == 'multi')\n                completer = None if completions_display == 'none' else self.pt_completer\n                line = get_input(\n                    mouse_support=mouse_support,\n                    auto_suggest=auto_suggest,\n                    get_prompt_tokens=token_func,\n                    style=style_cls,\n                    completer=completer,\n                    history=self.history,\n                    key_bindings_registry=self.key_bindings_manager.registry,\n                    display_completions_in_columns=multicolumn)\n                if not line:\n                    self.emptyline()\n                else:\n                    line = self.precmd(line)\n                    self.default(line)\n            except KeyboardInterrupt:\n                self.reset_buffer()\n            except EOFError:\n                break\n\n    def _get_prompt_tokens_and_style(self):\n        \"\"\"Returns function to pass as prompt to prompt_toolkit.\"\"\"\n        token_names, cstyles, strings = format_prompt_for_prompt_toolkit(self.prompt)\n        tokens = [getattr(Token, n) for n in token_names]\n\n        def get_tokens(cli):\n            return list(zip(tokens, strings))\n\n        class CustomStyle(Style):\n            styles = {\n                Token.Menu.Completions.Completion.Current: 'bg:#00aaaa #000000',\n                Token.Menu.Completions.Completion: 'bg:#008888 #ffffff',\n                Token.Menu.Completions.ProgressButton: 'bg:#003333',\n                Token.Menu.Completions.ProgressBar: 'bg:#00aaaa',\n                Token.AutoSuggestion: '#666666',\n                Token.Aborted: '#888888',\n            }\n            # update with the prompt styles\n            styles.update({t: s for (t, s) in zip(tokens, cstyles)})\n            # Update with with any user styles\n            userstyle = builtins.__xonsh_env__.get('PROMPT_TOOLKIT_STYLES')\n            if userstyle is not None:\n                styles.update(userstyle)\n\n        return get_tokens, CustomStyle\n", "path": "xonsh/prompt_toolkit_shell.py"}], "after_files": [{"content": "\"\"\"The prompt_toolkit based xonsh shell\"\"\"\nimport os\nimport builtins\nfrom warnings import warn\n\nfrom prompt_toolkit.shortcuts import get_input\nfrom prompt_toolkit.key_binding.manager import KeyBindingManager\nfrom prompt_toolkit.auto_suggest import AutoSuggestFromHistory\nfrom pygments.token import Token\nfrom pygments.style import Style\n\nfrom xonsh.base_shell import BaseShell\nfrom xonsh.tools import format_prompt_for_prompt_toolkit\nfrom xonsh.prompt_toolkit_completer import PromptToolkitCompleter\nfrom xonsh.prompt_toolkit_history import LimitedFileHistory\nfrom xonsh.prompt_toolkit_key_bindings import load_xonsh_bindings\n\n\ndef setup_history():\n    \"\"\"Creates history object.\"\"\"\n    env = builtins.__xonsh_env__\n    hfile = env.get('XONSH_HISTORY_FILE')\n    history = LimitedFileHistory()\n    try:\n        history.read_history_file(hfile)\n    except PermissionError:\n        warn('do not have read permissions for ' + hfile, RuntimeWarning)\n    return history\n\n\ndef teardown_history(history):\n    \"\"\"Tears down the history object.\"\"\"\n    env = builtins.__xonsh_env__\n    hsize = env.get('XONSH_HISTORY_SIZE')[0]\n    hfile = env.get('XONSH_HISTORY_FILE')\n    try:\n        history.save_history_to_file(hfile, hsize)\n    except PermissionError:\n        warn('do not have write permissions for ' + hfile, RuntimeWarning)\n\n\nclass PromptToolkitShell(BaseShell):\n    \"\"\"The xonsh shell.\"\"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.history = setup_history()\n        self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)\n        self.key_bindings_manager = KeyBindingManager(\n            enable_auto_suggest_bindings=True,\n            enable_open_in_editor=True,\n            enable_search=True, enable_abort_and_exit_bindings=True)\n        load_xonsh_bindings(self.key_bindings_manager)\n\n    def __del__(self):\n        if self.history is not None:\n            teardown_history(self.history)\n\n    def cmdloop(self, intro=None):\n        \"\"\"Enters a loop that reads and execute input from user.\"\"\"\n        if intro:\n            print(intro)\n        _auto_suggest = AutoSuggestFromHistory()\n        while not builtins.__xonsh_exit__:\n            try:\n                token_func, style_cls = self._get_prompt_tokens_and_style()\n                mouse_support = builtins.__xonsh_env__.get('MOUSE_SUPPORT')\n                if builtins.__xonsh_env__.get('AUTO_SUGGEST'):\n                    auto_suggest = _auto_suggest\n                else:\n                    auto_suggest = None\n                completions_display = builtins.__xonsh_env__.get('COMPLETIONS_DISPLAY')\n                multicolumn = (completions_display == 'multi')\n                completer = None if completions_display == 'none' else self.pt_completer\n                line = get_input(\n                    mouse_support=mouse_support,\n                    auto_suggest=auto_suggest,\n                    get_prompt_tokens=token_func,\n                    style=style_cls,\n                    completer=completer,\n                    history=self.history,\n                    key_bindings_registry=self.key_bindings_manager.registry,\n                    display_completions_in_columns=multicolumn)\n                if not line:\n                    self.emptyline()\n                else:\n                    line = self.precmd(line)\n                    self.default(line)\n            except KeyboardInterrupt:\n                self.reset_buffer()\n            except EOFError:\n                break\n\n    def _get_prompt_tokens_and_style(self):\n        \"\"\"Returns function to pass as prompt to prompt_toolkit.\"\"\"\n        token_names, cstyles, strings = format_prompt_for_prompt_toolkit(self.prompt)\n        tokens = [getattr(Token, n) for n in token_names]\n\n        def get_tokens(cli):\n            return list(zip(tokens, strings))\n\n        class CustomStyle(Style):\n            styles = {\n                Token.Menu.Completions.Completion.Current: 'bg:#00aaaa #000000',\n                Token.Menu.Completions.Completion: 'bg:#008888 #ffffff',\n                Token.Menu.Completions.ProgressButton: 'bg:#003333',\n                Token.Menu.Completions.ProgressBar: 'bg:#00aaaa',\n                Token.AutoSuggestion: '#666666',\n                Token.Aborted: '#888888',\n            }\n            # update with the prompt styles\n            styles.update({t: s for (t, s) in zip(tokens, cstyles)})\n            # Update with with any user styles\n            userstyle = builtins.__xonsh_env__.get('PROMPT_TOOLKIT_STYLES')\n            if userstyle is not None:\n                styles.update(userstyle)\n\n        return get_tokens, CustomStyle\n", "path": "xonsh/prompt_toolkit_shell.py"}]}