equalsraf / neovim-qt

Neovim client library and GUI, in Qt5.
https://github.com/equalsraf/neovim-qt/wiki
ISC License
1.85k stars 171 forks source link

[Feature Request] Ability to run a command when the GUI is started #265

Closed qwfy closed 2 years ago

qwfy commented 7 years ago

nvim has an option -c <command>: Execute <command> after loading the first file, this allows one to run a command when nvim starts, however, some command is better to be run when the GUI has started, because they rely on the dimension of the GUI, (for example, the plugin xolox/vim-session, which stores the window split information, so, nvim-qt --maximized -- -c 'OpenSession somesession' and nvim-qt -- -c 'OpenSession somesession' then maximize manually gives different split layout).

will something like nvim-qt --execute-command somecmd be implemented?

equalsraf commented 7 years ago

Maybe. Would this be equivalent of placing those commands in ginit.vim?

justinmk commented 7 years ago

Nvim-qt could just publish GuiEnter (after attaching).

doautocmd GuiEnter
qwfy commented 7 years ago

@equalsraf no, they are not equivalents, if placed in ginit.vim, those commands will be run for every GUI I started, (unless of course, you place some guards around it), while passing them using command line only affects that one process.

a use case would be, you are working on a project, every morning you start up the server and other stuff, and finally start nvim-qt --exec-command-after-everything-is-loaded 'OpenSession somesession' and pickup where you left yesterday, and you can put all these in a script and execute that script instead doing them manually every day.

this can also be achieved by something like a "project-wise init script", which means you put an additional ginit.vim in the project directory, and exec nvim-qt there.

equalsraf commented 2 years ago

I don't think we can avoid the need for "guards" around whatever option we choose here. The UI setup means neovim can have multiple UIs attaching to it at any time.

To summarize there are 2 options available for this, that produce a similar outcome

  1. put commands in ginit.vim
  2. call your commands as part of UIEnter event for autocmd

However there is no way to have a single call without some guard/lock around it, and I think this is for the best. We have cases where we actually want to be called every time, singleton cases are not that common and probably require some specific checks.