1. edward
    1. Repository
    2. Requirements
    3. API
    4. Example
    5. Version History
    6. License

edward

An implementation of the ed(1) text editor that can be extended with custom commands through a library component. Apart from the library, the Egg also ships a program component with a POSIX.1-2008 compatible ed editor which is implemented using the aforementioned library component. The library component itself leverages hygienic Scheme macros for the definition of custom editor commands and provides parser combinators for defining their input format.

Repository

https://github.com/nmeum/edward

Requirements

API

The API documentation is available separately: https://files.8pit.net/edward/1.1.0/doc/

This documentation is generated from Scheme source code comments using scmdoc. If you find any errors in the API description, then please file a bug report in the aforementioned GitHub repository.

Example

The following R7RS Scheme program utilizes the edward library component to create a custom version of the ed text editor which supports all POSIX commands, but additionally features a pipe command. The pipe command passes selected lines to a specified program via standard input and replace them with the standard output of this program.

(import (scheme base)
        (chicken process)
        (srfi 14)

        (edward cli)
        (edward util)
        (edward parse)
        (edward ed cmd)
        (edward ed addr)
        (edward ed posix)
        (edward ed editor))

;; Executor for the pipe command
(define (exec-pipe editor range cmd)
  (let-values (((in out _) (process cmd))
               ((lines) (editor-get-lines editor range)))
    (call-with-port
      out
      (lambda (port) (lines->port lines port)))
    (let ((recv (port->lines in)))
      (close-input-port in)
      (exec-delete editor range)
      (exec-insert editor (car range) (car recv)))))

;; Parser for the pipe command
(define-file-cmd (pipe exec-pipe (make-range))
  (parse-cmd-char #\|)
  (parse-token (char-set-complement (char-set #\newline))))

;; Start the editor
(edward-main)

Save this code in edward++.scm and compile it using:

 $ csc -R r7rs edward++.scm

The resulting binary behaves like a normal ed(1) implementation but additionally supports the aforementioned custom pipe command. As an example, this command allows passing the contents of an opened file with fold(1) using:

 1,$|fold -w 72 -s

More examples are provided as part of the edward-contrib repository.

Version History

1.1.0
POSIX compliance fixes, performance improvements, several API changes.
1.0.1
Initial release for the CHICKEN Egg index.

Prior releases are were not packaged as CHICKEN Eggs but are available on GitHub.

License

This module is licensed under GPL-3.0-or-later.