URI: 
       tFix comment option; add 'ignore whole line' to GUI - transliterate - Transliteration engine
  HTML git clone git://lumidify.org/transliterate.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 9420d98d90eabd8ad718a74e7e66bde7f5d221c6
   DIR parent 9bece82fb8385f9b72a49e7c2b98a9b4f2006182
  HTML Author: lumidify <nobody@lumidify.org>
       Date:   Wed,  8 Apr 2020 08:56:53 +0200
       
       Fix comment option; add 'ignore whole line' to GUI
       
       Diffstat:
         M transliterate.pl                    |      31 +++++++++++++++++++++++++++----
       
       1 file changed, 27 insertions(+), 4 deletions(-)
       ---
   DIR diff --git a/transliterate.pl b/transliterate.pl
       t@@ -158,6 +158,13 @@ sub prompt_unknown_word {
                                $window->destroy;
                        }, $window);
                $hbox->pack_start($button, FALSE, FALSE, 0);
       +        $button = Gtk2::Button->new("Whole line");
       +        $button->signal_connect(
       +                clicked => sub {
       +                        $action = ["ignore", "wholeline"];
       +                        $window->destroy;
       +                }, $window);
       +        $hbox->pack_start($button, FALSE, FALSE, 0);
                $vbox->pack_start($hbox, FALSE, FALSE, 0);
        
                # AHHHH! IT BURNS!!! THE CODE IS SO HORRIBLE!
       t@@ -897,9 +904,12 @@ sub load_config {
        # 0 - nothing needs to be done
        # 1 - the current line needs to be re-transliterated with the new config
        # 2 - an error occurred while reloading the config
       +# 3 - stop asking for unknown words on this line
        sub handle_unknown_word_action {
                my ($action, $config, $args) = @_;
                if ($action->[0] eq "ignore") {
       +                # yeah, this is a bit messy and inconsistent
       +                return 3 if $action->[1] eq "wholeline";
                        $config->{"ignore_words"}->{$action->[2]} = "";
                        if ($action->[1] eq "permanent") {
                                my $fh;
       t@@ -1249,6 +1259,7 @@ sub get_unknown_words {
                                        $word->[1], $contextr, $contextr_orig,
                                        $config, "$cur_lineno"
                                );
       +                        # if $ret == 3, just return here
                                # if $ret == 2, config could not be loaded
                                # if $ret == 1, line must be redone with new config
                                my $ret = handle_unknown_word_action($action, $config, $args);
       t@@ -1260,6 +1271,7 @@ sub get_unknown_words {
                                                $config, "$cur_lineno", 1);
                                        $ret = handle_unknown_word_action($action, $config, $args);
                                }
       +                        last if $ret == 3;
                                # re-transliterate the line with the new config
                                return 1 if $ret == 1;
                        }
       t@@ -1276,8 +1288,10 @@ sub replace {
                my ($config, $args, $total_lines, $inputfh, $outputfh) = @_;
                while (my $line = <$inputfh>) {
                        next if $. < $args->{"start"};
       +                my $comment;
                        if (exists $config->{"comment"}) {
       -                        $line =~ s/\Q$config->{comment}\E.*$//;
       +                        $line =~ s/\Q$config->{comment}\E(.*)\z//s;
       +                        $comment = $1;
                        }
                        my $nfd_line = NFD($line);
                        my $substrings = replace_line($config, $nfd_line);
       t@@ -1308,6 +1322,7 @@ sub replace {
                        foreach (@$substrings) {
                                print $outputfh $_->[1];
                        }
       +                print $outputfh $comment if $comment;
                }
        }
        
       t@@ -1546,7 +1561,12 @@ The possible actions are:
        
        "This run" only ignores the word until the program exist, while
        "Permanently" saves the word in the ignore file specified in the
       -configuration.
       +configuration. "Whole file" stops asking for unknown words  on
       +this line and prints the line out as is. Note that this still
       +leaves all replacements intact that have already been done.
       +If any words were replaced with multiple choices already, those
       +will also still cause the L<word choice window|/"WORD CHOICE WINDOW">
       +to appear.
        
        =item Retry without <display name>
        
       t@@ -1772,10 +1792,13 @@ B<Default:> C<$>
        =item B<comment> <string>
        
        If enabled, anything after C<< <string> >> will be ignored on all lines in
       -the input file.
       +the input file. This will not be displayed in the
       +L<unknown word window|/"UNKNOWN WORD WINDOW"> or L<word choice window|/"WORD CHOICE WINDOW">
       +but will still be printed in the end, with the comment character removed
       +(that seems to be the most sensible thing to do).
        
        Note that this is really just a "dumb replacement", so there's no way to
       -prevent a line with the comment character from being replaced. Just try
       +prevent a line with the comment character from being ignored. Just try
        to always set this to a character that does not occur anywhere in the text
        (or don't use the option at all).