##// END OF EJS Templates
Fix so exit is detected as an automagic and exits qtconsole.
Thomas Kluyver -
Show More
@@ -2094,69 +2094,77 b' class InteractiveShell(Configurable, Magic):'
2094 2094 # Store the untransformed code
2095 2095 raw_cell = cell
2096 2096
2097 # We need to break up the input into executable blocks that can be run
2098 # in 'single' mode, to provide comfortable user behavior.
2099 blocks = self.input_splitter.split_blocks(cell)
2100 2097
2101 if not blocks: # Blank cell
2102 return
2103
2104 # We only do dynamic transforms on a single line. But a macro can
2105 # be expanded to several lines, so we need to split it into input
2106 # blocks again.
2107 if len(cell.splitlines()) <= 1:
2108 cell = self.prefilter_manager.prefilter_line(blocks[0])
2098 # Code transformation and execution must take place with our
2099 # modifications to builtins.
2100 with self.builtin_trap:
2101
2102 # We need to break up the input into executable blocks that can
2103 # be runin 'single' mode, to provide comfortable user behavior.
2109 2104 blocks = self.input_splitter.split_blocks(cell)
2110
2111 # Store the 'ipython' version of the cell as well, since that's what
2112 # needs to go into the translated history and get executed (the
2113 # original cell may contain non-python syntax).
2114 cell = ''.join(blocks)
2115
2116 # Store raw and processed history
2117 if store_history:
2118 self.history_manager.store_inputs(self.execution_count,
2119 cell, raw_cell)
2120
2121 self.logger.log(cell, raw_cell)
2122
2123 # All user code execution must happen with our context managers active
2124 with nested(self.builtin_trap, self.display_trap):
2125
2126 # Single-block input should behave like an interactive prompt
2127 if len(blocks) == 1:
2128 out = self.run_source(blocks[0])
2129 # Write output to the database. Does nothing unless
2130 # history output logging is enabled.
2131 if store_history:
2132 self.history_manager.store_output(self.execution_count)
2133 # since we return here, we need to update the execution count
2134 self.execution_count += 1
2135 return out
2136
2137 # In multi-block input, if the last block is a simple (one-two
2138 # lines) expression, run it in single mode so it produces output.
2139 # Otherwise just run it all in 'exec' mode. This seems like a
2140 # reasonable usability design.
2141 last = blocks[-1]
2142 last_nlines = len(last.splitlines())
2143 2105
2144 if last_nlines < 2:
2145 # Here we consider the cell split between 'body' and 'last',
2146 # store all history and execute 'body', and if successful, then
2147 # proceed to execute 'last'.
2148
2149 # Get the main body to run as a cell
2150 ipy_body = ''.join(blocks[:-1])
2151 retcode = self.run_source(ipy_body, symbol='exec',
2152 post_execute=False)
2153 if retcode==0:
2154 # Last expression compiled as 'single' so it produces output
2155 self.run_source(last)
2156 else:
2157 # Run the whole cell as one entity, storing both raw and
2158 # processed input in history
2159 self.run_source(ipy_cell, symbol='exec')
2106 if not blocks: # Blank cell
2107 return
2108
2109 # We only do dynamic transforms on a single line. But a macro
2110 # can be expanded to several lines, so we need to split it
2111 # into input blocks again.
2112 if len(cell.splitlines()) <= 1:
2113 cell = self.prefilter_manager.prefilter_line(blocks[0])
2114 blocks = self.input_splitter.split_blocks(cell)
2115
2116 # Store the 'ipython' version of the cell as well, since
2117 # that's what needs to go into the translated history and get
2118 # executed (the original cell may contain non-python syntax).
2119 cell = ''.join(blocks)
2120
2121 # Store raw and processed history
2122 if store_history:
2123 self.history_manager.store_inputs(self.execution_count,
2124 cell, raw_cell)
2125
2126 self.logger.log(cell, raw_cell)
2127
2128 # All user code execution should take place with our
2129 # modified displayhook.
2130 with self.display_trap:
2131
2132 # Single-block input should behave like an interactive prompt
2133 if len(blocks) == 1:
2134 out = self.run_source(blocks[0])
2135 # Write output to the database. Does nothing unless
2136 # history output logging is enabled.
2137 if store_history:
2138 self.history_manager.store_output(self.execution_count)
2139 # Since we return here, we need to update the
2140 # execution count
2141 self.execution_count += 1
2142 return out
2143
2144 # In multi-block input, if the last block is a simple (one-two
2145 # lines) expression, run it in single mode so it produces output.
2146 # Otherwise just run it all in 'exec' mode. This seems like a
2147 # reasonable usability design.
2148 last = blocks[-1]
2149 last_nlines = len(last.splitlines())
2150
2151 if last_nlines < 2:
2152 # Here we consider the cell split between 'body' and 'last',
2153 # store all history and execute 'body', and if successful, then
2154 # proceed to execute 'last'.
2155
2156 # Get the main body to run as a cell
2157 ipy_body = ''.join(blocks[:-1])
2158 retcode = self.run_source(ipy_body, symbol='exec',
2159 post_execute=False)
2160 if retcode==0:
2161 # Last expression compiled as 'single' so it
2162 # produces output
2163 self.run_source(last)
2164 else:
2165 # Run the whole cell as one entity, storing both raw and
2166 # processed input in history
2167 self.run_source(ipy_cell, symbol='exec')
2160 2168
2161 2169 # Write output to the database. Does nothing unless
2162 2170 # history output logging is enabled.
General Comments 0
You need to be logged in to leave comments. Login now