diff options
-rw-r--r-- | core/gui.lua | 10 | ||||
-rw-r--r-- | doc/09_Themes.md | 21 |
2 files changed, 22 insertions, 9 deletions
diff --git a/core/gui.lua b/core/gui.lua index c8e593f2..bee5c567 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -164,14 +164,17 @@ end --- -- Sets the editor theme name to *name* or prompts the user to select one from a -- list of themes found in the *`_USERHOME`/themes/* and *`_HOME`/themes/* --- directories. +-- directories and optionally sets key-value pair argument properties. -- User themes override Textadept's default themes when they have the same name. -- If *name* contains slashes, it is assumed to be an absolute path to a theme -- instead of a theme name. -- @param name Optional name or absolute path of a theme to set. If `nil`, the -- user is prompted for one. +-- @param ... key-value argument pairs for theme properties to set. These +-- override the theme's defaults. +-- @usage gui.set_theme('light', 'font', 'Monospace', 'fontsize', 12) -- @name set_theme -function gui.set_theme(name) +function gui.set_theme(name, ...) if not name then local themes, themes_found = {}, {} for theme in lfs.dir(_HOME..'/themes') do @@ -193,15 +196,18 @@ function gui.set_theme(name) _HOME..'/themes/?.lua') end if not name or not lfs.attributes(name) then return end + local buffer, props = buffer, {...} local current_buffer, current_view = _BUFFERS[buffer], _VIEWS[view] for i = 1, #_BUFFERS do view:goto_buffer(i) dofile(name) + for j = 1, #props, 2 do buffer.property[props[j]] = props[j + 1] end end view:goto_buffer(current_buffer) for i = 1, #_VIEWS do gui.goto_view(i) dofile(name) + for j = 1, #props, 2 do buffer.property[props[j]] = props[j + 1] end end gui.goto_view(current_view) -- if not RESETTING then reset() end diff --git a/doc/09_Themes.md b/doc/09_Themes.md index b98d763c..ccdbf85e 100644 --- a/doc/09_Themes.md +++ b/doc/09_Themes.md @@ -49,17 +49,24 @@ There are two ways to go about customizing themes. You can create a new one from scratch or tweak an existing one. Creating a new one is straightforward -- all you need to do is define a set of colors and a set of styles. Just follow the example of existing themes. If instead you want to use an existing theme like -"light" but only change the font face and font size, you do not have to copy the -whole theme to your *~/.textadept/themes/light.lua* before changing the font -settings. Tweaking themes is very simple with Lua's `dofile()` function. In your -*~/.textadept/themes/light.lua*, put: +"light" but only change the font face and font size, you have two options: call +[`gui.set_theme()`][] with additional parameters from your +*~/.textadept/init.lua* or create an abbreviated *~/.textadept/themes/light.lua* +using Lua's `dofile()` function. For example: + -- File *~/.textadept/init.lua* + gui.set_theme('light', 'font', 'Monospace', 'fontsize', 12) + + -- File *~/.textadept/themes/light.lua* dofile(_HOME..'/themes/light.lua') - buffer.property['font'] = 'font face' + buffer.property['font'] = 'Monospace' buffer.property['fontsize'] = size -This loads Textadept's "light" theme, but applies your font preferences. The -same technique works for tweaking individual theme colors and/or styles. +Either one loads Textadept's "light" theme, but applies your font preferences. +The same techniques work for tweaking individual theme colors and/or styles, but +managing more changes is probably easier with the latter. + +[`gui.set_theme()`]: api/gui.html#set_theme ### Language-Specific |