commit f711e44bcfc451ea04994d699a7a2a10e18fef96
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Sat Mar 17 16:44:09 2018 +0100

    tex2lyx: complete minted support (inputminted)
    
    Also fix some whitespace issues in minted inset import.
    
    (cherry picked from commit f3c5bcd2be4edc37dec4c78422f31e07b322b298)
---
 src/tex2lyx/test/test-insets-basic.lyx.lyx |   10 +++---
 src/tex2lyx/test/test-insets.lyx.lyx       |   10 +++---
 src/tex2lyx/test/test-minted.lyx.lyx       |   24 ++++++---------
 src/tex2lyx/text.cpp                       |   43 ++++++++++++++++++++++-----
 status.23x                                 |    2 +
 5 files changed, 57 insertions(+), 32 deletions(-)

diff --git a/src/tex2lyx/test/test-insets-basic.lyx.lyx 
b/src/tex2lyx/test/test-insets-basic.lyx.lyx
index 9b2ea80..540c80c 100644
--- a/src/tex2lyx/test/test-insets-basic.lyx.lyx
+++ b/src/tex2lyx/test/test-insets-basic.lyx.lyx
@@ -1111,7 +1111,7 @@ Inline:
 \begin_inset listings
 lstparams "language={C++},keywordstyle={\color{green}}"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 int a=5;
@@ -1131,7 +1131,7 @@ int a=5;
 \begin_inset listings
 lstparams "caption={Example Listing 
float},label={lst:Example-Listing},language=Python"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 # Example listing float
@@ -1215,7 +1215,7 @@ symbol
 \begin_inset listings
 lstparams 
"extendedchars=true,firstline=3,language=Python,lastline=8,numbers=left,showspaces=true,stepnumber=3"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def func(param):
@@ -1263,7 +1263,7 @@ Special cases:
 \begin_inset listings
 lstparams 
"abovecaptionskip=2em,basicstyle={\large\ttfamily},breaklines=true,extendedchars=true,firstline=2,float=h,language={[R/3
 
3.1]ABAP},lastline=5,numbers=left,numberstyle={\scriptsize},showspaces=true,showstringspaces=false,stepnumber=3,tabsize=4"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 hello
@@ -1279,7 +1279,7 @@ hello
 \begin_inset listings
 lstparams "language=TeX"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 
diff --git a/src/tex2lyx/test/test-insets.lyx.lyx 
b/src/tex2lyx/test/test-insets.lyx.lyx
index 8af5bcd..cebb68e 100644
--- a/src/tex2lyx/test/test-insets.lyx.lyx
+++ b/src/tex2lyx/test/test-insets.lyx.lyx
@@ -1170,7 +1170,7 @@ Inline:
 \begin_inset listings
 lstparams "language={C++},keywordstyle={\color{green}}"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 int a=5;
@@ -1190,7 +1190,7 @@ int a=5;
 \begin_inset listings
 lstparams "caption={Example Listing 
float},label={lst:Example-Listing},language=Python"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 # Example listing float
@@ -1274,7 +1274,7 @@ symbol
 \begin_inset listings
 lstparams 
"extendedchars=true,firstline=3,language=Python,lastline=8,numbers=left,showspaces=true,stepnumber=3"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def func(param):
@@ -1322,7 +1322,7 @@ Special cases:
 \begin_inset listings
 lstparams 
"abovecaptionskip=2em,basicstyle={\large\ttfamily},breaklines=true,extendedchars=true,firstline=2,float=h,language={[R/3
 
3.1]ABAP},lastline=5,numbers=left,numberstyle={\scriptsize},showspaces=true,showstringspaces=false,stepnumber=3,tabsize=4"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 hello
@@ -1338,7 +1338,7 @@ hello
 \begin_inset listings
 lstparams "language=TeX"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 
diff --git a/src/tex2lyx/test/test-minted.lyx.lyx 
b/src/tex2lyx/test/test-minted.lyx.lyx
index 0af108d..426902b 100644
--- a/src/tex2lyx/test/test-minted.lyx.lyx
+++ b/src/tex2lyx/test/test-minted.lyx.lyx
@@ -102,7 +102,7 @@ Inline:
 \begin_inset listings
 lstparams "style=bw,language=C++"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 int a=5;
@@ -137,7 +137,7 @@ noprefix "false"
 \begin_inset listings
 lstparams "language=Python,float=h"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 # Example listing float
@@ -216,7 +216,7 @@ symbol
 \begin_inset listings
 lstparams "firstline=4,numbers=left,showspaces=true,language=Python"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def func(param):
@@ -252,7 +252,7 @@ A floating one-liner with [h] placement and without caption:
 \begin_inset listings
 lstparams 
"fontfamily=tt,fontsize={\large},bgcolor=lightgray,language=ABAP,float=h"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 hello
@@ -269,7 +269,7 @@ Another inline listing:
 \begin_inset listings
 lstparams "language=TeX"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 
@@ -298,11 +298,11 @@ noprefix "false"
 
 \end_inset
 
-):  
+): 
 \begin_inset listings
 lstparams "numbers=left,frame=lines,language=C"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 
@@ -372,7 +372,7 @@ noprefix "false"
 \begin_inset listings
 lstparams "numbers=left,frame=lines,language=Fortran"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 subroutine incr(i)
@@ -417,10 +417,6 @@ A Fortran subroutine
 
 \end_inset
 
-
-\end_layout
-
-\begin_layout Standard
 A framed floating listing with a caption and a label (Listing
 \begin_inset space ~
 
@@ -440,7 +436,7 @@ noprefix "false"
 \begin_inset listings
 lstparams "frame=single,language=Python,float=h"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def boring(args = None):
@@ -495,7 +491,7 @@ noprefix "false"
 ): \begin_inset listings
 lstparams "frame=single,language=Python,float=h"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def boring(args = None):
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 1bee520..333bdd6 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -1483,7 +1483,7 @@ void parse_listings(Parser & p, ostream & os, Context & 
parent_context,
                os << "inline true\n";
        else
                os << "inline false\n";
-       os << "status collapsed\n";
+       os << "status open\n";
        Context context(true, parent_context.textclass);
        context.layout = &parent_context.textclass.plainLayout();
        if (use_minted && prefixIs(minted_nonfloat_caption, "[t]")) {
@@ -2001,6 +2001,7 @@ void parse_environment(Parser & p, ostream & os, bool 
outer,
                                                parse_text_snippet(p, FLAG_ITEM,
                                                        false, parent_context);
                                        minted_nonfloat_caption = "[b]" + 
caption;
+                                       eat_whitespace(p, os, parent_context, 
true);
                                }
                        }
                        p.popPosition();
@@ -4431,6 +4432,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
                                // so simply skip it.
                                parse_text_snippet(p, FLAG_ITEM, false, 
context);
                        }
+                       eat_whitespace(p, os, context, true);
                        continue;
                }
 
@@ -4765,22 +4767,48 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
 
                if (t.cs() == "input" || t.cs() == "include"
                    || t.cs() == "verbatiminput"
-                   || t.cs() == "lstinputlisting") {
+                   || t.cs() == "lstinputlisting"
+                   || t.cs() == "inputminted") {
                        string name = t.cs();
                        if (name == "verbatiminput"
                            && p.next_token().asInput() == "*")
                                name += p.get_token().asInput();
                        context.check_layout(os);
                        string lstparams;
-                       bool literal = false;
                        if (name == "lstinputlisting" && p.hasOpt()) {
                                lstparams = p.getArg('[', ']');
-                               pair<bool, string> oa = 
convert_latexed_command_inset_arg(lstparams);
-                               literal = !oa.first;
-                               if (literal)
+                               lstparams = subst(lstparams, "\n", " ");
+                       } else if (name == "inputminted") {
+                               name = "lstinputlisting";
+                               string const lang = p.getArg('{', '}');
+                               if (lang != "tex") {
+                                       string cmd = "\\inputminted{" + lang + 
"}{";
+                                       cmd += p.getArg('{', '}') + "}";
+                                       output_ert_inset(os, cmd, context);
+                                       continue;
+                               }
+                               if (prefixIs(minted_nonfloat_caption, "[t]")) {
+                                       minted_nonfloat_caption.erase(0,3);
+                                       // extract label and caption from the 
already produced LyX code
+                                       vector<string> nfc = 
getVectorFromString(minted_nonfloat_caption, "\n");
+                                       string const caption = nfc.front();
+                                       string label;
+                                       vector<string>::iterator it =
+                                               find(nfc.begin(), nfc.end(), 
"LatexCommand label");
+                                       if (it != nfc.end()) {
+                                               ++it;
+                                               if (it != nfc.end())
+                                                       label = *it;
+                                               label = support::split(label, 
'"');
+                                               label.pop_back();
+                                       }
+                                       minted_nonfloat_caption.clear();
+                                       lstparams = "caption=" + caption;
+                                       if (!label.empty())
+                                               lstparams += ",label=" + label;
                                        lstparams = subst(lstparams, "\n", " ");
+                               }
                        }
-                       string lit = literal ? "\"true\"" : "\"false\"";
                        string filename(normalize_filename(p.getArg('{', '}')));
                        string const path = getMasterFilePath(true);
                        // We want to preserve relative / absolute filenames,
@@ -4890,7 +4918,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
                                      "filename \"" << outname << "\"\n";
                                if (!lstparams.empty())
                                        os << "lstparams \"" << lstparams << 
"\"\n";
-                               os << "literal " << lit << "\n";
                                if (t.cs() == "verbatiminput")
                                        
preamble.registerAutomaticallyLoadedPackage("verbatim");
                        }
diff --git a/status.23x b/status.23x
index b0fa2fd..59ef0bf 100644
--- a/status.23x
+++ b/status.23x
@@ -39,6 +39,8 @@ What's new
 
 - Add support for URW Classico, MinionPro and the new Libertine fonts.
 
+- Add support for \lstinputlisting and \inputminted.
+
 - Add support for the \t*{} (bottomtiebar) macro of TIPA.
 
 - Implement better parsing of some command options (via "literate"

Reply via email to