Skip to content

Commit 731d21f

Browse files
committed
Put uses of lcd inside a try/finally
1 parent ff8fe7d commit 731d21f

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

autoload/ghcmod.vim

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,24 @@ function! ghcmod#build_command(args) "{{{
280280
endfunction "}}}
281281

282282
function! ghcmod#system(...) "{{{
283-
lcd `=ghcmod#basedir()`
284-
let l:ret = call('vimproc#system', a:000)
285-
lcd -
283+
let l:dir = getcwd()
284+
try
285+
lcd `=ghcmod#basedir()`
286+
let l:ret = call('vimproc#system', a:000)
287+
finally
288+
lcd `=l:dir`
289+
endtry
286290
return l:ret
287291
endfunction "}}}
288292

289293
function! s:plineopen3(...) "{{{
290-
lcd `=ghcmod#basedir()`
291-
let l:ret = call('vimproc#plineopen3', a:000)
292-
lcd -
294+
let l:dir = getcwd()
295+
try
296+
lcd `=ghcmod#basedir()`
297+
let l:ret = call('vimproc#plineopen3', a:000)
298+
finally
299+
lcd `=l:dir`
300+
endtry
293301
return l:ret
294302
endfunction "}}}
295303

@@ -329,9 +337,14 @@ function! s:find_basedir() "{{{
329337
" search Cabal file
330338
if !exists('b:ghcmod_basedir')
331339
" `ghc-mod root` is available since v4.0.0.
332-
lcd `=expand('%:p:h')`
333-
let b:ghcmod_basedir = substitute(vimproc#system(['ghc-mod', 'root']), '\n*$', '', '')
334-
lcd -
340+
let l:dir = getcwd()
341+
try
342+
lcd `=expand('%:p:h')`
343+
let b:ghcmod_basedir =
344+
\ substitute(vimproc#system(['ghc-mod', 'root']), '\n*$', '', '')
345+
finally
346+
lcd `=l:dir`
347+
endtry
335348
endif
336349
return b:ghcmod_basedir
337350
endfunction "}}}

0 commit comments

Comments
 (0)