summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-03-21 13:09:02 +0000
committerw0rp <devw0rp@gmail.com>2017-03-21 13:09:02 +0000
commit2d1d6fb85011e07a6b5b29f57247254cbc4b8815 (patch)
tree7e789a6745525a7da99848424be7da3bd883293d
parent6550cdfbd0d8e4037e9097db5a0caa6284b35708 (diff)
downloadale-2d1d6fb85011e07a6b5b29f57247254cbc4b8815.zip
Add some utility functions for changing directories for commands
-rw-r--r--autoload/ale/util.vim13
-rw-r--r--test/util/test_cd_string_commands.vader9
2 files changed, 22 insertions, 0 deletions
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index 600717db..84ffe22e 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -144,3 +144,16 @@ endfunction
function! ale#util#ClockMilliseconds() abort
return float2nr(reltimefloat(reltime()) * 1000)
endfunction
+
+
+" Output 'cd <directory> && '
+" This function can be used changing the directory for a linter command.
+function! ale#util#CdString(directory) abort
+ return 'cd ' . fnameescape(a:directory) . ' && '
+endfunction
+
+" Output 'cd <buffer_filename_directory> && '
+" This function can be used changing the directory for a linter command.
+function! ale#util#BufferCdString(buffer) abort
+ return ale#util#CdString(fnamemodify(bufname(a:buffer), ':p:h'))
+endfunction
diff --git a/test/util/test_cd_string_commands.vader b/test/util/test_cd_string_commands.vader
new file mode 100644
index 00000000..0fdc0e30
--- /dev/null
+++ b/test/util/test_cd_string_commands.vader
@@ -0,0 +1,9 @@
+Before:
+ silent! cd /testplugin/test/util
+
+Execute(CdString should output the correct command string):
+ AssertEqual 'cd /foo\ bar/baz && ', ale#util#CdString('/foo bar/baz')
+
+Execute(BufferCdString should output the correct command string):
+ Assert match(ale#util#BufferCdString(bufnr('')), '^cd .*test/util && $') >= 0,
+ \ 'String didn''t match regex: ' . ale#util#BufferCdString(bufnr(''))