Skip to content

skyformat99/mle

 
 

Repository files navigation

mle

mle is a small, flexible, terminal-based text editor written in C.

Build Status

Demos

asciicast

Aims

  • Keep codebase small
  • Minimize build-time and run-time dependencies
  • Make extensible and configurable
  • Favor simplicity over portability
  • Use shell commands to enhance functionality (e.g., grep, tree)

Features

  • Small codebase (<10k sloc)
  • Only 1 out-of-repo dependency (PCRE)
  • Full UTF-8 support
  • Syntax highlighting
  • Stackable key maps (modes)
  • Extensible via Lua
  • Scriptable rc file
  • Key macros
  • Multiple splittable windows
  • Regex search and replace
  • Large file support
  • Incremental search
  • Linear undo and redo
  • Multiple cursors
  • Auto indent
  • Headless mode
  • Navigation via ctags
  • Movement via less
  • Fuzzy file search via fzf
  • File browsing via tree
  • File grep via grep
  • String manip via perl

Building

$ git clone --recursive https://github.com/adsr/mle.git
$ cd mle
$ sudo apt-get install libpcre3-dev # or `yum install pcre-devel`, `pacman -S pcre`, etc
$ make

You can run make mle_static instead to build a static binary.

Installing

To install to /usr/local/bin:

$ make install

To install to a custom directory, supply DESTDIR, e.g.:

$ DESTDIR=/usr/bin make install

Basic usage

$ mle             # Blank buffer
$ mle one.c       # Open one.c
$ mle one.c:100   # Open one.c at line 100
$ mle one.c two.c # Open one.c and two.c
$ mle -h          # Show command line help

Press F2 for help when inside the editor.

Advanced usage: mlerc

mle is customized via command line options. Run mle -h to view all cli options.

To set default options, make an rc file named ~/.mlerc (or /etc/mlerc). The contents of the rc file are any number of cli options separated by newlines. Lines that begin with a semi-colon are interpretted as comments.

If ~/.mlerc is executable, mle executes it and interprets the resulting stdout as described above. For example, consider the following snippet from an executable ~/.mlerc PHP script:

<?php if (file_exists('.git')): ?>
-kcmd_grep,M-q,git grep --color=never -P -i -I -n %s 2>/dev/null
<?php endif; ?>

This overrides the normal grep command with git grep if .git exists in the current working directory.

Advanced usage: Scripting

mle is extensible via the Lua programming language. Scripts are loaded via the -x cli option. Commands registered by scripts can be mapped to keys as normal via -k. See uscript.lua for a simple example.

There is also a wren branch with Wren scripting support. That work is on pause.

Advanced usage: Headless mode

mle provides support for non-interactive editing which may be useful for using the editor as a regular command line tool. In headless mode, mle reads stdin into a buffer, applies a startup macro if specified, and then writes the buffer contents to stdout. For example:

$ echo -n hello | mle -M 'test C-e space w o r l d enter' -p test
hello world

If stdin is a pipe, mle goes into headless mode automatically. Headless mode can be explicitly enabled or disabled with the -H option.

If stdin is a pipe and headless mode is disabled via -H0, mle reads stdin into a new buffer and then runs as normal in interactive mode.

Runtime dependencies (optional)

The following programs will enable or enhance certain features of mle if they exist in PATH.

  • bash (tab completion)
  • fzf (fuzzy file search)
  • grep (file grep)
  • less (less integration)
  • perl (perl 1-liners)
  • readtags (ctags integration)
  • tree (file browsing)

Known bugs

  • Multi-line style rules don't work properly when overlapped/staggered.

Fork

Also check out eon, a fork of mle with some cool features.

Acknowledgments

mle makes extensive use of the following libraries.

  • uthash for hash maps and linked lists
  • termbox for TUI
  • PCRE for syntax highlighting and search

About

flexible terminal-based text editor (C)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 63.7%
  • C++ 29.3%
  • Shell 3.7%
  • PHP 2.6%
  • Other 0.7%