Skip to content

Commit a47b8f3

Browse files
committed
fix(utilities): Normalize formatting of messages, warnings, and errors
1 parent 9b24a1b commit a47b8f3

File tree

25 files changed

+260
-190
lines changed

25 files changed

+260
-190
lines changed

classes/base.lua

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function class:declareOptions ()
122122
if self._legacy then
123123
self._name = name
124124
elseif name ~= self._name then
125-
SU.error("Cannot change class name after instantiation, derive a new class instead.")
125+
SU.error("Cannot change class name after instantiation, derive a new class instead")
126126
end
127127
end
128128
return self._name
@@ -247,10 +247,11 @@ function class:initPackage (pack, options)
247247
"0.14.0",
248248
"0.16.0",
249249
[[
250-
This package appears to be a legacy format package. It returns a table
251-
and expects SILE to guess about what to do. New packages inherit
252-
from the base class and have a constructor function (_init) that
253-
automatically handles setup.]]
250+
This package appears to be a legacy format package. It returns a table and
251+
expects SILE to guess about what to do. New packages inherit from the base
252+
class and have a constructor function (_init) that automatically handles
253+
setup.
254+
]]
254255
)
255256
if type(pack) == "table" then
256257
if pack.exports then
@@ -391,7 +392,11 @@ function class:registerCommands ()
391392
self:registerCommand(options["command"], content)
392393
return
393394
elseif options.command == "process" then
394-
SU.warn("Did you mean to re-definine the `\\process` macro? That probably won't go well.")
395+
SU.warn([[
396+
Did you mean to re-definine the `\\process` macro?
397+
398+
That probably won't go well.
399+
]])
395400
end
396401
self:registerCommand(options["command"], function (_, inner_content)
397402
SU.debug("macros", "Processing macro \\" .. options["command"])
@@ -438,7 +443,7 @@ function class:registerCommands ()
438443
self:registerCommand("comment", function (_, _) end, "Ignores any text within this command's body.")
439444

440445
self:registerCommand("process", function ()
441-
SU.error("Encountered unsubstituted \\process.")
446+
SU.error("Encountered unsubstituted \\process")
442447
end, "Within a macro definition, processes the contents of the macro body.")
443448

444449
self:registerCommand("script", function (options, content)
@@ -450,22 +455,21 @@ function class:registerCommands ()
450455
"0.15.0",
451456
"0.16.0",
452457
([[
453-
The \script function has been deprecated. It was overloaded to mean
454-
too many different things and more targeted tools were introduced in
455-
SILE v0.14.0. To load 3rd party modules designed for use with SILE,
456-
replace \script[src=...] with \use[module=...]. To run arbitrary Lua
457-
code inline use \lua{}, optionally with a require= parameter to load
458-
a (non-SILE) Lua module using the Lua module path or src= to load a
459-
file by file path.
458+
The \script function has been deprecated. It was overloaded to mean too many
459+
different things and more targeted tools were introduced in SILE v0.14.0. To
460+
load 3rd party modules designed for use with SILE, replace \script[src=...]
461+
with \use[module=...]. To run arbitrary Lua code inline use \lua{}, optionally
462+
with a require= parameter to load a (non-SILE) Lua module using the Lua module
463+
path or src= to load a file by file path.
460464
461-
For this use case consider replacing:
465+
For this use case consider replacing:
462466
463-
%s
467+
%s
464468
465-
with:
469+
with:
466470
467-
%s
468-
]]):format(original, suggested)
471+
%s
472+
]]):format(original, suggested)
469473
)
470474
end
471475
if SU.ast.hasContent(content) then
@@ -548,9 +552,12 @@ function class:registerCommands ()
548552
SILE.processString(doc, "lua", nil, packopts)
549553
else
550554
if options.src then
551-
SU.warn(
552-
"Use of 'src' with \\use is discouraged because some of it's path handling\n will eventually be deprecated. Use 'module' instead when possible."
553-
)
555+
SU.warn([[
556+
Use of 'src' with \\use is discouraged.
557+
558+
Its path handling will eventually be deprecated.
559+
Use 'module' instead when possible.
560+
]])
554561
SILE.processFile(options.src, "lua", packopts)
555562
else
556563
local module = SU.required(options, "module", "use")

classes/plain.lua

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,17 @@ function class:registerCommands ()
7878

7979
self:registerCommand("noindent", function (_, content)
8080
if #SILE.typesetter.state.nodes ~= 0 then
81-
SU.warn([[\noindent was called after paragraph content has already been processed.
82-
83-
This will not result in avoiding the current paragraph being indented.
84-
This function must be called before any content belonging to the
85-
paragraph is processed. If the intent was to suppress indentation of a
86-
following paragraph, first explicitly close the current paragraph. From
87-
an input document this is typically done with an empty line between
88-
paragraphs, but calling the \par command explicitly or from Lua code
89-
running SILE.call("par") will end the current paragraph.
90-
]])
81+
SU.warn([[
82+
\noindent was called after paragraph content has already been processed
83+
84+
This will not result in avoiding the current paragraph being indented. This
85+
function must be called before any content belonging to the paragraph is
86+
processed. If the intent was to suppress indentation of a following paragraph,
87+
first explicitly close the current paragraph. From an input document this is
88+
typically done with an empty line between paragraphs, but calling the \par
89+
command explicitly or from Lua code running SILE.call("par") will end
90+
the current paragraph.
91+
]])
9192
end
9293
SILE.settings:set("current.parindent", SILE.types.node.glue())
9394
SILE.process(content)
@@ -181,14 +182,22 @@ function class:registerCommands ()
181182

182183
self:registerCommand("framebreak", function (_, _)
183184
if not SILE.typesetter:vmode() then
184-
SU.warn("framebreak was not intended to work in horizontal mode. Behavior may change in future versions")
185+
SU.warn([[
186+
\\framebreak was not intended to work in horizontal mode
187+
188+
Behavior may change in future versions.
189+
]])
185190
end
186191
SILE.call("penalty", { penalty = -10000, vertical = true })
187192
end, "Requests a frame break (switching to vertical mode if needed)")
188193

189194
self:registerCommand("pagebreak", function (_, _)
190195
if not SILE.typesetter:vmode() then
191-
SU.warn("pagebreak was not intended to work in horizontal mode. Behavior may change in future versions")
196+
SU.warn([[
197+
\\pagebreak was not intended to work in horizontal mode
198+
199+
Behavior may change in future versions.
200+
]])
192201
end
193202
SILE.call("penalty", { penalty = -20000, vertical = true })
194203
end, "Requests a non-negotiable page break (switching to vertical mode if needed)")
@@ -263,7 +272,11 @@ function class:registerCommands ()
263272

264273
self:registerCommand("center", function (_, content)
265274
if #SILE.typesetter.state.nodes ~= 0 then
266-
SU.warn("\\center environment started after other nodes in a paragraph, may not center as expected")
275+
SU.warn([[
276+
\\center environment started after other nodes in a paragraph
277+
278+
Content may not be centered as expected.
279+
]])
267280
end
268281
SILE.settings:temporarily(function ()
269282
local lskip = SILE.settings:get("document.lskip") or SILE.types.node.glue()
@@ -366,12 +379,13 @@ function class:registerCommands ()
366379
"0.14.5",
367380
"0.16.0",
368381
[[
369-
The \quote command has *such* bad output it is being completely
370-
deprecated as unsuitable for general purpose use.
371-
The pullquote package (\use[module=packages.pullquote]) provides one
372-
alternative, and the blockquote environment provides another.
373-
But you can also copy and adapt the original source from the plain
374-
class if you need to maintain exact output past SILE v0.16.0.]]
382+
The \quote command has *such* bad output it is being completely deprecated as
383+
unsuitable for general purpose use. The pullquote package
384+
(\use[module=packages.pullquote]) provides one alternative, and the blockquote
385+
environment provides another. But you can also copy and adapt the original
386+
source from the plain class if you need to maintain exact output past
387+
SILE v0.16.0.
388+
]]
375389
)
376390
SILE.call("smallskip")
377391
SILE.call("par")
@@ -395,10 +409,11 @@ function class:registerCommands ()
395409
"0.14.6",
396410
"0.16.0",
397411
[[
398-
The new list package (\use[module=packages.lists) has much better
399-
typography for lists. If you want to maintain the exact output of listitem
400-
past SILE v0.16.0 copy the source of \listitem from the plain class into
401-
your project.]]
412+
The new list package (\use[module=packages.lists) has much better typography
413+
for lists. If you want to maintain the exact output of listitem past
414+
SILE v0.16.0 copy the source of \listitem from the plain class into your
415+
project.
416+
]]
402417
)
403418
SILE.call("medskip")
404419
SILE.typesetter:typeset("")
@@ -418,7 +433,11 @@ function class:registerCommands ()
418433
local hbox, hlist = SILE.typesetter:makeHbox(content)
419434
SILE.typesetter:pushHbox(hbox)
420435
if #hlist > 0 then
421-
SU.warn("Hbox has migrating content (ignored for now, but likely to break in future versions)")
436+
SU.warn([[
437+
\\hbox has migrating content
438+
439+
Ignored for now, but likely to break in future versions.
440+
]])
422441
-- Ugly shim:
423442
-- One day we ought to do SILE.typesetter:pushHlist(hlist) here, so as to push
424443
-- back the migrating contents from within the hbox'ed content.

core/cli.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ cli.parseArguments = function ()
6464
end
6565
end)
6666
if not has_input_filename and not opts.output then
67-
SU.error(
68-
"Unable to derive an output filename (perhaps because input is a STDIO stream).\n"
69-
.. " Please use --output to set one explicitly."
70-
)
67+
SU.error([[
68+
Unable to derive an output filename (perhaps because input is a STDIO stream)
69+
70+
Please use --output to set one explicitly.
71+
]])
7172
end
7273
SILE.input.filenames = opts.INPUTS
7374
end

core/deprecations.lua

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ local nostd = function ()
55
"0.13.0",
66
"0.14.0",
77
[[
8-
Lua stdlib (std.*) is no longer provided by SILE, you may use
9-
local std = require("std")
10-
in your project directly if needed. Note you may need to install the Lua
11-
rock as well since it no longer ships as a dependency.]]
12-
)
8+
Lua stdlib (std.*) is no longer provided by SILE. You may use
9+
10+
local std = require("std")
11+
12+
in your project directly if needed. Note you may need to install the Lua rock
13+
as well since it no longer ships as a dependency.
14+
]])
1315
end
1416
-- luacheck: push ignore std
1517
---@diagnostic disable: lowercase-global
@@ -31,12 +33,12 @@ local fluentglobal = function ()
3133
"0.14.0",
3234
"0.15.0",
3335
[[
34-
The SILE.fluent object was never more than just an instance of a
35-
third party library with no relation the scope of the SILE object.
36-
This was even confusing me and marking it awkward to work on
37-
SILE-as-a-library. Making it a provided global clarifies whot it
38-
is and is not. Maybe someday we'll actually make a wrapper that
39-
tracks the state of the document language.]]
36+
The SILE.fluent object was never more than just an instance of a third party
37+
library with no relation the scope of the SILE object. This was even confusing
38+
me and marking it awkward to work on SILE-as-a-library. Making it a provided
39+
global clarifies whot it is and is not. Maybe someday we'll actually make a
40+
wrapper that tracks the state of the document language.
41+
]]
4042
)
4143
fluent_once = true
4244
end
@@ -52,8 +54,9 @@ local nobaseclass = function ()
5254
"0.13.0",
5355
"0.14.0",
5456
[[
55-
The inheritance system for SILE classes has been refactored using a different
56-
object model.]]
57+
The inheritance system for SILE classes has been refactored using a different
58+
object model.
59+
]]
5760
)
5861
end
5962
SILE.baseClass = setmetatable({}, {
@@ -89,13 +92,13 @@ local usetypes = function (type)
8992
"0.15.0",
9093
"0.16.0",
9194
([[
92-
In order to keep things tidy internally, more easily allow 3rd party
93-
packages to override core functions, and substitute some slow bits
94-
with Rust modules, internal types have been moved from the top level
95-
SILE global to a types namespace.
95+
In order to keep things tidy internally, more easily allow 3rd party packages
96+
to override core functions, and substitute some slow bits with Rust modules,
97+
internal types have been moved from the top level SILE global to a types
98+
namespace.
9699
97-
Please substitute 'SILE.%s()' with 'SILE.types.%s()'.
98-
]]):format(type, type)
100+
Please substitute 'SILE.%s()' with 'SILE.types.%s()'.
101+
]]):format(type, type)
99102
)
100103
return SILE.types[type]
101104
end
@@ -134,13 +137,13 @@ local usetypes2 = function (old, new, type)
134137
"0.15.0",
135138
"0.16.0",
136139
([[
137-
In order to keep things tidy internally, more easily allow 3rd party
138-
packages to override core functions, and substitute some slow bits
139-
with Rust modules, internal types have been moved from the top level
140-
SILE global to a types namespace.
140+
In order to keep things tidy internally, more easily allow 3rd party packages
141+
to override core functions, and substitute some slow bits with Rust modules,
142+
internal types have been moved from the top level SILE global to a types
143+
namespace.
141144
142-
Please substitute 'SILE.%s.%s()' with 'SILE.types.%s.%s()'.
143-
]]):format(old, type, new, type)
145+
Please substitute 'SILE.%s.%s()' with 'SILE.types.%s.%s()'.
146+
]]):format(old, type, new, type)
144147
)
145148
return SILE.types[new][type]
146149
end
@@ -174,7 +177,7 @@ function SILE.doTexlike (doc)
174177
"SILE.processString",
175178
"0.14.0",
176179
"0.16.0",
177-
[[Add format argument "sil" to skip content detection and assume SIL input]]
180+
[[Add format argument "sil" to skip content detection and assume SIL input.]]
178181
)
179182
return SILE.processString(doc, "sil")
180183
end
@@ -186,14 +189,14 @@ local nopackagemanager = function ()
186189
"0.13.2",
187190
"0.15.0",
188191
[[
189-
The built in SILE package manager has been completely deprecated. In its place
190-
SILE can now load classes, packages, and other resources installed via
191-
LuaRocks. Any SILE package may be published on LuaRocks.org or any private
192-
repository. Rocks may be installed to the host system root filesystem, a user
193-
directory, or a custom location. Please see the SILE manual for usage
194-
instructions. Package authors especially can review the template repository
195-
on GitHub for how to create a package.
196-
]]
192+
The built in SILE package manager has been completely deprecated. In its place
193+
SILE can now load classes, packages, and other resources installed via
194+
LuaRocks. Any SILE package may be published on LuaRocks.org or any private
195+
repository. Rocks may be installed to the host system root filesystem, a user
196+
directory, or a custom location. Please see the SILE manual for usage
197+
instructions. Package authors especially can review the template repository
198+
on GitHub for how to create a package.
199+
]]
197200
)
198201
end
199202

core/font.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ SILE.registerCommand("font", function (options, content)
4444
if options.language ~= "und" and icu and icu.canonicalize_language then
4545
local newlang = icu.canonicalize_language(options.language)
4646
-- if newlang ~= options.language then
47-
-- SU.warn("Language '"..options.language.."' not canonical, '"..newlang.."' will be used instead.")
47+
-- SU.warn("Language '"..options.language.."' not canonical, '"..newlang.."' will be used instead")
4848
-- end
4949
options.language = newlang
5050
end

core/opentype-parser.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ local parseDeviceTable = function (offset, fd)
427427
elseif header.deltaFormat == 0x0003 then
428428
buf = vstruct.read("> " .. math.ceil(size / 2) .. "*[2| i8 i8 ]", fd)
429429
else
430-
SU.warn("DeltaFormat " .. header.deltaFormat .. " in Device Table is not supported. Ignore the table.")
430+
SU.warn("DeltaFormat " .. header.deltaFormat .. " in Device Table is not supported; ignore the table")
431431
return nil
432432
end
433433
local deviceTable = {}

core/papersize.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ setmetatable(papersize, {
7979
return geometry
8080
end
8181
SU.error(string.format(
82-
[[Unable to parse papersize '%s'.
83-
Custom sizes may be entered with 'papersize=<measurement> x <measurement>'.
84-
Predefined paper sizes include: %s]],
82+
[[
83+
Unable to parse papersize '%s'
84+
85+
Custom sizes may be entered with 'papersize=<measurement> x <measurement>'.
86+
Predefined paper sizes include: %s
87+
]],
8588
size,
8689
table.concat(pl.tablex.keys(papersize), ", ")
8790
))

0 commit comments

Comments
 (0)