Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhughes committed Apr 28, 2024
2 parents 9cc2d86 + 827006e commit 587f372
Show file tree
Hide file tree
Showing 78 changed files with 759 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ FROM perl:5.38.2-slim-threaded-buster
#

ARG LATEXINDENT_VERSION
ENV LATEXINDENT_VERSION ${LATEXINDENT_VERSION:-V3.23.9}
ENV LATEXINDENT_VERSION ${LATEXINDENT_VERSION:-V3.24}

RUN apt-get update \
&& apt-get install \
Expand Down
5 changes: 5 additions & 0 deletions LatexIndent/BackUpFileProcedure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ sub create_back_up_file {

# add the user's backup directory to the backup path
$backupFileNoExt = "${$self}{cruftDirectory}/$backupFileNoExt";
$backupFileNoExt =~ s/\\/\//g;
$backupFileNoExt =~ s/\/{2,}/\//g;
if ( $^O eq 'MSWin32' ) {
$backupFileNoExt =~ s/\//\\/g;
}

# local variables, determined from the YAML settings
my $onlyOneBackUp = $mainSettings{onlyOneBackUp};
Expand Down
24 changes: 18 additions & 6 deletions LatexIndent/Document.pm
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,32 @@ sub output_logfile {
if ${ $mainSettings{logFilePreferences} }{showGitHubInfoFooter};

# open log file
my $logfileName = $switches{logFileName} || "indent.log";
my $logfilePossible = 1;
my $logfile = open_with_encode( '>:encoding(UTF-8)', "${$self}{cruftDirectory}/$logfileName" )
or $logfilePossible = 0;
my $logfileName = $switches{logFileName} || "indent.log";

my $logfilePath;
$logfilePath = "${$self}{cruftDirectory}/$logfileName";
$logfilePath =~ s/\\/\//g;
$logfilePath =~ s/\/{2,}/\//g;
if ( $^O eq 'MSWin32' ) {
$logfilePath =~ s/\//\\/g;
}

my $logfile = open_with_encode( '>:encoding(UTF-8)', $logfilePath );

if ($logfilePossible) {
if ($logfile) {
foreach my $line ( @{LatexIndent::Logger::logFileLines} ) {
print $logfile $line, "\n";
}

# close log file
close($logfile);
}

else {
if ( $switches{screenlog} ) {
print "WARN: Could not open the logfile $logfilePath \n";
print " No logfile will be produced.\n";
}
}
}

sub process_body_of_text {
Expand Down
44 changes: 43 additions & 1 deletion LatexIndent/GetYamlSettings.pm
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,46 @@ sub yaml_read_settings {
$logger->info("Reading USER settings from $settings");
$userSettings = read_yaml_with_encode("$settings");

# update the absolute paths
if ( $userSettings and ( ref( $userSettings->[0] ) eq 'HASH' ) and $userSettings->[0]->{paths} ) {
$logger->info("Reading path information from $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, $_ );
}
}
}

# if we can read userSettings
if ($userSettings) {

Expand Down Expand Up @@ -477,7 +517,9 @@ sub yaml_read_settings {
}

# if amalgamate is set to 1, then append
if ( ${ $mainSettings{$firstLevelKey}[0] }{amalgamate} ) {
if ( ref( $mainSettings{$firstLevelKey}[0] ) eq "HASH"
and ${ $mainSettings{$firstLevelKey}[0] }{amalgamate} )
{

# loop through the other settings
foreach ( @{$firstLevelValue} ) {
Expand Down
15 changes: 11 additions & 4 deletions LatexIndent/LogFile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ ENDQUOTE

# cruft directory
${$self}{cruftDirectory} = $switches{cruftDirectory} || ( dirname ${$self}{fileName} );
${$self}{cruftDirectory} =~ s/\\/\//g;
${$self}{cruftDirectory} =~ s/\/{2,}/\//g;
if ( $^O eq 'MSWin32' ) {
${$self}{cruftDirectory} =~ s/\//\\/g;
}

my $cruftDirectoryCreation = 0;

Expand All @@ -149,11 +154,13 @@ ENDQUOTE
}
$cruftDirectoryCreation = 1;
}

my $logfileName = ( $switches{cruftDirectory} ? ${$self}{cruftDirectory} . "/" : '' )
. ( $switches{logFileName} || "indent.log" );

$logfileName = $logfileName;
$logfileName =~ s/\\/\//g;
$logfileName =~ s/\/{2,}/\//g;
if ( $^O eq 'MSWin32' ) {
$logfileName =~ s/\//\\/g;
}

# details of the script to log file
$logger->info("*$FindBin::Script version $versionNumber, $versionDate, a script to indent .tex files");
Expand Down Expand Up @@ -260,7 +267,7 @@ ENDQUOTE
$switches{outputToFile} = 0;
}

$logger->info("*Directory for backup files and $logfileName:");
$logger->info("*Directory for backup files and log file $logfileName:");
$logger->info( $switches{cruftDirectory} ? ${$self}{cruftDirectory} : ${$self}{cruftDirectory} );
$logger->info("cruft directory creation: ${$self}{cruftDirectory}") if $cruftDirectoryCreation;

Expand Down
23 changes: 15 additions & 8 deletions LatexIndent/UTF8CmdLineArgsFileOperation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,28 @@ sub open_with_encode {
require Win32::Unicode::File;
Win32::Unicode::File->import;
$fh = Win32::Unicode::File->new;
open $fh, $mode, $filename or die "Can't open file: $!";
return $fh;
if ( open $fh, $mode, $filename ) {
return $fh;
}
else {
return undef;
}
}
else {
open( $fh, $mode, $filename ) or die "Can't open file: $!";
return $fh;
if ( open( $fh, $mode, $filename ) ) {
return $fh;
}
else {
return undef;
}
}
}

sub read_yaml_with_encode {
use YAML::Tiny;
my $filename = shift;

my $fh = open_with_encode( '<:encoding(UTF-8)', $filename ) or die $!;
my $fh = open_with_encode( '<:encoding(UTF-8)', $filename ) or return undef;
my $yaml_string = join( "", <$fh> );
return YAML::Tiny->read_string($yaml_string);
}
Expand All @@ -105,14 +113,13 @@ sub mkdir_with_encode {
require Win32::Unicode::Dir;
Win32::Unicode::Dir->import(qw(mkdirW));

mkdirW($path) or die "Cannot create directory $path: $!";
mkdirW($path);
}
else {
require File::Path;
File::Path->import(qw(make_path));

my $created = make_path($path);
die "Cannot create directory $path" unless $created;
make_path($path);
}
}

Expand Down
4 changes: 2 additions & 2 deletions LatexIndent/Version.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ use warnings;
use Exporter qw/import/;
our @EXPORT_OK = qw/$versionNumber $versionDate/;

our $versionNumber = '3.23.9';
our $versionDate = '2024-04-06';
our $versionNumber = '3.24';
our $versionDate = '2024-04-28';
1
3 changes: 2 additions & 1 deletion defaultSettings.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# latexindent.pl, version 3.23.9, 2024-04-06
# latexindent.pl, version 3.24, 2024-04-28
#
# defaultSettings.yaml, the default settings for latexindent.pl
#
Expand Down Expand Up @@ -228,6 +228,7 @@ lookForAlignDelims:
tblr: 1
longtblr: 1
talltblr: 1
spreadtab: 1

# if you want the script to look for \item commands
# and format it, as follows (for example),
Expand Down
7 changes: 6 additions & 1 deletion documentation/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<!-- announcement: latexindent.exe oneSentencePerLine bug fix-->
<!-- announcement: paths feature update, log file bug fix-->

# changelog.md
## V3.24, April 28, 2024
* `paths` feature update, see [issue 516](https://github.com/cmhughes/latexindent.pl/issues/516)
* `lookForAlignDelims` updated to include `spreadtab`, see [issue 535](https://github.com/cmhughes/latexindent.pl/issues/535)
* log file bugfix, see [issue 537](https://github.com/cmhughes/latexindent.pl/issues/537), thanks to @fengzyf

## V3.23.9, April 6, 2024
`latexindent.exe` oneSentencePerLine bug fix, see [issue 514](https://github.com/cmhughes/latexindent.pl/issues/514)

Expand Down
4 changes: 2 additions & 2 deletions documentation/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
# built documents.
#
# The short X.Y version.
version = u'3.23.9'
version = u'3.24'
# The full version, including alpha/beta/rc tags.
release = u'3.23.9'
release = u'3.24'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
10 changes: 10 additions & 0 deletions documentation/demonstrations/documentation-test-cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -442,5 +442,15 @@ latexindent.pl --lines !5-7 -s myfile.tex -o=+-mod5
latexindent.pl --lines !5-7,!9-10 myfile.tex -s -o=+-mod6
latexindent.pl --lines 6 myfile1.tex -m -s -l env-mlb2,env-mlb7,env-mlb8 -o=+-mod1

# paths demo
latexindent.pl -l path1.yaml -s paths-demo.tex -o=+-mod1
cp indent.log path-test1.txt
perl -p0i -e 's/.*?(YAML\ssettings, reading)/$1/s' path-test1.txt
perl -p0i -e 's/INFO:.*//s' path-test1.txt

latexindent.pl -l path3.yaml -s paths-demo.tex -o=+-mod3
cp indent.log path-test3.txt
perl -p0i -e 's/.*?(YAML\ssettings, reading)/$1/s' path-test3.txt
perl -p0i -e 's/INFO:.*//s' path-test3.txt
[[ $noisyMode == 1 ]] && makenoise
[[ $gitStatus == 1 ]] && git status
17 changes: 17 additions & 0 deletions documentation/demonstrations/path-test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
YAML settings, reading from the following files:
Reading USER settings from path1.yaml
Reading path information from path1.yaml
---
defaultIndent: ''
paths:
- path2.yaml

---
defaultIndent: ''
paths:
- path2.yaml

Reading USER settings from path2.yaml
---
defaultIndent: ' '

29 changes: 29 additions & 0 deletions documentation/demonstrations/path-test3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
YAML settings, reading from the following files:
Reading USER settings from path3.yaml
Reading path information from path3.yaml
---
defaultIndent: ''
paths:
- path4.yaml

---
defaultIndent: ''
paths:
- path4.yaml

Reading USER settings from path4.yaml
Reading path information from path4.yaml
---
defaultIndent: ' '
paths:
- path5.yaml

---
defaultIndent: ' '
paths:
- path5.yaml

Reading USER settings from path5.yaml
---
defaultIndent: ' '

3 changes: 3 additions & 0 deletions documentation/demonstrations/path1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defaultIndent: ''
paths:
- path2.yaml
1 change: 1 addition & 0 deletions documentation/demonstrations/path2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaultIndent: ' '
3 changes: 3 additions & 0 deletions documentation/demonstrations/path3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defaultIndent: ''
paths:
- path4.yaml
3 changes: 3 additions & 0 deletions documentation/demonstrations/path4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defaultIndent: ' '
paths:
- path5.yaml
1 change: 1 addition & 0 deletions documentation/demonstrations/path5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaultIndent: ' '
5 changes: 5 additions & 0 deletions documentation/demonstrations/paths-demo-mod1.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\pathdemo[
opt arg
]{
mand arg
}
5 changes: 5 additions & 0 deletions documentation/demonstrations/paths-demo-mod3.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\pathdemo[
opt arg
]{
mand arg
}
5 changes: 5 additions & 0 deletions documentation/demonstrations/paths-demo.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\pathdemo[
opt arg
]{
mand arg
}
2 changes: 1 addition & 1 deletion documentation/demonstrations/pre-commit-config-conda.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- repo: https://github.com/cmhughes/latexindent.pl
rev: V3.23.9
rev: V3.24
hooks:
- id: latexindent-conda
args: [-s]
2 changes: 1 addition & 1 deletion documentation/demonstrations/pre-commit-config-cpan.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- repo: https://github.com/cmhughes/latexindent.pl
rev: V3.23.9
rev: V3.24
hooks:
- id: latexindent
args: [-s]
2 changes: 1 addition & 1 deletion documentation/demonstrations/pre-commit-config-demo.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- repo: https://github.com/cmhughes/latexindent.pl
rev: V3.23.9
rev: V3.24
hooks:
- id: latexindent
args: [-l, -m, -s, -w]
2 changes: 1 addition & 1 deletion documentation/demonstrations/pre-commit-config-docker.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- repo: https://github.com/cmhughes/latexindent.pl
rev: V3.23.9
rev: V3.24
hooks:
- id: latexindent-docker
args: [-s]
2 changes: 1 addition & 1 deletion documentation/documentation-default-settings-update.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{name=>"removeTrailingWhitespace",numberOfLines=>2},
{name=>"fileContentsEnvironments",numberOfLines=>2},
{name=>"lookForPreamble",numberOfLines=>5},
{name=>"lookForAlignDelims",numberOfLines=>18},
{name=>"lookForAlignDelims",numberOfLines=>19},
{name=>"indentAfterItems",numberOfLines=>7},
{name=>"itemNames",numberOfLines=>2},
{name=>"specialBeginEnd",numberOfLines=>14,mustBeAtBeginning=>1},
Expand Down
2 changes: 1 addition & 1 deletion documentation/latexindent-yaml-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/schema",
"$id": "latexindent-yaml-schema.json",
"title": "latexindent.pl YAML schema",
"description": "latexindent.pl YAML schema helper, V3.23.9 2024-04-06",
"description": "latexindent.pl YAML schema helper, V3.24 2024-04-28",
"type": "object",
"properties": {
"fileExtensionPreference": {
Expand Down

0 comments on commit 587f372

Please sign in to comment.