Open ctrlcctrlv opened 4 years ago
If what you want it to save the condition (not content) of the typesetter there is already SILE.typesetter.pushState()
and .popState()
. If what you want is to try something on for size, cache the content of SILE.typesetter.state.nodes and restore it when you are done. The catch is that you can't get away with doing so much with the content in the mean time that you get to a page break or other point that flushes the content to PDF or otherwise casts it in stone; everything is still processed a page at a time and once you finalize a page you can't really go back and undo anything.
It would be useful in some cases to do everything in memory to enable more sweeping use cases, but in most cases when you want to do this it's for a few nodes in the current horizontal queue anyway. You'll find lots of places scattered around the SILE code that does this already.
Also, you probably don't want to be inventing an eval like this:
local eval = function (evalme)
-- ...
SILE.process(evalme)
end
eval(string.format("\\glue[width=%d]", cursorX))
Ty just passing Lua lambdas:
local myfunc = function (content)
-- ...
SILE.process(content)
end
myfunc(function() SILE.call("glue", { width = cursorX }) end)
There are several other errors in that Lua code mockup, but using fewer layers of parsing and language switching would make it a lot easier to see them.
This is really really really an unclear issue, and I don't get where the discussion between @alerque and @ctrlcctrlv was heading. Can we have a better rewording of the actual need to address, or close it?
I get where this was going. And I've been headed towards this for a while.
We already have a settings API for this (push/pop state). What we need is one for ALL states including the outputter. As a partial measure we already do this in practice using an ugly hack to output some nodes, then measure, then rip them out of the node queue. What we don't have is a nice interface for it that makes it user friendly. Also it only works before the page break is finalized.
I think we should keep going in stages to achieve a full rewind capability.
E.g.:
issue925.lua
We have a function like this in the FontForge Python API, I think it is very useful.