summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-06-25 20:34:23 +0100
committerw0rp <devw0rp@gmail.com>2017-06-25 20:34:23 +0100
commit8b557f346c5b528e1a309b17a5baf2d014c7276e (patch)
treeb0644d0c8fba5836cef6fdd273c12db354804840
parent7f6e5dc65b9275d9a1a9905e11e990dc90b9e328 (diff)
downloadale-8b557f346c5b528e1a309b17a5baf2d014c7276e.zip
Move ale#handlers#c functions into ale#c
-rw-r--r--ale_linters/c/clang.vim4
-rw-r--r--ale_linters/c/gcc.vim4
-rw-r--r--ale_linters/cpp/clang.vim4
-rw-r--r--ale_linters/cpp/gcc.vim4
-rw-r--r--autoload/ale/c.vim62
-rw-r--r--autoload/ale/handlers/c.vim63
6 files changed, 69 insertions, 72 deletions
diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim
index ecfa5050..2cecc514 100644
--- a/ale_linters/c/clang.vim
+++ b/ale_linters/c/clang.vim
@@ -10,13 +10,13 @@ if !exists('g:ale_c_clang_options')
endif
function! ale_linters#c#clang#GetCommand(buffer) abort
- let l:paths = ale#handlers#c#FindLocalHeaderPaths(a:buffer)
+ let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
return 'clang -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
- \ . ale#handlers#c#IncludeOptions(l:paths)
+ \ . ale#c#IncludeOptions(l:paths)
\ . ale#Var(a:buffer, 'c_clang_options') . ' -'
endfunction
diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim
index bcf8017e..c988b30f 100644
--- a/ale_linters/c/gcc.vim
+++ b/ale_linters/c/gcc.vim
@@ -10,13 +10,13 @@ if !exists('g:ale_c_gcc_options')
endif
function! ale_linters#c#gcc#GetCommand(buffer) abort
- let l:paths = ale#handlers#c#FindLocalHeaderPaths(a:buffer)
+ let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
return 'gcc -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
- \ . ale#handlers#c#IncludeOptions(l:paths)
+ \ . ale#c#IncludeOptions(l:paths)
\ . ale#Var(a:buffer, 'c_gcc_options') . ' -'
endfunction
diff --git a/ale_linters/cpp/clang.vim b/ale_linters/cpp/clang.vim
index 953c8a71..f70101d3 100644
--- a/ale_linters/cpp/clang.vim
+++ b/ale_linters/cpp/clang.vim
@@ -7,13 +7,13 @@ if !exists('g:ale_cpp_clang_options')
endif
function! ale_linters#cpp#clang#GetCommand(buffer) abort
- let l:paths = ale#handlers#c#FindLocalHeaderPaths(a:buffer)
+ let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
return 'clang++ -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
- \ . ale#handlers#c#IncludeOptions(l:paths)
+ \ . ale#c#IncludeOptions(l:paths)
\ . ale#Var(a:buffer, 'cpp_clang_options') . ' -'
endfunction
diff --git a/ale_linters/cpp/gcc.vim b/ale_linters/cpp/gcc.vim
index 36e958e7..69b69e4f 100644
--- a/ale_linters/cpp/gcc.vim
+++ b/ale_linters/cpp/gcc.vim
@@ -17,13 +17,13 @@ if !exists('g:ale_cpp_gcc_options')
endif
function! ale_linters#cpp#gcc#GetCommand(buffer) abort
- let l:paths = ale#handlers#c#FindLocalHeaderPaths(a:buffer)
+ let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
return 'gcc -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
- \ . ale#handlers#c#IncludeOptions(l:paths)
+ \ . ale#c#IncludeOptions(l:paths)
\ . ale#Var(a:buffer, 'cpp_gcc_options') . ' -'
endfunction
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim
index 9cc2521e..17d72605 100644
--- a/autoload/ale/c.vim
+++ b/autoload/ale/c.vim
@@ -1,6 +1,66 @@
-" Author: gagbo <gagbobada@gmail.com>
+" Author: gagbo <gagbobada@gmail.com>, w0rp <devw0rp@gmail.com>
" Description: Functions for integrating with C-family linters.
+function! ale#c#FindProjectRoot(buffer) abort
+ for l:project_filename in ['configure', 'Makefile', 'CMakeLists.txt']
+ let l:full_path = ale#path#FindNearestFile(a:buffer, l:project_filename)
+
+ if !empty(l:full_path)
+ return fnamemodify(l:full_path, ':h')
+ endif
+ endfor
+
+ return ''
+endfunction
+
+" Given a buffer number, search for a project root, and output a List
+" of directories to include based on some heuristics.
+"
+" For projects with headers in the project root, the project root will
+" be returned.
+"
+" For projects with an 'include' directory, that directory will be returned.
+function! ale#c#FindLocalHeaderPaths(buffer) abort
+ let l:project_root = ale#c#FindProjectRoot(a:buffer)
+
+ if empty(l:project_root)
+ return []
+ endif
+
+ " See if we can find .h files directory in the project root.
+ " If we can, that's our include directory.
+ if !empty(globpath(l:project_root, '*.h', 0))
+ return [l:project_root]
+ endif
+
+ " Look for .hpp files too.
+ if !empty(globpath(l:project_root, '*.hpp', 0))
+ return [l:project_root]
+ endif
+
+ " If we find an 'include' directory in the project root, then use that.
+ if isdirectory(l:project_root . '/include')
+ return [simplify(l:project_root . '/include')]
+ endif
+
+ return []
+endfunction
+
+" Given a List of include paths, create a string containing the -I include
+" options for those paths, with the paths escaped for use in the shell.
+function! ale#c#IncludeOptions(include_paths) abort
+ let l:option_list = []
+
+ for l:path in a:include_paths
+ call add(l:option_list, '-I' . ale#Escape(l:path))
+ endfor
+
+ if empty(l:option_list)
+ return ''
+ endif
+
+ return ' ' . join(l:option_list) . ' '
+endfunction
let g:ale_c_build_dir_names = get(g:, 'ale_c_build_dir_names', [
\ 'build',
diff --git a/autoload/ale/handlers/c.vim b/autoload/ale/handlers/c.vim
deleted file mode 100644
index 266ab20a..00000000
--- a/autoload/ale/handlers/c.vim
+++ /dev/null
@@ -1,63 +0,0 @@
-" Author: w0rp <devw0rp@gmail.com>
-" Desciption: Functions for integrating with C and C++ compilers.
-
-function! ale#handlers#c#FindProjectRoot(buffer) abort
- for l:project_filename in ['configure', 'Makefile', 'CMakeLists.txt']
- let l:full_path = ale#path#FindNearestFile(a:buffer, l:project_filename)
-
- if !empty(l:full_path)
- return fnamemodify(l:full_path, ':h')
- endif
- endfor
-
- return ''
-endfunction
-
-" Given a buffer number, search for a project root, and output a List
-" of directories to include based on some heuristics.
-"
-" For projects with headers in the project root, the project root will
-" be returned.
-"
-" For projects with an 'include' directory, that directory will be returned.
-function! ale#handlers#c#FindLocalHeaderPaths(buffer) abort
- let l:project_root = ale#handlers#c#FindProjectRoot(a:buffer)
-
- if empty(l:project_root)
- return []
- endif
-
- " See if we can find .h files directory in the project root.
- " If we can, that's our include directory.
- if !empty(globpath(l:project_root, '*.h', 0))
- return [l:project_root]
- endif
-
- " Look for .hpp files too.
- if !empty(globpath(l:project_root, '*.hpp', 0))
- return [l:project_root]
- endif
-
- " If we find an 'include' directory in the project root, then use that.
- if isdirectory(l:project_root . '/include')
- return [simplify(l:project_root . '/include')]
- endif
-
- return []
-endfunction
-
-" Given a List of include paths, create a string containing the -I include
-" options for those paths, with the paths escaped for use in the shell.
-function! ale#handlers#c#IncludeOptions(include_paths) abort
- let l:option_list = []
-
- for l:path in a:include_paths
- call add(l:option_list, '-I' . ale#Escape(l:path))
- endfor
-
- if empty(l:option_list)
- return ''
- endif
-
- return ' ' . join(l:option_list) . ' '
-endfunction