Skip to content

Commit b642c87

Browse files
committed
Merge pull request #25 from drchaos/use_basedir
Changed g:ghcmod_use_basedir behaviour to use directory with cabal file ...
2 parents bcab2b7 + dfb3743 commit b642c87

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

autoload/ghcmod.vim

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -405,20 +405,7 @@ endif"}}}
405405
function! ghcmod#build_command(args)"{{{
406406
let l:cmd = ['ghc-mod']
407407

408-
" search Cabal file
409-
if !exists('b:ghcmod_basedir')
410-
let b:ghcmod_basedir = expand('%:p:h')
411-
let l:dir = b:ghcmod_basedir
412-
for _ in range(6)
413-
if !empty(glob(l:dir . '/*.cabal', 0))
414-
let b:ghcmod_basedir = l:dir
415-
break
416-
endif
417-
let l:dir = fnamemodify(l:dir, ':h')
418-
endfor
419-
endif
420-
421-
let l:build_dir = b:ghcmod_basedir . '/dist/build'
408+
let l:build_dir = s:find_basedir() . '/dist/build'
422409
if isdirectory(l:build_dir)
423410
" detect autogen directory
424411
let l:autogen_dir = l:build_dir . '/autogen'
@@ -455,23 +442,45 @@ function! ghcmod#build_command(args)"{{{
455442
endfunction"}}}
456443

457444
function! s:system(...)"{{{
458-
lcd `=expand('%:p:h')`
445+
lcd `=ghcmod#basedir()`
459446
let l:ret = call('vimproc#system', a:000)
460447
lcd -
461448
return l:ret
462449
endfunction"}}}
463450

464451
function! s:plineopen2(...)"{{{
465-
if empty(get(g:, 'ghcmod_use_basedir', ''))
466-
lcd `=expand('%:p:h')`
467-
else
468-
lcd `=g:ghcmod_use_basedir`
469-
endif
452+
lcd `=ghcmod#basedir()`
470453
let l:ret = call('vimproc#plineopen2', a:000)
471454
lcd -
472455
return l:ret
473456
endfunction"}}}
474457

458+
function! ghcmod#basedir()"{{{
459+
let l:use_basedir = get(g:, 'ghcmod_use_basedir', '')
460+
if !empty(l:use_basedir) && l:use_basedir ==? 'yes'
461+
return s:find_basedir()
462+
else
463+
return expand('%:p:h')
464+
endif
465+
endfunction"}}}
466+
467+
function! s:find_basedir()"{{{
468+
" search Cabal file
469+
if !exists('b:ghcmod_basedir')
470+
let l:ghcmod_basedir = expand('%:p:h')
471+
let l:dir = l:ghcmod_basedir
472+
for _ in range(6)
473+
if !empty(glob(l:dir . '/*.cabal', 0))
474+
let l:ghcmod_basedir = l:dir
475+
break
476+
endif
477+
let l:dir = fnamemodify(l:dir, ':h')
478+
endfor
479+
let b:ghcmod_basedir = l:ghcmod_basedir
480+
endif
481+
return b:ghcmod_basedir
482+
endfunction"}}}
483+
475484
function! ghcmod#print_error(msg)"{{{
476485
echohl ErrorMsg
477486
echomsg a:msg

doc/ghcmod.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,11 @@ g:ghcmod_type_highlight *g:ghcmod_type_highlight*
137137
let g:ghcmod_type_highlight = 'ghcmodType'
138138
<
139139
g:ghcmod_use_basedir *g:ghcmod_use_basedir*
140-
The directory to execute ghc-mod from. This can have an effect
141-
particularly on template Haskell splices that expect to find certain
142-
files in certain places. A good practice in these cases is to make
143-
them work from the projects base directory, and open Vim from there.
144-
>
145-
let g:ghcmod_use_basedir = getcwd()
146-
<
140+
When value is 'yes' ghc-mod is executed from project base directory,
141+
e.g. from directory where cabal file is placed. This can have an
142+
effect particularly on template Haskell splices that expect to find
143+
certain files in certain places.
144+
147145
If you do not set it, ghcmod will be executed from the folder the file
148146
current Haskell file is contained in.
149147

0 commit comments

Comments
 (0)