• Stars
    star
    160
  • Rank 234,703 (Top 5 %)
  • Language
    C++
  • License
    BSD 2-Clause "Sim...
  • Created over 8 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A minimal text-editor with lua scripting.

license

Kilua

Kilua is an small, extensible, and Lua-powered text editor.

screenshot

The project was originally based upon the minimal kilo editor originally written by @antirez, and introduced here on his blog, but now shares no code with that project, just ancestry.

kilua was written by Steve Kemp and features many updates and additions compared to the original project:

  • Complete handling for UTF-8 and multi-byte text.
  • The ability to open/edit/view multiple files
  • The addition of an embedded Lua instance.
    • You can define functions in your init-files, and invoke them via M-x function().
  • Regular expression support for searching.
  • The addition of syntax-highlighting via the lua-lpeg library.
    • NOTE: You should see the installation section for caveats here.
    • Syntax-highlighting is updated in the background, when the editor is idle, to avoid stalls and redraw delays.
    • Syntax-highlighting supports up to 256 colours, if your terminal supports them too.
  • The notion of named marks.
  • The status bar is configured via Lua.
  • Several bugfixes.

Launching kilua works as you would expect:

$ kilua [options] [file1] [file2] ... [fileN]

Once launched the arrow keys will move you around, and the main keybindings to learn are:

Ctrl-x Ctrl-o Open an existing file.
Ctrl-x Ctrl-f Open an existing file.

Ctrl-x Ctrl-s Save the current file.

Ctrl-x Ctrl-c Quit.

Ctrl-x c      Create a new buffer
Ctrl-x n      Move to the next buffer.
Ctrl-x p      Move to the previous buffer.
Ctrl-x b      Select buffer from a list

M-x           Evaluate lua at the prompt.

Ctrl-s        Regular expression search.

Command Line Options

The following command-line options are recognized and understood:

  • --config file
    • Load the named (lua) configuration file, in addition to the defaults.
  • --dump-config
    • Display the (embedded) default configuration file.
  • --eval
    • Evaluate the given lua, post-load.
  • --syntax-path
    • Specify the location of syntax-highlighting functions.
  • --version
    • Report the version and exit.

Installation

Installation should be straight-forward, to build the code run:

make

Once built you can run the binary in a portable fashion, like so:

./kilua --syntax-path ./syntax [options] [file1] [file2] .. [fileN]

The usage of --syntax-path is required to load the syntax files, but you can remove the option if you copy the contents of the ./syntax/ directory to either:

  • /etc/kilua/syntax/
  • ~/.kilua/syntax/

If you don't specify the location of the syntax-highlighting libraries, or you don't install them then you'll have zero syntax-highlighting support.

This is a consequence of placing the syntax-highlighting code in external libraries: If you can't load those libraries then the functionality will not be available.

Lua Support

We build with Lua 5.2 by default, but if you edit src/Makefile you should also be able to build successfully with Lua 5.1.

On startup the following configuration-files are read if present:

  • ~/.kilua/init.lua.
  • ./.kilua/$hostname.lua.
    • This is useful for those who store their dotfiles under revision control and share them across hosts.
    • You can use the *Messages* buffer to see which was found, if any.

If neither file is read then the embedded copy of kilua.lua, which was generated at build-time, will be executed, which ensures that the minimum functionality is present. (i.e. If you load zero config files then there won't be any keybindings setup so you can neither navigate nor edit!)

It is assumed you'll edit the supplied startup file, to change the bindings to suit your needs, add functionality via the supplied lua primitives, and then copy into ~/.kilua/init.lua (perhaps extending that with a per-host file too).

Without any changes you'll get a functional editor which follows my particular preferences.

Pull-requests implementing useful functionality will be received with thanks, even if just to add syntax-highlighting for additional languages.

Callbacks

In the future more callbacks might be implemented, which are functions the C-core calls at various points.

Right now the following callbacks exist and are invoked via the C-core:

  • get_status_bar()
    • This function is called to populate the status-bar in the footer.
  • on_complete(str)
    • This function is invoked to implement TAB-completion at the prompt.
  • on_idle()
    • Called roughly once a second, can be used to run background things.
    • If this function isn't defined it will not be invoked.
    • This is used to update syntax in the background.
  • on_key(key)
    • Called to process a single key input.
    • If this function isn't defined then input will not work, it is required.
  • on_loaded(filename)
    • Called when a file is loaded.
    • This sets up syntax highlighting in our default implementation for C and Lua files.
    • If this function is not defined then it will not be invoked.
  • on_save(filename)
    • Called before a file is saved.
    • Can be used to strip trailing whitespace, etc.
    • If this function is not defined then it will not be invoked.
  • on_saved(filename)
    • Called after a file is saved.
    • Can be used to make files executable, etc.
    • If this function is not defined then it will not be invoked.

Buffers

kilua allows multiple files to be opened, via the use of buffers. If kilua is launched without any filename parameters there will be two buffers:

  • *Messages*
    • This receives copies of the status-message.
  • An unnamed buffer for working with.
    • Enter your text here, then use Ctrl-x Ctrl-s, or M-x save("name"), to save it.

Otherwise there will be one buffer for each file named upon the command-line, as well as the *Messages* buffer. (You can kill the *Messages* buffer if you wish, but it's a handy thing to have around.)

The default key-bindings for working with buffers are:

Action Binding
Create a new buffer. Ctrl-x c
Kill the current buffer. Ctrl-x k
Kill the current buffer, forcibly. Ctrl-x K
Select the next buffer. Ctrl-x n or M-right
Select the previous buffer. Ctrl-x p or M-left
Choose a buffer, via menu. Ctrl-x b or Ctrl-x B

It's worth noting that you can easily create buffers dynamically, via lua, for example the following function can be called by M-x uptime(), and does what you expect:

  • Select the buffer with the name *uptime*.
    • If that buffer doesn't exist then create it.
  • Move to the end of the buffer.
    • Insert the output of running /usr/bin/uptime into the buffer.

Uptime sample:

  -- Run `uptime`, and show the result in a dedicated buffer.
  function uptime()
      local result = buffer( "*uptime*" )
      if ( result == -1 ) then create_buffer("*uptime*") end
      -- move to end of file.
      eof()
      insert(cmd_output("uptime"))
  end

Bookmarks

You can record your position (i.e. "mark") in a named key, and later jump to it, just like in vi.

To record the current position use M-m, and press the key you wish to use. To return to it use M-b XX where XX was the key you chose. (Marks record the buffer, as well as the current cursor-position.)

Status Bar

The status-bar, shown as the penultimate line in the display, contains the name of the current file/buffer, as well as the cursor position, etc.

The contents of the status-bar are generated via Lua, so it is simple to modify. The default display shows:

 "${buffer}/${buffers} - ${file} ${mode} ${modified} #BLANK# Col:${x} Row:${y} [${point}] ${time}"

Values inside "${...}" are expanded via substitutions and the following are provided by default:

Name Meaning
${buffers} The count of open buffers.
${buffer} The number of the current buffer.
${date} The current date.
${file} The name of the file/buffer.
${mode} The syntax-highlighting mode in use, if any.
${modified} A string that reports whether the buffer is modified.
${point} The character under the point.
${time} The current time.
${words} The count of words in the buffer.
${x} The X-coordinate of the cursor.
${y} The Y-coordinate of the cursor.

Pull-requests adding more options here would be most welcome.

Syntax Highlighting

Syntax highlighting is handled via the lua-lpeg library, and so if that is not installed it will not be available.

Each buffer has an associated syntax-highlighting mode, which is a string such as "c", "markdown", or "lua". The default configuration file sets the mode based upon the suffix of the file you're editing.

If you wish to change the mode interactively to Lua, for example, then run:

M-x syntax("lua")

The implementation of syntax highlighting requires the loading of a library. For example the syntax highlighting of lua requires that the library lua.lua is loaded - The syntax modes are looked for in these locations:

  • /etc/kilua/syntax
    • Global syntax-modes.
  • ~/.kilua/syntax
    • Per-user syntax-modes.
  • The path specified via the --syntax-path command-line option.

The implementation is pretty simple:

  • A buffer consists of rows of text.
    • Each row contains both the character(s) in the row and the colour of each character.
    • The Lua function update_colours will allow the colour of each single character in the buffer to be set.

To avoid delays when inserting text the rendering is updated in the background, via the on_idle() callback. This function does the obvious thing:

  • Retrieves the current contents of the buffer, via text().
  • Invokes the LPEG parser on it.
    • This will generate a long string containing the colour of each byte of the text.
  • Set those colours, via update_colours().

As a concrete example, if the buffer contains the string "Steve Kemp" then the call to update_colours should contain:

 `RED RED RED RED RED WHITE GREEN GREEN GREEN GREEN`

That would result in "Steve" being displayed in red, and "Kemp" in green.

Currently we include syntax-highlighting for:

  • C
  • C++
  • Go
  • HTML
  • Lua
  • Lisp
  • Makefiles.
  • Plain-text/markdown
    • This is a simple implementation which only highlights URLs and trailing whitespace.

Pull-requests adding more syntax modes would be most welcome.

Discussion on Hacker News

https://news.ycombinator.com/item?id=12137698

The Future

There are no obvious future plans, but bug reports may be made if you have a feature to suggest (or bug to report)!

One thing that might be useful is a split-display, to view two files side by side, or one above the other. This is not yet planned, but I think it could be done reasonably cleanly.

Steve -- https://steve.kemp.fi/

More Repositories

1

sysadmin-util

Tools for Linux/Unix sysadmins.
Perl
949
star
2

bookmarks.public

A template for self-hosted bookmarks using HTML & jQuery.
JavaScript
662
star
3

tunneller

Allow internal services, running on localhost, to be accessed over the internet..
Go
474
star
4

simple.vm

Simple virtual machine which interprets bytecode.
C
459
star
5

deployr

A simple golang application to automate the deployment of software releases.
Go
334
star
6

gobasic

A BASIC interpreter written in golang.
Go
325
star
7

go.vm

A simple virtual machine - compiler & interpreter - written in golang
Go
322
star
8

simple-vpn

A simple VPN allowing mesh-like communication between nodes, over websockets
Go
284
star
9

monkey

An interpreted language written in Go
Go
272
star
10

sysbox

sysadmin/scripting utilities, distributed as a single binary
Go
218
star
11

esp8266

Collection of projects for the WeMos Mini D1
C++
165
star
12

sos

Simple Object Storage (I wish I could call it Steve's Simple Storage, or S3 ;)
Go
150
star
13

github-action-publish-binaries

Publish binaries when new releases are made.
Shell
137
star
14

evalfilter

A bytecode-based virtual machine to implement scripting/filtering support in your golang project.
Go
117
star
15

rss2email

Convert RSS feeds to emails
Go
112
star
16

e-comments

External comments for static HTML pages, a lightweight self-hosted disqus alternative.
JavaScript
101
star
17

cpmulator

Golang CP/M emulator for zork, Microsoft BASIC, Turbo Pascal, Wordstar, lighthouse-of-doom, etc
Go
97
star
18

lighthouse-of-doom

A simple text-based adventure game
C
95
star
19

linux-security-modules

A place to store my toy linux-security modules.
C
90
star
20

marionette

Something like puppet, for the localhost only.
Go
85
star
21

kpie

Simple devilspie-like program for window manipulation, with Lua.
C
79
star
22

foth

Tutorial-style FORTH implementation written in golang
Go
78
star
23

dhcp.io

Dynamic DNS - Via Redis, Perl, and Amazon Route53.
Perl
68
star
24

templer

A modular extensible static-site-generator written in perl.
Perl
63
star
25

overseer

A golang-based remote protocol tester for testing sites & service availability
Go
62
star
26

assembler

Basic X86-64 assembler, written in golang
Go
61
star
27

math-compiler

A simple intel/AMD64 assembly-language compiler for mathematical operations
Go
60
star
28

node-reverse-proxy.js

A reverse HTTP-proxy in node.js
JavaScript
54
star
29

webmail

A golang webmail server.
Go
52
star
30

dotfiles

Yet another dotfile-repository
Emacs Lisp
49
star
31

github2mr

Export all your github repositories to a form suitable for 'myrepos' to work with.
Go
46
star
32

puppet-summary

The Puppet Summary is a web interface providing reporting features for Puppet, it replaces the Puppet Dashboard project
Go
46
star
33

org-worklog

A template for maintaining a work-log, via org-mode.
42
star
34

rss2hook

POST to webhook(s) when new feed-items appear.
Go
37
star
35

tweaked.io

The code behind http://tweaked.io/
JavaScript
36
star
36

pam_pwnd

A PAM module to test passwords against previous leaks at haveibeenpwned.com
C
35
star
37

critical

A simple/minimal TCL interpreter, written in golang
Go
34
star
38

alphavet

A golang linter to detect functions not in alphabetical order
Go
32
star
39

dns-api-go

The code behind https://dns-api.org/
Go
31
star
40

markdownshare.com

The code which was previously used at http://markdownshare.com/
Perl
29
star
41

github-action-tester

Run tests when pull-requests are opened, or commits pushed.
Shell
26
star
42

bfcc

BrainFuck Compiler Challenge
Go
22
star
43

maildir-tools

Golang-based utility which can be used for scripting Maildir things, and also as a basic email client
Go
22
star
44

purppura

A server for receiving and processing alerts & events.
Go
21
star
45

cpm-dist

A curated collection of CP/M software
C
20
star
46

implant

Simple utility for embedding files/resources inside golang binaries
Go
20
star
47

chronicle2

Chronicle is a simple blog compiler, written in Perl with minimal dependencies.
Perl
20
star
48

z80-examples

Z80 assembly-language programs.
Makefile
19
star
49

dns-api.org

The code which was previously used at https://dns-api.org/
Perl
19
star
50

yal

Yet another lisp interpreter
Go
16
star
51

ephemeris

A static blog-compiler
Go
15
star
52

markdownshare

The code behind https://markdownshare.com/
Go
15
star
53

aws-utils

A small collection of AWS utilities, packaged as a single standalone binary.
Go
14
star
54

z80retroshield

Arduino library for driving the Z80 retro-shield.
Shell
13
star
55

predis

A redis-server written in Perl.
Perl
12
star
56

github-action-build

Build a project, creating artifacts
Shell
12
star
57

webserver-attacks

Identify attacks against webservers via simple rules
Perl
12
star
58

Device-Osram-Lightify

Interface to the Osram Lightify system
Perl
12
star
59

labeller

Script label addition/removal for gmail/gsuite email.
Go
10
star
60

da-serverspec

ServerSpec.org configuration for the Debian-Administration cluster.
Ruby
10
star
61

docker-api-gateway

Trivial API-gateway for docker, via HAProxy
Go
10
star
62

http2xmpp

HTTP to XMPP (jabber) bridge.
Perl
9
star
63

nanoexec

Trigger commands over a nanomsg queue
C
9
star
64

go-experiments

Repository containing experiments as I learn about golang
Go
9
star
65

golang-metrics

Automatic submission of system metrics to graphite, for golang applications
Go
8
star
66

pass

password-store distribution, with plugins.
Shell
8
star
67

ms-lite

A collection of plugins for a qpsmtpd-powered virtual-host aware SMTP system.
Perl
8
star
68

remotehttp

Magic wrapper to deny HTTP-requests to to "local" resources.
Go
8
star
69

dashboard

Redis & node.js powered dashboard skeleton
JavaScript
8
star
70

Buffalo-220-NAS

Installing NFS on a Buffalo 220 NAS device
Shell
8
star
71

asql

A toy utility to process Apache log files via SQL.
Perl
7
star
72

knownfs

A FUSE-based filesystem that exports ~/.ssh/known_hosts
Go
7
star
73

mpd-web

Simple HTTP view of an MPD server
Go
7
star
74

DockerFiles

Container for various dockerfiles.
Shell
6
star
75

yawns

Yet another weblog/news site
Perl
6
star
76

org-diary

Easily maintain a simple work-log / journal with the use of org-mode
Emacs Lisp
6
star
77

cidr_match.js

A simple module to test whether a given IPv4 address is within a particular CIDR range.
JavaScript
6
star
78

mod_writable

Disallow serving writable files under Apache 2.4.x
C
5
star
79

mod_blacklist

A simple Apache module to blacklist remote hosts.
C
5
star
80

arduino-mega-z80-simplest

The simplest possible project combining an Arduino Mega and a Zilog Z80 processor
C++
4
star
81

turtle

A simple turtle-implementation, using FORTH as a scripting-language
Go
4
star
82

purple

A simplified version of mauvealert
Perl
3
star
83

subcommands

Easy subcommand handling for a golang based command-line application
Go
3
star
84

runme

A quick hack for running commands from README.md files
Go
3
star
85

thyme

A simple package-building system, using docker
Perl
2
star
86

httpd

Simple golang HTTP server
Go
2
star
87

edinburgh.io

Open pub database
JavaScript
2
star
88

lexing-parsing-linting-stuffs

Code to go with my talk
Python
2
star
89

run-directory

A simple application inspired by `run-parts`.
Go
2
star
90

Redis--SQLite

Redis-Compatible module which writes to SQLite
Perl
2
star
91

devopswithdocker.com

Repository created for the Helsinki University course.
Dockerfile
2
star
92

aws-list

Export a dump of all running EC2 instances, along with AMI details, AMI age, etc, etc.
1
star
93

WebService--Amazon--Route53--Caching

Perl module to cache the results of WebService::Amazon::Route53
Perl
1
star
94

calibre-plugins

A small collection of calibre-plugins.
Python
1
star
95

org-tag-cloud

Easily maintain a tag-cloud of org-mode tags.
Emacs Lisp
1
star
96

headerfile

Parse files with simple key:value headers, easily.
Go
1
star
97

z80-cpm-scripting-interpreter

A trivial I/O language, with repl, written in z80 assembler to run under CP/M.
Makefile
1
star
98

Test--RemoteServer

The Perl module Test::RemoteServer
Perl
1
star