Skip to content

Commit

Permalink
Use lazy enumeration to keep response time fast.
Browse files Browse the repository at this point in the history
With HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE, it can take a while to compute
all unique search results, which would normally keep the shell unresponsive
during this computation.

This commit separates the retrieval of all history matches from the
computation of the matches that need to be presented to the user (unique
matches only if HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE is set). The
computation of the matches needing to be displayed is then done lazily,
and only when the user requests a new previously undisplayed result.
This keeps the response time fast while still enabling us to filter for
unique search results.
  • Loading branch information
gezalore committed Mar 6, 2016
1 parent 3529438 commit 8224802
Show file tree
Hide file tree
Showing 2 changed files with 229 additions and 111 deletions.
20 changes: 13 additions & 7 deletions README.md
Expand Up @@ -102,13 +102,19 @@ default values only after having loaded this script into your ZSH session.
Flags" section in the zshexpn(1) man page to learn about the kinds of
values you may assign to this variable.

To always receive _unique_ search results, use `setopt HIST_IGNORE_ALL_DUPS`.
Alternatively, use `setopt HIST_FIND_NO_DUPS` which makes this plugin skip
duplicate _adjacent_ search results as you cycle through them---however, this
does not guarantee that search results are unique: if your search results were
"Dog", "Dog", "HotDog", "Dog", then cycling them gives "Dog", "HotDog", "Dog".
Notice that the "Dog" search result appeared twice as you cycled through them!
If you wish to avoid this limitation, then use `setopt HIST_IGNORE_ALL_DUPS`.
* HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE is a global variable that defines
whether all search results returned are _unique_. If set to a non-empty
value, then only unique search results are presented. It is unset by
default. An alternative way to ensure that search results are unique is
to use `setopt HIST_IGNORE_ALL_DUPS`. If both this configuration variable
and `setopt HIST_IGNORE_ALL_DUPS` are unset, then `setopt HIST_FIND_NO_DUPS`
is still respected, and makes this plugin skip duplicate _adjacent_ search
results as you cycle through them, but this does not guarantee that search
results are unique: if your search results were "Dog", "Dog", "HotDog",
"Dog", then cycling them gives "Dog", "HotDog", "Dog". Notice that the "Dog"
search result appeared twice as you cycled through them. If you wish to
receive globally unique search results only once, then set this
configuration variable, or use `setopt HIST_IGNORE_ALL_DUPS`.

------------------------------------------------------------------------------
History
Expand Down

0 comments on commit 8224802

Please sign in to comment.