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

Does not survive session save and restore #56

Open
poetaman opened this issue Jun 18, 2021 · 4 comments
Open

Does not survive session save and restore #56

poetaman opened this issue Jun 18, 2021 · 4 comments

Comments

@poetaman
Copy link

poetaman commented Jun 18, 2021

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:

  1. Full path of file that is actually open at the time of exiting vim.
  2. A way of knowing that current buffer is a vim-plugin-viewdoc buffer, &filetype correctly 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.

@powerman
Copy link
Owner

powerman commented Jun 18, 2021

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 😄). 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.

@poetaman
Copy link
Author

poetaman commented Jun 18, 2021

@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.

@powerman
Copy link
Owner

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

" call s:OpenBuf('doc') open existing '[Doc]' buffer (create if not exists)
" call s:OpenBuf('new') create and open new '[DocN]' buffer
function s:OpenBuf(target)
let bufname = escape(s:bufname, '[]\')
let [tabnr, winnr, bufnr] = s:FindBuf(bufname)
if a:target ==# 'new'
let s:bufid = s:bufid + 1
let bufname = substitute(bufname, '\(\]\?\)$', s:bufid . '\1', '')
execute g:viewdoc_open . ' ' . bufname
elseif tabnr == -1
execute g:viewdoc_open . ' ' . bufname
else
execute 'tabnext ' . tabnr
execute winnr . 'wincmd w'
endif
if g:viewdoc_only
only!
endif
setlocal noswapfile buflisted buftype=nofile bufhidden=hide
endfunction

@poetaman
Copy link
Author

@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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants