dhruvasagar / vim-prosession

Handle vim sessions like a pro
254 stars 22 forks source link

Does not work nice with +command #69

Closed jandamm closed 3 years ago

jandamm commented 4 years ago

I'm using neovim as my man command. Basically like this: nvim +Man fzf Since I installed prosession this doesn't work anymore since instead the session is loaded. Is there a way you can determine if vim was started with a command and then don't restore the saved session?

dhruvasagar commented 4 years ago

@jandamm Unfortunately, there's no vim api to determine if there were options passed to vim. The best solution I have so far is using the following command :

vim --cmd "let g:prosession_on_startup=0"

You could use the following in your context :

vim --cmd "let g:prosession_on_startup=0" +Man fzf
dhruvasagar commented 4 years ago

It may be easier to use an alias for the same. Let me know if that works for you.

jandamm commented 4 years ago

Sounds good for common tasks but it's easy to forget for other cases.

I had the idea to delay the initialization a bit and then check if there is only one window with [No Name] after 200ms. Not sure if this is viable though.

dhruvasagar commented 4 years ago

You could try tapping into the custom autocmd autocmd User ProsessionPre ... for something more reliable than waiting for an arbitrary amount of time. That should prove to be more meaningful @jandamm

jandamm commented 4 years ago

Is there a way to stop Prosession from ProsessionPre?

I'm currently trying to replace tmux with nvr and :terminal. If this works out fine, I wouldn't have any issues with Prosession and +command anymore. For now I've added your suggested snippet to man.

alecandido commented 3 years ago

Here the same issue.

I'm trying to use this together with jez/vim-superman, from vman command, that essentially issue:

${EDITOR:-vim} -c "SuperMan $*"

Actually I'd like prosession to run only when I start the editor without any argument, i.e.

Is it possible?

alecandido commented 3 years ago

For whoever would have the same issue for the moment I solved with an horrible hack:

#!/usr/bin/env bash

if [ $# -eq 0 ]; then
  echo "What manual page do you want?"
  exit 0
elif ! man -w "$@" >/dev/null; then
  # Check that manpage exists to prevent visual noise.
  exit 1
fi

RANDOM_FILENAME="ciao"
${EDITOR:-vim} $RANDOM_FILENAME -c "SuperMan $* | bdelete 1"
jandamm commented 3 years ago

@AleCandido nope this isn't possible with prosession. If you want to achieve this you need to start the session from your shell not at vim startup. I've created my own wrapper around vim-obsession but doesn't have the quirks I ran into with vim-prosession (project folders cannot be named *.vim, files won't get saved (you can do it via au but errors are ignored, always creates a session).

Feel free to copy code from it here (I won't make it a plugin): https://github.com/jandamm/dotfiles/blob/master/nvim/.config/nvim/autoload/my/sessions.vim https://github.com/jandamm/dotfiles/blob/master/nvim/.config/nvim/plugin/sessions.vim

To start up into a session I do this:

function nvim() {
    if [ $# -eq 0 ]; then
        command nvim -c 'Session!'
    else
        command nvim $@
    fi
}

:Session! loads the session corresponding to the current folder or silently fails. (You have to :Mksession before it can be saved).

alecandido commented 3 years ago

@jandamm thank you very much. Unfortunately I have to make a more careful merge: I was using prosession without thinking too much, and I liked that it was making all the magic on its own.

Most likely all the magic that I liked it's here:

https://github.com/dhruvasagar/vim-prosession/blob/ad008dbdcd04ee1758f4475263c2a37789d32702/plugin/prosession.vim#L209-L217

but if I have to reintroduce on my own I'll have to dedicate a while and consider what I like of one and the other (at the end of the day a huge part of the job it's done by obsession).

The black magic box was quite appealing on its own, the moment I have to dive in I can customize it properly for my needs (as you did :wink:).

jandamm commented 3 years ago

Unfortunately the all the magic part is the one which isn't working with vman. You can try to disable prosession for this command by setting g:prosession_on_startup to 0 in your shell alias/function.

alecandido commented 3 years ago

You're perfectly right, nothing to say.

Actually I tried to use the let g:prossesion_on_startup=0, but it failed somehow, then I resorted to the bad trick above: since prosession is checking for a file argument I can pass one, whatever, and immediately delete the buffer. It's a hack, but it's working.

For sure session management implementation it's now on my todo list, and yours is the starting point, but since the black box approached failed once the next time I'll do it properly.

blankname commented 3 years ago

@AleCandido, make sure you're using --cmd "let g:prosession_on_startup=0" (runs the command before processing vimrc) in your alias and not -c "let g:prosession_on_startup=0" (runs the command after reading the first file).

Using -c will set the variable after prosession has already done its thing.

alecandido commented 3 years ago

Thank you @blankname, it's actually working! (both for vim and neovim)

But I need to make a script nevertheless, I found no way to do it with an alias...

dhruvasagar commented 3 years ago

@AleCandido @blankname interesting conversation, if you think this is worth sharing with others, would you be able to contribute by adding the details within the README ?

Also I am closing this since it's not really something that can be fixed from within prosession at the moment.

alecandido commented 3 years ago

That's perfect: I can add a section on my hack (put a trivial file and cancel the buffer), but I would suggest to put it in the wiki with a link in the README. @dhruvasagar Tell me what do you prefer.

dhruvasagar commented 3 years ago

@AleCandido Wiki would also work.