Skip to content

Commit

Permalink
Output context with "unmatched #/" message
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
windymilla committed Dec 1, 2023
1 parent 9ce845d commit d6a8da4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/guiguts.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/Guiguts/SelectionMenu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d6a8da4

Please sign in to comment.