Permalink
Browse files

Merge pull request #74 from gasparch/master

Change directory to project root when running 'mix ...'
  • Loading branch information...
2 parents 6b763e9 + 04e06af commit a58605e982f5c0bdafc9f49af804d1015165af8d @slashmili committed on GitHub Jan 10, 2017
Showing with 36 additions and 0 deletions.
  1. +36 −0 after/plugin/alchemist.vim
@@ -422,13 +422,49 @@ endfunction
" }}}
+function! alchemist#findMixDirectory() "{{{
+ let fName = expand("%:p:h")
+
+ while 1
+ let mixFileName = fName . "/mix.exs"
+ if file_readable(mixFileName)
+ return fName
+ endif
+
+ let fNameNew = fnamemodify(fName, ":h")
+ " after we reached top of heirarchy
+ if fNameNew == fName
+ return ''
+ endif
+ let fName = fNameNew
+ endwhile
+endfunction "}}}
+
function! alchemist#mix(...)
+ let mixDir = alchemist#findMixDirectory()
+
+ let old_cwd = getcwd()
+ if mixDir != ''
+ execute 'lcd ' . fnameescape(mixDir)
+ endif
+
exe '!mix ' . join(copy(a:000), ' ')
+
+ execute 'lcd ' . fnameescape(old_cwd)
endfunction
function! alchemist#mix_complete(ArgLead, CmdLine, CursorPos, ...)
if !exists('g:mix_tasks')
+ let mixDir = alchemist#findMixDirectory()
+
+ let old_cwd = getcwd()
+ if mixDir != ''
+ execute 'lcd ' . fnameescape(mixDir)
+ endif
+
let g:mix_tasks = system("mix -h | awk '!/-S/ && $2 != \"#\" { print $2 }'")
+
+ execute 'lcd ' . fnameescape(old_cwd)
endif
return g:mix_tasks
endfunction

0 comments on commit a58605e

Please sign in to comment.