vim-plugin-viewdoc
vim-plugin-viewdoc copied to clipboard
Does not survive session save and restore
I use vim's sessions quite a lot, and this is one big disadvantage that I see in my testing of vim-plugin-viewdoc: The help file opened by it does not survive session save and restore. This disadvantage does not exist for vim help documentation opened using inbuilt :help command. User can detect the filetype upon restoring a session and make it behave exactly as if it was opened using :help and not opened as a file with :e <path_to_file> (which does not guarantee jumps to work for all references).
There are multiple ways to go about creating a perception that vim-plugin-viewdoc's buffer survives across sessions.
At the very least, it would be good to know 2 things:
- Full path of file that is actually open at the time of exiting vim.
- A way of knowing that current buffer is a vim-plugin-viewdoc buffer,
&filetypecorrectly says "help". Trying to do a regex match on file name\[Doc[0-9]+\]does not look the cleanest.
I think this would be sufficient for users who care about making vim-plugin-viewdoc's buffers survive across sessions.
AND perhaps you could add full support by using SessionLoadPost auto command to iterate over buffers and convert them to respective vim-plugin-viewdoc buffers & give users a new global variable to enable/disable that functionality.
Well, I didn't know :help does survive session save/load. Not sure how I missed this, maybe it was implemented in vim after viewdoc release date (i.e. in last 9 years or so :smile:). This is a cool feature and I'd like to have it in viewdoc. But, to be honest, unlikely I'll have enough spare time to implement it anytime soon. So, PR is welcome.
@powerman Ok, same here, times are a bit busy to read through your code and send a PR in coming weeks. What about the minimal information that I ask? 1) full filename+path of current file, 2) way of knowing that current buffer is a vim-plugin-viewdoc's buffer? Don't you already have that information available at your disposal in the plugin somewhere?
If you could provide that, then at least I will be able to make it going in my vimrc. Then maybe at a later point a clean PR could be sent.
In last years there was about 1 commit/year with minor updates, so I don't have viewdoc code base at the top of my head now.
AFAIR in most cases (doc sources) we don't have any source file, viewdoc run external tools and gather it output into vim buffer.
As for detecting viewdoc buffers - there was some way. One probably depends on concrete viewdoc plugin: usually they define a custom &ft value, like when you open documentation for Go you'll see ft=godoc, when you open documentation for shell script you'll see ft=man, etc. This was supposed to be used for doc-specific syntax highlight, but may be useful for you too. Or you may try to add some fixed marker into https://github.com/powerman/vim-plugin-viewdoc/blob/0a936155c3d62b3d1bb1453a5ee55d8639bc4d40/plugin/viewdoc.vim#L279-L299
@powerman The way :help partially survives session save and restore is that it does not change the buffer's filename like vim-plugin-viewdoc does. If you try doing :echo expand('%:p') from a help buffer opened by :help, it will show the full path of file. While restoring the session, vim would open this file using usual :edit command, then a user can fully restore :help functionality in that buffer by processing it.
I see... if there is no source file, then it would be hard to save state and restore it. At least for the sources like vim help, man pages, etc that do have a file, a function that returns file name would be ideal.
A hacky way of checking if its a viewdoc buffer would be to look if a buffer local variable b: unique to viewdoc exists...