neoformat icon indicating copy to clipboard operation
neoformat copied to clipboard

Question: Should local config of formatter have higher priority than vim setting e.g. for 'sw'

Open kiryph opened this issue 6 years ago • 5 comments

I was considering to create a pull request for the formatter latexindent for tex files to adjust the defaultIndent setting according to the current return value of shiftwidth() if 'expandtab' is set:

diff --git a/autoload/neoformat/formatters/tex.vim b/autoload/neoformat/formatters/tex.vim
index 2422336..03aa3e2 100644
--- a/autoload/neoformat/formatters/tex.vim
+++ b/autoload/neoformat/formatters/tex.vim
@@ -5,7 +5,7 @@ endfunction
 function! neoformat#formatters#tex#latexindent() abort
     return {
         \ 'exe': 'latexindent',
-        \ 'args': ['-l', '-w'],
+        \ 'args': ['-l', '-w', &expandtab?"-y='defaultIndent: \"".repeat(' ', shiftwidth())."\"'": ''],
         \ 'stdin': 0,
         \ 'replace': 1
         \ }

Note the -y switch has the highest priority for latexindent (Doc Section 4.4):

screenshot 2019-02-10 at 12 00 29

This means if a user has created a localSettings.yaml file in the same directory as the latex file, the value for defaultIndent is overwritten by the way latexindent is called by neoformat.

I am not sure if this is desired.

On the other hand I have tex files where I do not create a localSettings.yaml file and would appreciate if latexindent would respect my 'shiftwidth' and 'textwidth' setting.

What do others think about this?

kiryph avatar Feb 10 '19 11:02 kiryph

I think that makes sense.

Ideally all definitions would look for local settings files so that the user doesn't have to override anything in their init.vim

sbdchd avatar Feb 10 '19 19:02 sbdchd

Do you have a suggestion how can I use a vim setting 'sw' if I do not have a local settings file if the load order is as given by latexindent?

kiryph avatar Feb 11 '19 17:02 kiryph

you can use let shiftwith = &sw or similar to get it as a variable and then just add it to array of args

sbdchd avatar Feb 11 '19 23:02 sbdchd

I think my question was not well written:

Following works as wished

 function! neoformat#formatters#tex#latexindent() abort
     return {
         \ 'exe': 'latexindent',
         \ 'args': ['-l', '-w', &expandtab?"-y='defaultIndent: \"".repeat(' ', shiftwidth())."\"'": ''],
         \ 'stdin': 0,
         \ 'replace': 1
         \ }

The problem is that this always sets the defaultIndent to shiftwidth() and does overwrite a local config file.

kiryph avatar Feb 12 '19 07:02 kiryph

Oh, you'd need to check for the existence of the config file and not add the params when the config file exists. Probably need to walk the directories or similar.

sbdchd avatar Feb 12 '19 12:02 sbdchd