New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiline history #929
Multiline history #929
Conversation
make hlen_before_cell a class member and move all multiline history functionality into _replace_rlhist_multiline. Closes ipythongh-911
so one does not save e.g. raw_input entries in the history
Thanks! The new tests do pass on my Python 3.2. |
|
||
# Mark activity in the builtins | ||
__builtin__.__dict__['__IPYTHON__active'] += 1 | ||
|
||
if self.has_readline: | ||
self.readline_startup_hook(self.pre_readline) | ||
self.hlen_before_cell = self.readline.get_current_history_length() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the refs are still all in one call, this can still be a transient variable and arg to _replace_rlhist
, rather than adding an attribute, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, then it would have to return the history length which must be saved by the caller
I'm not sure which variant is better, both are prone to errors during refactoring/reuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also prefer a variant with less global state added to the instance. Those interactiveshell objects are already huge, much too large to conveniently handle. We can't remove a lot of what they have for historical reasons, but we shouldn't add more to them.
When state is needed, our approach lately has been to refactor the functionality into sub-objects that at least hold all related state together, rather than putting more and more weight into the top-level objects.
If you don't want to embark onto such a refactoring with a new object to manage all readline-related state (what would actually be a worthwhile effort, but perhaps one to entertain post-0.12), I suggest keeping a more lightweight functional interface for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want this as-is, just with the hlen as a variable instead of an attribute, I can make that change in the merge. It's only a couple of lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great, @minrk. Go for it. Thanks!
We've also got a regression from 0.11 where consecutive duplicate entries are stored multiple times, so if you do:
Pressing up-arrow gets you Thanks to @antoine-levitt for spotting this in our discussion on #943. |
interesting I was not aware readline did this by default. In bash you have to explicitly enable it. |
I would have thought it would work for any cell - if readline detects a duplicate, I imagine it's simply not adding it to its history list, so I thought it had always ignored duplicates in bash for me, but maybe it's only since I tweaked my .inputrc earlier this year. |
two equal two-line entries are are ABAB pattern for readline, but it only consecutive entries (AAA...) are skipped by it. |
Oh, yes, I see. Although the most plausible way to repeat a multiline cell exactly is to recall it from readline history via up-arrow, in which case it hopefully would be picked up as a duplicate (assuming it compares it with the same list we modify in _replace_rlhist_multiline). I think it's fine not to merge duplicate multiline cells if the user has actually typed them out again. |
Yes, huge +1 to fixing the duplicate entries in readline history. I only noticed it recently, but it's super annoying. @takluyver, if it doesn't get fixed in this PR, could you open a separate issue for it then? I suspect we'll hear a lot of complains if we release 0.12 with that problem... |
I was just about to open an issue when I noticed this PR. I think it should be possible to resolve it here, but if not I'll remind everyone about it. |
for the single line entries it can be resolved here with an extra length check. |
@juliantaylor, it would be great if you can add the fix here, we can review the lot and merge this. Thanks! |
preserves readlines consecutive duplicate removal for single lines
Scope issue in the recent change: When I try to run without readline (
after my first execution. |
forgot to test without readline again ._. |
Awesome, thanks. It's almost there. The tests that set In fact, we should probably even check for the existence of that method in |
On Mon, Nov 7, 2011 at 11:12 AM, Min RK
Good idea: someone may actually share their ipython config between Cheers, f |
"""Test that function does not throw on windows without | ||
remove_history_item""" | ||
ip = get_ipython() | ||
del ip.readline.remove_history_item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line will fail on Windows, where the function already isn't defined.
readline has no remove_history_item
some readline multiline-history fixes and tests * fixes crash when readline is absent (#911) * do not save input from e.g. raw_input in history * do not add empty or duplicate entries lines to the history. * add tests for _replace_rlhist_multiline * protect pyreadline from some incorrect assumptions of equivalence to regular readline closes gh-911
tested, and apparently works on my Windows VM, and on OSX with/without readline. merging. |
I'm still seeing duplicate lines in ipython's own history (the readline history in one session is fine, but upon restarting ipython, duplicates are present) |
@antione-levitt: I think that's a separate issue (and I can replicate it on 0.11, before any of this). I've made issue #1000 so we don't forget it. As an aside: that makes 1000 issues in a bit over a year, minus however many were transferred over from Launchpad. |
On Mon, Nov 14, 2011 at 7:02 AM, Thomas
And it makes you the proud winner of a Scipy 2009 T-Shirt and a Scipy Email me your home address at my Berkeley email and I'll post them :) Cheers, f |
some readline multiline-history fixes and tests * fixes crash when readline is absent (ipython#911) * do not save input from e.g. raw_input in history * do not add empty or duplicate entries lines to the history. * add tests for _replace_rlhist_multiline * protect pyreadline from some incorrect assumptions of equivalence to regular readline closes ipythongh-911
some readline multiline history fixes and tests
fixes crash when readline (gh-911)
do not save input from e.g. raw_input in history
do not add empty lines to the history.
add a testcase for _replace_rlhist_multiline
update the docstring for the configuration variable