Re: [code] [textadept]Some questions about buffer.set_theme()

From: Mitchell <m.att.foicica.com>
Date: Wed, 7 Feb 2018 10:11:57 -0500 (EST)

Hi Barna,

On Tue, 6 Feb 2018, Keresztes Barna wrote:

> Hi,
> I have some questions about the behavior of the buffer.set_theme() function.
>
> 1. It sets the theme only at the startup and for every buffer, it's clearly a
> function affecting the UI (like ui.menu), not a buffer-level function
> (properties that can be different for every buffer - like tab width or
> margin). So I don't really understand why was it moved from the ui class to
> buffer class?

I agree it's not perfect, but there are two reasons for the change: (1) ui.set_theme() can imply the entire ui is themed (menus, text boxes, buttons, etc.) and this is not the case; (2) [ui|buffer].set_theme() only ever sets buffer properties and calls buffer functions. With the new feature in Textadept 10 that makes any buffer settings on startup apply to all subsequent buffers, `buffer.set_theme()` seems more appropriate.

> 2. I understand that it works only at startup, but I don't find it normal
> that subsequent calls give "nil value" error (as it's an API function). IMO
> it should do nothing or give a warning.

That is a fair point. Despite the fact that the documentation states the function can only be called on startup, I will do something about it.

> 3. The most interesting question: It should be really interesting to be able
> to define a different theme for different buffers. I like to have a light
> theme for text editing (LaTex, Markdown) and a dark theme for code. Something
> like:
>
>     events.connect(events.LEXER_LOADED, function(lang)
>       if lang == 'markdown' or lang == 'latex' then
>         buffer.set_theme(not CURSES and 'base16-tomorrow-light')
>       else
>         buffer.set_theme(not CURSES and 'base16-monokai-dark')
>       end
>     end
>
> I don't think there is a technical obstacle as I found a workaround by
> replacing `buffer.set_theme` by `dofile('path/to/theme.lua')`.
> Could you implement the per buffer theme feature?

That's an interesting idea. I will explore it and get back to you.

> Second question: Is there any recommendation against using the dofile
> workaround?

No, there is no recommendation against. That will work.

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.
Received on Wed 07 Feb 2018 - 10:11:57 EST

This archive was generated by hypermail 2.2.0 : Thu 08 Feb 2018 - 06:41:21 EST