Skip to content

Commit

Permalink
Replace GAPDoc's PrintFormattedString by PrintWithoutFormatting
Browse files Browse the repository at this point in the history
`PrintWithoutFormatting` is a new helper function which calls
`(Set)PrintFormattingStatus("*current*")` suitably to temporarily
modify the formatting status for the currently active output stream.

This requires adjusting one test for `Info`, which printed a notice
about `InfoGlobal` which was in turn caused by a call to `IsBoundGlobal`
removed by this patch.
  • Loading branch information
fingolfin committed Jun 18, 2021
1 parent 5cc463b commit d8b9330
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
32 changes: 14 additions & 18 deletions lib/info.gi
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,25 @@ InstallGlobalFunction( "SetDefaultInfoOutput", function( out )
MakeReadOnlyGlobal("DefaultInfoOutput");
end);


BIND_GLOBAL( "PrintWithoutFormatting", function ( arg )
local old;
old := PrintFormattingStatus("*current*");
SetPrintFormattingStatus("*current*", false);
CallFuncList(Print, arg);
SetPrintFormattingStatus("*current*", old);
end );


InstallGlobalFunction( "DefaultInfoHandler", function( infoclass, level, list )
local out, fun, s;
local out, s;
out := InfoOutput(infoclass);
if out = "*Print*" then
if IsBoundGlobal( "PrintFormattedString" ) then
fun := function(s)
if (IsString(s) and Length(s) > 0 or IsStringRep(s)) and
#XXX this is a temporary hack, we would need a
# IsInstalledGlobal instead of IsBoundGlobal here
NARG_FUNC(ValueGlobal("PrintFormattedString")) <> -1 then
ValueGlobal( "PrintFormattedString" )(s);
else
Print(s);
fi;
end;
else
fun := Print;
fi;
fun("#I ");
PrintWithoutFormatting("#I ");
for s in list do
fun(s);
PrintWithoutFormatting(s);
od;
fun("\n");
PrintWithoutFormatting("\n");
else
AppendTo(out, "#I ");
for s in list do
Expand Down
14 changes: 4 additions & 10 deletions lib/package.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ InstallGlobalFunction( LoadPackageDocumentation, function( arg )
##
BindGlobal( "LoadPackage_ReadImplementationParts",
function( secondrun, banner )
local pair, info, bannerstring, fun, u, pkgname, namespace;
local pair, info, bannerstring, u, pkgname, namespace;

for pair in secondrun do
namespace := pair[1].PackageName;
Expand Down Expand Up @@ -1433,15 +1433,9 @@ BindGlobal( "LoadPackage_ReadImplementationParts",
bannerstring:= DefaultPackageBannerString( info );
fi;

# Be aware of umlauts, accents etc. in the banner.
if IsBoundGlobal( "Unicode" ) and IsBoundGlobal( "Encode" ) then
# The GAPDoc package is completely loaded.
fun:= ValueGlobal( "PrintFormattedString" );
fun( bannerstring );
else
# GAPDoc is not available, simply print the banner string as is.
Print( bannerstring );
fi;
# Suppress output formatting to avoid troubles with umlauts,
# accents etc. in the banner.
PrintWithoutFormatting( bannerstring );
od;
fi;
end );
Expand Down
1 change: 0 additions & 1 deletion tst/testinstall/info.tst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Error, usage : Info(<selectors>, <level>, ...)
gap> ShowUsedInfoClasses(true);
gap> Info(InfoTest2, 2, "apple");
#I Would print info with SetInfoLevel(InfoTest2,2)
#I Would print info with SetInfoLevel(InfoGlobal,3)
#I apple
gap> Info(InfoTest1 + InfoTest2, 2, "apple");
#I Would print info with SetInfoLevel(InfoTest1,2)
Expand Down

0 comments on commit d8b9330

Please sign in to comment.