|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://angg.twu.net/LUA/TProps1.lua.html
-- http://angg.twu.net/LUA/TProps1.lua
-- (find-angg "LUA/TProps1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
-- See: (find-angg "emlua/emlua-buttons.el")
--
-- (defun e () (interactive) (find-angg "LUA/TProps1.lua"))
-- -- (find-angg "LUA/Pict2e1.lua" "PradClass")
Es = Class {
type = "Es",
--
-- Low-level formatting words:
format = function (fmt, ...)
local args = {...}
local f = function (n) return tostring(args[tonumber(n)]) end
return (fmt:gsub("%%(%d)", f))
end,
find_fline = function (fname, n)
return Es.format('(find-fline "%1" %2)', fname, n)
end,
find_2a = function (sexp)
return Es.format("(find-2a nil '%1)", sexp)
end,
mkbutton = function (text, sexp)
return Es.format("(mkbutton \"%1\" '%2)", text, sexp)
end,
--
-- toe (to Emacs string) and variants:
toe = function (es)
if type(es) == "string" then return '"'..es..'"' end
return es:toe()
end,
insert = function (es) return "(insert "..Es.toe(es).."\n)" end,
concat = function (es) return "(concat "..Es.toe(es).."\n)" end,
insertn = function (es) return "(insert \"\\n\"\n"..Es.toe(es).."\n)" end,
--
__index = {
concat = function (es) return Es.concat(es) end,
insert = function (es) return Es.insert(es) end,
insertn = function (es) return Es.insertn(es) end,
},
}
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "TProps1.lua"
= Es.format("foo %1 %2 %1:", 22, "3_3")
= Es.find_fline("/tmp/foo", 42)
= Es.find_2a(Es.find_fline("/tmp/foo", 42))
= Es.mkbutton("tofile", Es.find_2a(Es.find_fline("/tmp/foo", 42)))
--]]
EsFindFline = Class {
type = "EsFindFline",
new = function (text, fname, linen)
return EsFindFline {text=text, fname=fname, linen=linen}
end,
__concat = function (a, b) return EsList {a, b} end,
__tostring = function (esfl) return esfl.text end,
__index = methodsover(Es.__index) {
find_fline = function (esfl)
return Es.find_fline(esfl.fname, esfl.linen)
end,
mkbutton = function (esfl)
return Es.mkbutton(esfl.text, Es.find_2a(esfl:find_fline()))
end,
toe = function (esfl)
return esfl:mkbutton()
end,
},
}
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "TProps1.lua"
esfl = EsFindFline.new("tofoo", "/tmp/foo", 42)
= esfl
= esfl:toe()
= esfl:insertn()
= esfl:toe()
= Es.insertn(esfl)
= Es.toe("foo")
esl = EsList { "foo: ", esfl }
= esl
= esl[1]
= esl[2]
= esl:toe()
= Es.insert(esl)
= Es.insertn(esl)
= Es.concat(esl)
--]]
EsList = Class {
type = "EsList",
mapconcat = function (f, A, sep)
if #A == 0 then return EsList {} end
local B = EsList { f(A[1]) }
for i=2,#B do
if sep then table.insert(B, sep) end
table.insert(B, f(A[i]))
end
return B
end,
__concat = function (a, b) return EsList {a, b} end,
__tostring = function (esl)
return mapconcat(tostring, esl)
end,
__index = methodsover(Es.__index) {
toe = function (esl)
return mapconcat(Es.toe, esl, "\n")
end,
},
}
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "TProps1.lua"
-- (find-emlua "emlua-buttons.el")
* (defun mkbutton (text sexp) (buttonize text `(lambda (&rest rest) ,sexp)))
= esl.."bar"
= (esl.."bar"):toe()
es = Es {a="aa", b="bb"}
--]]
-- Local Variables:
-- coding: utf-8-unix
-- End: