]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetListings.cpp
Fix assertion when checking if change in selection
[lyx.git] / src / insets / InsetListings.cpp
index de70ffeeea234a330003d8bdf66b1eb0329a7272..ec9ad7225f37254683f45ba25fcc7fa4851d2c7a 100644 (file)
@@ -120,7 +120,7 @@ void InsetListings::read(Lexer & lex)
 
 
 Encoding const * InsetListings::forcedEncoding(Encoding const * inner_enc,
-                                                                                          Encoding const * outer_enc) const
+                                              Encoding const * outer_enc) const
 {
        // The listings package cannot deal with multi-byte-encoded
        // glyphs, except if full-unicode aware backends
@@ -169,8 +169,20 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
                param_string = getStringFromVector(opts, ",");
        }
        // Minted needs a language specification
-       if (minted_language.empty())
-               minted_language = "TeX";
+       if (minted_language.empty()) {
+               // If a language has been set globally, use that,
+               // otherwise use TeX by default
+               string const & blp = buffer().params().listings_params;
+               size_t start = blp.find("language=");
+               if (start != string::npos) {
+                       start += strlen("language=");
+                       size_t len = blp.find(",", start);
+                       if (len != string::npos)
+                               len -= start;
+                       minted_language = blp.substr(start, len);
+               } else
+                       minted_language = "TeX";
+       }
 
        // get the paragraphs. We can not output them directly to given odocstream
        // because we can not yet determine the delimiter character of \lstinline
@@ -192,6 +204,9 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
                // the restrictions of the listings package (see above).
                // This needs to be consistent with
                // LaTeXFeatures::getTClassI18nPreamble().
+               // We need to put this into a group in order to prevent encoding leaks
+               // (happens with cprotect).
+               os << "\\bgroup";
                switchEncoding(os.os(), buffer().params(), runparams, *fixedlstenc, true);
                runparams.encoding = fixedlstenc;
                encoding_switched = true;
@@ -337,7 +352,9 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
 
        if (encoding_switched){
                // Switch back
-               switchEncoding(os.os(), buffer().params(), runparams, *save_enc, true);
+               switchEncoding(os.os(), buffer().params(),
+                              runparams, *save_enc, true, true);
+               os << "\\egroup" << breakln;
                runparams.encoding = save_enc;
        }