Change how 'Disable Formatting' works
This PR changes GAP so when formatting is disabled we still indent functions (and other objects), just disable line wrapping.
This also fixes a bug which where SetPrintFormattingStatus wouldn't work if stdout was opened twice (it might be we should also stop that happening, separately).
I'm not saying this should be final (we certainly want a whole bunch of tests), but I'm exploring options. Comments welcome.
Thanks for the PR, I can confirm that this makes indentation work regardless of the formatting status and makes SetPrintFormattingStatus work in the REPL again!
I noticed one additional issue which I assume is related to stdout being opened multiple times: If I put
SetPrintFormattingStatus("*stdout*", false);
in a file (or my gaprc), call gap with the filename and then check PrintFormattingStatus("*stdout*") in the REPL, it reports false (the value stored in GAPInfo.FormattingStatusStdout). However, the formatting is actually enabled in the REPL and I have to call SetPrintFormattingStatus("*stdout*", false); again to disable it. But that's a minor issue for me, I just wanted to mention it for the sake of completeness.
Since indentation is now always on, this breaks the changes @ChrisJefferson recently made in PR #4458, as those specifically relied on indentation turning off in this case.
We may need a more elaborate way to control the "formatting settings" of output streams than just a single boolean.
That said, SetPrintFormattingStatus explicitly is documented as turning off indentation, so if we change that, then at the very least we should also change the documentation. This may be acceptable, given that apparently in the past SetPrintFormattingStatus didn't reliably turn off indentation (or did it? We are not just talking about stdout here, but also about printing to files). And when did it change, exactly?
Or we leave it as it is, and instead add a way to let the user separately turn off "line wrapping" and "indentation".
I believe SetPrintFormattingStatus always worked, except for *stdout* was it has been broken (at least sometimes).
Personally, I've never seen a good reason to disable indentation, so I'd be happy to just remove the ability to disable it, but I realise some people might have a use case where they want to disable indentation. For that, we could split indenting and line wrapping into two options (I'd personally then suggest we disable line wrapping by default when writing to files, which would be another change of behaviour, but one I think, again, most users would want).
Sorry for the late reply, I lost track of the PR over the weekend.
This is much more intricate than I expected, so I thought a bit about what the simplest interface for my use case would be. My use case is: I never want line wrapping (because I prefer to let my terminal wrap lines and do not want "random" backslashes when printing to strings/files) and I always want indentation, regardless of the print target (stdout, file, string). So I think the easiest solution would be to introduce a function SetGlobalLineWrappingStatus which disables (or re-enables) line wrapping completely. With that, I would not need SetPrintFormattingStatus anywhere in my code, so the original issue would be void (for me).