Properly warn on missing pygmentize command

- Do not warn when the document properties pane is opened but only
  when minted is selected and the pygmentize command was not found.
- Warn before launching latex if minted is selected and the document
  actually uses listings insets.
This commit is contained in:
Enrico Forestieri 2017-07-31 11:32:28 +02:00
parent accb4846a8
commit 44babaf656
2 changed files with 39 additions and 1 deletions

View File

@ -19,14 +19,18 @@
#include "Encoding.h"
#include "ErrorList.h"
#include "Format.h"
#include "InsetList.h"
#include "Language.h"
#include "LaTeX.h"
#include "LyXRC.h"
#include "Mover.h"
#include "ParagraphList.h"
#include "Session.h"
#include "frontends/alert.h"
#include "insets/InsetInclude.h"
#include "support/debug.h"
#include "support/FileNameList.h"
#include "support/filetools.h"
@ -459,6 +463,40 @@ bool Converters::convert(Buffer const * buffer,
"tmpfile.out"));
}
if (buffer && buffer->params().use_minted
&& lyxrc.pygmentize_command.empty() && conv.latex()) {
bool dowarn = false;
// Warn only if listings insets are actually used
for (Paragraph const & par : buffer->paragraphs()) {
InsetList const & insets = par.insetList();
pos_type lstpos = insets.find(LISTINGS_CODE, 0);
pos_type incpos = insets.find(INCLUDE_CODE, 0);
if (incpos >= 0) {
InsetInclude const * include =
static_cast<InsetInclude *>
(insets.get(incpos));
if (include->params().getCmdName() !=
"inputminted") {
incpos = -1;
}
}
if (lstpos >= 0 || incpos >= 0) {
dowarn = true;
break;
}
}
if (dowarn) {
Alert::warning(_("Pygments driver command not found!"),
_("The driver command necessary to use the minted package\n"
"(pygmentize) has not been found. Make sure you have\n"
"the python-pygments module installed or, if the driver\n"
"is named differently, to add the following line to the\n"
"document preamble:\n\n"
"\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
"where 'driver' is name of the driver command."));
}
}
if (!checkAuth(conv, buffer ? buffer->absFileName() : string()))
return false;

View File

@ -1469,7 +1469,7 @@ GuiDocument::GuiDocument(GuiView & lv)
this, SLOT(setListingsMessage()));
connect(listingsModule->packageCO, SIGNAL(activated(int)),
this, SLOT(change_adaptor()));
connect(listingsModule->packageCO, SIGNAL(currentIndexChanged(int)),
connect(listingsModule->packageCO, SIGNAL(activated(int)),
this, SLOT(listingsPackageChanged(int)));
connect(listingsModule->listingsED, SIGNAL(textChanged()),
this, SLOT(setListingsMessage()));