An application wants to shell text out to vim and know what edits are being made, in real time.
The .swp file provides this information. Can anyone provide guidance on how to read this binary file, say, with Python?
I did my own investigation into .swp file formats when I wrote my ls.swp tool that views .swp contents (that's a perl script with lots of documentation in it).
My key sources of interest were:
Parsing this required a bit of reverse-engineering, and I was only able to extract certain data. All I wanted to get out of it was some basic information about the status of the edited file. My results look like this:
$ ls.swp .ls.swp.sw*
.ls.swp.swo:adamhotep@tabasco:~/git/misc-scripts/ls.swp (running) 85d ago
.ls.swp.swp:adamhotep@tabasco:~/git/misc-scripts/ls.swp 85d ago
I'm rather certain you're not going to get any real-time data since that'd just be a big pile of disk I/O for vim to maintain.
I wouldn't rely on the swapfile contents to get real-time updates. Its format is geared towards Vim's uses, and its format isn't documented other than by its implementation. You would have to duplicate large parts of the algorithm, and maintain that whenever the internal format changes (without prior notice).
Alternatively, I would use one of the embedded languages (e.g. Python) to interface with the outside program that wants to get real-time updates. A Python function could periodically send along the entire buffer contents on a socket, for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With