Embeddable ED in rust

Overview

Add-ED

The standard editor, now as a library

Some time ago I decided to write an ED clone with syntax highlighting. On my way to that goal I needed to write an implementation of ED's command parsing and execution to wrap in that syntax highlighting. And so, here it is.

Early APIs

The current API design is only based on my use-case. If you are interested in using it and need some change to make it work better you are more than welcome to suggest changes.

Core concepts:

The selection:

The original 'ed' keeps track of one line that you recently interacted with and defaults to working on that if no lines are given with a command. This is an extension of that logic, making it a span of lines. I find that this is more intuitive. (To avoid unpleasantries some commands don't default to the selection, such as 'w'. If you want to modify the selection behavior for any command create an issue, I may well have missed one.)

Flexible APIs:

The modules have been set up with clear traits to enable changing out the components easily. For example it should be somewhat trivial to code a SSH+sed Buffer implementation for remote editing or a GUI frontend conforming to the UI trait.

Commands:

This list is not fully updated. Hired now supports nearly all Ed commands, only missing 'z', 'u' and '!'.

Lone commands:

Commands that take no input or selection.

  • q: Quit. Returns error if you have unsaved changes.
  • Q: Force Quit. Ignores unsaved changes.
  • h: Print Error. Print the last occured error.
  • H: Toggle Error Printing. Toggle printing errors as they occur.

File commands:

  • f: If no filepath is given, prints filepath. Else sets the filepath to given path.

  • e: Closes current file and opens the given path. Returns error if you have unsaved changes.

  • E: Closes current file and opens the given path, ignoring unsaved changes.

  • r: Append the data from given path to given selection.

  • w: Write the given selection (default whole buffer) to given path (default filepath). Warning, silently overwrites the file.

  • W: Append the given selection (default whole buffer) to given path (default filepath).

Print commands:

  • p: Print the given selection.
  • n: Print the given selection with numbered lines.
  • l: Print the given selection with character escaping.

Basic editing commands:

  • a: Append. Append lines given after the command to given selection. Stop entry with only '.' on a line.
  • i: Insert. Insert lines given after the command before given selection. Stop entry with only '.' on a line.
  • c: Change. Replace given selection with lines given after the command. Stop entry with only '.' on a line.
  • d: Delete. Delete the given selection.

Advanced editing commands:

  • m: Move. Move given selection to given index.
  • t: Transfer. Copy given selection to given index.
  • j: Join. Append together given selection into one line.

Regex commands:

  • s: Substitute. Regex replace, just like 'sed'.
  • g: Global command. Command list given as arguments or text input runs on all matching lines.
  • v: inVerted global. Command list given as arguments or text input runs on all non-matching lines.
  • G: interactive Global. Prints matching lines and takes command list for each line as text input.
  • V: interactive inVerted global. Prints non-matching lines and takes commands for each as text input.

Special cases:

  • no command: Takes the given selection and sets it to the default selection.

Attributions:

This project has of course greatly benefited from all the crates it depends on. Especially I'd like to thank regex and syntect for helping me through my, to various degrees badly though out, issues.

Then I have also gotten a hand up from 'bat', which I also consider an excellent companion to this application, from their handling of 16-color terminals. My theme is currently copied from their repo and will probably always be based on theirs.

You might also like...
Bridge the gap between Haskell and Rust

Curryrs Curryrs (a play on the name of Haskell Curry, rs for Rust libraries, and it's pronunciation couriers) is a library for providing easy to use b

Rust in Haskell FFI Example

Provides an example for using Rust in Haskell. To use this you'll need cargo, rustc, cabal and GHC installed. To execute the example run the following

Run Java code from Rust!

Java Native Interface Bindings for Rust This library provides complete FFI bindings to the Java Native Interface, as well as a safe and intuitive wrap

Embedding Rust in Java

Java/Rust Example An example project showing how to call into Rust code from Java. OSX Linux Windows Requirements Java 7+ Rust (tested with 1.0, night

Rust-JDBC bindings

jdbc A Rust library that allows you to use JDBC and JDBC drivers. Usage First, add the following to your Cargo.toml: [dependencies] jdbc = "0.1" Next,

Lua 5.3 bindings for Rust

rust-lua53 Aims to be complete Rust bindings for Lua 5.3 and beyond. Currently, master is tracking Lua 5.3.3. Requires a Unix-like environment. On Win

Safe Rust bindings to Lua 5.1

rust-lua Copyright 2014 Lily Ballard Description This is a set of Rust bindings to Lua 5.1. The goal is to provide a (relatively) safe interface to Lu

Zero-cost high-level lua 5.3 wrapper for Rust

td_rlua This library is a high-level binding for Lua 5.3. You don't have access to the Lua stack, all you can do is read/write variables (including ca

Rust library to interface with Lua

hlua This library is a high-level binding for Lua 5.2. You don't have access to the Lua stack, all you can do is read/write variables (including callb

Comments
  • Separate w and W handling

    Separate w and W handling

    The differences are sufficient in how it affects the handling of current filepath to warrant a separate handler. Current implementation has some errors causing the filepath to be changed unduly if there is no explicit selection given to W, which has now caused me some minor data loss....

    opened by sidju 1
  • Undo behaviour

    Undo behaviour

    There is some debate over undo behaviours. The options (I currently know of) are:

    • "simple" undo, where all redo potential is lost when you perform an action
    • "tree" redo, where every action after you have undone creates a new branch
    • "revert" undo, where the undo is an undoable action (see here)

    Aside from simple (which is currently imlemented) the behaviours enable accessing every state the application has been in during this session.

    I don't have strong opinions, if someone is gifted with such please opine and/or share PRs here.

    opened by sidju 0
Owner
null
whydia is a small embeddable scripting language

whydia is a small embeddable scripting language It's inspired by Javascript, Lox, Lua, Python, Rust and more Reference Overview Declaring variables us

Adi Yenuubarii 4 Apr 15, 2022
Slitter is a C- and Rust-callable slab allocator implemented primarily in Rust, with some C for performance or to avoid unstable Rust features.

Slitter is a less footgunny slab allocator Slitter is a classically structured thread-caching slab allocator that's meant to help write reliable long-

Backtrace Labs 133 Dec 5, 2022
A Rust crate for automatically generating C header files from Rust source file.

Please be aware that this crate is no longer actively maintained, please look into the much more feature rich cbindgen instead. rusty-cheddar rusty-ch

Sean Marshallsay 190 Nov 12, 2022
Rust-ffi-guide - A guide for doing FFI using Rust

Using unsafe for Fun and Profit A guide to traversing the FFI boundary between Rust and other languages. A rendered version is available here. This gu

Michael Bryan 261 Dec 1, 2022
Rust library for build scripts to compile C/C++ code into a Rust library

A library to compile C/C++/assembly into a Rust library/application.

Alex Crichton 1.3k Dec 21, 2022
Rust based WASM/JS bindings for ur-rust

ur-wasm-js WASM/JS bindings for the ur-rust rust library Getting started Installation Either build the library yourself with wasm-pack or install for

Lightning Digital Entertainment 5 Feb 28, 2024
A project for generating C bindings from Rust code

cbindgen   Read the full user docs here! cbindgen creates C/C++11 headers for Rust libraries which expose a public C API. While you could do this by h

Ryan Hunt 1.7k Jan 3, 2023
Automatically generates Rust FFI bindings to C (and some C++) libraries.

bindgen bindgen automatically generates Rust FFI bindings to C (and some C++) libraries. For example, given the C header doggo.h: typedef struct Doggo

The Rust Programming Language 3.2k Jan 4, 2023
Safe interop between Rust and C++

CXX — safe FFI between Rust and C++ This library provides a safe mechanism for calling C++ code from Rust and Rust code from C++, not subject to the m

David Tolnay 4.4k Jan 7, 2023
Safe Rust bridge for creating Erlang NIF functions

Rustler Documentation | Getting Started | Example Rustler is a library for writing Erlang NIFs in safe Rust code. That means there should be no ways t

Rusterlium 3.5k Jan 7, 2023