Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Qt Console history search #627

Closed
wants to merge 1 commit into from

4 participants

@bthyreau

Using Qt console from IPython dev repo, i found out i'm missing the "Ctrl-R" feature from readline (search in
history), a feature difficult to emulate exactly.

This suggested patch make use of the shift modifier to implement the same behavior in an easier way.

@takluyver
Owner

Thanks, Benjamin. We're focussing on getting 0.11 out now, so it might be a few days before someone goes over this.

@epatters

The patch looks good to me. It would be nice to add a note to guiref so this has a hope of being discovered.

But like Thomas said, with 0.11 so near it is probably best to hold off on the merge for now. Thanks again for the patch.

@fperez
Owner

Benjamin, if you have a chance to update this PR with a small note about the feature in %guiref, located in /zmq/zmqshell.py, that would be awesome. We won't have a chance to merge this for a few more days (trying to actually release 0.11 :) so there's no rush.

Very happy to have this feature, it's been requested a lot already. Many thanks for the work!!

@epatters

I cherry picked the commit, added a note to %guiref, and pushed to master. Thanks for the patch!

@epatters epatters closed this
@fperez
Owner

@epatters, much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 28, 2011
  1. @bthyreau

    Navigating history holding shift make searches match even if non-prefix

    bthyreau authored Benjamin Thyreau committed
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 10 deletions.
  1. +18 −10 IPython/frontend/qt/console/history_console_widget.py
View
28 IPython/frontend/qt/console/history_console_widget.py
@@ -82,7 +82,8 @@ def _up_pressed(self, shift_modifier):
self._history_prefix = input_buffer[:col]
# Perform the search.
- self.history_previous(self._history_prefix)
+ self.history_previous(self._history_prefix,
+ as_prefix=not shift_modifier)
# Go to the first line of the prompt for seemless history scrolling.
# Emulate readline: keep the cursor position fixed for a prefix
@@ -110,7 +111,8 @@ def _down_pressed(self, shift_modifier):
return False
# Perform the search.
- replaced = self.history_next(self._history_prefix)
+ replaced = self.history_next(self._history_prefix,
+ as_prefix=not shift_modifier)
# Emulate readline: keep the cursor position fixed for a prefix
# search. (We don't need to move the cursor to the end of the buffer
@@ -130,13 +132,15 @@ def _down_pressed(self, shift_modifier):
# 'HistoryConsoleWidget' public interface
#---------------------------------------------------------------------------
- def history_previous(self, prefix=''):
+ def history_previous(self, substring='', as_prefix=True):
""" If possible, set the input buffer to a previous history item.
Parameters:
-----------
- prefix : str, optional
- If specified, search for an item with this prefix.
+ substring : str, optional
+ If specified, search for an item with this substring.
+ as_prefix : bool, optional
+ If True, the substring must match at the beginning (default).
Returns:
--------
@@ -147,7 +151,8 @@ def history_previous(self, prefix=''):
while index > 0:
index -= 1
history = self._get_edited_history(index)
- if history.startswith(prefix):
+ if (as_prefix and history.startswith(substring)) \
+ or (not as_prefix and substring in history):
replace = True
break
@@ -158,13 +163,15 @@ def history_previous(self, prefix=''):
return replace
- def history_next(self, prefix=''):
+ def history_next(self, substring='', as_prefix=True):
""" If possible, set the input buffer to a subsequent history item.
Parameters:
-----------
- prefix : str, optional
- If specified, search for an item with this prefix.
+ substring : str, optional
+ If specified, search for an item with this substring.
+ as_prefix : bool, optional
+ If True, the substring must match at the beginning (default).
Returns:
--------
@@ -175,7 +182,8 @@ def history_next(self, prefix=''):
while self._history_index < len(self._history):
index += 1
history = self._get_edited_history(index)
- if history.startswith(prefix):
+ if (as_prefix and history.startswith(substring)) \
+ or (not as_prefix and substring in history):
replace = True
break
Something went wrong with that request. Please try again.