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

Pollution of undo history #48

Open
DerWeh opened this issue Aug 2, 2018 · 5 comments
Open

Pollution of undo history #48

DerWeh opened this issue Aug 2, 2018 · 5 comments

Comments

@DerWeh
Copy link
Contributor

DerWeh commented Aug 2, 2018

First thanks for the great plug-in.

Just one thing is really annoying, every time I save the file, I get a new entry in my undo history for the change of the header. And even worse g; no brings me back to the header, and I am confused for a moment, as I expected to get to the line I changed last.

I don't really know, how to fix this in a sane way, but I would like to propose to changes:

  1. Check &mod. If I didn't modify anything, I don't want my header to show a new modified date (seems saner as the current version anyway right?). This at least gets rid of accidental multiple saves and similar.

  2. Only update the header, if it really changed. If the last changed date is already today, there is no need to update the header. With this the undo history/ last modified position would only be polluted once a day. I could easily bear with that.

@alpertuna
Copy link
Owner

You are right about pollution. It may take time to resolve this. By the time, you may disable auto add / update header using let g:header_auto_add_header = 0 in your .vimrc. In this case you should call :AddHeader or a shortcut when you want to add / update header.

@DerWeh
Copy link
Contributor Author

DerWeh commented Aug 21, 2018

Yes, disabling it is an alternative, sadly I always forget to add the headers then.

Another quick and unsatisfying fix, instead of checking whether the header changed, would be updating the header only once after opening the file.

This can be easily done the following way:
opening the buffer set a variable per auto-command, saving the file sets the header and removes the variable only if it was set.

This is by no means optimal, but should be easy enough to implement and would be in my opinion an improvement to the current situation.

@mg979
Copy link

mg979 commented Sep 17, 2018

Using keepjumps on all call append calls should solve this:

keepjumps call append(...)

See :help :keepjumps

@sQu1rr
Copy link

sQu1rr commented Apr 29, 2020

any progress on this? i hate to be forced to disable the auto-headers :(

@DerWeh
Copy link
Contributor Author

DerWeh commented Oct 16, 2021

It seems like undojoin might be a reasonable fix.

Replace the autocommand with

autocmd BufWritePre * silent! undojoin | :call header#update_header() " Update date when saving buffer

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

4 participants