Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions autoload/ghcmod.vim
Original file line number Diff line number Diff line change
Expand Up @@ -405,20 +405,7 @@ endif"}}}
function! ghcmod#build_command(args)"{{{
let l:cmd = ['ghc-mod']

" search Cabal file
if !exists('b:ghcmod_basedir')
let b:ghcmod_basedir = expand('%:p:h')
let l:dir = b:ghcmod_basedir
for _ in range(6)
if !empty(glob(l:dir . '/*.cabal', 0))
let b:ghcmod_basedir = l:dir
break
endif
let l:dir = fnamemodify(l:dir, ':h')
endfor
endif

let l:build_dir = b:ghcmod_basedir . '/dist/build'
let l:build_dir = s:find_basedir() . '/dist/build'
if isdirectory(l:build_dir)
" detect autogen directory
let l:autogen_dir = l:build_dir . '/autogen'
Expand Down Expand Up @@ -455,23 +442,45 @@ function! ghcmod#build_command(args)"{{{
endfunction"}}}

function! s:system(...)"{{{
lcd `=expand('%:p:h')`
lcd `=ghcmod#basedir()`
let l:ret = call('vimproc#system', a:000)
lcd -
return l:ret
endfunction"}}}

function! s:plineopen2(...)"{{{
if empty(get(g:, 'ghcmod_use_basedir', ''))
lcd `=expand('%:p:h')`
else
lcd `=g:ghcmod_use_basedir`
endif
lcd `=ghcmod#basedir()`
let l:ret = call('vimproc#plineopen2', a:000)
lcd -
return l:ret
endfunction"}}}

function! ghcmod#basedir()"{{{
let l:use_basedir = get(g:, 'ghcmod_use_basedir', '')
if !empty(l:use_basedir) && l:use_basedir ==? 'yes'
return s:find_basedir()
else
return expand('%:p:h')
endif
endfunction"}}}

function! s:find_basedir()"{{{
" search Cabal file
if !exists('b:ghcmod_basedir')
let l:ghcmod_basedir = expand('%:p:h')
let l:dir = l:ghcmod_basedir
for _ in range(6)
if !empty(glob(l:dir . '/*.cabal', 0))
let l:ghcmod_basedir = l:dir
break
endif
let l:dir = fnamemodify(l:dir, ':h')
endfor
let b:ghcmod_basedir = l:ghcmod_basedir
endif
return b:ghcmod_basedir
endfunction"}}}

function! ghcmod#print_error(msg)"{{{
echohl ErrorMsg
echomsg a:msg
Expand Down
12 changes: 5 additions & 7 deletions doc/ghcmod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,11 @@ g:ghcmod_type_highlight *g:ghcmod_type_highlight*
let g:ghcmod_type_highlight = 'ghcmodType'
<
g:ghcmod_use_basedir *g:ghcmod_use_basedir*
The directory to execute ghc-mod from. This can have an effect
particularly on template Haskell splices that expect to find certain
files in certain places. A good practice in these cases is to make
them work from the projects base directory, and open Vim from there.
>
let g:ghcmod_use_basedir = getcwd()
<
When value is 'yes' ghc-mod is executed from project base directory,
e.g. from directory where cabal file is placed. This can have an
effect particularly on template Haskell splices that expect to find
certain files in certain places.

If you do not set it, ghcmod will be executed from the folder the file
current Haskell file is contained in.

Expand Down