]> git.lyx.org Git - lyx.git/commitdiff
Fix bug #11203
authorEnrico Forestieri <forenr@lyx.org>
Sun, 22 Jul 2018 20:22:13 +0000 (22:22 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 9 Sep 2018 09:25:01 +0000 (11:25 +0200)
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
src/frontends/qt4/GuiListings.cpp
src/insets/InsetListings.cpp
status.23x

index 6d519f27f8c41674c21b91f0c7cec03b53d89393..5f57c6aa332472ac6c505a78aa79629d0019c29f 100644 (file)
@@ -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";
        }
index 1ab7c7e383b6b1a57d119dad3ca75c60952b6bfe..d41724f15bfa5a126aad3c097664efdcbea4f7bd 100644 (file)
@@ -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())
index d106da39092d5ab721fd2f475bf0b9817cfd9757..d114e7e5c98e197812ef7fda31c86720905737a5 100644 (file)
@@ -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
index 690313ae5df3694bd78810cf4576b0ddb63cbe9c..9474b7e7ffe82f62d2140dd079422183cb3e43bc 100644 (file)
@@ -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