Skip to content

Commit 175bf46

Browse files
committed
Improved search
* Make all searches case-sensitive since Python is as well * Search for substring match on word boundaries * Progressively smaller suffix search now uses word boundary * If verbose is >= 1 pyref.vim reports used search patterns
1 parent 5dd2e8b commit 175bf46

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

pyref.vim

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
" Vim plug-in
22
" Maintainer: Peter Odding <peter@peterodding.com>
3-
" Last Change: June 3, 2010
3+
" Last Change: June 8, 2010
44
" URL: http://peterodding.com/code/vim/pyref
55
" License: MIT
6-
" Version: 0.4
6+
" Version: 0.5
77

88
" Support for automatic update using the GLVS plug-in.
99
" GetLatestVimScripts: 3104 1 :AutoInstall: pyref.zip
@@ -132,7 +132,12 @@ function! s:PyRef() " {{{1
132132
let lines = []
133133
echoerr "pyref.vim: Failed to read index file! (" . indexfile . ")"
134134
endtry
135-
if s:JumpToEntry(lines, '^\(module-\|exceptions\.\)\?' . pattern . '\t')
135+
if s:JumpToEntry(lines, '^\C\(module-\|exceptions\.\)\?' . pattern . '\t')
136+
return
137+
endif
138+
139+
" Search for a substring match on word boundaries.
140+
if s:JumpToEntry(lines, '\C\<' . pattern . '\>.*\t')
136141
return
137142
endif
138143

@@ -149,7 +154,7 @@ function! s:PyRef() " {{{1
149154
endfor
150155

151156
" Search for a substring match in the index.
152-
if s:JumpToEntry(lines, pattern)
157+
if s:JumpToEntry(lines, '\C' . pattern . '.*\t')
153158
return
154159
endif
155160

@@ -160,7 +165,7 @@ function! s:PyRef() " {{{1
160165
let parts = split(ident, '\.')
161166
while len(parts) > 1
162167
call remove(parts, 0)
163-
let pattern = join(parts, '\.') . '$'
168+
let pattern = '\C\<' . join(parts, '\.') . '$'
164169
if s:JumpToEntry(lines, pattern)
165170
return
166171
endif
@@ -175,12 +180,15 @@ endfunction
175180
" to recognize calls to methods of objects that are one of Python's standard
176181
" types: strings, lists, dictionaries and file handles.
177182
let s:object_methods = [
178-
\ ['library/stdtypes.html#str.%s', '\.\@<=\(capitalize\|center\|count\|decode\|encode\|endswith\|expandtabs\|find\|format\|index\|isalnum\|isalpha\|isdigit\|islower\|isspace\|istitle\|isupper\|join\|ljust\|lower\|lstrip\|partition\|replace\|rfind\|rindex\|rjust\|rpartition\|rsplit\|rstrip\|split\|splitlines\|startswith\|strip\|swapcase\|title\|translate\|upper\|zfill\)$'],
179-
\ ['tutorial/datastructures.html#more-on-lists', '\.\@<=\(append\|count\|extend\|index\|insert\|pop\|remove\|reverse\|sort\)$'],
180-
\ ['library/stdtypes.html#dict.%s', '\.\@<=\(clear\|copy\|fromkeys\|get\|has_key\|items\|iteritems\|iterkeys\|itervalues\|keys\|pop\|popitem\|setdefault\|update\|values\)$'],
181-
\ ['library/stdtypes.html#file.%s', '\.\@<=\(close\|closed\|encoding\|errors\|fileno\|flush\|isatty\|mode\|name\|newlines\|next\|read\|readinto\|readline\|readlines\|seek\|softspace\|tell\|truncate\|write\|writelines\|xreadlines\)$']]
183+
\ ['library/stdtypes.html#str.%s', '\C\.\@<=\(capitalize\|center\|count\|decode\|encode\|endswith\|expandtabs\|find\|format\|index\|isalnum\|isalpha\|isdigit\|islower\|isspace\|istitle\|isupper\|join\|ljust\|lower\|lstrip\|partition\|replace\|rfind\|rindex\|rjust\|rpartition\|rsplit\|rstrip\|split\|splitlines\|startswith\|strip\|swapcase\|title\|translate\|upper\|zfill\)$'],
184+
\ ['tutorial/datastructures.html#more-on-lists', '\C\.\@<=\(append\|count\|extend\|index\|insert\|pop\|remove\|reverse\|sort\)$'],
185+
\ ['library/stdtypes.html#dict.%s', '\C\.\@<=\(clear\|copy\|fromkeys\|get\|has_key\|items\|iteritems\|iterkeys\|itervalues\|keys\|pop\|popitem\|setdefault\|update\|values\)$'],
186+
\ ['library/stdtypes.html#file.%s', '\C\.\@<=\(close\|closed\|encoding\|errors\|fileno\|flush\|isatty\|mode\|name\|newlines\|next\|read\|readinto\|readline\|readlines\|seek\|softspace\|tell\|truncate\|write\|writelines\|xreadlines\)$']]
182187

183188
function! s:JumpToEntry(lines, pattern) " {{{1
189+
if &verbose
190+
echomsg "pyref.vim: Trying to match" string(a:pattern)
191+
endif
184192
let index = match(a:lines, a:pattern)
185193
if index >= 0
186194
let url = split(a:lines[index], '\t')[1]

0 commit comments

Comments
 (0)