Beautify Textadept

Alejandro Baez
5 min readFeb 19, 2015

A guide in how to enlighten your Textadept.

If you are like me, you have installed Textadept, saw the default theme, and saw yourself cry in pain almost instantly. For all that Mitchell has done spectacular on the text editor, the theme is not one of them. However, there is a solution! Due to the extreme simplicity and ease of use of Textadept, you can very easily write your own theme. Yet, there is an even easier way, a lazier way. You can use one of the lovely themes of Base16 by Chris Kempson.

If you allow me, I will now begin to guide you through to enlightenment in Textadept. By the end of the journey, you will acknowledge all other text editors obsolete with how well your setup will look. We will begin with the simplicity of using one of those lovely base16 themes on your Textadept and expand to awakening with the use of semantic highlighting. In case you don’t know yet, semantic highlighting is life. Once you learned of it, you will never again want to be hidden under the shade of eye strain.

The first of the lovely steps that you will follow is to get a copy of the base16-builder repository and enter the repository.

git clone https://github.com/chriskempson/base16-builder.git
cd base16-builder/

Next my internet friend, you will build your themes for Textadept and Textadept alone.

./base16 -t textadept

Afterwards, comes the precursor to choice. Base16-builder has quite a repertoire of themes generated for you and you will want to have these themes ready for easy access. To accomplish such a task, you will copy the generated themes to a new themes directory in your userhome of Textadept.

cp output/textadept ~/.textadept/themes/

Now comes the moment of bliss. The themes are ready but your Textadept is not. To enable Textadept to use one of these generated themes, very simply add the following to your `init.lua` file in your Textadept userhome.

ui.set_theme(“base16-eighties-dark”)

However, we are not yet done. For everything that is holy, you MUST change your font and font size. It is not for me, but for the sake of your eyes!

ui.set_theme(“base16-eighties-dark”, {
font = “Inconsolata”,
fontsize = 14
})

‘Why mr. writer do you use Inconsolata and a font size fourteen!?’ I personally choose Inconsolata, due to my belief that nothing comes close to the font in ease of reading code. As for the font size 14? It is simple. I don’t want to be blind in the next 4 years.

Your chosen theme should now look something similar to the following:

_SEMANTIC = false

It does look nice. Much better than what was from the inception of your installation of Textadept. However, we can do better. We will now reach true nirvana. You see, ever since I learned of semantic highlighting all those years back when I used KDevelop and Kate, I have made it my purpose to have all my text editors use it.

So what’s darn special of semantic highlighting you ask? Well, for one, context sensitivity. Much of the code you DO want to have highlighted is usually in plain ol’ black/white and only the keywords and types are highlighted. The reason for such a form was due to how the code was processed by the texteditor to be presented. We are in the 21st century. It’s time to use some of our progressive technology. I won’t digress further and only state that if you ever wanted to find what you actually wrote and not simply the keywords(what I consider the ‘bloat’) of the code highlighted, then keep reading for your well being!

Anyway, sometimes the applying practice of converting to semantic on a text editor would not be kind to the fellow enlightened users. Very lucky for us, Textadept has graced us with the ease in applying these settings with very minimal setup.

Disclaimer: The following all requires the use of Base16 generated themes.

On your Textadept `properties.lua` file append the following:

—- enable semantic highlighting
_SEMANATIC = true

-- semantic highlighting. NEED base16 themes to work!
events.connect(events.LEXER_LOADED, function (lang)
if _SEMANATIC == false then return end

buffer.edge_colour = buffer.property_int[“color.base0A”]

buffer.property[‘style.operator’] = ‘fore:%(color.base0F)’
buffer.property[‘style.function’] = ‘fore:%(color.base08)’
buffer.property[‘style.library’] = ‘fore:%(color.base09)’
buffer.property[‘style.identifier’] = ‘fore:%(color.base0D)’
buffer.property[‘style.number’] = ‘fore:%(color.base0E)’
buffer.property[‘style.constant’] = ‘fore:%(color.base0A)’

buffer.property[‘style.keyword’] = ‘fore:%(color.base05)’
end)

Afterwards, kindly restart your session of Textadept and which ever of the Base16 themes you picked should now have semantic highlighting! The real awe inspiring peace of it all is since the Base16 generated themes are constructed the same, you only need to write the above once and have semantic highlighting for ALL of the Base16 generated themes. If only I have had transcended to Textadept after my time with KDevelop/Kate. *sigh* So many hours lost… But I digress once again. Your Textadept has now reached the peak and should be in the form as I call, “the only way to code in Rust”:

_SEMANTIC = true

As you can see, it’s a true wonder to behold. Yet, despite the beauty that is semantic highlighting, sometimes it may not work that well for a specific language. For example, how would it even work on Markdown? Then if it doesn’t really work for those type of languages, how do you selectively choose which languages receive semantic highlighting and which do not? Again, thanks to the ease of Textadept, you can add a table containing the names of the languages you want to disable semantic highlight to your `properties.lua` file.

—-- holds languages NOT to use semantic highlighting if semantic is on.
—- @param `language = true`: language being any one you choose.
local dont = {
perl = true,
yaml = true,
markdown = true,
}

As you can see, any language you deem not needing the beauty can be listed as shown.

Next, add the following below `if _SEMANTIC then return end` line:

if dont[lang] then return end

Lastly, what if you want to see how the world was before the bliss that is semantic highlighting? You can very easily disable semantic by changing the value of `_SEMANTIC` to `false`.

I hope after reading this guide, you have achieved a greater appreciation to Textadept.

Here is a gist for ease of appending to your Textadept `properties.lua` file:

Thanks goes to @textadept for being such joy in customizing and @ChrisKempson for the great Base16-builder.

--

--

Alejandro Baez

Programming a program to program in Rust. Let’s see how that goes…