From 47a10a7d72b4b15d71c9475d4df37c8e29e2cc77 Mon Sep 17 00:00:00 2001 From: Arnaud TANGUY Date: Fri, 9 Oct 2015 14:52:18 +0900 Subject: [PATCH] Make style lookup consistent with clang-format The current version was using -style=file option only, causing failure if pwd != file's directory. 2 kinds of failures occur: - If no .clang-format is present in PWD, and one is present in the file's directory, then clang-format fails for lack of style file, and dump its error message directly into the buffer - If a .clang-format is present in PWD, and one is present in the file's directory, then the wrong .clang-format from PWD is used This commit makes the behavior fully consistent with clang-format: - lookup .clang_format in the file's directory and recursively go up its parent directory until found. If no style file is found, defaults to g:clang_format#style_options --- autoload/clang_format.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/autoload/clang_format.vim b/autoload/clang_format.vim index f718439..939ec13 100644 --- a/autoload/clang_format.vim +++ b/autoload/clang_format.vim @@ -148,15 +148,16 @@ let g:clang_format#auto_formatexpr = s:getg('clang_format#auto_formatexpr', 0) function! s:detect_style_file() let dirname = expand('%:p:h') let style_file_name = has('win32') || has('win64') ? '_clang-format' : '.clang-format' - return findfile(style_file_name, dirname.';') != '' + return findfile(style_file_name, dirname.';') endfunction function! clang_format#format(line1, line2) let args = printf(" -lines=%d:%d", a:line1, a:line2) - if ! (g:clang_format#detect_style_file && s:detect_style_file()) + let style_file = s:detect_style_file() + if ! (g:clang_format#detect_style_file && style_file != '') let args .= printf(" -style=%s ", s:make_style_options()) else - let args .= " -style=file " + let args .= " -style=file --assume-filename=".style_file endif let args .= g:clang_format#extra_args let clang_format = printf("%s %s --", g:clang_format#command, args)