From 11532d9ec438ff9b81385b587e317a6f0e7b3cde Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 5 Sep 2023 02:35:51 +0300 Subject: [PATCH 1/3] style(utilities): Cleanup Lua formatting and variable names --- core/utilities.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/utilities.lua b/core/utilities.lua index 4c42d111c..e75698dd1 100644 --- a/core/utilities.lua +++ b/core/utilities.lua @@ -32,9 +32,9 @@ end local _skip_traceback_levels = 2 -utilities.error = function(message, bug) +utilities.error = function (message, isbug) _skip_traceback_levels = 3 - utilities.warn(message, bug) + utilities.warn(message, isbug) _skip_traceback_levels = 2 io.stderr:flush() SILE.outputter:finish() -- Only really useful from the REPL but no harm in trying @@ -42,10 +42,10 @@ utilities.error = function(message, bug) error(message, 2) end -utilities.warn = function(message, bug) +utilities.warn = function (message, isbug) if SILE.quiet then return end io.stderr:write("\n! " .. message) - if SILE.traceback or bug then + if SILE.traceback or isbug then io.stderr:write(" at:\n" .. SILE.traceStack:locationTrace()) if _skip_traceback_levels == 2 then io.stderr:write(debug.traceback("", _skip_traceback_levels) or "\t! debug.traceback() did not identify code location") From 18526ce75eeb8deb12e9b232e727993409ed8e06 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 5 Sep 2023 02:36:28 +0300 Subject: [PATCH 2/3] feat(utilities): Add utility function for console messages without trace info Sometimes it is helpful to know where a warning message got thrown. For a few cases of just wanting to tell something to the user it might not be relevant at all, and the "at ..." location trace is distracting and confusing. --- core/utilities.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/utilities.lua b/core/utilities.lua index e75698dd1..d83bde2b2 100644 --- a/core/utilities.lua +++ b/core/utilities.lua @@ -56,6 +56,11 @@ utilities.warn = function (message, isbug) io.stderr:write("\n") end +utilities.msg = function (message) + if SILE.quiet then return end + io.stderr:write("\n! " .. message .. "\n") +end + utilities.debugging = function (category) return SILE.debugFlags.all and category ~= "profile" or SILE.debugFlags[category] end From 87c443d1571f571b595c3e32febdcb03129f5b9a Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 5 Sep 2023 02:37:59 +0300 Subject: [PATCH 3/3] fix(packages): Don't warn on TOC content change if not actually used --- packages/tableofcontents/init.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/tableofcontents/init.lua b/packages/tableofcontents/init.lua index 9c74ef9d6..f0a0880d8 100644 --- a/packages/tableofcontents/init.lua +++ b/packages/tableofcontents/init.lua @@ -7,6 +7,8 @@ if not SILE.scratch._tableofcontents then SILE.scratch._tableofcontents = {} end +local toc_used = false + function package:moveTocNodes () local node = SILE.scratch.info.thispage.toc if node then @@ -24,8 +26,8 @@ function package.writeToc (_) tocfile:write("return " .. tocdata) tocfile:close() - if not pl.tablex.deepcompare(SILE.scratch.tableofcontents, SILE.scratch._tableofcontents) then - io.stderr:write("\n! Warning: table of contents has changed, please rerun SILE to update it.") + if toc_used and not pl.tablex.deepcompare(SILE.scratch.tableofcontents, SILE.scratch._tableofcontents) then + SU.msg("Notice: the table of contents has changed, please rerun SILE to update it.") end end @@ -115,6 +117,7 @@ function package:registerCommands () self:registerCommand("tableofcontents", function (options, _) local depth = SU.cast("integer", options.depth or 3) local linking = SU.boolean(options.linking, true) + local toc_used = true local toc = self:readToc() if toc == false then SILE.call("tableofcontents:notocmessage")