On Sun, Jun 11, 2017 at 10:19:15PM +0200, Enrico Forestieri wrote: > > Maybe, the only sensible thing to do is checking for a pygmentize command > and, if not found, warn the user but don't disable the widget.
Something like the attached. -- Enrico
diff --git a/lib/configure.py b/lib/configure.py index 1ce081cd07..8e7fedbb5a 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -1203,6 +1203,8 @@ def checkOtherEntries(): 'splitindex.class'], rc_entry = [ r'\splitindex_command "%%"' ]) checkProg('a nomenclature processor', ['makeindex'], rc_entry = [ r'\nomencl_command "makeindex -s nomencl.ist"' ]) + checkProg('a python-pygments driver command', ['pygmentize'], + rc_entry = [ r'\pygmentize_command "%%"' ]) ## FIXME: OCTAVE is not used anywhere # path, OCTAVE = checkProg('Octave', ['octave']) ## FIXME: MAPLE is not used anywhere @@ -1756,7 +1758,7 @@ if __name__ == '__main__': lyx_check_config = True lyx_kpsewhich = True outfile = 'lyxrc.defaults' - lyxrc_fileformat = 21 + lyxrc_fileformat = 22 rc_entries = '' lyx_keep_temps = False version_suffix = '' diff --git a/lib/scripts/prefs2prefs_prefs.py b/lib/scripts/prefs2prefs_prefs.py index b4acdc74d3..68b4d837dc 100644 --- a/lib/scripts/prefs2prefs_prefs.py +++ b/lib/scripts/prefs2prefs_prefs.py @@ -90,6 +90,10 @@ # default now) # No conversion necessary. +# Incremented to format 22, by ef +# Add pygmentize_command for the python pygments syntax highlighter +# No conversion necessary. + # NOTE: The format should also be updated in LYXRC.cpp and # in configure.py. @@ -387,5 +391,6 @@ conversions = [ [ 18, []], [ 19, [remove_print_support]], [ 20, []], - [ 21, []] + [ 21, []], + [ 22, []] ] diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index ae3569096e..e6244f2d2b 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -59,7 +59,7 @@ namespace { // The format should also be updated in configure.py, and conversion code // should be added to prefs2prefs_prefs.py. -static unsigned int const LYXRC_FILEFORMAT = 21; // spitz: jbibtex_alternatives +static unsigned int const LYXRC_FILEFORMAT = 22; // ef: pygmentize_command // when adding something to this array keep it sorted! LexerKeyword lyxrcTags[] = { @@ -158,6 +158,7 @@ LexerKeyword lyxrcTags[] = { { "\\print_landscape_flag", LyXRC::RC_PRINTLANDSCAPEFLAG }, { "\\print_paper_dimension_flag", LyXRC::RC_PRINTPAPERDIMENSIONFLAG }, { "\\print_paper_flag", LyXRC::RC_PRINTPAPERFLAG }, + { "\\pygmentize_command", LyXRC::RC_PYGMENTIZE_COMMAND }, { "\\save_compressed", LyXRC::RC_SAVE_COMPRESSED }, { "\\save_origin", LyXRC::RC_SAVE_ORIGIN }, { "\\screen_dpi", LyXRC::RC_SCREEN_DPI }, @@ -241,6 +242,7 @@ void LyXRC::setDefaults() fontenc = "default"; index_command = "makeindex -c -q"; nomencl_command = "makeindex -s nomencl.ist"; + pygmentize_command = string(); dpi = 75; // Because a screen is typically wider than a piece of paper: zoom = 150; @@ -544,6 +546,12 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format) lexrc >> print_paper_flag; break; + case RC_PYGMENTIZE_COMMAND: + if (lexrc.next(true)) { + pygmentize_command = lexrc.getString(); + } + break; + case RC_VIEWDVI_PAPEROPTION: if (lexrc.next()) view_dvi_paper_option = lexrc.getString(); @@ -1501,6 +1509,13 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c } if (tag != RC_LAST) break; + case RC_PYGMENTIZE_COMMAND: + if (ignore_system_lyxrc || + pygmentize_command != system_lyxrc.pygmentize_command) { + os << "\\pygmentize_command \"" << escapeCommand(pygmentize_command) << "\"\n"; + } + if (tag != RC_LAST) + break; case RC_TEX_EXPECTS_WINDOWS_PATHS: // Don't write this setting to the preferences file, // but allow temporary changes (bug 7557). @@ -2809,6 +2824,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_JBIBTEX_ALTERNATIVES: case LyXRC::RC_JINDEX_COMMAND: case LyXRC::RC_NOMENCL_COMMAND: + case LyXRC::RC_PYGMENTIZE_COMMAND: case LyXRC::RC_INPUT: case LyXRC::RC_KBMAP: case LyXRC::RC_KBMAP_PRIMARY: @@ -3067,6 +3083,10 @@ string const LyXRC::getDescription(LyXRCTags tag) str = _("Define the options of makeindex (cf. man makeindex) to be used for nomenclatures. This might differ from the index processing options."); break; + case RC_PYGMENTIZE_COMMAND: + str = _("The command to run the python pygments syntax highlighter."); + break; + case RC_INPUT: break; diff --git a/src/LyXRC.h b/src/LyXRC.h index c7207048c2..38fcd37394 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -133,6 +133,7 @@ public: RC_PRINTLANDSCAPEFLAG, RC_PRINTPAPERDIMENSIONFLAG, RC_PRINTPAPERFLAG, + RC_PYGMENTIZE_COMMAND, RC_SAVE_COMPRESSED, RC_SAVE_ORIGIN, RC_SCREEN_DPI, @@ -253,6 +254,8 @@ public: std::string splitindex_command; /// command to run makeindex incl. options for nomencl std::string nomencl_command; + /// command to run the python pygments syntax highlighter + std::string pygmentize_command; /// std::string document_path; /// diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index cba3f3e025..4f60b9f9d4 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -135,6 +135,12 @@ char const * backref_opts_gui[] = }; +char const * lst_packages[] = +{ + "Listings", "Minted", "" +}; + + vector<string> engine_types_; vector<pair<string, QString> > pagestyles; @@ -1461,13 +1467,18 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(listingsModule->bypassCB, SIGNAL(clicked()), this, SLOT(setListingsMessage())); - connect(listingsModule->mintedCB, SIGNAL(clicked()), + connect(listingsModule->packageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); + connect(listingsModule->packageCO, SIGNAL(currentIndexChanged(int)), + this, SLOT(listingsPackageChanged(int))); connect(listingsModule->listingsED, SIGNAL(textChanged()), this, SLOT(setListingsMessage())); listingsModule->listingsTB->setPlainText( qt_("Input listings parameters below. Enter ? for a list of parameters.")); + for (int i = 0; lst_packages[i][0]; ++i) + listingsModule->packageCO->addItem(lst_packages[i]); + // add the panels docPS->addPanel(latexModule, N_("Document Class")); @@ -1576,6 +1587,22 @@ void GuiDocument::setListingsMessage() } +void GuiDocument::listingsPackageChanged(int index) +{ + string const package = lst_packages[index]; + if (package == "Minted" && lyxrc.pygmentize_command.empty()) { + 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.")); + } +} + + void GuiDocument::setLSpacing(int item) { textLayoutModule->lspacingLE->setEnabled(item == 3); @@ -3072,7 +3099,8 @@ void GuiDocument::applyView() // Listings // text should have passed validation - bp_.use_minted = listingsModule->mintedCB->isChecked(); + idx = listingsModule->packageCO->currentIndex(); + bp_.use_minted = string(lst_packages[idx]) == "Minted"; bp_.listings_params = InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params(); @@ -3590,7 +3618,9 @@ void GuiDocument::paramsToDialog() string lstparams = InsetListingsParams(bp_.listings_params).separatedParams(); listingsModule->listingsED->setPlainText(toqstr(lstparams)); - listingsModule->mintedCB->setChecked(bp_.use_minted); + int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings"); + if (nn >= 0) + listingsModule->packageCO->setCurrentIndex(nn); // Fonts @@ -3674,7 +3704,7 @@ void GuiDocument::paramsToDialog() fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale()); fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts]; - int nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family); + nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family); if (nn >= 0) fontModule->fontsDefaultCO->setCurrentIndex(nn); diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index b5e09d3ec4..0c39bf8f91 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -92,6 +92,7 @@ private Q_SLOTS: void change_adaptor(); void includeonlyClicked(QTreeWidgetItem * item, int); void setListingsMessage(); + void listingsPackageChanged(int); void saveDefaultClicked(); void useDefaultsClicked(); void setLSpacing(int); diff --git a/src/frontends/qt4/ui/ListingsSettingsUi.ui b/src/frontends/qt4/ui/ListingsSettingsUi.ui index 66f8ca0734..f6147e7f3a 100644 --- a/src/frontends/qt4/ui/ListingsSettingsUi.ui +++ b/src/frontends/qt4/ui/ListingsSettingsUi.ui @@ -73,16 +73,6 @@ </property> </widget> </item> - <item row="3" column="0"> - <widget class="QCheckBox" name="mintedCB"> - <property name="toolTip"> - <string>Use the minted package instead of the listings one</string> - </property> - <property name="text"> - <string>Use &minted</string> - </property> - </widget> - </item> <item row="2" column="0"> <widget class="QCheckBox" name="bypassCB"> <property name="toolTip"> @@ -93,6 +83,28 @@ </property> </widget> </item> + <item row="3" column="0" rowspan="2"> + <widget class="QGroupBox" name="packageGB"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="packageLBL"> + <property name="buddy"> + <cstring>packageCO</cstring> + </property> + <property name="toolTip"> + <string>Choose the LaTeX package for code syntax highlighting</string> + </property> + <property name="text"> + <string>&Syntax Highlighting Package</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="packageCO"/> + </item> + </layout> + </widget> + </item> </layout> </widget> <includes>