#include "GuiInclude.h"
#include "Buffer.h"
+#include "BufferParams.h"
#include "FuncRequest.h"
#include "LyXRC.h"
if (typeCO->currentIndex() != 3 || bypassCB->isChecked())
return docstring();
string params = fromqstr(listingsED->toPlainText());
- return InsetListingsParams(params).validate();
+ InsetListingsParams lstparams(params);
+ lstparams.setMinted(buffer().params().use_minted);
+ return lstparams.validate();
}
if (cmdname != "include" &&
cmdname != "verbatiminput" &&
cmdname != "verbatiminput*" &&
- cmdname != "lstinputlisting")
+ cmdname != "lstinputlisting" &&
+ cmdname != "inputminted")
cmdname = "input";
if (cmdname == "include") {
typeCO->setCurrentIndex(2);
visiblespaceCB->setEnabled(true);
- } else if (cmdname == "lstinputlisting") {
+ } else if (cmdname == "lstinputlisting" || cmdname == "inputminted") {
typeCO->setCurrentIndex(3);
listingsGB->setEnabled(true);
listingsED->setEnabled(true);
} else if (item == 1) {
params_.setCmdName("input");
} else if (item == 3) {
- params_.setCmdName("lstinputlisting");
+ if (buffer().params().use_minted)
+ params_.setCmdName("inputminted");
+ else
+ params_.setCmdName("lstinputlisting");
// the parameter string should have passed validation
InsetListingsParams par(fromqstr(listingsED->toPlainText()));
string caption = fromqstr(captionLE->text());
return VERB;
if (s == "verbatiminput*")
return VERBAST;
- if (s == "lstinputlisting")
+ if (s == "lstinputlisting" || s == "inputminted")
return LISTINGS;
if (s == "include")
return INCLUDE;
break;
}
case LISTINGS: {
+ // Here, listings and minted have sligthly different behaviors.
+ // Using listings, it is always possible to have a caption,
+ // even for non-floats. Using minted, only floats can have a
+ // caption. So, with minted we use the following strategy.
+ // If a caption or the float parameter are specified, we
+ // assume that the listing is floating. In this case, the
+ // label parameter is taken as the label by which the float
+ // can be referenced, otherwise it will have the meaning
+ // intended by minted. In this last case, the label will
+ // serve as a sort of caption that, however, will be shown
+ // by minted only if the frame parameter is also specified.
+ bool const use_minted = buffer().params().use_minted;
runparams.exportdata->addExternalFile(tex_format, writefile,
exportfile);
- os << '\\' << from_ascii(params().getCmdName());
string const opt = to_utf8(params()["lstparams"]);
// opt is set in QInclude dialog and should have passed validation.
- InsetListingsParams params(opt);
- if (!params.params().empty())
- os << "[" << from_utf8(params.params()) << "]";
- os << '{' << from_utf8(incfile) << '}';
+ InsetListingsParams lstparams(opt);
+ string parameters = lstparams.params();
+ string language;
+ string caption;
+ string label;
+ string placement;
+ bool isfloat = false;
+ if (use_minted) {
+ // Get float placement, language, caption, and
+ // label, then remove the relative options.
+ vector<string> opts =
+ getVectorFromString(parameters, ",", false);
+ for (size_t i = 0; i < opts.size(); ++i) {
+ if (prefixIs(opts[i], "float")) {
+ isfloat = true;
+ if (prefixIs(opts[i], "float="))
+ placement = opts[i].substr(6);
+ opts.erase(opts.begin() + i--);
+ } else if (prefixIs(opts[i], "language=")) {
+ language = opts[i].substr(9);
+ opts.erase(opts.begin() + i--);
+ } else if (prefixIs(opts[i], "caption=")) {
+ isfloat = true;
+ caption = opts[i].substr(8);
+ opts.erase(opts.begin() + i--);
+ } else if (prefixIs(opts[i], "label=")) {
+ label = opts[i].substr(6);
+ opts.erase(opts.begin() + i--);
+ }
+ }
+ if (!label.empty()) {
+ if (isfloat)
+ label = trim(label, "{}");
+ else
+ opts.push_back("label=" + label);
+ }
+ parameters = getStringFromVector(opts, ",");
+ }
+ if (language.empty())
+ language = "TeX";
+ if (use_minted && isfloat) {
+ os << breakln << "\\begin{listing}";
+ if (!placement.empty())
+ os << '[' << placement << "]";
+ os << breakln;
+ }
+ os << (use_minted ? "\\inputminted" : "\\lstinputlisting");
+ if (!parameters.empty())
+ os << "[" << parameters << "]";
+ if (use_minted)
+ os << '{' << language << '}';
+ os << '{' << incfile << '}';
+ if (use_minted && isfloat) {
+ if (!caption.empty())
+ os << breakln << "\\caption{" << caption << "}";
+ if (!label.empty())
+ os << breakln << "\\label{" << label << "}";
+ os << breakln << "\\end{listing}\n";
+ }
break;
}
case INCLUDE: {
all_params_[1]["autogobble"] =
ListingsParam("", true, TRUEFALSE, "", empty_hint);
all_params_[1]["baselinestretch"] =
- ListingsParam("", false, LENGTH, "", empty_hint);
+ ListingsParam("", false, ALL, "", empty_hint);
all_params_[1]["breakafter"] =
ListingsParam("", false, ALL, "", empty_hint);
all_params_[1]["breakaftergroup"] =
all_params_[1]["labelposition"] =
ListingsParam("", false, ONEOF,
"none\ntopline\nbottomline\nall", empty_hint);
- all_params_[1]["language"] =
- ListingsParam("", false, ONEOF,
- allowed_languages, empty_hint);
all_params_[1]["language"] =
ListingsParam("", false, ALL, "", _(
- "This parameter should not be entered here. Please "
- "use the language combo box in the listings inset "
- "settings dialog, unless you need to enter a language "
- "not offered there."));
+ "Enter one of the supported languages. However, if you "
+ "are defining a listing inset, it is better using the "
+ "language combo box, unless you need to enter a language not "
+ "offered there, otherwise the combo box will be disabled."));
all_params_[1]["lastline"] =
ListingsParam("", false, INTEGER, "", empty_hint);
all_params_[1]["linenos"] =