summaryrefslogtreecommitdiff
path: root/autoload/ale.vim
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-07-15 18:24:53 +0100
committerw0rp <devw0rp@gmail.com>2018-07-15 18:28:28 +0100
commita42999a639b2916b769a85f37d037be314d9d61b (patch)
tree5ebfb4d357dc673efa93fd32a66b489c4510de40 /autoload/ale.vim
parent5155a35a80fe3b20659eb0f28cc6cc720532dd3f (diff)
downloadale-a42999a639b2916b769a85f37d037be314d9d61b.zip
Massively reduce the amount of code needed for linter tests
Diffstat (limited to 'autoload/ale.vim')
-rw-r--r--autoload/ale.vim19
1 files changed, 19 insertions, 0 deletions
diff --git a/autoload/ale.vim b/autoload/ale.vim
index f61418f6..26c73547 100644
--- a/autoload/ale.vim
+++ b/autoload/ale.vim
@@ -213,6 +213,25 @@ function! ale#Set(variable_name, default) abort
endif
endfunction
+" Given a string for adding to a command, return the string padded with a
+" space on the left if it is not empty. Otherwise return an empty string.
+"
+" This can be used for making command strings cleaner and easier to test.
+function! ale#Pad(string) abort
+ return !empty(a:string) ? ' ' . a:string : ''
+endfunction
+
+" Given a environment variable name and a value, produce part of a command for
+" setting an environment variable before running a command. The syntax will be
+" valid for cmd on Windows, or most shells on Unix.
+function! ale#Env(variable_name, value) abort
+ if has('win32')
+ return 'set ' . a:variable_name . '=' . ale#Escape(a:value) . ' && '
+ endif
+
+ return a:variable_name . '=' . ale#Escape(a:value) . ' '
+endfunction
+
" Escape a string suitably for each platform.
" shellescape does not work on Windows.
function! ale#Escape(str) abort