commit 15e1f5eb39951351cc50beec9e1db21b74535e13
Author: Enrico Forestieri <for...@lyx.org>
Date:   Fri May 16 14:21:48 2014 +0200

    Make use of otexstream also in external::writeExternal
    
    This was not necessary when LyX was generously outputting newlines.
    As it may happen that the output produced by writeExternal (the
    result of an external inset) starts right at the beginning of a
    line, if otexstream does not know that something is already on
    the line, the iomanip-like variable 'breakln' fails to actually
    break the line.

diff --git a/src/insets/ExternalSupport.cpp b/src/insets/ExternalSupport.cpp
index aa6f51c..6d009a5 100644
--- a/src/insets/ExternalSupport.cpp
+++ b/src/insets/ExternalSupport.cpp
@@ -333,23 +333,23 @@ string const substituteOptions(InsetExternalParams const 
& params,
 } // namespace anon
 
 
-int writeExternal(InsetExternalParams const & params,
-                 string const & format,
-                 Buffer const & buffer, odocstream & os,
-                 ExportData & exportdata,
-                 bool external_in_tmpdir,
-                 bool dryrun)
+void writeExternal(InsetExternalParams const & params,
+                  string const & format,
+                  Buffer const & buffer, otexstream & os,
+                  ExportData & exportdata,
+                  bool external_in_tmpdir,
+                  bool dryrun)
 {
        Template const * const et_ptr = getTemplatePtr(params);
        if (!et_ptr)
-               return 0;
+               return;
        Template const & et = *et_ptr;
 
        Template::Formats::const_iterator cit = et.formats.find(format);
        if (cit == et.formats.end()) {
                LYXERR(Debug::EXTERNAL, "External template format '" << format
                        << "' not specified in template " << 
params.templatename());
-               return 0;
+               return;
        }
 
        if (!dryrun || contains(cit->second.product, "$$Contents"))
@@ -383,7 +383,7 @@ int writeExternal(InsetExternalParams const & params,
        str = substituteOptions(params, str, format);
        // FIXME UNICODE
        os << from_utf8(str);
-       return int(count(str.begin(), str.end(),'\n'));
+       return;
 }
 
 namespace {
diff --git a/src/insets/ExternalSupport.h b/src/insets/ExternalSupport.h
index 9c282e8..79b4e1b 100644
--- a/src/insets/ExternalSupport.h
+++ b/src/insets/ExternalSupport.h
@@ -60,13 +60,13 @@ std::string const doSubstitution(InsetExternalParams const 
& params,
     If \p external_in_tmpdir == true, then the generated file is
     place in the buffer's temporary directory.
 */
-int writeExternal(InsetExternalParams const &,
-                 std::string const & format,
-                 Buffer const &,
-                 odocstream &,
-                 ExportData &,
-                 bool external_in_tmpdir,
-                 bool dryrun);
+void writeExternal(InsetExternalParams const &,
+                  std::string const & format,
+                  Buffer const &,
+                  otexstream &,
+                  ExportData &,
+                  bool external_in_tmpdir,
+                  bool dryrun);
 
 } // namespace external
 } // namespace lyx
diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp
index 9d4d6c1..278168a 100644
--- a/src/insets/InsetExternal.cpp
+++ b/src/insets/InsetExternal.cpp
@@ -673,21 +673,19 @@ void InsetExternal::latex(otexstream & os, OutputParams 
const & runparams) const
                        et.formats.find("PDFLaTeX");
 
                if (cit != et.formats.end()) {
-                       int l = external::writeExternal(params_, "PDFLaTeX",
-                                                       buffer(), os.os(),
-                                                       *(runparams.exportdata),
-                                                       external_in_tmpdir,
-                                                       dryrun);
-                       os.texrow().newlines(l);
+                       external::writeExternal(params_, "PDFLaTeX",
+                                               buffer(), os,
+                                               *(runparams.exportdata),
+                                               external_in_tmpdir,
+                                               dryrun);
                        return;
                }
        }
 
-       int l = external::writeExternal(params_, "LaTeX", buffer(), os.os(),
-                                       *(runparams.exportdata),
-                                       external_in_tmpdir,
-                                       dryrun);
-       os.texrow().newlines(l);
+       external::writeExternal(params_, "LaTeX", buffer(), os,
+                               *(runparams.exportdata),
+                               external_in_tmpdir,
+                               dryrun);
 }
 
 
@@ -698,8 +696,10 @@ int InsetExternal::plaintext(odocstringstream & os,
        if (runparams.for_tooltip)
                return 0;
 
-       os << '\n'; // output external material on a new line
-       external::writeExternal(params_, "Ascii", buffer(), os,
+       TexRow texrow;
+       otexstream ots(os, texrow);
+       ots << '\n'; // output external material on a new line
+       external::writeExternal(params_, "Ascii", buffer(), ots,
                                *(runparams.exportdata), false,
                                runparams.dryrun || runparams.inComment);
        return PLAINTEXT_NEWLINE;
@@ -709,9 +709,14 @@ int InsetExternal::plaintext(odocstringstream & os,
 int InsetExternal::docbook(odocstream & os,
                           OutputParams const & runparams) const
 {
-       return external::writeExternal(params_, "DocBook", buffer(), os,
-                                      *(runparams.exportdata), false,
-                                      runparams.dryrun || runparams.inComment);
+       TexRow texrow;
+       odocstringstream ods;
+       otexstream ots(ods, texrow);
+       external::writeExternal(params_, "DocBook", buffer(), ots,
+                               *(runparams.exportdata), false,
+                               runparams.dryrun || runparams.inComment);
+       os << ods.str();
+       return int(count(ods.str().begin(), ods.str().end(), '\n'));
 }
 
 

Reply via email to