Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings not applied for files in new directory #126

Open
sersorrel opened this issue Jul 29, 2019 · 4 comments
Open

Settings not applied for files in new directory #126

sersorrel opened this issue Jul 29, 2019 · 4 comments
Labels

Comments

@sersorrel
Copy link

If you edit a file which does not exist, editorconfig settings are applied, but if you edit a file in a directory which does not exist, editorconfig settings are not applied.

~/.editorconfig:

[*.js]
indent_style = space
indent_size = 2

vim foo.js, :verb set et? sw?:

  expandtab
        Last set from ~/.vim/plugged/editorconfig-vim/plugin/editorconfig.vim line 547
  shiftwidth=2
        Last set from ~/.vim/plugged/editorconfig-vim/plugin/editorconfig.vim line 563

vim foo/bar.js, :verb set et? sw?:

noexpandtab
  shiftwidth=8
@cxw42
Copy link
Member

cxw42 commented Jul 30, 2019

I can reproduce this on Vim 8.0 + 1-1453 on Ubuntu. Thanks for reporting!

For context, what is your use case? I agree this is a surprising behaviour, but there's not much you can do with a file in a nonexistent directory :) .

@sersorrel
Copy link
Author

I have the following snippet in my vimrc, which automatically creates any missing directories on save (credit to Stack Overflow):

fun! s:CreateNonexistentDirs(file, buf) abort
	if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
		let dir=fnamemodify(a:file, ':h')
		if !isdirectory(dir)
			call mkdir(dir, 'p')
		endif
	endif
endfun
augroup BWCCreateDir
	au!
	au BufWritePre * :call s:CreateNonexistentDirs(expand('<afile>'), +expand('<abuf>'))
augroup end

@cxw42
Copy link
Member

cxw42 commented Jul 31, 2019

Nice!

@cxw42
Copy link
Member

cxw42 commented Aug 18, 2019

Per editorconfig/editorconfig-vote#8, nonexistent directories should now be treated as if existing and empty. Therefore, this is officially a bug in the editorconfig-vim plugin, and I have labeled it as such. Thanks for reporting! It's on the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants