Re: [code] [textadept] New Theme and Settings Proposal

From: Russell Dickenson <russelldickenson.att.gmail.com>
Date: Fri, 17 May 2013 22:17:23 +1000

I really like the new proposal because to my mind it greatly simplifies
theming. Separating aspects such as the colour scheme and buffer properties
is a great approach IMHO. I can't wait until it's implemented.

On 17 May 2013 17:43, Gilles Grégoire <gilles.gregoire.att.gmail.com> wrote:

> Mitchell,
> I am all for the removal of the need for 3 separate files for themes. I
> think having one file for each theme to define colors and another to define
> all other properties is a good idea.
>
> To me, the 'property' style of initialization can be harder to read. For
> example, this:
> property['style.error'] = 'fore:$(color.red),italics'
>
> I think it is better written in a simple "programmatic" style, which is
> much closer to the original source:
> property.style_error = style { fore=color.red, italic=true }
>
> Also, I don't understand _why_ using buffer properties to set colors is a
> simplification over the actual scheme. Will it still be possible to use the
> 'old style' initialization?
>
> Best,
>
>
>
> 2013/5/17 Mitchell <m.att.foicica.com>
>
>> Hi,
>>
>> I've been working on a new implementation for themes and settings and
>> have something workable that I'd like to share as a proposal.
>>
>> Themes are now a single Lua file (e.g. light.lua). No more keeping track
>> of buffer.lua, lexer.lua, and view.lua files. All color and style settings
>> are done via buffer properties instead of the custom Lua tables in
>> lexer.lua. This allows themes to share Textadept's Lua state instead of
>> residing in a separate lexer Lua state. Here's an example:
>>
>> local buffer = buffer
>> local property, property_int = buffer.property, buffer.property_int
>>
>> -- Normal colors.
>> property['color.red'] = 0x4D4D99
>> property['color.yellow'] = 0x4D9999
>> property['color.green'] = 0x4D994D
>> ...
>>
>> -- Token styles.
>> property['style.nothing'] = ''
>> property['style.class'] = 'fore:$(color.yellow)'
>> property['style.comment'] = 'fore:$(color.grey)'
>> property['style.constant'] = 'fore:$(color.red)'
>> property['style.error'] = 'fore:$(color.red),italics'
>> ...
>>
>> -- Caret and Selection Styles.
>> buffer:set_sel_fore(true, property_int['color.light_**black'])
>> buffer:set_sel_back(true, property_int['color.light_**grey'])
>>
>> Notice that view properties have access to theme colors now. It was so
>> annoying matching colors in lexer.lua with view.lua...
>>
>> With the previous theme implementation, any changes, however small,
>> required you to copy a theme to your *~/.textadept/themes/* and edit it. We
>> know that for Lua modules at least, a *post_init.lua* file solves this
>> issue. We can do something similar with themes now. Suppose I wanted to
>> tweak the "error" style above to make the background color red instead of
>> the foreground, but keep everything the same. I would create a
>> *~/.textadept/themes/light.**lua* with this:
>>
>> dofile(_HOME..'/themes/light.**lua')
>> buffer.property['style.error'] = 'back:$(color.red),italic'
>>
>> Similarly I could tweak the default font and keep everything else the
>> same:
>>
>> dofile(_HOME..'/themes/light.**lua')
>> local style = buffer.property['style.**default']
>> style = style..',font:DejaVu Sans Mono,size:11'
>> buffer.property['style.**default'] = style
>>
>> In either case, I now add the following to my *~/.textadept/init.lua*:
>>
>> gui.set_theme('light')
>>
>> This will load my modified light.lua theme, not Textadept's default one.
>>
>> So what about the old view.lua and buffer.lua? Are they still grouped in
>> with themes? No :) Textadept has a new *settings.lua* that contains all
>> non-color buffer properties. For example:
>>
>> -- Multiple Selection and Virtual Space
>> buffer.multiple_selection = true
>> buffer.additional_selection_**typing = true
>> ...
>>
>> -- Line Number Margin.
>> local width = 4 * buffer:text_width(c.STYLE_**LINENUMBER, '9')
>> buffer.margin_width_n[0] = width + (not CURSES and 4 or 0)
>> ...
>>
>> -- Tabs and Indentation Guides.
>> -- Note: tab and indentation settings apply to individual buffers.
>> buffer.tab_width = 2
>> buffer.use_tabs = false
>> --buffer.indent = 2
>> buffer.tab_indents = true
>> buffer.back_space_un_indents = true
>> ...
>>
>> This *settings.lua* file is run every time a new buffer or view is
>> created. If you have a *~/.textadept/settings.lua*, it will be run after
>> Textadept's, so you have the option of overwriting Textadept's defaults.
>>
>> I am quite happy with cutting the legacy buffer and view settings crap
>> out of themes and leaving them to be just colors. Those of you that have
>> wanted this will be happy too I hope :) That and simpler theme modification
>> by using buffer properties. I'm also happy to hide the separate lexer Lua
>> state that causes confusion in themes and feels dirty. Perhaps
>> *settings.lua* is a bit mis-leading since one might want to put module
>> options in there (e.g. _M.textadept.editing.AUTO_**PAIR), but I'm fairly
>> confident the manual will make things clear.
>>
>> Thoughts and suggestions are very welcome.
>>
>> Cheers,
>> Mitchell
>> --
>> You are subscribed to code.att.foicica.com.
>> To change subscription settings, send an e-mail to code+help.att.foicica.com.
>> To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
>>
>>
>

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Fri 17 May 2013 - 08:17:23 EDT

This archive was generated by hypermail 2.2.0 : Sat 18 May 2013 - 06:31:27 EDT