Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showframe should have an option to apply for every page just like \background. #1909

Closed
wants to merge 1 commit into from

Conversation

jodros
Copy link
Contributor

@jodros jodros commented Nov 11, 2023

I missed an option for this and here is a possible solution.

@alerque
Copy link
Member

alerque commented Nov 11, 2023

I've never felt the need for this because if I'm debugging an entire document then sile -d frames doc.sil makes more sense to me than editing the doc to embed debug info. Only localized fiddling makes sense to me.

Not saying this can't go in, just thinking out loud about ergonomics...

@jodros
Copy link
Contributor Author

jodros commented Nov 11, 2023

sile -d frames doc.sil

What a shame, I had no idea of this command 🤦. I'm aware of a debugging facility but never tried it so far... Well, anyway, thanks for telling me that, I'll take a look at the debugging part of documentation...

Copy link
Member

@alerque alerque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides some of the code comments, this option needs documentation in the package docs.

if id == "all" then
for _, frame in pairs(SILE.frames) do
SILE.outputter:debugFrame(frame)
options.allpages = options.allpages or true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should default to false and use SU.boolean() to do so.

options.allpages = options.allpages or true

local show = function()
if id == "all" then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even local functions should not use variables outside of their scope with a documented reason for needing to. This is called a side effect and has lots of downsides, not to mention will make porting harder down the road. Just add an id field to the function and pass it through explicitly.

end
end

if options.allpages and options.allpages ~= "false" then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, but since this should already be cast to a boolean at this point the logic is much simpler: if not options.allpages then.


if options.allpages and options.allpages ~= "false" then
show()
local oldNewPage = SILE.documentState.documentClass.newPage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, don't do this. I know we do funky things like this elsewhere but we're trying to move away from this, not towards it. Set a new page hook instead and just leave the class:newPage() function alone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't know how to play with hooks for now. I read this part of the documentation and searched for uses of it in this repository, but still can't manage to set hooks around there... Can you give me at least an example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, happy to help. I think in this case this whole section of code can be reduced as in this code suggestion comment.

class:loadPackage("frametricks")

SILE.call("showframe",{ id = "all"})
for i = 1, 50 do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writing regression test, we want as little output as possible to prove the case. In this case just one supereject and a tiny bit of content should do the trick, no need for 50 pages. Unless you expect to stop functioning after passing 42 for ... galaxy reasons.

@alerque alerque added this to the v0.14.14 milestone Nov 11, 2023
@alerque alerque added enhancement Software improvement or feature request modules:packages Issue relates to core or 3rd party packages labels Nov 11, 2023
Comment on lines +170 to 175
local oldNewPage = SILE.documentState.documentClass.newPage
SILE.documentState.documentClass.newPage = function (self_)
local page = oldNewPage(self_)
show()
return page
end
Copy link
Member

@alerque alerque Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up from this review comment, I had to start a new thread to get all the relevant lines tagged in the comment. This replacement should get the job done with a bit less fuss:

Suggested change
local oldNewPage = SILE.documentState.documentClass.newPage
SILE.documentState.documentClass.newPage = function (self_)
local page = oldNewPage(self_)
show()
return page
end
self.class:registerHook("newpage", show)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip. I got the following error when testing:

`Using code at: ./core/frame.lua:261: Passed a table, expected a string

So when I do self.class:registerHook("newpage", show(id) the error isn't raised, but it still gives the same output: just the first page is debugged...

@jodros
Copy link
Contributor Author

jodros commented Nov 17, 2023

Sorry for the waste of time, after using the -d frames options I realized how unnecessary and silly this PR is...

@jodros jodros closed this Nov 17, 2023
@jodros jodros deleted the showframes branch November 17, 2023 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Software improvement or feature request modules:packages Issue relates to core or 3rd party packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants