From 47811da62e4e9011e5134446f6e5d2bb47e715f5 Mon Sep 17 00:00:00 2001 From: Carlo Hamalainen Date: Sun, 25 Sep 2016 07:42:22 +0800 Subject: [PATCH] Updates to work against https://github.com/DanielG/ghc-mod/pull/823 --- after/ftplugin/haskell/ghcmod.vim | 4 ++-- autoload/ghcmod.vim | 5 ++--- autoload/ghcmod/command.vim | 14 +++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/after/ftplugin/haskell/ghcmod.vim b/after/ftplugin/haskell/ghcmod.vim index 113248a..61866c8 100644 --- a/after/ftplugin/haskell/ghcmod.vim +++ b/after/ftplugin/haskell/ghcmod.vim @@ -59,8 +59,8 @@ command! -buffer -nargs=0 -bang GhcModCheckAsync call ghcmod#command#async_make( command! -buffer -nargs=0 -bang GhcModLintAsync call ghcmod#command#async_make('lint', 0) command! -buffer -nargs=0 -bang GhcModCheckAndLintAsync call ghcmod#command#check_and_lint_async(0) command! -buffer -nargs=0 -bang GhcModExpand call ghcmod#command#expand(0) -command! -buffer -nargs=? -bang GhcModOpenDoc call ghcmod#command#opendoc(, 0) -command! -buffer -nargs=? -bang GhcModDocUrl call ghcmod#command#echo_doc_url(, 0) +command! -buffer -nargs=? -bang GhcModOpenDoc call ghcmod#command#opendoc(, 0, 0) +command! -buffer -nargs=? -bang GhcModDocUrl call ghcmod#command#echo_doc_url(, 0, 0) command! -buffer -nargs=? -bang GhcModOpenHaddockVismode call ghcmod#command#opendoc(, 0, 1) command! -buffer -nargs=? -bang GhcModEchoUrlVismode call ghcmod#command#echo_doc_url(, 0, 1) diff --git a/autoload/ghcmod.vim b/autoload/ghcmod.vim index 390636e..5968659 100644 --- a/autoload/ghcmod.vim +++ b/autoload/ghcmod.vim @@ -36,10 +36,9 @@ function! ghcmod#get_doc_url(path, module, fexp, line, col) "{{{ let l:cmd = ghcmod#build_command(['imported-from', a:path, a:line, a:col, a:fexp]) let l:output = ghcmod#system(l:cmd) let l:lines = split(l:output, '\n') - let l:lastline = l:lines[-1] - if l:lastline =~ "^file.*" - return l:lastline + if len(l:lines) > 0 + return l:lines[0] endif endfunction "}}} diff --git a/autoload/ghcmod/command.vim b/autoload/ghcmod/command.vim index 19bfe7d..3ff4cf8 100644 --- a/autoload/ghcmod/command.vim +++ b/autoload/ghcmod/command.vim @@ -290,21 +290,25 @@ function! ghcmod#command#opendoc(fexp, force, vismode) "{{{ let l:doc_url = ghcmod#get_doc_url(l:path, ghcmod#detect_module(), l:fexp, l:line, l:col) - if l:doc_url =~ '^file' + let l:bits = split(l:doc_url) + + if len(l:bits) == 3 + let l:the_url = l:bits[-1] + if exists('g:ghcmod_browser') - execute 'silent !' . g:ghcmod_browser . ' ' . l:doc_url . ' >& /dev/null &' + execute 'silent !' . g:ghcmod_browser . ' ' . l:the_url . ' >& /dev/null &' execute ':redraw!' else if has("win") - echo 'Error, not implemented. Go here: ' . l:doc_url + echo 'Error, not implemented. Go here: ' . l:the_url endif if has("unix") if system('uname')=~'Darwin' " Redirect output to /dev/null? - execute "silent !open " . l:doc_url + execute "silent !open " . l:the_url else - execute "silent !xdg-open " . l:doc_url . ' >& /dev/null' + execute "silent !xdg-open " . l:the_url . ' >& /dev/null' endif execute ':redraw!'