Skip to content

Repository files navigation

ze

ze - zach's extensible text editor

ze is an extensible text editor that uses GNU Guile as its extension language. It supports running guile code as pre- and post- hooks upon opening a file, opening a directory, or saving a file. It supports highlighting for C, Python, Ruby, PHP, Rust, APL, Swift, and TypeScript.

See the docs for more information.

Features

  • Simple and lightweight: Minimal text editor with essential functionality
  • Extensible: Uses GNU Guile for scripting and customization
  • Syntax highlighting: Supports C, Python, Ruby, PHP, Rust, APL, Swift, and TypeScript
  • Hooks system: Pre- and post- hooks for file operations
  • Template system: Clone predefined templates for common file types
  • Search functionality: Forward search with navigation
  • Cross-platform: Works on macOS, Linux, and other Unix-like systems

Installation

Prerequisites

First, you must install GNU Guile (and its related libraries) on your system. You can follow the official installation instructions or by simply doing:

brew install guile

if you are using macOS.

Building from Source

  1. Clone the repository:

    git clone git@github.com:zachwick/ze
    cd ze
  2. Set up configuration:

    mkdir ~/.ze
    cp zerc.scm ~/.ze/
    cp -R templates ~/.ze/templates
  3. Edit the configuration path: You must edit the path supplied to scm_c_primitive_load in the main method to match wherever your local zerc.scm configuration file is located. A common practice is to copy the example configuration file from the repo into a .ze directory in your home directory.

  4. Build and install:

    make install

Usage

Basic Usage

  • Start ze: ze
  • Open a file: ze <filename>

Default Keybindings

Guile Scheme REPL

KeyActionDescription
Ctrl+xOpen a REPLOpens a Guile Scheme REPL

File Operations

KeyActionDescription
Ctrl+oOpen pathPrompts the user for a path to open in ze
Ctrl+wWrite to fileWrite/Save the current buffer to a file
Ctrl+tClone templatePrompts the user for a template to clone into the current buffer

Search

KeyActionDescription
Ctrl+sForward searchPrompt for a string to search forward in the document
Ctrl+nNext matchMove to the next search match (while searching)
Ctrl+bPrevious matchMove to the previous search match (while searching)
ESCQuit searchQuit searching and return cursor to original position
EnterAccept matchQuit searching and leave cursor at current match

Editing

KeyActionDescription
Ctrl+iInsert timestampInserts current timestamp at cursor
Ctrl+dDelete lineDeletes the entire line that the cursor is currently on
Ctrl+kDelete rest of lineDeletes from cursor position to end of line
Ctrl+hDelete characterDeletes the character at cursor position

Navigation

KeyActionDescription
Ctrl+pMove upMove cursor up one line
Ctrl+nMove downMove cursor down one line
Ctrl+fMove forwardMove cursor one column to the right
Ctrl+bMove backwardMove cursor one column to the left
Ctrl+vPage downMove cursor to beginning of next page
Ctrl+gPage upMove cursor to beginning of previous page

Advanced Usage

Plugin System

ze supports Guile Scheme plugins that are automatically loaded at startup.

  • Location: Plugins are .scm files placed in ~/.ze/plugins. All non-hidden .scm files in that directory are loaded at startup.
  • Examples: make install creates ~/.ze/plugins and copies the example plugins from the repo.
  • API exposed to Scheme:
    • set-editor-status(string) — set the status line message
    • bind-key(key-spec, procedure) — bind a key to a Scheme procedure
  • Key specs: Either a single character (e.g., "y") or Control chords like "C-y".
  • Input handling: When a key is pressed, ze checks plugin bindings first. If a bound procedure runs, the built-in handler is skipped for that keypress.
  • REPL: Press Ctrl+x to open a one-line Scheme prompt inside ze to evaluate expressions in the current environment.

Minimal examples

Bind a key and set a status message (~/.ze/plugins/hello.scm):

(display"ze: loaded plugin hello.scm") (newline)
(define (ze-hello)
(set-editor-status "Hello from ze plugin!"))
(bind-key "C-y" ze-hello)

Override a hook from a plugin (~/.ze/plugins/hooks.scm):

(define (postSaveHook contents)
(string-append "Post-save plugin says: wrote "
(number->string (string-length contents))
" bytes"))

See the Hooks section below for the list of available hooks and their return values.

Guile Hooks

ze supports various Guile hooks for customization:

Hook FunctionReturnsDescription
preSaveHookstringCalled prior to writing buffer to file
postSaveHookstringCalled after writing buffer to file
preDirOpenHookstringCalled prior to opening a directory in ze
postDirOpenHookstringCalled after opening a directory in ze
preFileOpenHookstringCalled prior to opening a file into a buffer
postFileOpenHookstringCalled after opening a file into a buffer

Templates

To add a new template, you must make changes in three places in ze.c and one place in your zerc.scm configuration file:

  1. Define global variable in ze.c (around line 90):

    char*email_template="";
  2. Add template option in editorCloneTemplate method:

    char*template=editorPrompt("Select Template: (N)otes | (R)eadme | (E)mail", NULL);
  3. Add template handling in the if/else block:

    elseif (strcasecmp(template, "e") ==0) {
    editorSetStatusMessage("LoadEmailtemplate");
    templateFile=fopen(email_template, "r");
    }
  4. Define template path in zerc.scm:

    (defineemail_template '"/Users/zwick/.ze/templates/email")
  5. Read template in main method:

    SCMemail_template_scm;
    email_template_scm=scm_variable_ref(scm_c_lookup("email_template"));
    email_template=scm_to_locale_string(email_template_scm);

After making these changes, run make install to build and install your new version of ze.

Configuration

The main configuration file is ~/.ze/zerc.scm. This file contains:

  • Template file paths
  • Custom Guile functions and hooks
  • Editor behavior customization

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

ze is copyright 2018, 2019, 2020 zach wick zach@zachwick.com and is licensed under the GNU GPLv3 or later. You can find a copy of the GNU GPLv3 included in the project as the file named LICENSE.txt.

Author

Acknowledgments

  • Built with GNU Guile for extensibility
  • Inspired by simple, efficient text editors such as kilo.

About

A simple extensible text editor

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages