diff --git a/Dockerfile b/Dockerfile index f781f83c..f77e7f62 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ FROM perl:5.38.2-slim-threaded-buster # ARG LATEXINDENT_VERSION -ENV LATEXINDENT_VERSION ${LATEXINDENT_VERSION:-V3.24.1} +ENV LATEXINDENT_VERSION ${LATEXINDENT_VERSION:-V3.24.2} RUN apt-get update \ && apt-get install \ diff --git a/LatexIndent/GetYamlSettings.pm b/LatexIndent/GetYamlSettings.pm index 4d494037..6365e0fd 100644 --- a/LatexIndent/GetYamlSettings.pm +++ b/LatexIndent/GetYamlSettings.pm @@ -389,36 +389,8 @@ sub yaml_read_settings { # output the contents of indentconfig to the log file $logger->info( Dump \%{ $userSettings->[0] } ); - # change the encoding of the paths according to the field `encoding` - if ( $userSettings and ( ref( $userSettings->[0] ) eq 'HASH' ) and $userSettings->[0]->{encoding} ) { - use Encode; - my $encoding = $userSettings->[0]->{encoding}; - my $encodingObject = find_encoding($encoding); - - # Check if the encoding is valid. - if ( ref($encodingObject) ) { - $logger->info("*Encoding of the paths is $encoding"); - foreach ( @{ $userSettings->[0]->{paths} } ) { - my $temp = $encodingObject->encode("$_"); - $logger->info("Transform file encoding: $_ -> $temp"); - push( @absPaths, $temp ); - } - } - else { - $logger->warn("*encoding \"$encoding\" not found"); - $logger->warn("Ignore this setting and will take the default encoding."); - @absPaths = @{ $userSettings->[0]->{paths} }; - foreach ( @{ $userSettings->[0]->{paths} } ) { - push( @absPaths, $_ ); - } - } - } - else # No such setting, and will take the default - { - # $logger->info("*Encoding of the paths takes the default."); - foreach ( @{ $userSettings->[0]->{paths} } ) { - push( @absPaths, $_ ); - } + foreach ( @{ $userSettings->[0]->{paths} } ) { + push( @absPaths, $_ ); } } diff --git a/LatexIndent/Logger.pm b/LatexIndent/Logger.pm index 425c8eae..7c4352a9 100644 --- a/LatexIndent/Logger.pm +++ b/LatexIndent/Logger.pm @@ -18,7 +18,7 @@ package LatexIndent::Logger; use strict; use warnings; -use Exporter; +use Exporter qw/import/; use LatexIndent::Switches qw/%switches/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/@logFileLines/; diff --git a/LatexIndent/Special.pm b/LatexIndent/Special.pm index 096d2935..8dac47bf 100644 --- a/LatexIndent/Special.pm +++ b/LatexIndent/Special.pm @@ -17,14 +17,14 @@ package LatexIndent::Special; # For all communication, please visit: https://github.com/cmhughes/latexindent.pl use strict; use warnings; +use Exporter qw/import/; use LatexIndent::Tokens qw/%tokens/; use LatexIndent::TrailingComments qw/$trailingCommentRegExp/; use LatexIndent::GetYamlSettings qw/%mainSettings/; use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; use LatexIndent::LogFile qw/$logger/; -use LatexIndent::IfElseFi qw/$ifElseFiBasicRegExp/; +use LatexIndent::IfElseFi; use Data::Dumper; -use Exporter qw/import/; our @ISA = "LatexIndent::Document"; # class inheritance, Programming Perl, pg 321 our @EXPORT_OK = qw/find_special construct_special_begin $specialBeginAndBracesBracketsBasicRegExp $specialBeginBasicRegExp/; diff --git a/LatexIndent/TrailingComments.pm b/LatexIndent/TrailingComments.pm index 9d653250..5e47ae3f 100644 --- a/LatexIndent/TrailingComments.pm +++ b/LatexIndent/TrailingComments.pm @@ -27,12 +27,20 @@ our @EXPORT_OK = qw/remove_trailing_comments put_trailing_comments_back_in $trailingCommentRegExp add_comment_symbol construct_trailing_comment_regexp @trailingComments/; our @trailingComments; our $commentCounter = 0; +our $notPrecededByRegExp; our $trailingCommentRegExp; sub construct_trailing_comment_regexp { - my $notPreceededBy = qr/${${$mainSettings{fineTuning}}{trailingComments}}{notPreceededBy}/; + $notPrecededByRegExp = qr/${${$mainSettings{fineTuning}}{trailingComments}}{notPrecededBy}/; + my $notPreceededBy = ${${mainSettings{fineTuning}}{trailingComments}}{notPreceededBy}; - $trailingCommentRegExp = qr/$notPreceededBy%$tokens{trailingComment}\d+$tokens{endOfToken}/; + if ( $notPreceededBy ) { + $logger->warn( + "*fineTuning:trailingComments:notPreceededBy is ok for now, but in future versions, fineTuning:trailingComments:notPrecededBy will be used" ); + $notPrecededByRegExp = qr/$notPreceededBy/; + } + + $trailingCommentRegExp = qr/$notPrecededByRegExp%$tokens{trailingComment}\d+$tokens{endOfToken}/; } sub add_comment_symbol { @@ -66,17 +74,16 @@ sub remove_trailing_comments { $logger->trace("*Storing trailing comments") if $is_t_switch_active; - my $notPreceededBy = qr/${${$mainSettings{fineTuning}}{trailingComments}}{notPreceededBy}/; - my $afterComment = qr/${${$mainSettings{fineTuning}}{trailingComments}}{afterComment}/; + my $afterComment = qr/${${$mainSettings{fineTuning}}{trailingComments}}{afterComment}/; # perform the substitution ${$self}{body} =~ s/ - $notPreceededBy # not preceded by a \ - % # % + $notPrecededByRegExp # not preceded by a \ + % # % ( - $afterComment # anything else + $afterComment # anything else ) - $ # up to the end of a line + $ # up to the end of a line / # increment comment counter and store comment $commentCounter++; @@ -134,14 +141,13 @@ sub put_trailing_comments_back_in { # replace the line-broken trailing comment ID with a non-broken trailing comment ID ${$self}{body} =~ s/%\R?$trailingcommentIDwithLineBreaksRegExp/%$trailingcommentID/s; } - my $notPreceededBy = qr/${${$mainSettings{fineTuning}}{trailingComments}}{notPreceededBy}/; if (${$self}{body} =~ m/%$trailingcommentID ( - (?! # not immediately preceded by - $notPreceededBy # \ - % # % + (?! # not immediately preceded by + $notPrecededByRegExp # \ + % # % ).*? - ) # captured into $1 + ) # captured into $1 (\h*)?$ /mx and $1 ne '' ) diff --git a/LatexIndent/UTF8CmdLineArgsFileOperation.pm b/LatexIndent/UTF8CmdLineArgsFileOperation.pm index 45a2b6f5..d6d8b595 100644 --- a/LatexIndent/UTF8CmdLineArgsFileOperation.pm +++ b/LatexIndent/UTF8CmdLineArgsFileOperation.pm @@ -5,22 +5,39 @@ use warnings; use feature qw( say state ); use utf8; use Config qw( %Config ); -use Encode qw( decode encode ); +use Encode qw(find_encoding decode encode ); use Exporter qw/import/; our @EXPORT_OK = qw/commandlineargs_with_encode @new_args copy_with_encode exist_with_encode open_with_encode zero_with_encode read_yaml_with_encode isdir_with_encode mkdir_with_encode/; +our $encodingObject; + +if ($^O eq 'MSWin32') { + my $encoding_sys = 'cp' . Win32::GetACP(); + $encodingObject = find_encoding( $encoding_sys ); + + # Check if the encoding is valid. + unless ( ref($encodingObject) ) { + $encodingObject = find_encoding( 'utf-8' ); + } +} +else { + $encodingObject = find_encoding( 'utf-8' ); +} + sub copy_with_encode { use File::Copy; my ( $source, $destination ) = @_; - if ( $FindBin::Script eq 'latexindent.exe' ) { + if ( $FindBin::Script =~ /\.exe$/ ) { require Win32::Unicode::File; Win32::Unicode::File->import(qw(copyW)); copyW( $source, $destination, 1 ); } else { + $source = $encodingObject->encode($source); + $destination = $encodingObject->encode($destination); copy( $source, $destination ); } } @@ -28,12 +45,13 @@ sub copy_with_encode { sub exist_with_encode { my ($filename) = @_; - if ( $FindBin::Script eq 'latexindent.exe' ) { + if ( $FindBin::Script =~ /\.exe$/ ) { require Win32::Unicode::File; Win32::Unicode::File->import(qw(statW)); return statW($filename); } else { + $filename = $encodingObject->encode($filename); return -e $filename; } } @@ -41,7 +59,7 @@ sub exist_with_encode { sub zero_with_encode { my ($filename) = @_; - if ( $FindBin::Script eq 'latexindent.exe' ) { + if ( $FindBin::Script =~ /\.exe$/ ) { require Win32::Unicode::File; Win32::Unicode::File->import(qw(file_size)); my $size = file_size($filename); @@ -53,6 +71,7 @@ sub zero_with_encode { } } else { + $filename = $encodingObject->encode($filename); return -z $filename; } } @@ -62,7 +81,7 @@ sub open_with_encode { my $filename = shift; my $fh; - if ( $FindBin::Script eq 'latexindent.exe' ) { + if ( $FindBin::Script =~ /\.exe$/ ) { require Win32::Unicode::File; Win32::Unicode::File->import; $fh = Win32::Unicode::File->new; @@ -74,6 +93,7 @@ sub open_with_encode { } } else { + $filename = $encodingObject->encode($filename); if ( open( $fh, $mode, $filename ) ) { return $fh; } @@ -95,13 +115,14 @@ sub read_yaml_with_encode { sub isdir_with_encode { my $path = shift; - if ( $FindBin::Script eq 'latexindent.exe' ) { + if ( $FindBin::Script =~ /\.exe$/ ) { require Win32::Unicode::File; Win32::Unicode::File->import(qw(file_type)); return file_type( 'd', $path ); } else { + $path = $encodingObject->encode($path); return -d $path; } } @@ -109,7 +130,7 @@ sub isdir_with_encode { sub mkdir_with_encode { my $path = shift; - if ( $FindBin::Script eq 'latexindent.exe' ) { + if ( $FindBin::Script =~ /\.exe$/ ) { require Win32::Unicode::Dir; Win32::Unicode::Dir->import(qw(mkdirW)); @@ -118,7 +139,7 @@ sub mkdir_with_encode { else { require File::Path; File::Path->import(qw(make_path)); - + $path = $encodingObject->encode($path); make_path($path); } } @@ -126,7 +147,7 @@ sub mkdir_with_encode { #https://stackoverflow.com/a/63868721 #https://stackoverflow.com/a/44489228 sub commandlineargs_with_encode { - if ( $FindBin::Script eq 'latexindent.exe' ) { + if ( $FindBin::Script =~ /\.exe$/ ) { require Win32::API; import Win32::API qw( ReadMemory ); @@ -207,7 +228,6 @@ sub commandlineargs_with_encode { @ARGV = @{$args}; } else { - my $encodingObject = "utf-8"; @ARGV = map { decode( $encodingObject, $_ ) } @ARGV; our @new_args = @ARGV; } diff --git a/LatexIndent/Version.pm b/LatexIndent/Version.pm index 0198585f..5232967f 100644 --- a/LatexIndent/Version.pm +++ b/LatexIndent/Version.pm @@ -20,6 +20,6 @@ use warnings; use Exporter qw/import/; our @EXPORT_OK = qw/$versionNumber $versionDate/; -our $versionNumber = '3.24.1'; -our $versionDate = '2024-05-12'; +our $versionNumber = '3.24.2'; +our $versionDate = '2024-06-15'; 1 diff --git a/defaultSettings.yaml b/defaultSettings.yaml index 80120978..15073c2f 100644 --- a/defaultSettings.yaml +++ b/defaultSettings.yaml @@ -1,5 +1,5 @@ # -# latexindent.pl, version 3.24.1, 2024-05-12 +# latexindent.pl, version 3.24.2, 2024-06-15 # # defaultSettings.yaml, the default settings for latexindent.pl # @@ -649,7 +649,7 @@ fineTuning: before: (?:#\d\h*;?,?\/?)+|\<.*?\> between: _|\^|\* trailingComments: - notPreceededBy: (? + # changelog.md +## V3.24.2, June 15, 2024 +encoding bug fix, see [issue 547](https://github.com/cmhughes/latexindent.pl/issues/547), thanks to @fengzyf + ## V3.24.1, May 12, 2024 oneSentencePerLine par issue bug fix, see [issue 527](https://github.com/cmhughes/latexindent.pl/issues/527) diff --git a/documentation/conf.py b/documentation/conf.py index b063691e..2adec41d 100644 --- a/documentation/conf.py +++ b/documentation/conf.py @@ -63,9 +63,9 @@ # built documents. # # The short X.Y version. -version = u'3.24.1' +version = u'3.24.2' # The full version, including alpha/beta/rc tags. -release = u'3.24.1' +release = u'3.24.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/documentation/contributors.bib b/documentation/contributors.bib index 2da6ea81..49fc2deb 100644 --- a/documentation/contributors.bib +++ b/documentation/contributors.bib @@ -224,3 +224,14 @@ @online{jessestricker author = "Jesse Stricker", urldate = {2023-07-12}, keywords = {contributor},} + +% +% 2024 +% +@online{fengzyf, + title = "Encoding work", + url = "https://github.com/cmhughes/latexindent.pl/pull/548", + date = {2024-06-15}, + author = "fengzyf", + urldate = {2024-06-15}, + keywords = {contributor},} diff --git a/documentation/demonstrations/fine-tuning3.yaml b/documentation/demonstrations/fine-tuning3.yaml index 44f5259e..077ee0f6 100644 --- a/documentation/demonstrations/fine-tuning3.yaml +++ b/documentation/demonstrations/fine-tuning3.yaml @@ -1,6 +1,6 @@ fineTuning: trailingComments: - notPreceededBy: (? minorVersion=0 -oldVersion='3.24' -newVersion='3.24.1' -oldDate='2024-04-28' -newDate='2024-05-12' +oldVersion='3.24.1' +newVersion='3.24.2' +oldDate='2024-05-12' +newDate='2024-06-15' updateVersion=0 gitMode=0 diff --git a/latexindent.pl b/latexindent.pl index 36855f46..c85bdf20 100755 --- a/latexindent.pl +++ b/latexindent.pl @@ -1,6 +1,6 @@ #!/usr/bin/env perl # -# latexindent.pl, version 3.24.1, 2024-05-12 +# latexindent.pl, version 3.24.2, 2024-06-15 # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/readme.md b/readme.md index ffcb9e2f..a703cf91 100644 --- a/readme.md +++ b/readme.md @@ -21,7 +21,7 @@ and [pre-commit](https://latexindentpl.readthedocs.io/en/latest/sec-appendices.h ## version - latexindent.pl, version 3.24.1, 2024-05-12 + latexindent.pl, version 3.24.2, 2024-06-15 ## author Chris Hughes (cmhughes) @@ -157,7 +157,7 @@ framework](https://pre-commit.com) by adding this to your ```yaml - repo: https://github.com/cmhughes/latexindent.pl.git - rev: V3.24.1 + rev: V3.24.2 hooks: - id: latexindent ``` @@ -234,7 +234,7 @@ I align with many of the approaches and details at [Dramatically increase your p ## perl version -I develop latexindent.pl on Ubuntu Linux, using [perlbrew](https://perlbrew.pl/); I currently develop on perl version v5.38.2 +I develop latexindent.pl on Ubuntu Linux, using [perlbrew](https://perlbrew.pl/); I currently develop on perl version v5.39.1 ## GitHub Actions The standalone executables `latexindent.exe`, `latexindent-linux`, `latexindent-macos` are created and released by [GitHub Actions](https://github.com/features/actions); the diff --git a/test-cases/alignment/alignment-test-cases.sh b/test-cases/alignment/alignment-test-cases.sh index afe9fcd7..fb361150 100755 --- a/test-cases/alignment/alignment-test-cases.sh +++ b/test-cases/alignment/alignment-test-cases.sh @@ -341,7 +341,7 @@ latexindent.pl -s issue-535.tex -o=+-mod1 latexindent.pl -s issue-543.tex -o=+-mod1 -latexindent.pl -s issue-541.tex -l issue-541.yaml -o=+-mod1 +latexindent.pl -s -m issue-541.tex -l issue-541.yaml -o=+-mod1 [[ $silentMode == 0 ]] && set -x [[ $gitStatus == 1 ]] && git status diff --git a/test-cases/alignment/issue-541-mod1.tex b/test-cases/alignment/issue-541-mod1.tex index 95d925f4..fcb07655 100644 --- a/test-cases/alignment/issue-541-mod1.tex +++ b/test-cases/alignment/issue-541-mod1.tex @@ -2,7 +2,8 @@ \usepackage{tabularray}%tabular \begin{document} -\begin{tblr}[long, +\begin{tblr}[ + long, label= {market_fuyanshan} ]{ cells = {c,m}, diff --git a/test-cases/alignment/issue-541.yaml b/test-cases/alignment/issue-541.yaml index 26b81b91..9f1c656f 100644 --- a/test-cases/alignment/issue-541.yaml +++ b/test-cases/alignment/issue-541.yaml @@ -1,3 +1,7 @@ +modifyLineBreaks: + optionalArguments: + tblr: + OptArgBodyStartsOnOwnLine: 1 # -1,0,1,2,3,4 fineTuning: keyEqualsValuesBracesBrackets: name: |- diff --git a/test-cases/fine-tuning/href2.yaml b/test-cases/fine-tuning/href2.yaml index 83554ade..0a42946c 100644 --- a/test-cases/fine-tuning/href2.yaml +++ b/test-cases/fine-tuning/href2.yaml @@ -1,6 +1,6 @@ fineTuning: trailingComments: - notPreceededBy: '(?:(?<-]+? + follow: \h|\R|\{|\[|\$|\)|\(|, diff --git a/test-cases/namedGroupingBracesBrackets/named-grouping-test-cases.sh b/test-cases/namedGroupingBracesBrackets/named-grouping-test-cases.sh index 9ff795ae..810eafe0 100755 --- a/test-cases/namedGroupingBracesBrackets/named-grouping-test-cases.sh +++ b/test-cases/namedGroupingBracesBrackets/named-grouping-test-cases.sh @@ -45,5 +45,7 @@ latexindent.pl -s issue-501.tex -o +-mod1 latexindent.pl -s -l issue-501.yaml issue-501.tex -o +-mod2 latexindent.pl -s -m -y "modifyLineBreaks:textWrapOptions:columns:25,modifyLineBreaks:textWrapOptions:blocksBeginWith:other:(?:\\\\),noAdditionalIndentGlobal:namedGroupingBracesBrackets:1" issue-501a.tex -o=+-mod2 + +latexindent.pl -s -l issue-544.yaml issue-544.tex -o=+-mod1 [[ $gitStatus == 1 ]] && git status [[ $noisyMode == 1 ]] && makenoise diff --git a/test-cases/path-tests/path-test3.txt b/test-cases/path-tests/path-test3.txt index 865135ae..2189e557 100644 --- a/test-cases/path-tests/path-test3.txt +++ b/test-cases/path-tests/path-test3.txt @@ -6,8 +6,6 @@ YAML settings, reading from the following files: paths: - /absolute/path/to/config.yaml -WARN: encoding "zzz" not found - Ignore this setting and will take the default encoding. --- encoding: zzz paths: diff --git a/test-cases/path-tests/path-test4.txt b/test-cases/path-tests/path-test4.txt index aa54cfd2..1c4330cb 100644 --- a/test-cases/path-tests/path-test4.txt +++ b/test-cases/path-tests/path-test4.txt @@ -6,8 +6,6 @@ YAML settings, reading from the following files: paths: - ./a-nested-path1.yaml -WARN: encoding "zzz" not found - Ignore this setting and will take the default encoding. --- encoding: zzz paths: diff --git a/test-cases/specials/issue-448b.yaml b/test-cases/specials/issue-448b.yaml index 8068aa74..af5c0a11 100644 --- a/test-cases/specials/issue-448b.yaml +++ b/test-cases/specials/issue-448b.yaml @@ -8,5 +8,5 @@ specialBeginEnd: fineTuning: trailingComments: - notPreceededBy: (?