Skip to content

Commit

Permalink
Merge 91b274c into 8dfe3c3
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Dec 14, 2023
2 parents 8dfe3c3 + 91b274c commit 87e2faa
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions documentation/c05-packages.sil
Expand Up @@ -274,6 +274,10 @@ This section introduces packages that could not fit in another category.
\status:low
\package-documentation{ifattop}

\subsection{defaults}
\status:high
\package-documentation{defaults}

\section{Frames and page layouts}

As we mentioned in the first chapter, SILE uses frames as an indication of where to put text onto
Expand Down
75 changes: 75 additions & 0 deletions packages/defaults/init.lua
@@ -0,0 +1,75 @@
local base = require("packages.base")

local package = pl.class(base)
package._name = "defaults"

local semver = require("semver")

local semver_descending = function (a, b)
a, b = semver(a), semver(b)
return a > b
end

-- Defaults that go out of fassion
package.old_defaults = {
["0.15.0"] = {
["shaper.spaceenlargementfactor"] = 1.2,
["document.parindent"] = SILE.nodefactory.glue(20),
-- ["linespacing.method"] = "tex",
},
}

function package:_init (options)
base._init(self, options)
self:defaults(options.target)
end

function package:defaults (target)
target = semver(target and target or SILE.version)
local target_hit = false
for version, settings in pl.tablex.sort(self.old_defaults, semver_descending) do
version = semver(version)
for parameter, value in pairs(settings) do
SU.debug("defaults", ("Resetting '%s' to '%s' as it was prior to v%s"):format(parameter, tostring(value), version))
SILE.settings:set(parameter, value, true)
end
if target_hit then break end
if version <= target then target_hit = true end
end
end

function package:registerCommands ()

self:registerCommand("defaults", function (options, content)
if content then
SILE.settings:temporarily(function ()
self:defaults(options.target)
end)
else
self:defaults(options.target)
end
end)

end

local doctarget = "v" .. tostring(semver(SILE.version))
package.documentation = ([[
\begin{document}
From time to time, the default value of a setting in SILE might change with a new release.
If these changes are expected to cause document reflows they will be marked as breaking changes.
The previous behaviour can always be restored by manually setting the old values, but knowing what those are requires carefully reading the release notes.
This package tries to restore as many previous setting values as possible to make old document render like they would have in previous releases without changing the documents themselves (beyond loading this package).
From inside a document, use \autodoc:command{\use[module=packages.defaults,target=%s]} to set defaults as they would have been in SILE %s.
This can also be triggered from the command line with no changes to a document:
\begin{autodoc:codeblock}
$ sile -u 'packages.defaults[target=%s]'
\end{autodoc:codeblock}
\end{document}
]]):format(doctarget, doctarget, doctarget)

return package

0 comments on commit 87e2faa

Please sign in to comment.