From 23cf0b808a389f0ca7db875f3b036de281ea26c7 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 19 Apr 2015 22:41:13 +0000 Subject: latexindent (19apr15) git-svn-id: svn://tug.org/texlive/trunk@36955 c570f23f-e606-0410-a88d-b1316a301751 --- .../linked_scripts/latexindent/latexindent.pl | 92 +++++++++++++++++----- 1 file changed, 73 insertions(+), 19 deletions(-) (limited to 'Build') diff --git a/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl b/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl index d023ef014d0..f273ab7b890 100755 --- a/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl +++ b/Build/source/texk/texlive/linked_scripts/latexindent/latexindent.pl @@ -17,10 +17,13 @@ use strict; use warnings; +# list of modules +my @listOfModules = ('FindBin','YAML::Tiny','File::Copy','File::Basename','Getopt::Long','File::HomeDir'); + # check the other modules are available -foreach my $moduleName ('FindBin','YAML::Tiny','File::Copy','File::Basename','Getopt::Long','File::HomeDir') +foreach my $moduleName (@listOfModules) { - # references: + # references: # http://stackoverflow.com/questions/251694/how-can-i-check-if-i-have-a-perl-module-before-using-it # http://stackoverflow.com/questions/1917261/how-can-i-dynamically-include-perl-modules-without-using-eval eval { @@ -60,7 +63,7 @@ GetOptions ("w"=>\$overwrite, ); # version number -my $versionNumber = "2.0R"; +my $versionNumber = "2.1R"; # Check the number of input arguments- if it is 0 then simply # display the list of options (like a manual) @@ -83,7 +86,7 @@ ENDQUOTE exit(2); } -# set up default for cruftDirectory using the one from the input file, +# set up default for cruftDirectory using the one from the input file, # unless it has been specified using -c="/some/directory" $cruftDirectory=dirname $ARGV[0] unless(defined($cruftDirectory)); @@ -103,14 +106,40 @@ print $logfile $time; # output version to log file print $logfile <new; -print $logfile "Reading defaultSettings.yaml from $FindBin::RealBin/defaultSettings.yaml\n\n"; - # Open defaultSettings.yaml $defaultSettings = YAML::Tiny->read( "$FindBin::RealBin/defaultSettings.yaml" ); +print $logfile "Reading defaultSettings.yaml from $FindBin::RealBin/defaultSettings.yaml\n\n" if($defaultSettings); +# if latexindent.exe is invoked from TeXLive, then defaultSettings.yaml won't be in +# the same directory as it; we need to navigate to it +if(!$defaultSettings) +{ + $defaultSettings = YAML::Tiny->read( "$FindBin::RealBin/../../texmf-dist/scripts/latexindent/defaultSettings.yaml"); + print $logfile "Reading defaultSettings.yaml (2nd attempt, TeXLive, Windows) from $FindBin::RealBin/../../texmf-dist/scripts/latexindent/defaultSettings.yaml\n\n" if($defaultSettings); +} + +# if both of the above attempts have failed, we need to exit if(!$defaultSettings) { for my $fh ($out,$logfile) { @@ -255,9 +291,26 @@ my $userSettings; # get information about user settings- first check if indentconfig.yaml exists my $indentconfig = File::HomeDir->my_home . "/indentconfig.yaml"; +# if indentconfig.yaml doesn't exist, check for the hidden file, .indentconfig.yaml +$indentconfig = File::HomeDir->my_home . "/.indentconfig.yaml" if(! -e $indentconfig); + if ( -e $indentconfig and !$onlyDefault ) { - print $logfile "Reading path information from ",File::HomeDir->my_home,"/indentconfig.yaml\n"; + print $logfile "Reading path information from $indentconfig\n"; + # if both indentconfig.yaml and .indentconfig.yaml exist + if ( -e File::HomeDir->my_home . "/indentconfig.yaml" and -e File::HomeDir->my_home . "/.indentconfig.yaml") + { + print $logfile File::HomeDir->my_home,"/.indentconfig.yaml has been found, but $indentconfig takes priority\n"; + } + elsif ( -e File::HomeDir->my_home . "/indentconfig.yaml" ) + { + print $logfile "Alternatively, ",File::HomeDir->my_home,"/.indentconfig.yaml can be used\n"; + + } + elsif ( -e File::HomeDir->my_home . "/.indentconfig.yaml" ) + { + print $logfile "Alternatively, ",File::HomeDir->my_home,"/indentconfig.yaml can be used\n"; + } # read the absolute paths from indentconfig.yaml $userSettings = YAML::Tiny->read( "$indentconfig" ); @@ -284,15 +337,16 @@ else { if($onlyDefault) { - print $logfile "Only default settings requested, not reading USER settings from indentconfig.yaml \n"; + print $logfile "Only default settings requested, not reading USER settings from $indentconfig\n"; print $logfile "Ignoring localSettings.yaml\n" if($readLocalSettings); $readLocalSettings = 0; } else { - # give the user instructions on where to put indentconfig.yaml + # give the user instructions on where to put indentconfig.yaml or .indentconfig.yaml print $logfile "Home directory is ",File::HomeDir->my_home,"\n"; print $logfile "To specify user settings you would put indentconfig.yaml here: \n\t",File::HomeDir->my_home,"/indentconfig.yaml\n\n"; + print $logfile "Alternatively, you can use the hidden file .indentconfig.yaml as: \n\t",File::HomeDir->my_home,"/.indentconfig.yaml\n\n"; } } @@ -1561,7 +1615,7 @@ sub at_beg_of_env_or_eq{ # () empty just so that $1 and $2 are defined # (\\\[) \[ there are lots of \ because both \ and [ need escaping # \\begin{\\?(.*?)} \begin{something} where something could start - # with a backslash, e.g \my@env@ which can happen + # with a backslash, e.g \my@env@ which can happen # in a style or class file, for example if( ( ( $_ =~ m/^\s*(\$)?\\begin{\\?(.*?)}/ and $_ !~ m/\\end{$2}/) @@ -1648,9 +1702,9 @@ sub at_end_of_env_or_eq{ &decrease_indent($indentNames[-1]); } - # some commands contain \end{environmentname}, which - # can cause a problem if \begin{environmentname} was not - # started previously; if @environmentStack is empty, + # some commands contain \end{environmentname}, which + # can cause a problem if \begin{environmentname} was not + # started previously; if @environmentStack is empty, # then we don't need to check for \end{environmentname} if(@environmentStack) { -- cgit v1.2.3