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
|
local c,cs,cT,lT,lP="","",{},{},1
|
||||||
if s then
|
local function lf(s)
|
||||||
if f then
|
local f=fopen(s,"rb")
|
||||||
c=s
|
local nc=fread(f,2048)
|
||||||
else
|
while nc ~= nil and nc ~= "" do
|
||||||
local f=fopen(s,"rb")
|
c=c..nc
|
||||||
local nc=fread(f,2048)
|
nc=fread(f,2048)
|
||||||
while nc ~= nil and nc ~= "" do
|
|
||||||
c=c..nc
|
|
||||||
nc=fread(f,2048)
|
|
||||||
end
|
|
||||||
end
|
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
|
for l in c:gmatch("(.-)\n") do lT[#lT+1]=l end
|
||||||
end
|
end
|
||||||
while true do
|
while true do
|
||||||
@ -40,22 +44,23 @@ function skex(s,f)
|
|||||||
c=""
|
c=""
|
||||||
for k,v in ipairs(lT) do c=c..v.."\n" end
|
for k,v in ipairs(lT) do c=c..v.."\n" end
|
||||||
print(pcall(load(c)))
|
print(pcall(load(c)))
|
||||||
|
elseif cT[1] == "r" then
|
||||||
|
s=cT[2] or s
|
||||||
|
wf(s)
|
||||||
elseif cT[1] == "w" then
|
elseif cT[1] == "w" then
|
||||||
f=fopen(s,"wb")
|
s=cT[2] or s
|
||||||
c=""
|
wf(s)
|
||||||
for k,v in ipairs(lT) do fwrite(f,v.."\n") end
|
|
||||||
fclose(f)
|
|
||||||
elseif cT[1] == "d" then
|
elseif cT[1] == "d" then
|
||||||
for i = 1, TN(cT[3])-TN(cT[2]) do
|
for i = 1, TN(cT[3])-TN(cT[2]) do
|
||||||
T.remove(lT,cT[2])
|
T.remove(lT,cT[2])
|
||||||
end
|
end
|
||||||
elseif cT[1] == "p" then
|
elseif cT[1] == "p" then
|
||||||
nPT=TN(cT[2])
|
lP=TN(cT[2]) or lP
|
||||||
if nPT then
|
print(lP)
|
||||||
lP=nPT
|
elseif cs:sub(1,1) == "!" then
|
||||||
else
|
c=""
|
||||||
print(lP)
|
for k,v in ipairs(lT) do c=c..v.."\n" end
|
||||||
end
|
print(pcall(load(cs:sub(2))))
|
||||||
else
|
else
|
||||||
print("?")
|
print("?")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user