diff --git a/IPython/core/history.py b/IPython/core/history.py index 9bcdc03..7da04a7 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -186,7 +186,7 @@ class HistoryManager(object): if self.shell.has_readline: self.populate_readline_history() - def get_history(self, index=None, raw=False, output=True): + def get_history(self, index=None, raw=False, output=True,this_session=True): """Get the history list. Get the input and output history. @@ -201,6 +201,9 @@ class HistoryManager(object): If True, return the raw input. output : bool If True, then return the output as well. + this_session : bool + If True, indexing is from 1 at the start of this session. + If False, indexing is from 1 at the start of the whole history. Returns ------- @@ -214,9 +217,13 @@ class HistoryManager(object): input_hist = self.input_hist_parsed if output: output_hist = self.output_hist + + if this_session: + offset = self.session_offset + else: + offset = -1 n = len(input_hist) - offset = self.session_offset if index is None: start=offset+1; stop=n elif isinstance(index, int): diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index c7c952b..340828a 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1277,8 +1277,8 @@ class InteractiveShell(Configurable, Magic): self.reload_history() return wrapper - def get_history(self, index=None, raw=False, output=True): - return self.history_manager.get_history(index, raw, output) + def get_history(self, index=None, raw=False, output=True,this_session=True): + return self.history_manager.get_history(index, raw, output,this_session) #------------------------------------------------------------------------- diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py index 8083e49..626c91f 100644 --- a/IPython/frontend/qt/console/ipython_widget.py +++ b/IPython/frontend/qt/console/ipython_widget.py @@ -213,7 +213,8 @@ class IPythonWidget(FrontendWidget): """ Reimplemented to make a history request. """ super(IPythonWidget, self)._started_channels() - self.kernel_manager.xreq_channel.history(raw=True, output=False) + self.kernel_manager.xreq_channel.history(raw=True, output=False, + this_session=False) #--------------------------------------------------------------------------- # 'ConsoleWidget' public interface diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index 8a77e0c..c3d2754 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -309,10 +309,9 @@ class Kernel(Configurable): logger.debug(msg) def history_request(self, ident, parent): - output = parent['content']['output'] - index = parent['content']['index'] - raw = parent['content']['raw'] - hist = self.shell.get_history(index=index, raw=raw, output=output) + # parent['content'] should contain keys "index", "raw", "output" and + # "this_session". + hist = self.shell.get_history(**parent['content']) content = {'history' : hist} msg = self.session.send(self.reply_socket, 'history_reply', content, parent, ident) diff --git a/IPython/zmq/kernelmanager.py b/IPython/zmq/kernelmanager.py index 9a4c412..b9c8421 100644 --- a/IPython/zmq/kernelmanager.py +++ b/IPython/zmq/kernelmanager.py @@ -282,7 +282,7 @@ class XReqSocketChannel(ZmqSocketChannel): self._queue_request(msg) return msg['header']['msg_id'] - def history(self, index=None, raw=False, output=True): + def history(self, index=None, raw=False, output=True, this_session=True): """Get the history list. Parameters @@ -295,12 +295,16 @@ class XReqSocketChannel(ZmqSocketChannel): If True, return the raw input. output : bool If True, then return the output as well. + this_session : bool + If True, returns only history from the current session. Otherwise, + includes reloaded history from previous sessions. Returns ------- The msg_id of the message sent. """ - content = dict(index=index, raw=raw, output=output) + content = dict(index=index, raw=raw, output=output, + this_session=this_session) msg = self.session.msg('history_request', content) self._queue_request(msg) return msg['header']['msg_id']