mirror of
https://github.com/zdharma-continuum/history-search-multi-word
synced 2024-11-22 03:13:09 +00:00
hsmw: Miracle optimization of query highlighting – via math function
For query A|B|C the time is 44 ms vs 502 ms – for the lines of code that highlight words A,B,C. No more Zaw license – the borrowed line of code is now removed, and whole code is licensed under GPLv3 and MIT.
This commit is contained in:
parent
58faf8d701
commit
2641b1da89
2 changed files with 10 additions and 31 deletions
27
LICENSE
27
LICENSE
|
@ -698,30 +698,3 @@ may consider it more useful to permit linking proprietary applications with
|
|||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
||||
Zaw
|
||||
---
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the author nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
|
@ -30,7 +30,7 @@ zmodload zsh/termcap 2>/dev/null
|
|||
typeset -g __hsmw_hcw_index
|
||||
typeset -g __hsmw_hcw_widget_name __hsmw_hcw_restart __hsmw_hcw_call_count
|
||||
typeset -g __hsmw_page_size __hsmw_hl_color __hsmw_synhl __hsmw_active
|
||||
typeset -ga __hsmw_disp_list __hsmw_disp_list_newlines
|
||||
typeset -ga __hsmw_disp_list __hsmw_disp_list_newlines __hsmw_region_highlight_data
|
||||
typeset -gi __hsmw_page_start_idx __hsmw_prev_offset __hsmw_recedit_trap_executed
|
||||
typeset -gaU __hsmw_hcw_found
|
||||
|
||||
|
@ -70,7 +70,7 @@ _hsmw_main() {
|
|||
fi
|
||||
|
||||
# Find history entries matching pattern *word1*~^*word2*~^*word3* etc.
|
||||
local search_buffer="${BUFFER%% ##}" search_pattern="" colsearch_pattern="" nl=$'\n' nul=$'\0'
|
||||
local search_buffer="${BUFFER%% ##}" search_pattern="" colsearch_pattern="" nl=$'\n' MATCH MBEGIN MEND
|
||||
search_buffer="${search_buffer## ##}"
|
||||
search_buffer="${search_buffer//(#m)[][*?|#~^()><\\]/\\$MATCH}"
|
||||
# Pattern will be *foo*~^*bar* (inventor: Mikael Magnusson)
|
||||
|
@ -157,8 +157,9 @@ _hsmw_main() {
|
|||
fi
|
||||
|
||||
if [ -n "$colsearch_pattern" ]; then
|
||||
# Following line is taken from Zaw (GH zsh-users/zaw) and modified – license of original parts is named "Zaw", it is in LICENSE file
|
||||
region_highlight+=( "${(0)${(S)text//*(#bi)(${~colsearch_pattern})/$(( offset + mbegin[1] - 1 )) $(( offset + mend[1] )) ${__hsmw_hl_color}${nul}}%$nul*}" )
|
||||
__hsmw_region_highlight_data=( )
|
||||
: "${text//(#mi)(${~colsearch_pattern})/$(( hsmw_append(MBEGIN,MEND) ))}"
|
||||
region_highlight+=( $__hsmw_region_highlight_data )
|
||||
fi
|
||||
else
|
||||
region_highlight[-1]=()
|
||||
|
@ -170,6 +171,11 @@ _hsmw_main() {
|
|||
region_highlight+=( "$(( offset + ${#txt_before} )) $(( offset + ${#txt_before} + ${#entry} + 1 )) $__hsmw_active" )
|
||||
}
|
||||
|
||||
_hsmw_shappend() {
|
||||
__hsmw_region_highlight_data+=( "$(( offset + $1 - 1 )) $(( offset + $2 )) ${__hsmw_hl_color}" )
|
||||
}
|
||||
functions -M hsmw_append 2 2 _hsmw_shappend
|
||||
|
||||
fi
|
||||
|
||||
_hsmw_main
|
||||
|
|
Loading…
Reference in a new issue