From da2b15eb64ee0e14eff3e8f606930bce4cedbdd8 Mon Sep 17 00:00:00 2001 From: cmhughes Date: Sat, 24 Apr 2021 19:50:49 +0100 Subject: [PATCH] log file process will no longer cause script to fail if the log file can not be opened: https://github.com/cmhughes/latexindent.pl/issues/145 --- LatexIndent/Document.pm | 17 ++++++++++------- documentation/sec-default-user-local.tex | 3 ++- documentation/sec-how-to-use.tex | 8 ++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/LatexIndent/Document.pm b/LatexIndent/Document.pm index 0b3ea9b2..25bf3876 100644 --- a/LatexIndent/Document.pm +++ b/LatexIndent/Document.pm @@ -162,15 +162,18 @@ sub output_indented_text{ # open log file my $logfileName = $switches{logFileName}||"indent.log"; my $logfile; - open($logfile,">","${$self}{cruftDirectory}/$logfileName") or die "Can't open $logfileName"; + my $logfilePossible = 1; + open($logfile,">","${$self}{cruftDirectory}/$logfileName") or $logfilePossible =0; - foreach my $line (@{LatexIndent::Logger::logFileLines}){ - print $logfile $line,"\n"; - } + if($logfilePossible){ + foreach my $line (@{LatexIndent::Logger::logFileLines}){ + print $logfile $line,"\n"; + } + + # close log file + close($logfile); + } - # close log file - close($logfile); - # output to screen, unless silent mode print ${$self}{body} unless $switches{silentMode}; diff --git a/documentation/sec-default-user-local.tex b/documentation/sec-default-user-local.tex index 5e04637e..2e5afbcd 100644 --- a/documentation/sec-default-user-local.tex +++ b/documentation/sec-default-user-local.tex @@ -152,7 +152,8 @@ \section{defaultSettings.yaml}\label{sec:defuseloc} %(*@@*)\end{noindent} \end{cmhlistings} - Important note: it is assumed that the \texttt{noindent} block statements appear on their own line. + Important note: it is assumed that the \texttt{noindent} block statements appear on + their own line. \yamltitle{removeTrailingWhitespace}*{fields}\label{yaml:removeTrailingWhitespace} diff --git a/documentation/sec-how-to-use.tex b/documentation/sec-how-to-use.tex index 8c7d9b95..510df8c6 100644 --- a/documentation/sec-how-to-use.tex +++ b/documentation/sec-how-to-use.tex @@ -317,6 +317,14 @@ \subsection{From the command line}\label{sec:commandline} if you wish to change the name of this file, simply call the script with your chosen name after the \texttt{-g} switch as demonstrated above. + \announce{new}{log file updated} If \texttt{latexindent.pl} can not open the log file that you + specify, then the script + will operate, and no log file will be produced; this might be helpful to users who wish + to specify the following, for example + \begin{commandshell} +latexindent.pl -g /dev/null myfile.tex +\end{commandshell} + \flagbox{-sl, --screenlog} \index{switches!-sl, --screenlog definition and details} \begin{commandshell}