An implementation of the standard Unix editor "ed", written in Lua
Lua Shell D Perl R Rebol Other
Permalink
Failed to load latest commit information.
testsuite Add ed-1.5 testsuite, modified where necessary for different regex sy… Apr 12, 2011
Makefile
README Document more changes ("P What now? ") in README Apr 15, 2011
buffer.lua
ed Add README, Makefile and the "ed" shell script Apr 12, 2011
ed.lua Modifications for lua5.2: ed.lua must return ed for lua(.sh) to work Oct 24, 2012
inout.lua Merge branch 'master' of github.com:martinwguy/lua-ed Jul 18, 2012
mainloop.lua From ed-1.11: Fixed 'z' command. (zN printed N + 1 lines). Jan 16, 2015
regex.lua

README

This is a version of the standard Unix editor "ed", implemented in Lua.

It was written by translating the sources of GNU ed 1.5 into Lua, but using
the Lua search-and-replace patterns instead of standard regex.

CHANGES

- Patterns for search and replace are Lua 5.1 patterns (as used in string.gsub)
  which has different syntax for matching and replacing, including:
  - s/foo/bar/3 replaces the first three occurrences of foo instead of the
    third because that is how the Lua "snum" parameter works.
  However, the replacement pattern "%" (the same as the previous substitution)
  is recognized.
- The contents of the yank buffer remain intact when editing a different file
  so you can yank lines from one file and put them into another.
- The 'l' command lists control characters as \nnn in decimal, not octal
  (to follow the Lua convention).
- The 'P' command can be followed by an optional parameter after a space to set
  the prompt string.  Trailing spaces are recognized and preserved. e.g.:
  P >>> 
- Prompt and error message printing are on by default.

BUGS

- Shell escapes and piping are not implemented
- The pattern cannot contain the search pattern delimiter,
  which should be able to occur inside character ranges "/[/]/
  or if quoted as "\/" (or maybe "%/").
- Unbalanced square brackets in patterns are not an error here.
  (e.g. testsuite s10 succeeds when it should fail)
- There are some rare cases (bugs) when an error value (nil) is returned from
  below without having printed (or set) an error message.
  In these cases we print "Something went wrong". This should never happen...
- NUL characters in files are not handled.  They have the effect of truncating
  the line at that character.  This is due to the Lua 5.1 string library
  failing to handle NULs (and is fixed in Lua 5.2 but untested here).

It passes the GNU ed 1.5 test suite, modulo scripts that use shell escapes
and modulo the different regular expression syntax.
In the copy of "testsuite" here, the regex syntax for runnable tests has been
modified to use the Lua syntax.

Enjoy

   Martin Guy <martinwguy@gmail.com>, March 2011