idanarye / vim-dutyl

Coordinate D tools to work together for you
http://www.vim.org/scripts/script.php?script_id=5003
79 stars 13 forks source link

dfmt and indentation #31

Open John-Colvin opened 8 years ago

John-Colvin commented 8 years ago

I've been having problems with the dfmt integration for indentation. There are two problems with it:

1) it doesn't integrate well with vim indentation settings (I guess this is just unavoidable) 2) dfmt doesn't seem to be picking up on .editorconfig files correctly when used through dutyl

Is there a convenient way to turn off using dfmt for indentation and let vim handle it normally?

idanarye commented 8 years ago

You can try :call dutyl#register#tool('dfmt', '') to disable dfmt completely, but then you won't get it for formatting(gq) either. I'll add separate flags for disabling it for each feature.

As for .editorconfig support - it works fine for me, but I try and help you debug. dfmt should be picking the config file by itself(no help from dutyl required), so it shouldn't be causing dutyl-specific problems, unless...

There is one scenario I know of where dfmt won't recognize .editorconfig when used via dutyl. Say your working directory(:pwd) is /a and you are editing /a/b/c.d and your .editorconfig is at /a/b/.editorconfig. Dutyl is not invoking dfmt directly on your file - it pipes your code to it through STDIN. This means that dfmt will think it's in /a and won't be able to use the .editorconfig in the /a/b subdirectory.

Is this you scenario?

idanarye commented 8 years ago

Pull the latest develop and put in your .vimrc:

let g:dutyl_dontHandleFormat = 1
let g:dutyl_dontHandleIndent = 1

(or just one of them)

John-Colvin commented 8 years ago

So this is what I have:

% cd test
% cat .editorconfig
root = true

[*.{d,js,es6,json,sdl}]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4
tab_width = 4
% cat blah.d 
struct S
{
int a;
}
% dfmt blah.d
struct S
{
    int a;
}

so as you can see, dfmt correctly indents with a single tab (also works if I do dfmt < blah.d so it's not a stdin v.s. file argument problem in dfmt).

However, when I do vim blah.d and then =G to indent everything, I get this:

struct S
{
 int a;
}

which is just a single space. If I add

let g:dutyl_dontHandleFormat = 1
let g:dutyl_dontHandleIndent = 1

to my .vimrc the indenting matches my vim settings, as expected.