Do a fresh compile for preview after error (#9061)

As Enrico said, the user might have installed a package that was
missing (in which case the .tex file would not have changed).

Another reason is that changing some document settings did not
automatically lead to a fresh compile after an error (#9061).

Our old mechanism for detemining whether there was an error was to
check if the dependent file existed in the temporary directory. If
it did not exist, that meant it was removed, presumably because
there was an error during compilation. That mechanism cannot be used
anymore because we keep the files around even after error because of
the "Show Output Anyway" button (09700d5b). This commit implements a
more straightforward way of checking whether there was an error in
the previous preview by simply storing the success of last compile
in a buffer variable.
This commit is contained in:
Scott Kostyshak 2015-05-03 01:22:03 -04:00
parent a1aeea3f16
commit 72c5385f83
5 changed files with 29 additions and 8 deletions

View File

@ -288,10 +288,15 @@ public:
/// we ran updateBuffer(), i.e., whether citation labels may need /// we ran updateBuffer(), i.e., whether citation labels may need
/// to be updated. /// to be updated.
mutable bool cite_labels_valid_; mutable bool cite_labels_valid_;
/// these hold the file name and format, written to by Buffer::preview
/// and read from by LFUN_BUFFER_VIEW_CACHE. /// These two hold the file name and format, written to by
/// Buffer::preview and read from by LFUN_BUFFER_VIEW_CACHE.
FileName preview_file_; FileName preview_file_;
string preview_format_; string preview_format_;
/// If there was an error when previewing, on the next preview we do
/// a fresh compile (e.g. in case the user installed a package that
/// was missing).
bool preview_error_;
mutable RefCache ref_cache_; mutable RefCache ref_cache_;
@ -429,6 +434,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
internal_buffer = cloned_buffer_->d->internal_buffer; internal_buffer = cloned_buffer_->d->internal_buffer;
preview_file_ = cloned_buffer_->d->preview_file_; preview_file_ = cloned_buffer_->d->preview_file_;
preview_format_ = cloned_buffer_->d->preview_format_; preview_format_ = cloned_buffer_->d->preview_format_;
preview_error_ = cloned_buffer_->d->preview_error_;
} }
@ -1164,6 +1170,12 @@ void Buffer::setFullyLoaded(bool value)
} }
bool Buffer::lastPreviewError() const
{
return d->preview_error_;
}
PreviewLoader * Buffer::loader() const PreviewLoader * Buffer::loader() const
{ {
if (!isExporting() && lyxrc.preview == LyXRC::PREVIEW_OFF) if (!isExporting() && lyxrc.preview == LyXRC::PREVIEW_OFF)
@ -4235,6 +4247,7 @@ Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) con
LATTEST (isClone()); LATTEST (isClone());
d->cloned_buffer_->d->preview_file_ = previewFile; d->cloned_buffer_->d->preview_file_ = previewFile;
d->cloned_buffer_->d->preview_format_ = format; d->cloned_buffer_->d->preview_format_ = format;
d->cloned_buffer_->d->preview_error_ = (status != ExportSuccess);
if (status != ExportSuccess) if (status != ExportSuccess)
return status; return status;

View File

@ -648,6 +648,9 @@ public:
/// Export buffer to format \p format and open the result in a suitable viewer. /// Export buffer to format \p format and open the result in a suitable viewer.
/// Note: This has nothing to do with preview of graphics or math formulas. /// Note: This has nothing to do with preview of graphics or math formulas.
ExportStatus preview(std::string const & format) const; ExportStatus preview(std::string const & format) const;
/// true if there was a previous preview this session of this buffer and
/// there was an error on the previous preview of this buffer.
bool lastPreviewError() const;
private: private:
/// ///

View File

@ -644,7 +644,7 @@ bool Converters::runLaTeX(Buffer const & buffer, string const & command,
// do the LaTeX run(s) // do the LaTeX run(s)
string const name = buffer.latexName(); string const name = buffer.latexName();
LaTeX latex(command, runparams, FileName(makeAbsPath(name)), LaTeX latex(command, runparams, FileName(makeAbsPath(name)),
buffer.filePath()); buffer.filePath(), buffer.lastPreviewError());
TeXErrors terr; TeXErrors terr;
ShowMessage show(buffer); ShowMessage show(buffer);
latex.message.connect(show); latex.message.connect(show);

View File

@ -92,7 +92,7 @@ bool operator!=(AuxInfo const & a, AuxInfo const & o)
*/ */
LaTeX::LaTeX(string const & latex, OutputParams const & rp, LaTeX::LaTeX(string const & latex, OutputParams const & rp,
FileName const & f, string const & p) FileName const & f, string const & p, bool const clean_start)
: cmd(latex), file(f), path(p), runparams(rp), biber(false) : cmd(latex), file(f), path(p), runparams(rp), biber(false)
{ {
num_errors = 0; num_errors = 0;
@ -105,6 +105,8 @@ LaTeX::LaTeX(string const & latex, OutputParams const & rp,
output_file = output_file =
FileName(changeExtension(file.absFileName(), ".dvi")); FileName(changeExtension(file.absFileName(), ".dvi"));
} }
if (clean_start)
removeAuxiliaryFiles();
} }
@ -169,8 +171,6 @@ int LaTeX::run(TeXErrors & terr)
theBufferList().updateIncludedTeXfiles(FileName::getcwd().absFileName(), theBufferList().updateIncludedTeXfiles(FileName::getcwd().absFileName(),
runparams); runparams);
// Never write the depfile if an error was encountered.
// 0 // 0
// first check if the file dependencies exist: // first check if the file dependencies exist:
// ->If it does exist // ->If it does exist

View File

@ -151,11 +151,16 @@ public:
/** /**
cmd = the latex command, file = name of the (temporary) latex file, cmd = the latex command, file = name of the (temporary) latex file,
path = name of the files original path. path = name of the files original path,
clean_start = This forces a fresh run by deleting the files in the temp
dir. We set this e.g. if there was an error on previous
preview, which is good if the user installed a package
or changed certain document settings (#9061).
*/ */
LaTeX(std::string const & cmd, OutputParams const &, LaTeX(std::string const & cmd, OutputParams const &,
support::FileName const & file, support::FileName const & file,
std::string const & path = empty_string()); std::string const & path = empty_string(),
bool const clean_start = false);
/// runs LaTeX several times /// runs LaTeX several times
int run(TeXErrors &); int run(TeXErrors &);