Wednesday, June 24, 2015

Re: gvim colorscheme is run before global variables restored

On Wed, Jun 24, 2015 at 6:45 PM, Nikolay Pavlov <zyx.vim_AT_gmail.com>
wrote:
> 2015-06-25 1:24 GMT+03:00 Paul <paul.domaskis_AT_gmail.com>:
>> My color scheme checks for the existence of a global variable
>> g:Lapscreen and modified colours accordingly. The colorscheme is
>> invoked from my vimrc. I have sessionoption set to include globals
>> so that the colorscheme does the right thing when my session is
>> restored -- or rather, that's what I'm aiming to accomplish.
>>
>> When I restore a session, however, the my colorscheme is invoked as
>> if g:Lapscreen doesn't exist. Would I be correct in assuming that
>> the globals are restored *after* the colorscheme is invoked? I
>> examined my session file and found no invocation of my colorscheme.
>
> Check out :h initialization. It contains all necessary answers
> (note: it is not explicitly mentioned *there* (it is in :h -S), but
> -S and -c are processed in the same loop in the same initialization
> stage).
>
> Note that &sessionoptions setting that allows disabling almost
> everything is a great hint on *why* initialization is being done in
> this order: it is rather explicit that session file assumes that
> most of the initialization is done prior to loading it or omitting
> e.g. options or mappings would not work normally (there are three
> main variants:
>
> 1. Sessions are loaded prior to doing normal initialization: saving
> mappings, options and globals in session files is almost pointless
> because this way vimrc will simply override options from session.
> 2. Sessions are loaded *instead* of regular initialization:
> *omitting* to save mappings, options and globals damages user
> experience, especially given that most plugin managers require user
> to have something in vimrc for plugins to work meaning that more
> things need to be saved to work properly.
> 3. Sessions are loaded after regular initialization: mostly has no
> problems, except cases like yours.

Huh. The initialization help page is indeed very informative.

The vimrc is run in phase/step#3, while buffers are loaded in step#11.
And the -S file that capture the past session are run *after* the
first file is loaded. I'm assuming that this means after the 1st
buffer is loaded. If that's the case, then it's clear why g:Lapscreen
is not set when colorscheme is run -- globals are restored in step#11.

Oh well. I guess it's not too much trouble to type ":color mine".
Thanks.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: