From 70b6da3ec7c6c6abc12ff4c5dfbd7fc494204240 Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal Date: Mon, 23 Dec 2024 10:20:06 -0500 Subject: [PATCH 1/2] fix: Capture specific warnings from `PDL::Graphics::Gnuplot` Otherwise these show up in the notebook and visually clutter the output. --- lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm b/lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm index 2734c00..8d1c566 100644 --- a/lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm +++ b/lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm @@ -41,6 +41,11 @@ around new => sub { # C is called. capture_stderr(sub { # capture to avoid printing out the dumping warning + local $SIG{__WARN__} = sub { + warn $_[0] unless $_[0] =~ m{ + WARNING\s+-\s+dumping\s+ON + }xs; + }; $gpwin->option( dump => 1 ); }); } @@ -57,6 +62,11 @@ around _printGnuplotPipe => sub { #local *STDERR; open STDOUT, '>', \$dump_stdout or die "Can't open STDOUT: $!"; #open STDERR, '>', \$dump_stderr or die "Can't open STDERR $!"; + local $SIG{__WARN__} = sub { + warn $_[0] unless $_[0] =~ m{ + \(killed\s+gnuplot\) + }xs; + }; return $orig->(@_); } else { return $orig->(@_); @@ -68,7 +78,12 @@ sub iperl_data_representations { return unless $Devel::IPerl::Plugin::PDLGraphicsGnuplot::IPerl_compat; capture_stderr(sub { # capture to avoid printing out the dumping warning - $gpwin->option( dump => 0); + local $SIG{__WARN__} = sub { + warn $_[0] unless $_[0] =~ m{ + WARNING\s+-\s+dumping\s+OFF + }xs; + }; + $gpwin->option( dump => 0 ); }); my $format = $Devel::IPerl::Plugin::PDLGraphicsGnuplot::IPerl_format; @@ -88,6 +103,11 @@ sub iperl_data_representations { capture_stderr( sub { # capture to avoid printing out the dumping warning + local $SIG{__WARN__} = sub { + warn $_[0] unless $_[0] =~ m{ + WARNING\s+-\s+dumping\s+OFF + }xs; + }; $gpwin->option( dump => 0 ); } ); From 7ad7c90cd4d5192052811c0b502d21705abca6d7 Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal Date: Mon, 23 Dec 2024 10:24:46 -0500 Subject: [PATCH 2/2] fix: check for `replottable` flag before replotting Prevent replot attempts when nothing has been plotted yet. This commonly occurs when a code cell ends with just initializing the Gnuplot window, e.g., ```perl my $gp = gpwin(); ``` Note: Uses internal `replottable` flag, but this should be fine for now. --- lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm b/lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm index 8d1c566..3d8969a 100644 --- a/lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm +++ b/lib/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm @@ -76,6 +76,7 @@ around _printGnuplotPipe => sub { sub iperl_data_representations { my ($gpwin) = @_; return unless $Devel::IPerl::Plugin::PDLGraphicsGnuplot::IPerl_compat; + return unless $gpwin->{replottable}; capture_stderr(sub { # capture to avoid printing out the dumping warning local $SIG{__WARN__} = sub {