Lite XL - Fast, Lightweight, Extensible Text Editor

These are some of the text editors I've used:

  • Notepad++
  • Sublime Text 3 and 4
  • VSCode
  • Atom

After having tried different text editors I used to go with Sublime Text. It was somewhat lightweight (25 MB) and it was fast on small projects. This was until I ran into rxi/lite, a tiny (1 MB) and really fast text editor, which is incredibly easy to write plugins and syntax highlighting for. After having used this editor for some time, I realized that the editor wasn't really being updated anymore, this is where I ran into lite-xl. A fork of lite but with the focus on better rendering and even better performance.

One of the things I didn't like about Sublime Text was creating plugins and syntax highlighting. This is for Sublime Text:

Below is a syntax definition file for our logs. It is good for a starting point because it is simple.

patterns:
- name: text.command
  match: \"command\":[0-9]{4}

- name: text.command_name
  match: \"command_name\":\"(.*?)\"
  captures:
    '1': {name : text.command_name.1}

- name: text.fsm
  match: (.*)(FSM :.*(\[.*\]).*)
  captures:
    '1': {name : text.fsm.prefix}
    '2': {name : text.fsm.suffix}
    '3': {name : text.fsm.event}

- name: text.errors
  match: (.*(\"error_code\":[1-9]).*)
  captures:
    '1': {name : text.error.fullline}
    '2': {name : text.error.code}

- name: text.ping
  match: .*\"command\":8888.*

- name: text.exception.message
  match: (.*)Exception(.*)

- name: text.exception.stacktrace
  match: ^((?![0-9]{8}).)*$

- name: text.log.error
  match: .*\| E \|.*

Sure, while that might be somewhat simple, that is not fully complete syntax highlighting for a regular programming language, that would require more definitions. Try however, to take a look at this:

-- mod-version:1 -- lite-xl 1.16
local syntax = require "core.syntax"

syntax.add {
  files = { "%.wren$" },
  comment = "//",
  patterns = {
    { pattern = "//.-\n",                 type = "comment"  },
    { pattern = { "/%*", "%*/" },         type = "comment"  },
    { pattern = { '"', '"', '\\' },       type = "string"   },
    { pattern = { "'", "'", '\\' },       type = "string"   },
    { pattern = "-?%.?%d+",               type = "number"   },
    { pattern = "%.%.%.?",                type = "operator" },
    { pattern = "[<>!=]=",                type = "operator" },
    { pattern = "[%+%-=/%*%^%%<>!~|&?:]", type = "operator" },
    { pattern = "[%a_][%w_]*%s*%f[(\"{]", type = "function" },
    { pattern = "[%a_][%w_]*",            type = "symbol"   },
  },
  symbols = {
    ["break"]     = "keyword",
    ["class"]     = "keyword",
    ["construct"] = "keyword",
    ["else"]      = "keyword",
    ["false"]     = "keyword",
    ["for"]       = "keyword",
    ["foreign"]   = "keyword",
    ["if"]        = "keyword",
    ["import"]    = "keyword",
    ["in"]        = "keyword",
    ["is"]        = "keyword",
    ["null"]      = "keyword",
    ["return"]    = "keyword",
    ["static"]    = "keyword",
    ["super"]     = "keyword",
    ["this"]      = "keyword",
    ["true"]      = "keyword",
    ["var"]       = "keyword",
    ["while"]     = "keyword",
    ["this"]      = "keyword2",
    ["true"]      = "literal",
    ["false"]     = "literal",
    ["null"]      = "literal",
  },
}

This is syntax highlighting for the Wren programming language, it's normal and short Lua code. The regex matching might look a bit unfamiliar if you're not used to Lua, and that's because Lua has it's own lightweight regex alternative called "patterns". It's almost exactly like regex, and does not take very long to learn.

Now how would make use of this syntax highlighting? You just move your .lua file into the lite-xl/plugins folder... that's it.

What if you wanted to edit the source code or change something about the application? You just open up the lite-xl directory and start making the changes you want. This can be anything from the interface to the way documents are processed and more. You have full customizability.

Plugins are also easy to make, and there's quite a lot to get inspiration and/or help from: https://github.com/lite-xl/lite-plugins

I highly recommend anyone to give lite-xl a try if they like minimalism, efficiency and extensibility: https://github.com/lite-xl/lite-xl

26