Skip to content

Commit

Permalink
fix(classes): Correct order of operations when paragraphs are ended m…
Browse files Browse the repository at this point in the history
…anually
  • Loading branch information
alerque committed Jun 7, 2024
1 parent 6ad9b76 commit 08f1a7b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
19 changes: 11 additions & 8 deletions classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -696,16 +696,18 @@ end

-- WARNING: not called as class method
function class.endPar (typesetter)
-- If we're already explicitly out of hmode don't do anything special in the way of skips or indents. Assume the user
-- has handled that how they want, e.g. with a skip.
local queue = typesetter.state.outputQueue
local last_vbox = queue and queue[#queue]
local last_is_vglue = last_vbox and last_vbox.is_vglue
local last_is_vpenalty = last_vbox and last_vbox.is_penalty
if typesetter:vmode() and (last_is_vglue or last_is_vpenalty) then
return
end
SILE.settings:set("current.parindent", nil)
typesetter:leaveHmode()
typesetter:pushVglue(SILE.settings:get("document.parskip"))
if SILE.settings:get("current.hangIndent") then
SILE.settings:set("current.hangIndent", nil)
SILE.settings:set("linebreak.hangIndent", nil)
end
if SILE.settings:get("current.hangAfter") then
SILE.settings:set("current.hangAfter", nil)
SILE.settings:set("linebreak.hangAfter", nil)
end
end

function class:newPage ()
Expand All @@ -725,6 +727,7 @@ end

function class:finish ()
SILE.inputter:postamble()
SILE.typesetter:endline()
SILE.call("vfill")
while not SILE.typesetter:isQueueEmpty() do
SILE.call("supereject")
Expand Down
13 changes: 9 additions & 4 deletions classes/book.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,19 @@ function class:registerCommands ()
if SILE.Commands[postcmd .. ":" .. lang] then
postcmd = postcmd .. ":" .. lang
end
SILE.call("nofoliothispage")
SILE.call(postcmd)
SILE.call("book:chapterfont", {}, content)
SILE.call("left-running-head", {}, function ()
SILE.settings:temporarily(function ()
SILE.call("book:left-running-head-font", {}, content)
end)
end)
SILE.call("novbreak")
SILE.call("par")
SILE.call("novbreak")
SILE.call("bigskip")
SILE.call("nofoliothispage")
SILE.call("novbreak")
-- English typography (notably) expects the first paragraph under a section
-- not to be indented. Frenchies, don't use this class :)
SILE.call("noindent")
Expand Down Expand Up @@ -215,12 +219,13 @@ function class:registerCommands ()
end)
end
SILE.call("novbreak")
SILE.call("par")
SILE.call("novbreak")
SILE.call("bigskip")
SILE.call("novbreak")
-- English typography (notably) expects the first paragraph under a section
-- not to be indented. Frenchies, don't use this class :)
SILE.call("noindent")
SILE.typesetter:inhibitLeading()
end, "Begin a new section")

self:registerCommand("subsection", function (options, content)
Expand All @@ -242,14 +247,14 @@ function class:registerCommands ()
SILE.call(postcmd)
SILE.process(content)
end)
SILE.typesetter:leaveHmode()
SILE.call("novbreak")
SILE.call("par")
SILE.call("novbreak")
SILE.call("medskip")
SILE.call("novbreak")
-- English typography (notably) expects the first paragraph under a section
-- not to be indented. Frenchies, don't use this class :)
SILE.call("noindent")
SILE.typesetter:inhibitLeading()
end, "Begin a new subsection")

self:registerCommand("book:chapterfont", function (_, content)
Expand Down
12 changes: 10 additions & 2 deletions classes/plain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ function class:registerCommands ()

self:registerCommand("noindent", function (_, content)
if #SILE.typesetter.state.nodes ~= 0 then
SU.warn(
"\\noindent called after nodes already received in a paragraph, the setting will have no effect because the parindent (if any) has already been output"
SU.warn([[\noindent was called after paragraph content has already been procesed.
This will not result in avoiding the current paragraph being indented.
This function must be called before any content belonging to the
paragraph is processed. If the intent was to suppress indentation of a
following paragraph, first explicitly close the current paragraph. From
an input document this is typically done with an empty line between
paragraphs, but calling the \par command explicitly or from Lua code
running SILE.call("par") will end the current paragraph.
]]
)
end
SILE.settings:set("current.parindent", SILE.types.node.glue())
Expand Down
1 change: 1 addition & 0 deletions tests/bug-1647.sil
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
This paragraph is at the page top.

This paragraph has a big parskip before it.

\vfill
This paragraph must be at the page bottom.
\par
Expand Down
10 changes: 9 additions & 1 deletion typesetters/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,16 @@ function typesetter:initline ()
end

function typesetter:endline ()
self:leaveHmode()
SILE.documentState.documentClass.endPar(self)
self:leaveHmode()
if SILE.settings:get("current.hangIndent") then
SILE.settings:set("current.hangIndent", nil)
SILE.settings:set("linebreak.hangIndent", nil)
end
if SILE.settings:get("current.hangAfter") then
SILE.settings:set("current.hangAfter", nil)
SILE.settings:set("linebreak.hangAfter", nil)
end
end

-- Just compute once, to avoid unicode characters in source code.
Expand Down

0 comments on commit 08f1a7b

Please sign in to comment.