editorconfig / editorconfig-vim

EditorConfig plugin for Vim
http://editorconfig.org
Other
3.14k stars 139 forks source link

Use the correct filename when applying settings to an empty buffer #209

Closed cxw42 closed 1 year ago

cxw42 commented 1 year ago

When running in an autocmd, % is not necessarily the buffer the autocmd applies to. Instead, it turns out you have to use <afile> and <abuf> for that (ref.). Therefore, change all the references to % to refer to the relevant buffer by number.

Additionally, for consistency, replace setlocal calls with setbufvar() calls to the numbered buffer. That way, all the changes will affect the same buffer.

Fixes #208.

xuhdev commented 1 year ago

Just in case, are you expecting review?

cxw42 commented 1 year ago

@xuhdev would you be willing to try this branch and see if it works for you? I have been pretty much AFK on personal projects since I opened this :( . Please let me know either way. Thanks!

xuhdev commented 1 year ago

Could you rebase the changes? Looks like I have no permission to push the rebased change.

xuhdev commented 1 year ago

I also tested the changes locally and I haven't encountered any problems with either named or unnamed buffers.

cxw42 commented 1 year ago

@xuhdev thanks! I have rebased/resolved/force-pushed. I am going to run with this branch for a little bit just in case I missed anything, and then merge the PR.

yous commented 1 year ago

Hi, recently I have an issue with editorconfig-vim after this PR merged.

test.vimrc:

set nocompatible

call plug#begin()
Plug 'editorconfig/editorconfig-vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
call plug#end()

autocmd FileType c EditorConfigReload

.editorconfig:

root = true

[*]
tab_width = 8

test.c:

#include <stdio.h>

int main() {
  int x = 1;
  printf("%d\n", x);
  return 0;
}

How to reproduce the problem:

I couldn't reduce test.vimrc further as I don't know much about popup windows. I've also run git bisect, and it pointed e269673.

cxw42 commented 1 year ago

@yous Open at #224