akiyosi / goneovim

A GUI frontend for neovim.
MIT License
2.36k stars 59 forks source link

Errors calling Goneovim commands during initialization #440

Open mars0i opened 1 year ago

mars0i commented 1 year ago

I don't know whether this is an issue--maybe only a question.

I define some vim functions that configure the goneovim window. Some of these functions calls the new GonvimWinPos command. The commands work if I entered them at at the : prompt. However, they usually won't work in my initialization script .vim/vimrc. If I put the line Code in .vim/vimrc, I two similar errors. The first is "E492: Not an editor command GonvimWinpos 400 0" from this script, which is called from .vim/vimrc:

function! Tall()
    set lines=59
    GonvimWinpos 400 0
endfunction
function! CodeWide()
    set columns=100
    call Tall()
    GonvimWinpos 980 0
endfunction
command! Code call CodeWide()

However, if I enter Code at the : prompt, it always works.

I don't always get the error! Sometimes columns gets set to 100, and the window is moved to the correct position, but the lines are not set to 59.

Is there a special way to call goneovim commands during initialization? (Could there be a race conditions, since it works sometimes??)

Thanks!

akiyosi commented 1 year ago

@mars0i Hi :) Thanks for the issue report!

Goneovim registers Goneovim's own commands and functions necessary for command execution with neovim at startup. The problem may be a timing issue between this registration process and the vimrc loading process in startup. One solution is to run your vimscript with Ginitvim in settings.toml. Ginitvim is run after the Goneovim initialization process so timing issues do not arise.

[Editor]
# ...
Ginitvim = '''
function! Tall()
    set lines=59
    GonvimWinpos 400 0
endfunction
function! CodeWide()
    set columns=100
    call Tall()
    GonvimWinpos 980 0
endfunction
command! Code call CodeWide()

Code
'''
mars0i commented 1 year ago

Thanks @akiyosi . That's exactly what I wanted to know. Trying that out now. Since the behavior wasn't entirely consistent, I'll wait to see after I run Goneovim several times.

mars0i commented 1 year ago

The Code command is consistently being executed from settings.toml. It works the same way whether I define CodeWide() directly in the Ginitvim block, or source it in another file. I can also just put the commands I want directly into the Ginitvim block, i.e.

Ginitvim = '''
GonvimWinpos 980 0
set columns=100
set lines=66
'''

However, there is one odd thing. GonvimWinpos is executed, and set columnes=100 is executed, but set lines=66 is not. If I then enter Code at the : prompt, the set lines command is executed.

Or if I add sleep 1 before set lines in settings.toml or in the script file that I source from there, then set lines=66 is executed (after a pause, of course).

Maybe set lines needs something that's not yet loaded at first? I don't know. This is not a big problem for me, but I thought I should mention it.

mars0i commented 1 year ago

If I add sleep 100m, set lines works, and the delay is not noticeable to me. So my problem is solved--though the issue is interesting.

mars0i commented 1 year ago

That was on a Macbook Pro. On my Macbook Air, no sleep is needed--maybe because the computer is slower. (It also uses a different MacOS version, but it seems unlikely that that would matter.)

akiyosi commented 1 year ago

@mars0i I imagine that in a fast-processing computer, these commands are instantaneously transmitted to the OS window management system, but there are layers where they are processed asynchronously, so that one may be ignored at certain times.