From 2d1d6fb85011e07a6b5b29f57247254cbc4b8815 Mon Sep 17 00:00:00 2001 From: w0rp Date: Tue, 21 Mar 2017 13:09:02 +0000 Subject: [PATCH] Add some utility functions for changing directories for commands --- autoload/ale/util.vim | 13 +++++++++++++ test/util/test_cd_string_commands.vader | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/util/test_cd_string_commands.vader 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 && ' +" 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 && ' +" 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(''))