commit 4862e00c1fb730b4fe332b9d7183fcf605f97ca4
Author: Enrico Forestieri <for...@lyx.org>
Date:   Sun Jul 22 22:22:13 2018 +0200

    Fix bug #11203
    
    Minted does not have a language option but it is possible to enter
    this option in the LyX interface for compatibility with the listings
    package, and also for letting to enter a language not present in the
    gui. So, this option is only used for properly specifying a language
    in a listing, unless it is entered in the document settings dialog.
    This case was not foreseen and thus the option was being passed to
    the package as is, causing havoc. With this commit the option is
    still available but is used to set a default language for a new
    listing in place of the default "tex" language used so far.
    
    (cherry picked from commit 16ca5290c0d619df23406275e6698594b90ce7ab)
---
 src/BufferParams.cpp              |   15 +++++++++++++--
 src/frontends/qt4/GuiListings.cpp |   15 ++++++++++++---
 src/insets/InsetListings.cpp      |   16 ++++++++++++++--
 status.23x                        |    2 ++
 4 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 6d519f2..5f57c6a 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -2269,7 +2269,18 @@ bool BufferParams::writeLaTeX(otexstream & os, 
LaTeXFeatures & features,
                else
                        os << "\\usepackage{listings}\n";
        }
-       if (!listings_params.empty()) {
+       string lst_params = listings_params;
+       // If minted, do not output the language option (bug 11203)
+       if (use_minted && contains(lst_params, "language=")) {
+               vector<string> opts =
+                       getVectorFromString(lst_params, ",", false);
+               for (size_t i = 0; i < opts.size(); ++i) {
+                       if (prefixIs(opts[i], "language="))
+                               opts.erase(opts.begin() + i--);
+               }
+               lst_params = getStringFromVector(opts, ",");
+       }
+       if (!lst_params.empty()) {
                if (use_minted)
                        os << "\\setminted{";
                else
@@ -2277,7 +2288,7 @@ bool BufferParams::writeLaTeX(otexstream & os, 
LaTeXFeatures & features,
                // do not test validity because listings_params is
                // supposed to be valid
                string par =
-                       
InsetListingsParams(listings_params).separatedParams(true);
+                       InsetListingsParams(lst_params).separatedParams(true);
                os << from_utf8(par);
                os << "}\n";
        }
diff --git a/src/frontends/qt4/GuiListings.cpp 
b/src/frontends/qt4/GuiListings.cpp
index 1ab7c7e..d41724f 100644
--- a/src/frontends/qt4/GuiListings.cpp
+++ b/src/frontends/qt4/GuiListings.cpp
@@ -320,9 +320,18 @@ string GuiListings::construct_params()
        InsetListingsParams par;
        par.setMinted(use_minted);
        if (use_minted) {
-               if (language == "no language" && !contains(extra, "language="))
-                       par.addParam("language", "TeX");
-               else
+               if (language == "no language" && !contains(extra, "language=")) 
{
+                       string const & blp = buffer().params().listings_params;
+                       size_t start = blp.find("language=");
+                       if (start != string::npos) {
+                               start += strlen("language=");
+                               size_t len = blp.find(",", start);
+                               if (len != string::npos)
+                                       len -= start;
+                               par.addParam("language", blp.substr(start, 
len));
+                       } else
+                               par.addParam("language", "TeX");
+               } else
                        par.addParam("language", language);
        } else if (language != "no language" && !contains(extra, "language=")) {
                if (dialect.empty())
diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp
index d106da3..d114e7e 100644
--- a/src/insets/InsetListings.cpp
+++ b/src/insets/InsetListings.cpp
@@ -169,8 +169,20 @@ void InsetListings::latex(otexstream & os, OutputParams 
const & runparams) const
                param_string = getStringFromVector(opts, ",");
        }
        // Minted needs a language specification
-       if (minted_language.empty())
-               minted_language = "TeX";
+       if (minted_language.empty()) {
+               // If a language has been set globally, use that,
+               // otherwise use TeX by default
+               string const & blp = buffer().params().listings_params;
+               size_t start = blp.find("language=");
+               if (start != string::npos) {
+                       start += strlen("language=");
+                       size_t len = blp.find(",", start);
+                       if (len != string::npos)
+                               len -= start;
+                       minted_language = blp.substr(start, len);
+               } else
+                       minted_language = "TeX";
+       }
 
        // get the paragraphs. We can not output them directly to given 
odocstream
        // because we can not yet determine the delimiter character of 
\lstinline
diff --git a/status.23x b/status.23x
index 690313a..9474b7e 100644
--- a/status.23x
+++ b/status.23x
@@ -62,6 +62,8 @@ What's new
 
 - Fix loss of citation list after Undo (bug 9158).
 
+- Fix document-wide language setting with minted (bug 11203).
+
 
 * INTERNALS
 

Reply via email to