From 34f847b862ccec91da7b1103c2f5d7f856e219c6 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Mon, 19 Aug 2024 16:02:42 +0200 Subject: [PATCH] 0.3.10 --- Changes | 6 +++-- META6.json | 2 +- lib/App/Rak.rakumod | 55 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 451d620..5bb76ee 100644 --- a/Changes +++ b/Changes @@ -1,9 +1,11 @@ Revision history for App-Rak {{$NEXT}} + +0.3.10 2024-08-19T16:01:23+02:00 + - Make --per-paragraph and --modify-files work properly + without eating whitespace between paragraphs - Bump dependency on String::Utils to get "paragraphs" fix - so that --per-paragraph and --modify-files will work - properly 0.3.9 2024-08-19T12:14:12+02:00 - Add support for --also-first to produce the first N lines diff --git a/META6.json b/META6.json index 3a6487f..b36b7ab 100644 --- a/META6.json +++ b/META6.json @@ -59,5 +59,5 @@ ], "test-depends": [ ], - "version": "0.3.9" + "version": "0.3.10" } diff --git a/lib/App/Rak.rakumod b/lib/App/Rak.rakumod index 1a8c9e9..1247cfc 100644 --- a/lib/App/Rak.rakumod +++ b/lib/App/Rak.rakumod @@ -3145,6 +3145,61 @@ my sub action-modify-files(--> Nil) { } } + # Producing haystacks per line + elsif %rak { + my @changed-files; + my int $nr-files-seen; + my int $nr-paragraphs-changed; + + %rak := %listing:delete // True; + %rak := -> $io, @matches --> Empty { + ++$nr-files-seen; + + LAST { + my int $nr-files-changed = @changed-files.elems; + my $fb = "Processed $nr-files-seen file&s($nr-files-seen)"; + $fb ~= ", $nr-files-changed file&s($nr-files-changed) changed" + if $nr-files-changed; + $fb ~= ", $nr-paragraphs-changed line&s($nr-paragraphs-changed) changed" + if $nr-paragraphs-changed; + + if $verbose { + $fb ~= "\n"; + for @changed-files -> ($io, $changed) { + $fb ~= "$io.relative():"; + $fb ~= " $changed change&s($changed)" if $changed; + $fb ~= "\n"; + } + $fb .= chomp; + $fb ~= no-changes if $dryrun; + } + elsif $dryrun { + $fb ~= no-changes; + } + + sayer $fb; + } + + my int $paragraphs-changed; + for @matches { + ++$paragraphs-changed if .changed; + } + if $paragraphs-changed { + unless $dryrun { + if $backup { + $io.spurt(@matches.map(*.value).join("\n")) + if $io.rename($io.sibling($io.basename ~ $backup)); + } + else { + $io.spurt: @matches.map(*.value).join("\n"); + } + } + $nr-paragraphs-changed += $paragraphs-changed; + @changed-files.push: ($io, $paragraphs-changed); + } + } + } + # Producing haystacks per line else { my @changed-files;