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

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

Merged
merged 5 commits into from
Aug 7, 2023

Conversation

cxw42
Copy link
Member

@cxw42 cxw42 commented Jan 21, 2023

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.

@cxw42 cxw42 marked this pull request as ready for review January 21, 2023 23:15
@cxw42 cxw42 self-assigned this Jan 21, 2023
@cxw42 cxw42 added the Bug label Jan 21, 2023
@cxw42 cxw42 force-pushed the issue208 branch 3 times, most recently from 65b8c87 to 6ce4a81 Compare January 21, 2023 23:39
@xuhdev
Copy link
Member

xuhdev commented May 21, 2023

Just in case, are you expecting review?

@cxw42
Copy link
Member Author

cxw42 commented May 27, 2023

@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
Copy link
Member

xuhdev commented Jul 10, 2023

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

@xuhdev
Copy link
Member

xuhdev commented Jul 10, 2023

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

cxw42 added 4 commits July 15, 2023 14:26
- Rather than just skipping the buffer, say why it was skipped if
  g:EditorConfig_verbose is truthy.
- Don't print the "Applying EditorConfig" message until we're sure
  we won't be skipping this buffer.
A micro-optimization.  Check the exclude patterns first since those can be done
on-CPU.  Then, if the file isn't pattern-excluded, check for files on disk.
This sets up for a fix in the next commit to use the correct buffer
when running in an autocommand.
In an autocmd (e.g., BufNew), `%` may not be the buffer being processed.
Use `<afile>` and `<abuf>` in those cases instead.
@cxw42
Copy link
Member Author

cxw42 commented Jul 15, 2023

@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.

If the buffer had no fileencoding, and we changed fenc to match the Vim-wide
encoding, we haven't actually changed the file.  However, we have set
modified on the buffer by virtue of assigning fenc.  In this case, set
nomodified since we didn't actually change anything.

This affects new buffers created during the VimEnter autocmd.
@cxw42 cxw42 merged commit e014708 into editorconfig:master Aug 7, 2023
@cxw42 cxw42 deleted the issue208 branch August 7, 2023 01:55
cxw42 added a commit to cxw42/toolconfig-vim that referenced this pull request Aug 7, 2023
@yous
Copy link
Contributor

yous commented Aug 16, 2023

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:

  • Run vim -u test.vimrc test.c
  • Place the cursor anywhere except the first column
  • Run :FZF
  • Press Esc to close the popup
  • The cursor goes to the first column of line 1

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
Copy link
Member Author

cxw42 commented Aug 19, 2023

@yous Open at #224

@cxw42 cxw42 mentioned this pull request Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autocmds: use correct buffer name
3 participants