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

From: Mitchell <>
Date: Sun, 18 Mar 2018 11:46:33 -0400 (EDT)


On Sat, 10 Feb 2018, Keresztes Barna wrote:

> On Wed, 7 Feb 2018 10:11:57 Mitchell wrote:
>>> Second question: Is there any recommendation against using the dofile
>>> workaround?
>> No, there is no recommendation against. That will work.
> Thanks for the answers, Mitchell!
> So I wrote a small module based on the original `set_theme` function that
> enables the per-buffer theming, I'll share it with the community:
> ```
> function set_buffer_theme(name, props)
> name = name:find('[/\\]') and name or
> package.searchpath(name, _USERHOME..'/themes/?.lua;'..
> _HOME..'/themes/?.lua')
> if not name or not lfs.attributes(name) then return end
> props = props or {}
> dofile(name)
> for prop, value in pairs(props) do[prop] = value end
> end
> ```
> It can be used at the LEXER_LOADED event to set the buffer theme based on
> the file type.
> There is only a small bug: When opening a new file, the themes might be
> mixed: some elements have the background color of the startup theme. To
> correct is, switch to another tab, then switch back to the current tab: the
> colors will be fine.
> If somebody has an idea how to correct this, I would be happy to correct
> the code :)

At the end of your function you can put this:

   if buffer.get_lexer then buffer:set_lexer(buffer:get_lexer()) end -- refresh

It's a bit of hack, but that should immediately refresh the entire buffer's styles.


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Sun 18 Mar 2018 - 11:46:33 EDT

This archive was generated by hypermail 2.2.0 : Mon 19 Mar 2018 - 06:28:50 EDT