skex2 updates and documentation
This commit is contained in:
parent
8b2d6778dc
commit
ed85e857ff
57
doc/skex2.md
Normal file
57
doc/skex2.md
Normal file
@ -0,0 +1,57 @@
|
||||
# skex2
|
||||
|
||||
## interactive line editor
|
||||
|
||||
skex2 is a simple but functional line editor for MultICE.
|
||||
|
||||
### invocation
|
||||
|
||||
To start skex2, simply run skex(filename) from the Lua prompt.
|
||||
|
||||
### usage
|
||||
|
||||
Generally, commands and arguments are entered in the form of `command argument1 argument2 argument3` with the exception of inline execution, which is in the form of `!lua code here`.
|
||||
|
||||
If skex does not understand what you mean, it will output a line with a question mark.
|
||||
|
||||
### commands
|
||||
|
||||
#### q - quit skex2
|
||||
|
||||
Exits the program.
|
||||
|
||||
#### l \[start\] \[end\] - list contents
|
||||
|
||||
Output the lines from start to end, inclusive.
|
||||
|
||||
#### f \[filename\] - set the filename
|
||||
|
||||
This sets the filename to be used for I/O, or prints the current one.
|
||||
|
||||
#### r \[filename\] - load file
|
||||
|
||||
Reads from *filename* or the current set via **f**
|
||||
|
||||
#### w \[filename\] - write to file
|
||||
|
||||
Writes to *filename* or the current set via **f**
|
||||
|
||||
#### p \[line\] - print or set current line
|
||||
|
||||
As skex2 is a line editor, your pointer is a line, and this either prints the current one or sets a new one.
|
||||
|
||||
#### a \[line\] - append to buffer
|
||||
|
||||
Appends lines after the current line or *line* until a line with only . is entered.
|
||||
|
||||
#### i \[line\] - insert into buffer
|
||||
|
||||
Inserts lines before the current line or *line* until a line with only . is entered.
|
||||
|
||||
#### s \[line\] - replace line
|
||||
|
||||
Removes the current line or *line* and enters insert mode
|
||||
|
||||
#### e - executes the contents of the buffer
|
||||
|
||||
Basically converts it into one big string and loads it.
|
@ -1,16 +1,20 @@
|
||||
function skex(s,f)
|
||||
function skex(s)
|
||||
local c,cs,cT,lT,lP="","",{},{},1
|
||||
if s then
|
||||
if f then
|
||||
c=s
|
||||
else
|
||||
local f=fopen(s,"rb")
|
||||
local nc=fread(f,2048)
|
||||
while nc ~= nil and nc ~= "" do
|
||||
c=c..nc
|
||||
nc=fread(f,2048)
|
||||
end
|
||||
local function lf(s)
|
||||
local f=fopen(s,"rb")
|
||||
local nc=fread(f,2048)
|
||||
while nc ~= nil and nc ~= "" do
|
||||
c=c..nc
|
||||
nc=fread(f,2048)
|
||||
end
|
||||
end
|
||||
local function wf(s)
|
||||
local f,c=fopen(s,"wb"),""
|
||||
for k,v in ipairs(lT) do fwrite(f,v.."\n") end
|
||||
fclose(f)
|
||||
end
|
||||
if s then
|
||||
lf(s)
|
||||
for l in c:gmatch("(.-)\n") do lT[#lT+1]=l end
|
||||
end
|
||||
while true do
|
||||
@ -40,22 +44,23 @@ function skex(s,f)
|
||||
c=""
|
||||
for k,v in ipairs(lT) do c=c..v.."\n" end
|
||||
print(pcall(load(c)))
|
||||
elseif cT[1] == "r" then
|
||||
s=cT[2] or s
|
||||
wf(s)
|
||||
elseif cT[1] == "w" then
|
||||
f=fopen(s,"wb")
|
||||
c=""
|
||||
for k,v in ipairs(lT) do fwrite(f,v.."\n") end
|
||||
fclose(f)
|
||||
s=cT[2] or s
|
||||
wf(s)
|
||||
elseif cT[1] == "d" then
|
||||
for i = 1, TN(cT[3])-TN(cT[2]) do
|
||||
T.remove(lT,cT[2])
|
||||
end
|
||||
elseif cT[1] == "p" then
|
||||
nPT=TN(cT[2])
|
||||
if nPT then
|
||||
lP=nPT
|
||||
else
|
||||
print(lP)
|
||||
end
|
||||
lP=TN(cT[2]) or lP
|
||||
print(lP)
|
||||
elseif cs:sub(1,1) == "!" then
|
||||
c=""
|
||||
for k,v in ipairs(lT) do c=c..v.."\n" end
|
||||
print(pcall(load(cs:sub(2))))
|
||||
else
|
||||
print("?")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user