Skip to content

Commit

Permalink
Add history file to pdb history
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed Aug 13, 2019
1 parent 82cad82 commit b484822
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
20 changes: 18 additions & 2 deletions spyder/plugins/ipythonconsole/widgets/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
# (see spyder/__init__.py for details)

"""Control widgets used by ShellWidget"""
import os
import time

from qtpy.QtCore import Qt, Signal
from qtpy.QtWidgets import QTextEdit

from spyder.config.base import get_conf_path
from spyder.utils.qthelpers import restore_keyevent
from spyder.widgets.calltip import CallTipWidget
from spyder.widgets.mixins import (BaseEditMixin, GetHelpMixin,
TracebackLinksMixin,
BrowseHistoryMixin)
BrowseHistoryMixin,
SaveHistoryMixin)


class ControlWidget(TracebackLinksMixin, GetHelpMixin, BrowseHistoryMixin,
QTextEdit, BaseEditMixin):
QTextEdit, BaseEditMixin, SaveHistoryMixin):
"""
Subclass of QTextEdit with features from Spyder's mixins to use as the
control widget for IPython widgets
Expand All @@ -26,13 +30,25 @@ class ControlWidget(TracebackLinksMixin, GetHelpMixin, BrowseHistoryMixin,
visibility_changed = Signal(bool)
go_to_error = Signal(str)
focus_changed = Signal()
SEPARATOR = '{0}## ---({1})---'.format(os.linesep*2, time.ctime())
INITHISTORY = ['# -*- coding: utf-8 -*-',
'# *** Spyder Python Console History Log ***',]
PDB_HIST_MAX = 400

def __init__(self, parent=None):
QTextEdit.__init__(self, parent)
BaseEditMixin.__init__(self)
TracebackLinksMixin.__init__(self)
GetHelpMixin.__init__(self)
BrowseHistoryMixin.__init__(self)
history_filename = get_conf_path('pdb_history.py')
SaveHistoryMixin.__init__(
self, history_filename=history_filename)
with open(history_filename) as f:
self.history = f.readlines()
# Remove old history
with open(history_filename, 'w') as f:
f.writelines(self.history[:self.PDB_HIST_MAX])

self.calltip_widget = CallTipWidget(self, hide_timer_on=False)
self.found_results = []
Expand Down
8 changes: 5 additions & 3 deletions spyder/plugins/ipythonconsole/widgets/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ def callback(line):
# Save history to browse it later
if not (len(self._control.history) > 0
and self._control.history[-1] == line):
# do not save pdb commands
# do not save pdb commands unless they have arguments
cmd = line.split(" ")[0]
if cmd and "do_" + cmd not in dir(pdb.Pdb):
self._control.history.append(line)
args = line.split(" ")[1:]
is_pdb_cmd = "do_" + cmd in dir(pdb.Pdb)
if cmd and (not is_pdb_cmd or len(args) > 0):
self._control.add_to_history(line)

# must match ConsoleWidget.do_execute
self._executing = True
Expand Down
1 change: 1 addition & 0 deletions spyder/widgets/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,7 @@ def browse_history(self, backward):
tocursor = self.get_current_line_to_cursor()
text, self.histidx = self.find_in_history(tocursor, self.histidx,
backward)
text = text.strip()
if text is not None:
if self.hist_wholeline:
self.clear_line()
Expand Down

0 comments on commit b484822

Please sign in to comment.