]> git.lyx.org Git - features.git/commitdiff
Do a fresh compile for preview after error (#9061)
authorScott Kostyshak <skostysh@lyx.org>
Sun, 3 May 2015 05:22:03 +0000 (01:22 -0400)
committerScott Kostyshak <skostysh@lyx.org>
Tue, 5 May 2015 04:30:50 +0000 (00:30 -0400)
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.

src/Buffer.cpp
src/Buffer.h
src/Converter.cpp
src/LaTeX.cpp
src/LaTeX.h

index ed94503c14631e77844a214f279e12613ad127a6..c313883b1c3f2032ed0afe2fde0aa15985b95d50 100644 (file)
@@ -288,10 +288,15 @@ public:
        /// we ran updateBuffer(), i.e., whether citation labels may need
        /// to be updated.
        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_;
        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_;
 
@@ -429,6 +434,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
        internal_buffer = cloned_buffer_->d->internal_buffer;
        preview_file_ = cloned_buffer_->d->preview_file_;
        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
 {
        if (!isExporting() && lyxrc.preview == LyXRC::PREVIEW_OFF)
@@ -4235,6 +4247,7 @@ Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) con
        LATTEST (isClone());
        d->cloned_buffer_->d->preview_file_ = previewFile;
        d->cloned_buffer_->d->preview_format_ = format;
+       d->cloned_buffer_->d->preview_error_ = (status != ExportSuccess);
 
        if (status != ExportSuccess)
                return status;
index 718fe1e2e123d318613b6b230b1463368b0d6911..46075d7e6b8c98e5db75f0c8fcf8925adf0d193b 100644 (file)
@@ -648,6 +648,9 @@ public:
        /// 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.
        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:
        ///
index 3d3181aae0ab6339d42465c0a98ec5d738f3c679..0e0251eb39e766343745bf74915523fd24e46e7e 100644 (file)
@@ -644,7 +644,7 @@ bool Converters::runLaTeX(Buffer const & buffer, string const & command,
        // do the LaTeX run(s)
        string const name = buffer.latexName();
        LaTeX latex(command, runparams, FileName(makeAbsPath(name)),
-                   buffer.filePath());
+                   buffer.filePath(), buffer.lastPreviewError());
        TeXErrors terr;
        ShowMessage show(buffer);
        latex.message.connect(show);
index a86dc92dfabb6ca5895866b5b5b0dedc8960e166..ba13b22c22fb006974dbf13e7354bbf0eca6b9d2 100644 (file)
@@ -92,7 +92,7 @@ bool operator!=(AuxInfo const & a, AuxInfo const & o)
  */
 
 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)
 {
        num_errors = 0;
@@ -105,6 +105,8 @@ LaTeX::LaTeX(string const & latex, OutputParams const & rp,
                output_file =
                        FileName(changeExtension(file.absFileName(), ".dvi"));
        }
+       if (clean_start)
+               removeAuxiliaryFiles();
 }
 
 
@@ -169,8 +171,6 @@ int LaTeX::run(TeXErrors & terr)
        theBufferList().updateIncludedTeXfiles(FileName::getcwd().absFileName(),
                runparams);
 
-       // Never write the depfile if an error was encountered.
-
        // 0
        // first check if the file dependencies exist:
        //     ->If it does exist
index 978e33f866f581c8d697b8b8d03174e8af089c67..d040b43b474503a88a66f24b7d4c8cb967b405a6 100644 (file)
@@ -151,11 +151,16 @@ public:
 
        /**
           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 &,
              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
        int run(TeXErrors &);