From d6a8da4d07fead00cdbebb0880d7707d2daf593a Mon Sep 17 00:00:00 2001 From: Nigel Date: Fri, 1 Dec 2023 20:07:08 +0000 Subject: [PATCH] Output context with "unmatched `#/`" message Output up to two lines before the closing `#/` to give the user context if they have unmatched blockquote markup when rewrapping. Also, set stdout & stderr to utf8 to avoid "wide character" errors when printing utf8 characters. --- src/guiguts.pl | 4 ++++ src/lib/Guiguts/SelectionMenu.pm | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/guiguts.pl b/src/guiguts.pl index 2d606554..52f080f7 100755 --- a/src/guiguts.pl +++ b/src/guiguts.pl @@ -322,6 +322,10 @@ # Redirect warn by overriding signal handler local $SIG{__WARN__} = \&::warnerror; +# Ensure stdout & stderr accept utf8 characters +binmode( STDOUT, ":utf8" ); +binmode( STDERR, ":utf8" ); + # An alternative for catching Tk background errors, # but they are caught by the warn override above # sub Tk::Error { diff --git a/src/lib/Guiguts/SelectionMenu.pm b/src/lib/Guiguts/SelectionMenu.pm index 609fe467..89123b60 100644 --- a/src/lib/Guiguts/SelectionMenu.pm +++ b/src/lib/Guiguts/SelectionMenu.pm @@ -504,6 +504,16 @@ sub selectrewrap { ( $leftmargin, $firstmargin, $rightmargin ) = setblockmargins($::blockwrap); } else { ::warnerror("Close blockquote (#/) found with no matching open markup"); + + # Last line in block is the closing markup, and output up to + # two more context lines before that + my @splitsel = split( /\n/, $notpmselection ); + my $ncontext = scalar @splitsel; + $ncontext = 3 if $ncontext > 3; + ::infoerror("Context:"); + for my $ln ( 1 .. $ncontext ) { + ::infoerror(" $splitsel[$ln-$ncontext-1]"); + } } } } else {