Skip to content

Commit 7cc23b1

Browse files
committed
Add buffer-local version of g:ghcmod_ghc_options
1 parent a7c64c0 commit 7cc23b1

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ If you'd like to give GHC options, set `g:ghcmod_ghc_options`.
2727
let g:ghcmod_ghc_options = ['-idir1', '-idir2']
2828
~~~
2929

30+
Also, there's buffer-local version `b:ghcmod_ghc_options`.
31+
32+
~~~vim
33+
autocmd BufRead,BufNewFile ~/.xmonad/* call s:add_xmonad_path()
34+
function! s:add_xmonad_path()
35+
if !exists('b:ghcmod_ghc_options')
36+
let b:ghcmod_ghc_options = []
37+
endif
38+
call add(b:ghcmod_ghc_options, '-i' . expand('~/.xmonad/lib'))
39+
endfunction
40+
~~~
41+
3042
### :GhcModType, :GhcModTypeClear
3143
Type `:GhcModType` on a expression, then the sub-expression is highlighted and its type is echoed.
3244
If you type `:GhcModType` multiple times, the sub-expression changes.

autoload/ghcmod.vim

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,14 @@ function! ghcmod#build_command(args)"{{{
437437
endif
438438
endif
439439

440-
" Taking the -fno-code flag here results in a *massive* speed increase.
441-
" Overrideable by the user setting g:ghcmod_ghc_options themselves.
442-
for l:opt in get(g:, 'ghcmod_ghc_options', ["-fno-code"])
440+
if exists('b:ghcmod_ghc_options')
441+
let l:opts = b:ghcmod_ghc_options
442+
else
443+
" Taking the -fno-code flag here results in a *massive* speed increase.
444+
" Overrideable by the user setting g:ghcmod_ghc_options themselves.
445+
let l:opts = get(g:, 'ghcmod_ghc_options', ["-fno-code"])
446+
endif
447+
for l:opt in l:opts
443448
call extend(l:cmd, ['-g', l:opt])
444449
endfor
445450
call extend(l:cmd, a:args)

doc/ghcmod.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ g:ghcmod_ghc_options *g:ghcmod_ghc_options*
108108
let g:ghcmod_ghc_options = []
109109
<
110110

111+
b:ghcmod_ghc_options *b:ghcmod_ghc_options*
112+
Buffer-local version of |g:ghcmod_ghc_options|. When both
113+
|b:ghcmod_ghc_options| and |g:ghcmod_ghc_options| are defined,
114+
|b:ghcmod_ghc_options| is given preference and |g:ghcmod_ghc_options|
115+
is ignored.
116+
117+
Example: adding ~/.xmonad/lib when editing XMonad configs.
118+
>
119+
autocmd BufRead,BufNewFile ~/.xmonad/* call s:add_xmonad_path()
120+
function! s:add_xmonad_path()
121+
if !exists('b:ghcmod_ghc_options')
122+
let b:ghcmod_ghc_options = []
123+
endif
124+
call add(b:ghcmod_ghc_options, '-i' . expand('~/.xmonad/lib'))
125+
endfunction
126+
<
127+
111128
g:ghcmod_hlint_options *g:ghcmod_hlint_options*
112129
Pass these options to hlint. By default, ghcmod doesn't pass any GHC
113130
options.

0 commit comments

Comments
 (0)