Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve quote/bracket highlighting #789

Merged
merged 1 commit into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/Guiguts/FileMenu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ sub openfile { # and open it
}
}
::highlight_scannos();
::highlight_quotbrac();
::update_indicators();
file_mark_pages() if $::auto_page_marks;
::readlabels();
Expand Down
67 changes: 66 additions & 1 deletion src/lib/Guiguts/Highlight.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN {
@ISA = qw(Exporter);
@EXPORT =
qw(&scannosfile &hilite &hiliteremove &hilitesinglequotes &hilitedoublequotes &hilitepopup &highlight_scannos
&hilite_alignment_start &hilite_alignment_stop &hilite_alignment_toggle);
&highlight_quotbrac &hilite_alignment_start &hilite_alignment_stop &hilite_alignment_toggle);
}

# Routine to find highlight word list
Expand Down Expand Up @@ -304,6 +304,71 @@ sub highlight_scannos { # Enable / disable word highlighting in the text
::savesettings();
}

#
# Enable/disable quote/bracket highlighting in the text
sub highlight_quotbrac {
my $textwindow = $::textwindow;
my $top = $::top;
if ($::nohighlights) {
highlightquotbrac();
$::lglobal{quotbrac_highlightedid} = $top->repeat( 400, \&highlightquotbrac );
} else {
$::lglobal{quotbrac_highlightedid}->cancel if $::lglobal{quotbrac_highlightedid};
undef $::lglobal{quotbrac_highlightedid};
highlight_quotbrac_remove();
}
::update_indicators();
::savesettings();
}

#
# Action routine to highlight quotes/brackets
# Calls to HighlightSinglePairBracketingCursor adapted from TextEdit.pm
sub highlightquotbrac {
my $textwindow = $::textwindow;
my $top = $::top;
return 0 unless $::nohighlights;
$textwindow->HighlightSinglePairBracketingCursor( '(', ')', '[()]', 'CURSOR_HIGHLIGHT_PARENS',
'CURSOR_HIGHLIGHT_PARENS', 0 );
$textwindow->HighlightSinglePairBracketingCursor( '{', '}', '[{}]', 'CURSOR_HIGHLIGHT_CURLIES',
'CURSOR_HIGHLIGHT_CURLIES', 0 );
$textwindow->HighlightSinglePairBracketingCursor( '[', ']', '[][]', 'CURSOR_HIGHLIGHT_BRACES',
'CURSOR_HIGHLIGHT_BRACES', 0 );
$textwindow->HighlightSinglePairBracketingCursor(
'"', '"', '"',
'CURSOR_HIGHLIGHT_DOUBLEQUOTE',
'CURSOR_HIGHLIGHT_DOUBLEQUOTE', 0
);
$textwindow->HighlightSinglePairBracketingCursor(
"\x{201c}", "\x{201d}", "[\x{201c}\x{201d}]",
'CURSOR_HIGHLIGHT_DOUBLECURLY',
'CURSOR_HIGHLIGHT_DOUBLECURLY', 0
);
$textwindow->HighlightSinglePairBracketingCursor(
"'", "'", "'",
'CURSOR_HIGHLIGHT_SINGLEQUOTE',
'CURSOR_HIGHLIGHT_SINGLEQUOTE', 0
);
$textwindow->HighlightSinglePairBracketingCursor(
"\x{2018}", "\x{2019}", "[\x{2018}\x{2019}]",
'CURSOR_HIGHLIGHT_SINGLECURLY',
'CURSOR_HIGHLIGHT_SINGLECURLY', 0
);
}

#
# Remove quote/bracket highlighting tags from file
sub highlight_quotbrac_remove {
my $textwindow = $::textwindow;
$textwindow->tagRemove( 'CURSOR_HIGHLIGHT_PARENS', '1.0', 'end' );
$textwindow->tagRemove( 'CURSOR_HIGHLIGHT_CURLIES', '1.0', 'end' );
$textwindow->tagRemove( 'CURSOR_HIGHLIGHT_BRACES', '1.0', 'end' );
$textwindow->tagRemove( 'CURSOR_HIGHLIGHT_DOUBLEQUOTE', '1.0', 'end' );
$textwindow->tagRemove( 'CURSOR_HIGHLIGHT_DOUBLECURLY', '1.0', 'end' );
$textwindow->tagRemove( 'CURSOR_HIGHLIGHT_SINGLEQUOTE', '1.0', 'end' );
$textwindow->tagRemove( 'CURSOR_HIGHLIGHT_SINGLECURLY', '1.0', 'end' );
}

#
# Start alignment highlighter at column of current insert position
sub hilite_alignment_start {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/Guiguts/MenuStructure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,11 @@ sub menu_preferences_appearance {
],
[ 'separator', '' ],
[
Checkbutton => 'Enable Quotes Highlighting',
Checkbutton => 'Enable Quotes/Brackets Highlighting',
-variable => \$::nohighlights,
-onvalue => 1,
-offvalue => 0
-offvalue => 0,
-command => \&::highlight_quotbrac
],
[
Checkbutton => 'Enable Scanno Highlighting',
Expand Down
21 changes: 12 additions & 9 deletions src/lib/Guiguts/Utilities.pm
Original file line number Diff line number Diff line change
Expand Up @@ -967,15 +967,7 @@ sub initialize {
$top->configure( -menu => $::menubar = $top->Menu );

# routines to call every time the text is edited
$::textwindow->SetGUICallbacks(
[
\&::update_indicators,
sub {
return unless $::nohighlights;
$::textwindow->HighlightAllPairsBracketingCursor;
},
]
);
$::textwindow->SetGUICallbacks( [ \&::update_indicators, ] );

# Ignore any watchdog timer alarms. Subroutines that take a long time to
# complete can trip it
Expand Down Expand Up @@ -1160,6 +1152,17 @@ sub initialize {
$textwindow->tagConfigure( 'highlight', -background => 'orange' );
$textwindow->tagConfigure( 'linesel', -background => '#8EFD94' );
$textwindow->tagConfigure( 'alignment', -background => '#8EFD94' );
$textwindow->tagConfigure(
'CURSOR_HIGHLIGHT_DOUBLECURLY',
-foreground => 'black',
-background => 'green'
); # From TextEdit.pm
$textwindow->tagConfigure(
'CURSOR_HIGHLIGHT_SINGLECURLY',
-foreground => 'black',
-background => 'grey'
); # From TextEdit.pm

$textwindow->tagConfigure(
'pagenum',
-background => 'yellow',
Expand Down