Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |