From 0b342648bc8c2a11ffddc7edf0626bec4129fd21 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Tue, 20 Aug 2024 16:22:46 +0200 Subject: [PATCH] 0.3.12 --- Changes | 5 +++++ META6.json | 2 +- README.md | 4 +++- doc/App-Rak.rakudoc | 7 +++++-- lib/App/Rak.rakumod | 6 +++--- resources/help/content.txt | 5 ++++- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Changes b/Changes index eb169c3..ce81fa5 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,11 @@ Revision history for App-Rak {{$NEXT}} +0.3.12 2024-08-20T16:21:00+02:00 + - Make --modify-files present the target without line endings + by default. Specify --with-line-endings if you want them + included + 0.3.11 2024-08-19T21:37:28+02:00 - Bump "rak" to get ParaSeq's exception handling fix diff --git a/META6.json b/META6.json index 6322e2e..3dd3ee6 100644 --- a/META6.json +++ b/META6.json @@ -59,5 +59,5 @@ ], "test-depends": [ ], - "version": "0.3.11" + "version": "0.3.12" } diff --git a/README.md b/README.md index cdbdc68..de574ff 100644 --- a/README.md +++ b/README.md @@ -1240,7 +1240,9 @@ See "CHECKING TIMES ON FILES" for more information about features that can be us Flag. Only makes sense if the specified pattern is a `Callable`. Indicates whether the output of the pattern should be applied to the file in which it was found. Defaults to `False`. -The `Callable` will be called for each file (in sorted order) and each line of the file, giving the line (**including** its line ending). The `$*N` dynamic variable is available inside the `Callable` and is initialized to 0 (in case modifications require keeping numeric state between calls). It is then up to the `Callable` to return: +The `Callable` will be called for each file (in sorted order) and each line of the file, giving the line. By default, the line will be presented to the code **without** its line ending. You need to specify `--with-line-endings` if you want to have the line ending also. + +The `$*N` dynamic variable is available inside the `Callable` and is initialized to 0 (in case modifications require keeping numeric state between calls). It is then up to the `Callable` to return: ### False diff --git a/doc/App-Rak.rakudoc b/doc/App-Rak.rakudoc index 599ad16..43379f5 100644 --- a/doc/App-Rak.rakudoc +++ b/doc/App-Rak.rakudoc @@ -1576,8 +1576,11 @@ Indicates whether the output of the pattern should be applied to the file in which it was found. Defaults to C. The C will be called for each file (in sorted order) and each -line of the file, giving the line (B its line ending). The -C<$*N> dynamic variable is available inside the C and is +line of the file, giving the line. By default, the line will be presented +to the code B its line ending. You need to specify +C<--with-line-endings> if you want to have the line ending also. + +The C<$*N> dynamic variable is available inside the C and is initialized to 0 (in case modifications require keeping numeric state between calls). It is then up to the C to return: diff --git a/lib/App/Rak.rakumod b/lib/App/Rak.rakumod index b5a04c2..9e73fbf 100644 --- a/lib/App/Rak.rakumod +++ b/lib/App/Rak.rakumod @@ -3207,7 +3207,7 @@ my sub action-modify-files(--> Nil) { my int $nr-lines-changed; my int $nr-lines-removed; - %rak := True unless %rak:exists; + my $joiner := %rak ?? "" !! "\n"; %rak := %listing:delete // True; %rak := -> $io, @matches --> Empty { ++$nr-files-seen; @@ -3254,11 +3254,11 @@ my sub action-modify-files(--> Nil) { if $lines-changed || $lines-removed { unless $dryrun { if $backup { - $io.spurt(@matches.map(*.value).join) + $io.spurt(@matches.map(*.value).join($joiner)) ~ $joiner if $io.rename($io.sibling($io.basename ~ $backup)); } else { - $io.spurt: @matches.map(*.value).join; + $io.spurt: @matches.map(*.value).join($joiner) ~ $joiner; } } $nr-lines-changed += $lines-changed; diff --git a/resources/help/content.txt b/resources/help/content.txt index b0805f8..07c2a8f 100644 --- a/resources/help/content.txt +++ b/resources/help/content.txt @@ -25,13 +25,16 @@ Else it will be kept unchanged because of an implicit --passthru-context argument being active. Files are presented in a sorted order, allowing for repeatable and -ordered renaming. The $*N dynamic variable (initialized to 0) is +ordered modification. The $*N dynamic variable (initialized to 0) is available to the pattern, to allow keeping state between files. Defaults to False, indicating that files should **not** be changed. Can also specify --dryrun to see which files would be changed without actually making any changes. +By default, lines will be presented **without** their line ending. +If you want to have them included, specify --with-line-endings. + --rename-files Only makes sense with a Callable pattern. Assumes --find semantics