Skip to content

Commit

Permalink
Merge pull request #1858 from alerque/toc-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Sep 5, 2023
2 parents 17eb656 + 87c443d commit 848920b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 9 additions & 4 deletions core/utilities.lua
Expand Up @@ -32,20 +32,20 @@ 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
SILE.scratch.caughterror = true
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")
Expand All @@ -56,6 +56,11 @@ utilities.warn = function(message, bug)
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
Expand Down
7 changes: 5 additions & 2 deletions packages/tableofcontents/init.lua
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 848920b

Please sign in to comment.