We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
xonsh hangs on incorrectly indented for loop
```
condamaster%=🐚 for i in range(1):
.............. print(i)
..............

```

Xonsh hangs here. The issue is that the print(i) isn't indented (side-issue, it should indent automatically, just like IPython). 


--- 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/execer.py`
Content:
```
1 """Implements the xonsh executer"""
2 from __future__ import print_function, unicode_literals
3 import re
4 import os
5 import types
6 import inspect
7 import builtins
8 from collections import Iterable, Sequence, Mapping
9 
10 from xonsh import ast
11 from xonsh.parser import Parser
12 from xonsh.tools import subproc_toks
13 from xonsh.built_ins import load_builtins, unload_builtins
14 
15 
16 class Execer(object):
17     """Executes xonsh code in a context."""
18 
19     def __init__(self,
20                  filename='<xonsh-code>',
21                  debug_level=0,
22                  parser_args=None,
23                  unload=True):
24         """Parameters
25         ----------
26         filename : str, optional
27             File we are to execute.
28         debug_level : int, optional
29             Debugging level to use in lexing and parsing.
30         parser_args : dict, optional
31             Arguments to pass down to the parser.
32         unload : bool, optional
33             Whether or not to unload xonsh builtins upon deletion.
34         """
35         parser_args = parser_args or {}
36         self.parser = Parser(**parser_args)
37         self.filename = filename
38         self.debug_level = debug_level
39         self.unload = unload
40         self.ctxtransformer = ast.CtxAwareTransformer(self.parser)
41         load_builtins(execer=self)
42 
43     def __del__(self):
44         if self.unload:
45             unload_builtins()
46 
47     def parse(self, input, ctx, mode='exec'):
48         """Parses xonsh code in a context-aware fashion. For context-free
49         parsing, please use the Parser class directly.
50         """
51         if ctx is None:
52             ctx = set()
53         elif isinstance(ctx, Mapping):
54             ctx = set(ctx.keys())
55 
56         # Parsing actually happens in a couple of phases. The first is a
57         # shortcut for a context-free parser. Normally, all subprocess
58         # lines should be wrapped in $(), to indicate that they are a
59         # subproc. But that would be super annoying. Unfortnately, Python
60         # mode - after indentation - is whitespace agnostic while, using
61         # the Python token, subproc mode is whitespace aware. That is to say,
62         # in Python mode "ls -l", "ls-l", and "ls - l" all parse to the
63         # same AST because whitespace doesn't matter to the minus binary op.
64         # However, these phases all have very different meaning in subproc
65         # mode. The 'right' way to deal with this is to make the entire
66         # grammar whitespace aware, and then ignore all of the whitespace
67         # tokens for all of the Python rules. The lazy way implemented here
68         # is to parse a line a second time with a $() wrapper if it fails
69         # the first time. This is a context-free phase.
70         tree = self._parse_ctx_free(input, mode=mode)
71         if tree is None:
72             return None
73 
74         # Now we need to perform context-aware AST transformation. This is
75         # because the "ls -l" is valid Python. The only way that we know
76         # it is not actually Python is by checking to see if the first token
77         # (ls) is part of the execution context. If it isn't, then we will
78         # assume that this line is supposed to be a subprocess line, assuming
79         # it also is valid as a subprocess line.
80         tree = self.ctxtransformer.ctxvisit(tree, input, ctx, mode=mode)
81         return tree
82 
83     def compile(self, input, mode='exec', glbs=None, locs=None, stacklevel=2,
84                 filename=None):
85         """Compiles xonsh code into a Python code object, which may then
86         be execed or evaled.
87         """
88         if filename is None:
89             filename = self.filename
90         if glbs is None or locs is None:
91             frame = inspect.stack()[stacklevel][0]
92             glbs = frame.f_globals if glbs is None else glbs
93             locs = frame.f_locals if locs is None else locs
94         ctx = set(dir(builtins)) | set(glbs.keys()) | set(locs.keys())
95         tree = self.parse(input, ctx, mode=mode)
96         if tree is None:
97             return None  # handles comment only input
98         code = compile(tree, filename, mode)
99         return code
100 
101     def eval(self, input, glbs=None, locs=None, stacklevel=2):
102         """Evaluates (and returns) xonsh code."""
103         if isinstance(input, types.CodeType):
104             code = input
105         else:
106             code = self.compile(input=input,
107                                 glbs=glbs,
108                                 locs=locs,
109                                 mode='eval',
110                                 stacklevel=stacklevel)
111         if code is None:
112             return None  # handles comment only input
113         return eval(code, glbs, locs)
114 
115     def exec(self, input, mode='exec', glbs=None, locs=None, stacklevel=2):
116         """Execute xonsh code."""
117         if isinstance(input, types.CodeType):
118             code = input
119         else:
120             code = self.compile(input=input,
121                                 glbs=glbs,
122                                 locs=locs,
123                                 mode=mode,
124                                 stacklevel=stacklevel)
125         if code is None:
126             return None  # handles comment only input
127         return exec(code, glbs, locs)
128 
129     def _find_next_break(self, line, mincol):
130         if mincol >= 1:
131             line = line[mincol:]
132         if ';' not in line:
133             return None
134         maxcol = None
135         self.parser.lexer.input(line)
136         for tok in self.parser.lexer:
137             if tok.type == 'SEMI':
138                 maxcol = tok.lexpos + mincol + 1
139                 break
140         return maxcol
141 
142     def _parse_ctx_free(self, input, mode='exec'):
143         last_error_line = last_error_col = -1
144         parsed = False
145         original_error = None
146         while not parsed:
147             try:
148                 tree = self.parser.parse(input,
149                                          filename=self.filename,
150                                          mode=mode,
151                                          debug_level=self.debug_level)
152                 parsed = True
153             except IndentationError as e:
154                 if original_error is None:
155                     raise e
156                 else:
157                     raise original_error
158             except SyntaxError as e:
159                 if original_error is None:
160                     original_error = e
161                 if (e.loc is None) or (last_error_line == e.loc.lineno and
162                                        last_error_col in (e.loc.column + 1,
163                                                           e.loc.column)):
164                     raise original_error
165                 last_error_col = e.loc.column
166                 last_error_line = e.loc.lineno
167                 idx = last_error_line - 1
168                 lines = input.splitlines()
169                 line = lines[idx]
170                 if input.endswith('\n'):
171                     lines.append('')
172                 if len(line.strip()) == 0:
173                     # whitespace only lines are not valid syntax in Python's
174                     # interactive mode='single', who knew?! Just ignore them.
175                     # this might cause actual sytax errors to have bad line
176                     # numbers reported, but should only effect interactive mode
177                     del lines[idx]
178                     last_error_line = last_error_col = -1
179                     input = '\n'.join(lines)
180                     continue
181                 maxcol = self._find_next_break(line, last_error_col)
182                 sbpline = subproc_toks(line,
183                                        returnline=True,
184                                        maxcol=maxcol,
185                                        lexer=self.parser.lexer)
186                 if sbpline is None:
187                     # subprocess line had no valid tokens, likely because
188                     # it only contained a comment.
189                     del lines[idx]
190                     last_error_line = last_error_col = -1
191                     input = '\n'.join(lines)
192                     continue
193                 else:
194                     lines[idx] = sbpline
195                 last_error_col += 3
196                 input = '\n'.join(lines)
197         return tree
198
```
--- 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/execer.py b/xonsh/execer.py
--- a/xonsh/execer.py
+++ b/xonsh/execer.py
@@ -178,6 +178,12 @@
                     last_error_line = last_error_col = -1
                     input = '\n'.join(lines)
                     continue
+                if last_error_line > 1 and lines[idx-1].rstrip()[-1] == ':':
+                    # catch non-indented blocks and raise error.
+                    prev_indent = len(lines[idx-1]) - len(lines[idx-1].lstrip())
+                    curr_indent = len(lines[idx]) - len(lines[idx].lstrip())
+                    if prev_indent == curr_indent:
+                        raise original_error
                 maxcol = self._find_next_break(line, last_error_col)
                 sbpline = subproc_toks(line,
                                        returnline=True,

{"golden_diff": "diff --git a/xonsh/execer.py b/xonsh/execer.py\n--- a/xonsh/execer.py\n+++ b/xonsh/execer.py\n@@ -178,6 +178,12 @@\n                     last_error_line = last_error_col = -1\n                     input = '\\n'.join(lines)\n                     continue\n+                if last_error_line > 1 and lines[idx-1].rstrip()[-1] == ':':\n+                    # catch non-indented blocks and raise error.\n+                    prev_indent = len(lines[idx-1]) - len(lines[idx-1].lstrip())\n+                    curr_indent = len(lines[idx]) - len(lines[idx].lstrip())\n+                    if prev_indent == curr_indent:\n+                        raise original_error\n                 maxcol = self._find_next_break(line, last_error_col)\n                 sbpline = subproc_toks(line,\n                                        returnline=True,\n", "issue": "xonsh hangs on incorrectly indented for loop\n```\ncondamaster%=\ud83d\udc1a for i in range(1):\n.............. print(i)\n..............\n\n```\n\nXonsh hangs here. The issue is that the print(i) isn't indented (side-issue, it should indent automatically, just like IPython). \n\n", "before_files": [{"content": "\"\"\"Implements the xonsh executer\"\"\"\nfrom __future__ import print_function, unicode_literals\nimport re\nimport os\nimport types\nimport inspect\nimport builtins\nfrom collections import Iterable, Sequence, Mapping\n\nfrom xonsh import ast\nfrom xonsh.parser import Parser\nfrom xonsh.tools import subproc_toks\nfrom xonsh.built_ins import load_builtins, unload_builtins\n\n\nclass Execer(object):\n    \"\"\"Executes xonsh code in a context.\"\"\"\n\n    def __init__(self,\n                 filename='<xonsh-code>',\n                 debug_level=0,\n                 parser_args=None,\n                 unload=True):\n        \"\"\"Parameters\n        ----------\n        filename : str, optional\n            File we are to execute.\n        debug_level : int, optional\n            Debugging level to use in lexing and parsing.\n        parser_args : dict, optional\n            Arguments to pass down to the parser.\n        unload : bool, optional\n            Whether or not to unload xonsh builtins upon deletion.\n        \"\"\"\n        parser_args = parser_args or {}\n        self.parser = Parser(**parser_args)\n        self.filename = filename\n        self.debug_level = debug_level\n        self.unload = unload\n        self.ctxtransformer = ast.CtxAwareTransformer(self.parser)\n        load_builtins(execer=self)\n\n    def __del__(self):\n        if self.unload:\n            unload_builtins()\n\n    def parse(self, input, ctx, mode='exec'):\n        \"\"\"Parses xonsh code in a context-aware fashion. For context-free\n        parsing, please use the Parser class directly.\n        \"\"\"\n        if ctx is None:\n            ctx = set()\n        elif isinstance(ctx, Mapping):\n            ctx = set(ctx.keys())\n\n        # Parsing actually happens in a couple of phases. The first is a\n        # shortcut for a context-free parser. Normally, all subprocess\n        # lines should be wrapped in $(), to indicate that they are a\n        # subproc. But that would be super annoying. Unfortnately, Python\n        # mode - after indentation - is whitespace agnostic while, using\n        # the Python token, subproc mode is whitespace aware. That is to say,\n        # in Python mode \"ls -l\", \"ls-l\", and \"ls - l\" all parse to the\n        # same AST because whitespace doesn't matter to the minus binary op.\n        # However, these phases all have very different meaning in subproc\n        # mode. The 'right' way to deal with this is to make the entire\n        # grammar whitespace aware, and then ignore all of the whitespace\n        # tokens for all of the Python rules. The lazy way implemented here\n        # is to parse a line a second time with a $() wrapper if it fails\n        # the first time. This is a context-free phase.\n        tree = self._parse_ctx_free(input, mode=mode)\n        if tree is None:\n            return None\n\n        # Now we need to perform context-aware AST transformation. This is\n        # because the \"ls -l\" is valid Python. The only way that we know\n        # it is not actually Python is by checking to see if the first token\n        # (ls) is part of the execution context. If it isn't, then we will\n        # assume that this line is supposed to be a subprocess line, assuming\n        # it also is valid as a subprocess line.\n        tree = self.ctxtransformer.ctxvisit(tree, input, ctx, mode=mode)\n        return tree\n\n    def compile(self, input, mode='exec', glbs=None, locs=None, stacklevel=2,\n                filename=None):\n        \"\"\"Compiles xonsh code into a Python code object, which may then\n        be execed or evaled.\n        \"\"\"\n        if filename is None:\n            filename = self.filename\n        if glbs is None or locs is None:\n            frame = inspect.stack()[stacklevel][0]\n            glbs = frame.f_globals if glbs is None else glbs\n            locs = frame.f_locals if locs is None else locs\n        ctx = set(dir(builtins)) | set(glbs.keys()) | set(locs.keys())\n        tree = self.parse(input, ctx, mode=mode)\n        if tree is None:\n            return None  # handles comment only input\n        code = compile(tree, filename, mode)\n        return code\n\n    def eval(self, input, glbs=None, locs=None, stacklevel=2):\n        \"\"\"Evaluates (and returns) xonsh code.\"\"\"\n        if isinstance(input, types.CodeType):\n            code = input\n        else:\n            code = self.compile(input=input,\n                                glbs=glbs,\n                                locs=locs,\n                                mode='eval',\n                                stacklevel=stacklevel)\n        if code is None:\n            return None  # handles comment only input\n        return eval(code, glbs, locs)\n\n    def exec(self, input, mode='exec', glbs=None, locs=None, stacklevel=2):\n        \"\"\"Execute xonsh code.\"\"\"\n        if isinstance(input, types.CodeType):\n            code = input\n        else:\n            code = self.compile(input=input,\n                                glbs=glbs,\n                                locs=locs,\n                                mode=mode,\n                                stacklevel=stacklevel)\n        if code is None:\n            return None  # handles comment only input\n        return exec(code, glbs, locs)\n\n    def _find_next_break(self, line, mincol):\n        if mincol >= 1:\n            line = line[mincol:]\n        if ';' not in line:\n            return None\n        maxcol = None\n        self.parser.lexer.input(line)\n        for tok in self.parser.lexer:\n            if tok.type == 'SEMI':\n                maxcol = tok.lexpos + mincol + 1\n                break\n        return maxcol\n\n    def _parse_ctx_free(self, input, mode='exec'):\n        last_error_line = last_error_col = -1\n        parsed = False\n        original_error = None\n        while not parsed:\n            try:\n                tree = self.parser.parse(input,\n                                         filename=self.filename,\n                                         mode=mode,\n                                         debug_level=self.debug_level)\n                parsed = True\n            except IndentationError as e:\n                if original_error is None:\n                    raise e\n                else:\n                    raise original_error\n            except SyntaxError as e:\n                if original_error is None:\n                    original_error = e\n                if (e.loc is None) or (last_error_line == e.loc.lineno and\n                                       last_error_col in (e.loc.column + 1,\n                                                          e.loc.column)):\n                    raise original_error\n                last_error_col = e.loc.column\n                last_error_line = e.loc.lineno\n                idx = last_error_line - 1\n                lines = input.splitlines()\n                line = lines[idx]\n                if input.endswith('\\n'):\n                    lines.append('')\n                if len(line.strip()) == 0:\n                    # whitespace only lines are not valid syntax in Python's\n                    # interactive mode='single', who knew?! Just ignore them.\n                    # this might cause actual sytax errors to have bad line\n                    # numbers reported, but should only effect interactive mode\n                    del lines[idx]\n                    last_error_line = last_error_col = -1\n                    input = '\\n'.join(lines)\n                    continue\n                maxcol = self._find_next_break(line, last_error_col)\n                sbpline = subproc_toks(line,\n                                       returnline=True,\n                                       maxcol=maxcol,\n                                       lexer=self.parser.lexer)\n                if sbpline is None:\n                    # subprocess line had no valid tokens, likely because\n                    # it only contained a comment.\n                    del lines[idx]\n                    last_error_line = last_error_col = -1\n                    input = '\\n'.join(lines)\n                    continue\n                else:\n                    lines[idx] = sbpline\n                last_error_col += 3\n                input = '\\n'.join(lines)\n        return tree\n", "path": "xonsh/execer.py"}], "after_files": [{"content": "\"\"\"Implements the xonsh executer\"\"\"\nfrom __future__ import print_function, unicode_literals\nimport re\nimport os\nimport types\nimport inspect\nimport builtins\nfrom collections import Iterable, Sequence, Mapping\n\nfrom xonsh import ast\nfrom xonsh.parser import Parser\nfrom xonsh.tools import subproc_toks\nfrom xonsh.built_ins import load_builtins, unload_builtins\n\n\nclass Execer(object):\n    \"\"\"Executes xonsh code in a context.\"\"\"\n\n    def __init__(self,\n                 filename='<xonsh-code>',\n                 debug_level=0,\n                 parser_args=None,\n                 unload=True):\n        \"\"\"Parameters\n        ----------\n        filename : str, optional\n            File we are to execute.\n        debug_level : int, optional\n            Debugging level to use in lexing and parsing.\n        parser_args : dict, optional\n            Arguments to pass down to the parser.\n        unload : bool, optional\n            Whether or not to unload xonsh builtins upon deletion.\n        \"\"\"\n        parser_args = parser_args or {}\n        self.parser = Parser(**parser_args)\n        self.filename = filename\n        self.debug_level = debug_level\n        self.unload = unload\n        self.ctxtransformer = ast.CtxAwareTransformer(self.parser)\n        load_builtins(execer=self)\n\n    def __del__(self):\n        if self.unload:\n            unload_builtins()\n\n    def parse(self, input, ctx, mode='exec'):\n        \"\"\"Parses xonsh code in a context-aware fashion. For context-free\n        parsing, please use the Parser class directly.\n        \"\"\"\n        if ctx is None:\n            ctx = set()\n        elif isinstance(ctx, Mapping):\n            ctx = set(ctx.keys())\n\n        # Parsing actually happens in a couple of phases. The first is a\n        # shortcut for a context-free parser. Normally, all subprocess\n        # lines should be wrapped in $(), to indicate that they are a\n        # subproc. But that would be super annoying. Unfortnately, Python\n        # mode - after indentation - is whitespace agnostic while, using\n        # the Python token, subproc mode is whitespace aware. That is to say,\n        # in Python mode \"ls -l\", \"ls-l\", and \"ls - l\" all parse to the\n        # same AST because whitespace doesn't matter to the minus binary op.\n        # However, these phases all have very different meaning in subproc\n        # mode. The 'right' way to deal with this is to make the entire\n        # grammar whitespace aware, and then ignore all of the whitespace\n        # tokens for all of the Python rules. The lazy way implemented here\n        # is to parse a line a second time with a $() wrapper if it fails\n        # the first time. This is a context-free phase.\n        tree = self._parse_ctx_free(input, mode=mode)\n        if tree is None:\n            return None\n\n        # Now we need to perform context-aware AST transformation. This is\n        # because the \"ls -l\" is valid Python. The only way that we know\n        # it is not actually Python is by checking to see if the first token\n        # (ls) is part of the execution context. If it isn't, then we will\n        # assume that this line is supposed to be a subprocess line, assuming\n        # it also is valid as a subprocess line.\n        tree = self.ctxtransformer.ctxvisit(tree, input, ctx, mode=mode)\n        return tree\n\n    def compile(self, input, mode='exec', glbs=None, locs=None, stacklevel=2,\n                filename=None):\n        \"\"\"Compiles xonsh code into a Python code object, which may then\n        be execed or evaled.\n        \"\"\"\n        if filename is None:\n            filename = self.filename\n        if glbs is None or locs is None:\n            frame = inspect.stack()[stacklevel][0]\n            glbs = frame.f_globals if glbs is None else glbs\n            locs = frame.f_locals if locs is None else locs\n        ctx = set(dir(builtins)) | set(glbs.keys()) | set(locs.keys())\n        tree = self.parse(input, ctx, mode=mode)\n        if tree is None:\n            return None  # handles comment only input\n        code = compile(tree, filename, mode)\n        return code\n\n    def eval(self, input, glbs=None, locs=None, stacklevel=2):\n        \"\"\"Evaluates (and returns) xonsh code.\"\"\"\n        if isinstance(input, types.CodeType):\n            code = input\n        else:\n            code = self.compile(input=input,\n                                glbs=glbs,\n                                locs=locs,\n                                mode='eval',\n                                stacklevel=stacklevel)\n        if code is None:\n            return None  # handles comment only input\n        return eval(code, glbs, locs)\n\n    def exec(self, input, mode='exec', glbs=None, locs=None, stacklevel=2):\n        \"\"\"Execute xonsh code.\"\"\"\n        if isinstance(input, types.CodeType):\n            code = input\n        else:\n            code = self.compile(input=input,\n                                glbs=glbs,\n                                locs=locs,\n                                mode=mode,\n                                stacklevel=stacklevel)\n        if code is None:\n            return None  # handles comment only input\n        return exec(code, glbs, locs)\n\n    def _find_next_break(self, line, mincol):\n        if mincol >= 1:\n            line = line[mincol:]\n        if ';' not in line:\n            return None\n        maxcol = None\n        self.parser.lexer.input(line)\n        for tok in self.parser.lexer:\n            if tok.type == 'SEMI':\n                maxcol = tok.lexpos + mincol + 1\n                break\n        return maxcol\n\n    def _parse_ctx_free(self, input, mode='exec'):\n        last_error_line = last_error_col = -1\n        parsed = False\n        original_error = None\n        while not parsed:\n            try:\n                tree = self.parser.parse(input,\n                                         filename=self.filename,\n                                         mode=mode,\n                                         debug_level=self.debug_level)\n                parsed = True\n            except IndentationError as e:\n                if original_error is None:\n                    raise e\n                else:\n                    raise original_error\n            except SyntaxError as e:\n                if original_error is None:\n                    original_error = e\n                if (e.loc is None) or (last_error_line == e.loc.lineno and\n                                       last_error_col in (e.loc.column + 1,\n                                                          e.loc.column)):\n                    raise original_error\n                last_error_col = e.loc.column\n                last_error_line = e.loc.lineno\n                idx = last_error_line - 1\n                lines = input.splitlines()\n                line = lines[idx]\n                if input.endswith('\\n'):\n                    lines.append('')\n                if len(line.strip()) == 0:\n                    # whitespace only lines are not valid syntax in Python's\n                    # interactive mode='single', who knew?! Just ignore them.\n                    # this might cause actual sytax errors to have bad line\n                    # numbers reported, but should only effect interactive mode\n                    del lines[idx]\n                    last_error_line = last_error_col = -1\n                    input = '\\n'.join(lines)\n                    continue\n                if last_error_line > 1 and lines[idx-1].rstrip()[-1] == ':':\n                    # catch non-indented blocks and raise error.\n                    prev_indent = len(lines[idx-1]) - len(lines[idx-1].lstrip())\n                    curr_indent = len(lines[idx]) - len(lines[idx].lstrip())\n                    if prev_indent == curr_indent:\n                        raise original_error\n                maxcol = self._find_next_break(line, last_error_col)\n                sbpline = subproc_toks(line,\n                                       returnline=True,\n                                       maxcol=maxcol,\n                                       lexer=self.parser.lexer)\n                if sbpline is None:\n                    # subprocess line had no valid tokens, likely because\n                    # it only contained a comment.\n                    del lines[idx]\n                    last_error_line = last_error_col = -1\n                    input = '\\n'.join(lines)\n                    continue\n                else:\n                    lines[idx] = sbpline\n                last_error_col += 3\n                input = '\\n'.join(lines)\n        return tree\n", "path": "xonsh/execer.py"}]}