Crates.io | add-ed |
lib.rs | add-ed |
version | 0.13.0 |
source | src |
created_at | 2021-05-18 10:36:43.497705 |
updated_at | 2023-11-12 19:42:04.324503 |
description | Embeddable pure rust editor based on ED |
homepage | |
repository | https://github.com/sidju/add-ed |
max_upload_size | |
id | 398932 |
size | 417,382 |
Some time ago I decided to write an ED clone with syntax highlighting,
hired. On my way to that I found that the
macro commands (g
, v
, G
, V
, :
) pretty much require that you write an
ED library for them. So I did, and here it is.
I have taken some liberties in the commands I have found less than ergonomic, so especially advanced commands have some differences (both syntax and behaviour) from GNU Ed. This strives to be a list of these changes.
g
and related commands take command list in input mode (with the regex
separator as terminator instead of '.').
(Also, the 'I' suffix for case insensitive matching isn't implemented)#
accepts a selection and will set state.selection to it without printing
anything. This is added to be able to set selection without printing.The original ED keeps track of the last line you interacted with and defaults to
working on that for most commands. I felt this deserved expanding, so add-ed
instead tracks the last span of lines you interacted with. My hope is that this
is more intuitive. (To avoid unpleasantries such as partial saving some commands
default to the whole buffer instead, ie. w
.)
The library has been designed with clear traits to enable changing out most components easily. For example it should be somewhat easy to create a SSH/SFTP IO implementation for remote editing, a GUI frontend implementing the UI trait or a MacroGetter that loads macros from any given filepath.
A
and I
commands, which first a
/i
and then j
the preceding/following
line. Perfect for commenting out a single line or adding a forgotten ';'.
C
command, acts as c
but hands out the selection's previous value to the
UI's input method. This enables you to edit the selection instead of replacing
it.
(Availability depends on UI and the initial_input_data
feature.)
P
command, toggles the default for the given print flags.
:
command, runs the macro with the name given as argument (whitespace
trimmed). Macro execution behaves like 'g' execution. 'q' or error returns
early.
|
command, pipes selection through given shell command (like <selection>!
does in vim). It is distinct from !
to enable defaulting to current
selection when no explicit selection is given.
Include and expose a simple local fs and shell IO
implementation.
Add 'C' command. This modifies the UI trait.
#[derive(serde::Serialize, serde::Deserialize)]
on Macro
struct.
Other structs can get derived on upon request, but Macro
(and its members) was
the only one that seemed relevant.
This project is essentially built upon the regex crate, as regex is the heart of Ed.
There are two main contributions welcomed as of now.