Skip to content

Commit

Permalink
(improvement): do not echo version. add fruzzy#version()
Browse files Browse the repository at this point in the history
refs #14
  • Loading branch information
raghur committed Oct 17, 2018
1 parent f3d1bc8 commit 30e6220
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
22 changes: 21 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ let g:fruzzy#usenative = 1
" Useful if you're bouncing a lot between similar files.
" To turn off this behavior, set the variable below to 0

let g:fruzzy#sortonempty = 1 "default value
let g:fruzzy#sortonempty = 1 " default value

" tell denite to use this matcher by default for all sources
call denite#custom#source('_', 'matchers', ['matcher/fruzzy'])

" tell CtrlP to use this matcher
let g:ctrlp_match_func = {'match': 'fruzzy#ctrlp#matcher'}
let g:ctrlp_match_current_file = 1 " to include current file in matches
```

## Native modules
Expand All @@ -43,6 +44,25 @@ it in usual operation (python impl is at 300 - 600μs)
. Run command `:call fruzzy#install()` if you're not using vim-plug.
. restart nvim

## Troubleshooting/Support

Raise a ticket - please include the following info:

.Get the version
. Start vim/nvim
. Activate denite/ctrlp as the case may be.
. Execute `:call fruzzy#version()` - this will print one of the following
.. version number and branch - all is good
.. `purepy` - you're using the pure python version.
.. `modnotfound` - you requested the native mod with `let g:fruzzy#usenative=1` but it could not be loaded
.. `outdated` - native mod was loaded but it's < v0.3. You can update the native mod from the releases.
. include output of the above

.Describe the issue
. include the list of items
. include your query
. What it did vs what you expected it to do.

## Development

.Build native module
Expand Down
16 changes: 16 additions & 0 deletions autoload/fruzzy.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
function! fruzzy#install()
py3 import fruzzy_installer; fruzzy_installer.install()
endfunction


function! fruzzy#version()
if !exists("g:fruzzy#version")
echo "version not set. Depending on your usage:"
echo "For denite: make sure that: "
echo " fruzzy is set as the matcher "
echo " Activate denite and filter list once to ensure it's loaded"
echo "For Ctrlp: make sure that: "
echo " matcher is set as fruzzy#ctrlp#matcher"
echo " Ctrlp is activated once to ensure it's loaded"
return
endif
echomsg g:fruzzy#version
return g:fruzzy#version
endfunction
11 changes: 8 additions & 3 deletions python3/ctrlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@
if USE_NATIVE:
try:
from fruzzy_mod import scoreMatchesStr
import fruzzy_mod
if 'version' in dir(fruzzy_mod):
vim.vars["fruzzy#version"] = fruzzy_mod.version()
else:
vim.vars["fruzzy#version"] = "outdated"
except ImportError:
vim.vars["fruzzy#version"] = "modnotfound"
from fruzzy import scoreMatches
USE_NATIVE = False
else:
from fruzzy import scoreMatches
vim.vars["fruzzy#version"] = "purepy"
# pylint: enable=import-error, wrong-import-position


Expand All @@ -25,12 +32,10 @@ def fruzzy_match():
args['limit'] = int(args['limit'])
args['ispath'] = int(args['ispath'])

sortonempty = vim.vars.get('fruzzy#sortonempty', 1)
current = args['current'] if sortonempty else ""
if USE_NATIVE:
output = scoreMatchesStr(args['query'],
args['candidates'],
current,
args['current'],
args['limit'],
args['ispath'])
matches = [args['candidates'][i[0]] for i in output]
Expand Down
7 changes: 5 additions & 2 deletions rplugin/python3/denite/filter/matcher/fruzzymatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ def __init__(self, vim):
if 'version' not in dir(fruzzy_mod):
self.debug("You have an old version of the native module")
self.debug("please execute :call fruzzy#install()")
self.vim.vars["fruzzy#version"] = "outdated"
else:
self.debug("fruzzy_mod ver: %s" %
fruzzy_mod.version())
self.vim.vars["fruzzy#version"] = fruzzy_mod.version()
except ImportError:
self.debug("Native module requested but module was not found")
self.debug("falling back to python implementation")
self.debug("execute :call fruzzy#install() to install the native module")
self.debug("and then check if you have fruzzy_mod.so or fruzzy_mod.pyd at %s" %
pkgPath)
self.vim.vars["fruzzy#version"] = "modnotfound"
self.useNative = False
else:
self.vim.vars["fruzzy#version"] = "purepy"
# self.debug("usenative: %s" % self.useNative)

def filter(self, context):
Expand Down

0 comments on commit 30e6220

Please sign in to comment.