ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.58k stars 233 forks source link

Required vim compiled with +python and Unknown function: merlin#FindBinary #416

Closed yufangfred closed 9 years ago

yufangfred commented 9 years ago

i have ocaml 4.01.0

I followed the steps in "With opam"

opam install merlin

and put this in vimrc

let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
execute "set rtp+=" . g:opamshare . "/merlin/vim"

But merlin seems not working because when I save a .ml file with :w error message like this shows up in vim.

"330/p3/cekaml.ml" 255L, 10075C written
Error: Required vim compiled with +python
Error detected while processing function <SNR>42_BufWritePostHook..<SNR>42_UpdateErrors..<SNR>42_CacheErrors..260..SyntaxCheckers_ocaml
_merlin_IsAvailable:
line    1:
E117: Unknown function: merlin#FindBinary
E116: Invalid arguments for function executable(merlin#FindBinary()) | catch | return 0 | endtry
E15: Invalid expression: executable(merlin#FindBinary()) | catch | return 0 | endtry
Error detected while processing function <SNR>42_BufWritePostHook..<SNR>42_UpdateErrors..<SNR>42_CacheErrors..260:
line    3:
E171: Missing :endif
Error detected while processing function <SNR>42_BufWritePostHook..<SNR>42_UpdateErrors..<SNR>42_CacheErrors:
line   27:
E171: Missing :endif
Error detected while processing function <SNR>42_BufWritePostHook..<SNR>42_UpdateErrors:
line   13:
E171: Missing :endif
Press ENTER or type command to continue

Please help

Khady commented 9 years ago

I think that you need a version of vim compiled with the support of python. Can you provide the output of vim --version | grep python?

Here is an example of the output for my vim:

vim --version | grep python
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace

If you don't have +python in the output, it means that you don't have a good version of vim. The solution depends of you environnement.

yufangfred commented 9 years ago

Mine has " +python/dyn" --- is that equivalent? +path_extra -perl +persistent_undo +postscript +printer -profile +python/dyn -python3 +quickfix +reltime -rightleft +ruby/dyn +scrollbind +signs I am using mac. I checked brew install macvim it says macvim-7.4-74 already installed which I believe is the latest version.

yufangfred commented 9 years ago

Problem solved. Thanks a lot. Instead of building vim myself, I switched to the prebuilt snapshot.
Also, probably good to know, I find out you can check "+python" support by :echo has("python")@Khady

let-def commented 9 years ago

We are already checking that, that's why merlin was able to print "Error: Required vim compiled with +python". We should probably extend the fix with || has("python/dyn") I guess

let-def commented 9 years ago

@CrazyBookSeller do you still have a vim with python/dyn? If so, could you check if this patch makes it work:

diff --git a/vim/merlin/autoload/merlin.vim b/vim/merlin/autoload/merlin.vim
index a173653..d353bde 100644
--- a/vim/merlin/autoload/merlin.vim
+++ b/vim/merlin/autoload/merlin.vim
@@ -1,6 +1,6 @@
 if !exists('g:merlin') | let g:merlin = {} | endif | let s:c = g:merlin

-if !has('python')
+if !has('python') && !has('python/dyn')
   echo "Error: Required vim compiled with +python"
   finish
 endif
yufangfred commented 9 years ago

Sure, how do I suppose to add the patch? @def-lkb

let-def commented 9 years ago

Just edit the "autoload/merlin.vim" file, you can find its path by running :scriptnames in vim.

let-def commented 9 years ago

I tested on a local build with +python/dyn:

I guess in your case, has("python") == 0 because python couldn't be dynamically loaded. Don't bother patching.