[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-cvs
Subject:    [LyX/master] Properly warn on missing pygmentize command
From:       Enrico Forestieri <forenr () lyx ! org>
Date:       2017-07-31 9:39:27
Message-ID: 20170731093927.598F3280736 () lyx ! lyx ! org
[Download RAW message or body]

commit 44babaf6569898deaa9ba02b1f3170e7144e6791
Author: Enrico Forestieri <forenr@lyx.org>
Date:   Mon Jul 31 11:32:28 2017 +0200

    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.
---
 src/Converter.cpp                 |   38 +++++++++++++++++++++++++++++++++++++
 src/frontends/qt4/GuiDocument.cpp |    2 +-
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/src/Converter.cpp b/src/Converter.cpp
index 489f5df..66a71c2 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -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;
 
diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp
index e8d66ec..c21ce4f 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -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()));

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic