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

"E325: ATTENTION" does not appear when a swapfile exists #672

Closed
cwfoo opened this issue Jan 31, 2021 · 12 comments
Closed

"E325: ATTENTION" does not appear when a swapfile exists #672

cwfoo opened this issue Jan 31, 2021 · 12 comments

Comments

@cwfoo
Copy link

cwfoo commented Jan 31, 2021

Does this bug happen when you install plugin without vim-polyglot?

Not applicable because the problem is with vim-polyglot itself (ftdetect/polyglot.vim).

Describe the bug:

When opening a file that has a swapfile, E325: ATTENTION will not be shown.

This bug was introduced in v4.16.0 in commit 739102e.

To Reproduce:

  1. Add set swapfile to your Vim configuration file.
  2. Open a new file in Vim (e.g. test.py) and save it. Do not close Vim.
  3. Open the file from step (2) in another instance of Vim.

Observation: E325: ATTENTION does not appear in step (3).

Expected behavior: E325: ATTENTION appears.

Please make this behavior optional.

@kronion
Copy link

kronion commented Feb 23, 2021

Related to #638. The noswapfile change was reverted, but vim still does not prompt the user when a swapfile already exists. Instead, it starts a new swapfile, eg. [filename].swo. This means that the preexisting swapfile ([filename].swp) sits around unused and forgotten about.

It's possible to manually recover the existing swapfile with :recover, but I doubt many vimmers know to do this, especially if they never had to before. This plugin changes the behavior on them silently.

@jaawerth
Copy link

If this is left as the default, I'd at least strongly request that it be documented somewhere prominent in the README, if not print a warning upon install/upgrade; set shortmess+=A changes an important assumption about a core (n)vim behavior, and it isn't something one would expect a plugin that manages syntax files to change without warning the user.

I myself finally got to the point where I grepped my entire ~/.config/nvim directory for it to figure out which plugin was letting me open the same file in two different instances without warning me unless I attempt to save one after changing it from the other.

@cwfoo
Copy link
Author

cwfoo commented Apr 23, 2021

For those who want to avoid this problem, and who don't mind running an older version of vim-polyglot from October 2020:

git checkout f52f6b95
# Or equivalently:
git checkout v4.16.0~1

@Farzat07
Copy link

Farzat07 commented Apr 23, 2021

let g:polyglot_disabled = ['sensible'] should solve the problem.

Really though - this functionality is really annoying and should be at least documented, or even better, removed.

If one doesn't like swap file warnings they can edit their own vimrc - that's what the file is there for.

@smemsh
Copy link

smemsh commented May 14, 2021

I am not sure what is the relation to vim-sensible? This does not fix the problem and I don't see shortmess anywhere in sensible plugin, what am I missing?

The problem is here in init.py from autoload introduced in commit 05b8bbc and seems to come from #613. The comment is:

This is needed to avoid swapfile warning when auto-reloading

but seems to ignore that the swapfile warning is used in many other contexts.

If polyglot is starting to go around changing random global settings this is sure to cause problems; what one person thinks is no big deal, another will find disastrous. In no way should polyglot be changing global settings like this, which break core vim assumptions. It's for syntax highlighting.

This commit brazenly changes shortmess, this is nuts. People have vim settings for a reason. Not quite as crazy as disabling swap files but it's up there...

@smemsh
Copy link

smemsh commented May 14, 2021

ok, now I see that the new shortmess setting is protected under

if !has_key(g:polyglot_is_disabled, 'sensible')

trying this in polyglot_is_disabled did not work for me because it was getting overwritten later in my config. I can confirm it does work when disabling it correctly. I suppose that makes it better but this is certainly surprising and I don't think it should be the default. It's written in the main project README that it uses vim-sensible, but that never caused issues before and I wouldn't dream it would be messing with these kinds of settings (I don't see anything with shortmess in tpope's vim-sensible either).

I did overwrite files which had other editing sessions because of this, which is what led me here. I do rely on vim to tell me if a file edit is actually open somewhere else. I imagine many people do. I also think people wouldn't necessarily want to disable all of sensible just to get their shortmess sane.

smemsh added a commit to smemsh/.vim that referenced this issue May 14, 2021
this thing disabled "file is already open" messages in a syntax
highlighting bundle, amazing

see sheerun/vim-polyglot#672
@ZeroKnight
Copy link

ZeroKnight commented Jun 9, 2021

I found this issue when I realized my swapfile setting was disabled and A mysteriously wound up in my shortmess...

Why is "sensible" even part of this plugin, let alone enabled by default? Setting things like noswapfile and shortmess+=A globally is well beyond the scope of a filetype plugin; users can make these choices on their own. Why is vim-sleuth bundled in this plugin? If users wanted sleuth, they should just install sleuth...

I appreciate the time and effort put into assembling so many filetype plugins into a single collection. However, these inclusions are unnecessary bloat at best, and at worst duplicate and possibly conflict with user settings and/or the plugins being emulated here. Please consider removing them, or at the very least leave them disabled by default. This is frankly a very puzzling and out-of-place addition with surprising behavior.

[EDIT] noswapfile is not set globally, I misinterpreted my grep output.

@sheerun
Copy link
Owner

sheerun commented Jun 9, 2021

A means: don't give the "ATTENTION" message when an existing swap file is found. Setting it or not doesn't matter if swapfile is disabled by user. Vim-polyglot sets defaults for some settings that are relevant for good language support. Disabling this message is necessary for auto-reloading of buffers if multiple vim windows are used, otherwise you'd need to confirm warning in each of the windows.

@sheerun
Copy link
Owner

sheerun commented Jun 9, 2021

Related to #638. The noswapfile change was reverted, but vim still does not prompt the user when a swapfile already exists. Instead, it starts a new swapfile, eg. [filename].swo. This means that the preexisting swapfile ([filename].swp) sits around unused and forgotten about.

It's automatically removed when vim closes, unless someone exited vim in crashing fashion, like closing terminal window instead of exiting Vim first. In this case swapfiles being left on the disk is proper behavior to prevent potential losses.

It's possible to manually recover the existing swapfile with :recover, but I doubt many vimmers know to do this, especially if they never had to before. This plugin changes the behavior on them silently.

If they want to recover something, they will for sure google for "vim recover file" which explains this command.

@ZeroKnight
Copy link

ZeroKnight commented Jun 9, 2021

A means: don't give the "ATTENTION" message when an existing swap file is found. Setting it or not doesn't matter if swapfile is disabled by user.

Sorry, I'll have to retract that part; I misread my grep output and conflated some unrelated setl noswapfile lines for scratch buffers with the sensible section. I didn't catch it at first because I was checking set swapfile? at the vim-startify splash screen, which locally sets noswapfile (I should have checked in an empty buffer). Kindly disregard.

Disabling this message is necessary for auto-reloading of buffers if multiple vim windows are used, otherwise you'd need to confirm warning in each of the windows.

The "Attention" prompt would only be shown in windows with modified buffers, which I think is a reasonable warning; unmodified ones would still reload without the prompt. I see the value in disabling the message and just using :recover when needed, but I don't agree that it should be the default.

@sheerun
Copy link
Owner

sheerun commented Jun 9, 2021

The "Attention" prompt would only be shown in windows with modified buffers

All buffers can be modified e.g. when you checkout a commit, then you need to manually "unblock" all instances by confirming ATTENTION message in each of the windows individually

@sheerun sheerun closed this as completed in e3ad29c Jun 9, 2021
@bb010g
Copy link

bb010g commented Aug 6, 2021

Disabling this message is necessary for auto-reloading of buffers if multiple vim windows are used, otherwise you'd need to confirm warning in each of the windows.

https://github.com/chrisbra/Recover.vim handles this case without disrupting normal swapfile usage. Adding A to 'shortmess' stops any autocommands for the SwapExists event from working, as neither vim -r nor :recover trigger the SwapExists event.

bb010g added a commit to bb010g/dotfiles that referenced this issue Oct 5, 2022
this issue is, in
`vim-polyglot/autoload/polyglot/init.vim`:

```vim
if !has_key(g:polyglot_is_disabled, 'sensible')
  " ...

  " This is needed to avoid swapfile warning when auto-reloading
  set shortmess+=A

  " ...
endif
```

see <sheerun/vim-polyglot#672>.

this happens upon sourcing the file. I could figure out a way to prevent this,
but this patch works for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants