Comments (5)
Hey,
I was having some issues with this with respect to 2 usecases:
- plugin https://github.com/terryma/vim-multiple-cursors, which seems to trigger a change event each character entered, which especially when using many cursors in a bigger file, make it quite slow. Also because writing the file would trigger my completion engine to reparse the file, and I have semantic highlighting that would get updated after each write.
- another issue I had was with one particular file that was specifying a database of values in a big C source file (40k+ lines), and my completion engine would reparse it all the time even when I was editing another file while this file was in another buffer open (not sure why it was doing that, but still), which uses a lot of cpu, and I'm speculating it would trigger some communication of a huge completion database (I think) between the completer executable and vim, which seemed to be blocking (is vim really multithreaded? could be something else though).
A little bit of research seems to indicate that job_start
/jobstart
is not the correct tool to asynchronously trigger a vim command such as the saving of a buffer, it seems to be only for triggering external commands/executables asynchronously.
Also in my case I was thinking if there was a maximum frequency of saving the file, of say 5 seconds or so, that would lessen the vim-multiple-cursors issue.
One way I could think of, based on very little vimscript knowledge and not very well researched atm though, to accomplish this asynchronous write, is to use vim's timer_start()
functionality to start some 'worker thread' that checks if an event has occurred for a particular buffer, and then saves that buffer (or all buffers depending on the autosave settings).
The autosave events could, for example, add the name of the buffer they are triggered for to a queue that is shared with and checked in the 'worker thread' every so often.
Although I'm not sure how this timer works, is it really in another thread or would it be blocking anyway? And if it is in another thread, is it even possible to have a shared queue that is 'threadsafe'? Also this could introduce a number of issues that should be handled.. for example: when you switch to a shell you'd expect the files to be saved before compiling/interpreting the source code you just edited, and not have to wait a second or 2 (depending on the setting), so maybe also force writing on FocusLost
event or something (though iirc that this FocusLost only works in gvim, not in the shell).
But yeah, just a thought that might inspire someone (maybe me later, I have a some holidays coming up).
from vim-auto-save.
@qsdrqs Hello! Thank you for your question! Unfortunately, I'm not able to support this project anymore. But the source code of the plugin is very simple. It would be great if you try to implement and test the feature you asked by yourself. Please, create a PR if it will work. Have a good day!
from vim-auto-save.
Ok, I will have a try soon.
from vim-auto-save.
@Frydac great comment!
from vim-auto-save.
Hey,
I was having some issues with this with respect to 2 usecases:
* plugin https://github.com/terryma/vim-multiple-cursors, which seems to trigger a change event each character entered, which especially when using many cursors in a bigger file, make it quite slow. Also because writing the file would trigger my completion engine to reparse the file, and I have semantic highlighting that would get updated after each write. * another issue I had was with one particular file that was specifying a database of values in a big C source file (40k+ lines), and my completion engine would reparse it all the time even when I was editing another file while this file was in another buffer open (not sure why it was doing that, but still), which uses a lot of cpu, and I'm speculating it would trigger some communication of a huge completion database (I think) between the completer executable and vim, which seemed to be blocking (is vim really multithreaded? could be something else though).
A little bit of research seems to indicate that
job_start
/jobstart
is not the correct tool to asynchronously trigger a vim command such as the saving of a buffer, it seems to be only for triggering external commands/executables asynchronously.
Also in my case I was thinking if there was a maximum frequency of saving the file, of say 5 seconds or so, that would lessen the vim-multiple-cursors issue.One way I could think of, based on very little vimscript knowledge and not very well researched atm though, to accomplish this asynchronous write, is to use vim's
timer_start()
functionality to start some 'worker thread' that checks if an event has occurred for a particular buffer, and then saves that buffer (or all buffers depending on the autosave settings).
The autosave events could, for example, add the name of the buffer they are triggered for to a queue that is shared with and checked in the 'worker thread' every so often.
Although I'm not sure how this timer works, is it really in another thread or would it be blocking anyway? And if it is in another thread, is it even possible to have a shared queue that is 'threadsafe'? Also this could introduce a number of issues that should be handled.. for example: when you switch to a shell you'd expect the files to be saved before compiling/interpreting the source code you just edited, and not have to wait a second or 2 (depending on the setting), so maybe also force writing onFocusLost
event or something (though iirc that this FocusLost only works in gvim, not in the shell).
But yeah, just a thought that might inspire someone (maybe me later, I have a some holidays coming up).
Hello Frydac! I have made some experiments about timer_start()
. Unfortunately, it only wait for several time asynchronously and still call the function in sync way. You can add sleep 5
in Do_Save()
function then you can find out it still run in sync way.
I asked for a vim community about this question. However, They told me that there is no way to save file in async way because it would be unsafe if people change their file when saving. Thus there may be not any way to implement it. Sorry about that.
from vim-auto-save.
Related Issues (20)
- Any idea to disabe auto save for some file type? HOT 2
- don't touch file if no changes has been made HOT 2
- Undo list is modified for every repetition of a macro HOT 1
- Don't work with "Ctrl + C" way to leave insert mode HOT 5
- Isn't working as desired with TextChangedI HOT 4
- what is the interval after which autosave will work? HOT 3
- Normal mode only? HOT 3
- Throttling / batching for InsertLeave and TextChanged HOT 2
- Undo not working on go files when auto-save is enabled. HOT 1
- Plugin breaks jump for snippets HOT 1
- Duplicate entry is created in undo history HOT 4
- Feature request: settings to exclude some files HOT 2
- Installation directions for people who don't have vundle HOT 1
- Autosave only after the file is written HOT 2
- Change from 24 hour time to AM/PM HOT 2
- Save file, after window lose focus. HOT 2
- Enable auto-save only on git folders HOT 2
- Error while opening fuzzy finder listing buffer
- Offer to help facilitate maintenence HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-auto-save.