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)
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
// 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";
}
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())
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
- Fix loss of citation list after Undo (bug 9158).
+- Fix document-wide language setting with minted (bug 11203).
+
* INTERNALS