Re: Set the font size from home directroy

From: Robert <ro....at.web.de>
Date: Wed, 30 Jun 2010 18:49:16 +0200

Hi,

an idea for simplifying slight theme modifications (without having to
copy themes):
A file ~/.textadept/themes/buffer.lua could be processed (if it
exists) after the usual theme loading for opened files or new buffers.
There one could simply have, e.g.

buffer.zoom = 2
buffer.tab_width = 4

I tested this with the following in my init.lua (which could be
included in the already existing functions):

events.connect('buffer_new', function ()
  if lfs.attributes(_USERHOME..'/themes/buffer.lua') then
    local ret, errmsg = pcall(dofile, _USERHOME..'/themes/buffer.lua')
    if ret then return end
    io.stderr:write(errmsg)
  end
end)

events.connect('file_opened', function ()
  if lfs.attributes(_USERHOME..'/themes/buffer.lua') then
    local ret, errmsg = pcall(dofile, _USERHOME..'/themes/buffer.lua')
    if ret then return end
    io.stderr:write(errmsg)
  end
end)

Maybe, a themes/view.lua as well?

Another thing I experimented with this morning is the setting of the
theme. I put the following function in core/init.lua:

function _G.set_theme(theme)
  if theme then _THEME = theme end
  if not _THEME:find('[/\\]') then
    local theme = _THEME
    _THEME = _USERHOME..'/themes/'..theme
    if not lfs.attributes(_THEME) then _THEME = _HOME..'/themes/'..theme end
  end

  if _THEME and #_THEME > 0 then
    local ret, errmsg = pcall(dofile, _THEME..'/view.lua')
    if ret then return end
    io.stderr:write(errmsg)

    buffer.property['lexer.lua.color.theme'] = _THEME..'/lexer.lua'

    local ret, errmsg = pcall(dofile, _THEME..'/buffer.lua')
    if ret then return end
    io.stderr:write(errmsg)
  end
end

Then, I have in my init.lua, e.g.
set_theme('black')

Then I experimented with theme switching and ended up with this:

function _G.switch_theme(theme)
  set_theme(theme)
  new_buffer()
  buffer:close()
end

So I can switch_theme('light') from the command entry.
Is there another way to trigger whatever it is that is happening when
a new buffer is created?
The only issue I encountered so far is when switching to the Scite
theme as some things are defined/undefined in their view.luas so some
settings from the old theme persist. Is there a way to reset every
theming? (And if no session files are loaded, the default light theme
is loaded, the "set_theme" is only applied once I open a file)
I think it would be nice to have functionality like this (maybe in
3.1), one could have the themes selectable in the menu, switch themes
in init.lua adjusted to day time :-)

Robert
Received on Wed 30 Jun 2010 - 12:49:16 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:49:10 EST