Re: What's the exact meaning of the set 'background'?

2006-10-18 Thread A.J.Mechelynck
[EMAIL PROTECTED] wrote:
> "A.J.Mechelynck" <[EMAIL PROTECTED]> 写于 2006-10-19 13:42:46:
>> (I "think" I read the help correctly in
>> understanding that ctermbg=NONE and ctermfg=NONE are not syntactically
> valid
>> settings, but I'm not 100% sure that I understood it correctly.)
>>
>>
>> Best regards,
>> Tony.
> 
> 
> Hi Tony,
> 
> Thanks very much for your through explanation, I'll read it for some more
> time.
> 
> What I can confirm is that you have not correctly understand one thing:
> ctermbg=NONE is valid and this setting is very important for most
> color-scheme developers. It means the background being transparent.
> 
> i.e. when the ctermbg=NONE, the background color will be the same as the
> terminal background, if your terminal can have a semi-transparent
> background, then the background color of the highlight group will be
> semi-transparent. Note that the ctermfg=bg and ctermbg=bg is not possible
> when ctermbg=NONE. And the ctermbg=NONE is the Vim default setting for most
> highlight groups! You must override all those defaults if you don't want
> the background be determined by the terminal instead of your Vim
> colorscheme.
> 
> If you set the ctermbg=Black, then it will always be black, even if your
> terminal has a light background by default. So generally you don't need to
> worry about the default background of your terminal. What you need to do is
> to set ctermbg=Black for Normal highlight group and set ctermbg=bg for all
> the rest of highlight groups which you expect the same background as the
> Normal highlight group.
> 
> If I had not misunderstood the Vim Help document, I should have this: when
> the color scheme overrides all the default values, the 'background' option
> will have no effect since it only changes the default highlight and they
> are all overriden by the color scheme.
> 
> This seems to be a "frozen" way but it works better for me. Consider that
> the gvim will always have the background="light" and the cterm will have
> this determined by the terminal. Many 8-color terminal cannot have a bright
> color as the background so it is not be very portable to design a
> light-background scheme for color terminal. I forced dark background for
> color terminal then nothing need to be detected.
> 
> --
> Sincerely, Pan, Shi Zhu. ext: 2606
> 
> 

This is my (a) method for colorschemes: decide everything. It has the
advantage (to the colorscheme writer) of needing only one set of cterm colours
and one set of gui colours.

Thanks for the clarification about ctermbg=NONE (and, I suppose, ctermfg=NONE).


Best regards,
Tony.


Re: What's the exact meaning of the set 'background'?

2006-10-18 Thread panshizhu
Peter Hodge <[EMAIL PROTECTED]> 写于 2006-10-19 13:44:19:
> Hello,
>
> If you change the background=light, Vim reloads the colorscheme so it has
a
> chance to give you new colors.  But if the colorscheme changes
background=dark
> again, then Vim knows that the colorscheme isn't capable of picking
colors for
> a light background.  In that case, Vim will just ignore whatever the
> colorscheme says and will use default colors instead.
>
> regards,
> peter

This is a good choice anyway, if the colorscheme can only do bg=dark and
the user want bg=light, the defaults are loaded...

However, this "feature" seems to be buggy:

When I'm using a dark-background scheme, I want a light background and type
:set bg=light. It tries to load the color scheme and found the color scheme
set bg=dark, then it ignores the color scheme then loads the default. If
all you said is true, I expect the bg=light now and the light-background
version of the default should be loaded. however the bg=dark now, and the
dark-background version of the default color scheme is loaded.

A bug ?

--
Sincerely, Pan, Shi Zhu. ext: 2606

Re: What's the exact meaning of the set 'background'?

2006-10-18 Thread panshizhu
"A.J.Mechelynck" <[EMAIL PROTECTED]> 写于 2006-10-19 13:42:46:
> (I "think" I read the help correctly in
> understanding that ctermbg=NONE and ctermfg=NONE are not syntactically
valid
> settings, but I'm not 100% sure that I understood it correctly.)
>
>
> Best regards,
> Tony.


Hi Tony,

Thanks very much for your through explanation, I'll read it for some more
time.

What I can confirm is that you have not correctly understand one thing:
ctermbg=NONE is valid and this setting is very important for most
color-scheme developers. It means the background being transparent.

i.e. when the ctermbg=NONE, the background color will be the same as the
terminal background, if your terminal can have a semi-transparent
background, then the background color of the highlight group will be
semi-transparent. Note that the ctermfg=bg and ctermbg=bg is not possible
when ctermbg=NONE. And the ctermbg=NONE is the Vim default setting for most
highlight groups! You must override all those defaults if you don't want
the background be determined by the terminal instead of your Vim
colorscheme.

If you set the ctermbg=Black, then it will always be black, even if your
terminal has a light background by default. So generally you don't need to
worry about the default background of your terminal. What you need to do is
to set ctermbg=Black for Normal highlight group and set ctermbg=bg for all
the rest of highlight groups which you expect the same background as the
Normal highlight group.

If I had not misunderstood the Vim Help document, I should have this: when
the color scheme overrides all the default values, the 'background' option
will have no effect since it only changes the default highlight and they
are all overriden by the color scheme.

This seems to be a "frozen" way but it works better for me. Consider that
the gvim will always have the background="light" and the cterm will have
this determined by the terminal. Many 8-color terminal cannot have a bright
color as the background so it is not be very portable to design a
light-background scheme for color terminal. I forced dark background for
color terminal then nothing need to be detected.

--
Sincerely, Pan, Shi Zhu. ext: 2606

Re: What's the exact meaning of the set 'background'?

2006-10-18 Thread Peter Hodge
Hello,

If you change the background=light, Vim reloads the colorscheme so it has a
chance to give you new colors.  But if the colorscheme changes background=dark
again, then Vim knows that the colorscheme isn't capable of picking colors for
a light background.  In that case, Vim will just ignore whatever the
colorscheme says and will use default colors instead.

Therefore, your colorscheme could just read the value of 'background' and
choose appropriate colors, or it could set it the value of background to light
or dark, and choose those colors, because if Vim sees the colorscheme trying to
set 'dark' when you have just selected 'light', it ignores your colorscheme.

regards,
peter



--- [EMAIL PROTECTED] wrote:

> 
> Hi Vimmers,
> 
> Recently, I've been thinking what this option is designed for.
> 
> The document saids that:
> 
>   when 'background' is set Vim will adjust the default color groups for the
> new value. But the colors used for syntax highlighting will not change.
> 
> But in fact, I had tested and found that when I set the 'background'
> option, Vim will source the color scheme script again. The idea seems to be
> good, if the color scheme script reads the 'background' option and set a
> different color according to the option everything should work...
> 
> However, we could imagine... what will happen if I set background=light
> while the color scheme set background=dark inside the script? When we set
> background=light in command line, the script will be launched, and the
> background set to dark. then we will never be able to set background=light.
> Then, if another color scheme wants the value, it will always get
> background=dark even if the user set background=light. (Okay the "System"
> will try to set the 'background' option too, and that will more more
> confusing...)
> 
> So, is 'background' option designed so that the color scheme should not
> read or write it at all? In my opinion it is introducing more confusing
> than good if it works this way.
> 
> Could anyone explains what this option "exactly" means and what it is
> designed to and how should we use it? I've been quite confused now.
> 
> --
> Sincerely, Pan, Shi Zhu. ext: 2606
> 
> 




 
Do you Yahoo!? 
Spring Racing Carnival - Check out Sonia Kruger's blog
http://au.sports.yahoo.com/racing/


Re: What's the exact meaning of the set 'background'?

2006-10-18 Thread A.J.Mechelynck

[EMAIL PROTECTED] wrote:

Hi Vimmers,

Recently, I've been thinking what this option is designed for.

The document saids that:

  when 'background' is set Vim will adjust the default color groups for the
new value. But the colors used for syntax highlighting will not change.

But in fact, I had tested and found that when I set the 'background'
option, Vim will source the color scheme script again. The idea seems to be
good, if the color scheme script reads the 'background' option and set a
different color according to the option everything should work...

However, we could imagine... what will happen if I set background=light
while the color scheme set background=dark inside the script? When we set
background=light in command line, the script will be launched, and the
background set to dark. then we will never be able to set background=light.
Then, if another color scheme wants the value, it will always get
background=dark even if the user set background=light. (Okay the "System"
will try to set the 'background' option too, and that will more more
confusing...)

So, is 'background' option designed so that the color scheme should not
read or write it at all? In my opinion it is introducing more confusing
than good if it works this way.

Could anyone explains what this option "exactly" means and what it is
designed to and how should we use it? I've been quite confused now.

--
Sincerely, Pan, Shi Zhu. ext: 2606




'background' _tells_ vim whether the current default background is _currently_ 
dark or light.


When gvim starts, it sets the default colors (for the Normal group and for any 
other group not having guibg= guifg= ) to guibg=white guifg=black, and 
'backgound' to "light".


When console Vim starts, it's not so easy. The current background and 
foreground are set by the underlying OS or terminal-emulator, and Vim tries to 
find out what they are set to. Depending on the underlying OS and terminal, it 
may or may not be possible to determine exactly what the current background is 
set to. If it cannot find out, Console Vim assumes that it is loaded in what 
used to be the "hardware" default colors of text terminals -- light grey on 
black for a color console, amber or green or grey on black for a monochrome 
console -- and sets 'background' to "dark".


When creating a colorscheme, the following philosophies are possible:

a) Set the Normal group to always the same defaults, and set 'background' 
accordingly. This is the simplest possibility, but it does _not_ let the user 
choose between "dark" and "light" versions of a single colorscheme, and it may 
look ugly on some console displays, depending on how the author's choices 
"marry" with the terminal's capabilities.


b) Accept the current user-set setting of 'background' (and possibly the 
user-set highlight for the Normal group), and define the highlight groups 
accordingly:


- some highlight groups may have both ctermbg/guibg and ctermfg/guifg set
- if setting ctermbg/guibg for the Normal group, it should be set to a 
"brighter" colour if 'background' is "light", and to a "darker" colour if 
'background' is "dark".
- when not setting ctermbg/guibg for some group, ctermfg/guifg should be set 
to a relatively "darker" colour if 'background' is set to "light", or to a 
relatively "brighter" colour if 'background' is set to "dark".


This second method is the most versatile, but in effect it doubles the 
workload of the colorscheme author, since the single colorscheme script must 
contain two sets of settings for cterm and also two sets for gui.


c) Start the colorscheme with
hi clear Normal
set bg&
hi clear
to reset every color not set by the colorscheme to the program-startup 
defaults. Then proceed as in (b) above. When used in a cterm, this third 
method assumes that when "set bg&" 'guesses' whether the current Normal 
background is light or dark, the result can be accepted. This is what the 
"default" colorscheme does (and some others like my "almost-default" which has 
been circulated as an attachment to some of my posts in this list); it may be 
off on some terminal emulators, if they start with a dark-on-bright setting 
and don't (or can't) respond properly to a program's query about "what are the 
current display colors set to?".


This third method is less versatile than the second but less frozen than the 
first one. It lies more or less halfway between them in terms of workload for 
the colorscheme author, since in most cases it must take into account the 
possibilities cterm/dark cterm/light and gui/light (and possibly term/dark if 
it wants compatibility with monochrome text displays). The user has no choice 
over whether a dark or light background is used, except by changing the cterm 
colours before starting console Vim. This third method is also the only one of 
the three where Vim may have to "guess" what the system colours are set to, 
and this introduces the risk of guessing wrong.


If the colorscheme

What's the exact meaning of the set 'background'?

2006-10-18 Thread panshizhu

Hi Vimmers,

Recently, I've been thinking what this option is designed for.

The document saids that:

  when 'background' is set Vim will adjust the default color groups for the
new value. But the colors used for syntax highlighting will not change.

But in fact, I had tested and found that when I set the 'background'
option, Vim will source the color scheme script again. The idea seems to be
good, if the color scheme script reads the 'background' option and set a
different color according to the option everything should work...

However, we could imagine... what will happen if I set background=light
while the color scheme set background=dark inside the script? When we set
background=light in command line, the script will be launched, and the
background set to dark. then we will never be able to set background=light.
Then, if another color scheme wants the value, it will always get
background=dark even if the user set background=light. (Okay the "System"
will try to set the 'background' option too, and that will more more
confusing...)

So, is 'background' option designed so that the color scheme should not
read or write it at all? In my opinion it is introducing more confusing
than good if it works this way.

Could anyone explains what this option "exactly" means and what it is
designed to and how should we use it? I've been quite confused now.

--
Sincerely, Pan, Shi Zhu. ext: 2606