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

From: Ryan Pusztai <rpusztai.att.gmail.com>
Date: Fri, 17 May 2013 12:44:55 -0400

Hi Mitchell,

On Fri, May 17, 2013 at 1:30 AM, Mitchell <m.att.foicica.com> wrote:

> 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.
>

This design seems very good. I especially like how you can set the buffer
setting like font and font size. I vote "go for it".

--
Regards,
Ryan
-- 
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 - 12:44:55 EDT

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