Skip to content

Commit

Permalink
Merge pull request #1522 from alerque/order-of-ops
Browse files Browse the repository at this point in the history
Touchup package annoyances
  • Loading branch information
alerque authored Aug 11, 2022
2 parents a88575e + 215e83a commit 625f5fd
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 28 deletions.
8 changes: 4 additions & 4 deletions classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ class.hooks = {
class.packages = {}

function class:_init (options)
SILE.scratch.half_initialized_class = self
if self == options then options = {} end
SILE.languageSupport.loadLanguage('und') -- preload for unlocalized fallbacks
self:declareOptions()
self:registerRawHandlers()
self:registerCommands()
self:declareSettings()
self:registerCommands()
self:setOptions(options)
self:declareFrames(self.defaultFrameset)
self:registerPostinit(function (self_)
Expand All @@ -72,6 +73,7 @@ function class:_post_init ()
func(self)
self.deferredInit[i] = nil
end
SILE.scratch.half_initialized_class = nil
end

function class:setOptions (options)
Expand All @@ -83,6 +85,7 @@ function class:setOptions (options)
end

function class:declareOption (option, setter)
rawset(getmetatable(self.options)._opts, option, nil)
self.options[option] = setter
end

Expand Down Expand Up @@ -138,9 +141,6 @@ end
function class:loadPackage (packname, options)
local pack = require(("packages.%s"):format(packname))
if type(pack) == "table" and pack.type == "package" then -- new package
if not self._initialized then
SILE.scratch.half_initialized_class = self
end
self.packages[pack._name] = pack(options)
else -- legacy package
self:initPackage(pack, options)
Expand Down
14 changes: 7 additions & 7 deletions classes/book.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class.defaultFrameset = {
}

function class:_init (options)
plain._init(self, options)
self:loadPackage("counters")
self:loadPackage("masters", {{
id = "right",
Expand All @@ -41,7 +42,6 @@ function class:_init (options)
oddPageMaster = "right",
evenPageMaster = "left"
})
plain._init(self, options)
self:loadPackage("tableofcontents")
self:loadPackage("footnotes", {
insertInto = "footnotes",
Expand Down Expand Up @@ -213,14 +213,14 @@ function class:registerCommands ()
toc = options.toc,
level = 3
}, content)
local lang = SILE.settings:get("document.language")
local postcmd = "book:subsection:post"
if SILE.Commands[postcmd .. ":" .. lang] then
postcmd = postcmd .. ":" .. lang
end
SILE.call(postcmd)
SILE.process(content)
end)
local lang = SILE.settings:get("document.language")
local postcmd = "book:subsection:post"
if SILE.Commands[postcmd .. ":" .. lang] then
postcmd = postcmd .. ":" .. lang
end
SILE.call(postcmd)
SILE.typesetter:leaveHmode()
SILE.call("novbreak")
SILE.call("medskip")
Expand Down
7 changes: 4 additions & 3 deletions core/measurement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ local measurement = pl.class({
if not parsed then SU.error("Could not parse measurement '"..amount.."'") end
self.amount, self.unit = parsed.amount, parsed.unit
end
if not SILE.units[self.unit] then SU.error("Unknown unit: " .. unit) end
self.relative = SILE.units[self.unit].relative
local _su = SILE.units[self.unit]
if not _su then SU.error("Unknown unit: " .. unit) end
self.relative = _su.relative
if self.unit == "pt" then self._mutable = true end
end,

Expand All @@ -79,7 +80,7 @@ local measurement = pl.class({

tonumber = function (self)
local def = SILE.units[self.unit]
local amount = def.converter and def.converter(self.amount) or self.amount * def.value
local amount = def.converter and def.converter(self.amount) or (self.amount * def.value)
return amount
end,

Expand Down
2 changes: 1 addition & 1 deletion packages/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package.class = nil
package.exports = {}

function package:_init (_)
self.class = SILE.documentState.documentClass or SILE.scratch.half_initialized_class
self.class = SILE.scratch.half_initialized_class or SILE.documentState.documentClass
if not self.class then
SU.error("Attempted to initialize package before class, should have been queued in the preamble", true)
end
Expand Down
4 changes: 2 additions & 2 deletions packages/math/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ function package:_init ()
local texlike = require("packages.math.texlike")
self.convertTexlike, self.compileToMathML = texlike[1], texlike[2]
-- Register a new unit that is 1/18th of the current math font size
SILE.units["mu"] = {
SILE.registerUnit("mu", {
relative = true,
definition = function (value)
return value * SILE.settings:get("math.font.size") / 18
end
}
})
end

function package.declareSettings (_)
Expand Down
7 changes: 5 additions & 2 deletions packages/parallel/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ function package:_init (options)
-- Fixed leading here is obviously a bug, but n-way leading calculations
-- get very complicated...
-- typesetterPool[frame].leadingFor = function() return SILE.nodefactory.vglue(SILE.settings:get("document.lineskip")) end
local fontcommand = frame .. ":font"
self:registerCommand(frame, function (_, _) -- \left ...
SILE.typesetter = typesetterPool[frame]
SILE.call(frame..":font")
SILE.call(fontcommand)
end)
self:registerCommand(frame..":font", function (_, _) end) -- to be overridden
if not SILE.Commands[fontcommand] then
self:registerCommand(fontcommand, function (_, _) end) -- to be overridden
end
end
if not options.folios then
folioOrder = { {} }
Expand Down
14 changes: 7 additions & 7 deletions packages/tableofcontents/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ if not SILE.scratch._tableofcontents then
SILE.scratch._tableofcontents = {}
end

local function _moveTocNodes (class)
function package:moveTocNodes ()
local node = SILE.scratch.info.thispage.toc
if node then
for i = 1, #node do
node[i].pageno = class.packages.counters:formatCounter(SILE.scratch.counters.folio)
node[i].pageno = self.packages.counters:formatCounter(SILE.scratch.counters.folio)
table.insert(SILE.scratch.tableofcontents, node[i])
end
end
end

local function _writeToc (_)
function package.writeToc (_)
local tocdata = pl.pretty.write(SILE.scratch.tableofcontents)
local tocfile, err = io.open(SILE.masterFilename .. '.toc', "w")
if not tocfile then return SU.error(err) end
Expand Down Expand Up @@ -76,10 +76,10 @@ function package:_init ()
end
self.class:loadPackage("infonode")
self.class:loadPackage("leaders")
self.class:registerHook("endpage", _moveTocNodes)
self.class:registerHook("finish", _writeToc)
self:deprecatedExport("writeToc", _writeToc)
self:deprecatedExport("moveTocNodes", _moveTocNodes)
self.class:registerHook("endpage", self.moveTocNodes)
self.class:registerHook("finish", self.writeToc)
self:deprecatedExport("writeToc", self.writeToc)
self:deprecatedExport("moveTocNodes", self.moveTocNodes)
end

function package:registerCommands ()
Expand Down
4 changes: 2 additions & 2 deletions sile.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ SILE = require("core.sile")

io.stdout:setvbuf 'no'

SILE.cli:parseArguments()

if not os.getenv 'LUA_REPL_RLWRAP' then
io.stderr:write(SILE.full_version .. '\n')
end

SILE.cli:parseArguments()

local ProFi
if SU.debugging("profile") then
ProFi = require("ProFi")
Expand Down

0 comments on commit 625f5fd

Please sign in to comment.