]> git.lyx.org Git - lyx.git/blob - src/insets/InsetListings.cpp
New attempt on #9906: allow following hyperlinks via context menu.
[lyx.git] / src / insets / InsetListings.cpp
1 /**
2  * \file InsetListings.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Bo Peng
7  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetListings.h"
15
16 #include "Buffer.h"
17 #include "BufferView.h"
18 #include "BufferParams.h"
19 #include "Counters.h"
20 #include "Cursor.h"
21 #include "DispatchResult.h"
22 #include "Encoding.h"
23 #include "FuncRequest.h"
24 #include "FuncStatus.h"
25 #include "InsetCaption.h"
26 #include "Language.h"
27 #include "LaTeXFeatures.h"
28 #include "Lexer.h"
29 #include "output_latex.h"
30 #include "output_docbook.h"
31 #include "output_xhtml.h"
32 #include "OutputParams.h"
33 #include "TextClass.h"
34 #include "TexRow.h"
35 #include "texstream.h"
36
37 #include "support/debug.h"
38 #include "support/docstream.h"
39 #include "support/gettext.h"
40 #include "support/lstrings.h"
41 #include "support/lassert.h"
42
43 #include "frontends/alert.h"
44 #include "frontends/Application.h"
45
46 #include "support/regex.h"
47
48 #include <sstream>
49
50 using namespace std;
51 using namespace lyx::support;
52
53 namespace lyx {
54
55
56 InsetListings::InsetListings(Buffer * buf, InsetListingsParams const & par)
57         : InsetCaptionable(buf,"listing")
58 {
59         params_.setMinted(buffer().params().use_minted);
60         status_ = par.status();
61 }
62
63
64 InsetListings::~InsetListings()
65 {
66         hideDialogs("listings", this);
67 }
68
69
70 Inset::RowFlags InsetListings::rowFlags() const
71 {
72         return params().isInline() || params().isFloat() ? Inline : Display | AlignLeft;
73 }
74
75
76 docstring InsetListings::layoutName() const
77 {
78         if (buffer().params().use_minted)
79                 return from_ascii("MintedListings");
80         else
81                 return from_ascii("Listings");
82 }
83
84
85 void InsetListings::write(ostream & os) const
86 {
87         os << "listings" << "\n";
88         InsetListingsParams const & par = params();
89         // parameter string is encoded to be a valid lyx token.
90         string opt = par.encodedString();
91         if (!opt.empty())
92                 os << "lstparams \"" << opt << "\"\n";
93         if (par.isInline())
94                 os << "inline true\n";
95         else
96                 os << "inline false\n";
97         InsetCaptionable::write(os);
98 }
99
100
101 void InsetListings::read(Lexer & lex)
102 {
103         while (lex.isOK()) {
104                 lex.next();
105                 string token = lex.getString();
106                 if (token == "lstparams") {
107                         lex.next();
108                         string const value = lex.getString();
109                         params().fromEncodedString(value);
110                 } else if (token == "inline") {
111                         lex.next();
112                         params().setInline(lex.getBool());
113                 } else {
114                         // no special option, push back 'status' etc
115                         lex.pushToken(token);
116                         break;
117                 }
118         }
119         InsetCaptionable::read(lex);
120 }
121
122
123 Encoding const * InsetListings::forcedEncoding(Encoding const * inner_enc,
124                                                Encoding const * outer_enc) const
125 {
126         // The listings package cannot deal with multi-byte-encoded
127         // glyphs, except for Xe/LuaTeX (with non-TeX fonts) or pLaTeX.
128         // Minted can deal with all encodings.
129         if (buffer().params().use_minted
130                 || inner_enc->name() == "utf8-plain"
131                 || inner_enc->package() == Encoding::japanese
132                 || inner_enc->hasFixedWidth())
133                 return 0;
134
135         // We try if there's a singlebyte encoding for the outer
136         // language; if not, fall back to latin1.
137         // Power-users can set inputenc to utf8-plain to bypass this workaround
138         // and provide alternatives in the user-preamble.
139         return (outer_enc->hasFixedWidth()) ?
140                         outer_enc : encodings.fromLyXName("iso8859-1");
141 }
142
143
144 void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
145 {
146         string param_string = params().params();
147         // NOTE: I use {} to quote text, which is an experimental feature
148         // of the listings package (see page 25 of the manual)
149         bool const isInline = params().isInline();
150         bool const use_minted = buffer().params().use_minted;
151         static regex const reg1("(.*)(basicstyle=\\{)([^\\}]*)(\\\\ttfamily)([^\\}]*)(\\})(.*)");
152         static regex const reg2("(.*)(basicstyle=\\{)([^\\}]*)(\\\\rmfamily)([^\\}]*)(\\})(.*)");
153         static regex const reg3("(.*)(basicstyle=\\{)([^\\}]*)(\\\\sffamily)([^\\}]*)(\\})(.*)");
154         static regex const reg4("(.*)(basicstyle=\\{)([^\\}]*)(\\\\(tiny|scriptsize|footnotesize|small|normalsize|large|Large))([^\\}]*)(\\})(.*)");
155         static regex const reg5("(.*)(fontfamily=)(tt|sf|rm)(.*)");
156         static regex const reg6("(.*)(fontsize=\\{)(\\\\(tiny|scriptsize|footnotesize|small|normalsize|large|Large))(\\})(.*)");
157         if (use_minted) {
158                 // If params have been entered with "listings", and then the user switched to "minted",
159                 // we have params that need to be translated.
160                 // FIXME: We should use a backend-abstract syntax in listings params instead!
161                 // Substitute fontstyle option
162                 smatch sub;
163                 if (regex_match(param_string, sub, reg1))
164                         param_string = sub.str(1) + "fontfamily=tt," + sub.str(2) + sub.str(3)
165                                         + sub.str(5) + sub.str(6) + sub.str(7);
166                 if (regex_match(param_string, sub, reg2))
167                         param_string = sub.str(1) + "fontfamily=rm," + sub.str(2) + sub.str(3)
168                                         + sub.str(5) + sub.str(6) + sub.str(7);
169                 if (regex_match(param_string, sub, reg3))
170                         param_string = sub.str(1) + "fontfamily=sf," + sub.str(2) + sub.str(3)
171                                         + sub.str(5) + sub.str(6) + sub.str(7);
172                 // as well as fontsize option
173                 if (regex_match(param_string, sub, reg4))
174                         param_string = sub.str(1) + "fontsize={" + sub.str(4) + sub.str(3) + sub.str(7) + sub.str(8);
175         } else {
176                 // And the same vice versa
177                 // Substitute fontstyle option
178                 smatch sub;
179                 string basicstyle;
180                 if (regex_match(param_string, sub, reg5)) {
181                         basicstyle = "\\" + sub.str(3) + "family";
182                         param_string = sub.str(1) + sub.str(4);
183                 }
184                 // as well as fontsize option
185                 if (regex_match(param_string, sub, reg6)) {
186                         basicstyle += sub.str(3);
187                         param_string = sub.str(1) + sub.str(6);
188                 }
189                 if (!basicstyle.empty())
190                         param_string = rtrim(param_string, ",") + ",basicstyle={" + basicstyle + "}";
191         }
192         if (runparams.use_polyglossia && runparams.local_font->isRightToLeft()) {
193                 // We need to use the *latin switches (#11554)
194                 smatch sub;
195                 if (regex_match(param_string, sub, reg1))
196                         param_string = sub.str(1) + sub.str(2) + sub.str(3) + sub.str(4)
197                                         + "latin"  + sub.str(5) + sub.str(6) + sub.str(7);
198                 if (regex_match(param_string, sub, reg2))
199                         param_string = sub.str(1) + sub.str(2) + sub.str(3) + sub.str(4)
200                                         + "latin"  + sub.str(5) + sub.str(6) + sub.str(7);
201                 if (regex_match(param_string, sub, reg3))
202                         param_string = sub.str(1) + sub.str(2) + sub.str(3) + sub.str(4)
203                                         + "latin"  + sub.str(5) + sub.str(6) + sub.str(7);
204         }
205         string minted_language;
206         string float_placement;
207         bool const isfloat = params().isFloat();
208         if (use_minted && (isfloat || contains(param_string, "language="))) {
209                 // Get float placement and/or language of the code,
210                 // then remove the relative options.
211                 vector<string> opts =
212                         getVectorFromString(param_string, ",", false);
213                 for (size_t i = 0; i < opts.size(); ++i) {
214                         if (prefixIs(opts[i], "float")) {
215                                 if (prefixIs(opts[i], "float="))
216                                         float_placement = opts[i].substr(6);
217                                 opts.erase(opts.begin() + int(i--));
218                         }
219                         else if (prefixIs(opts[i], "language=")) {
220                                 minted_language = opts[i].substr(9);
221                                 opts.erase(opts.begin() + int(i--));
222                         }
223                 }
224                 param_string = getStringFromVector(opts, ",");
225         }
226         // Minted needs a language specification
227         if (minted_language.empty()) {
228                 // If a language has been set globally, use that,
229                 // otherwise use TeX by default
230                 string const & blp = buffer().params().listings_params;
231                 size_t start = blp.find("language=");
232                 if (start != string::npos) {
233                         start += strlen("language=");
234                         size_t len = blp.find(",", start);
235                         if (len != string::npos)
236                                 len -= start;
237                         minted_language = blp.substr(start, len);
238                 } else
239                         minted_language = "TeX";
240         }
241
242         // get the paragraphs. We can not output them directly to given odocstream
243         // because we can not yet determine the delimiter character of \lstinline
244         docstring code;
245         docstring uncodable;
246         ParagraphList::const_iterator par = paragraphs().begin();
247         ParagraphList::const_iterator end = paragraphs().end();
248
249         bool encoding_switched = false;
250         Encoding const * const save_enc = runparams.encoding;
251
252         Encoding const * const outer_encoding =
253                 (runparams.local_font != 0) ?
254                         runparams.local_font->language()->encoding()
255                         : buffer().params().language->encoding();
256         Encoding const * fixedlstenc = forcedEncoding(runparams.encoding, outer_encoding);
257         if (fixedlstenc) {
258                 // We need to switch to a singlebyte encoding, due to
259                 // the restrictions of the listings package (see above).
260                 // This needs to be consistent with
261                 // LaTeXFeatures::getTClassI18nPreamble().
262                 // We need to put this into a group in order to prevent encoding leaks
263                 // (happens with cprotect).
264                 os << "\\bgroup";
265                 switchEncoding(os.os(), buffer().params(), runparams, *fixedlstenc, true);
266                 runparams.encoding = fixedlstenc;
267                 encoding_switched = true;
268         }
269
270         bool const captionfirst = !isfloat && par->isInset(0)
271                                 && par->getInset(0)->lyxCode() == CAPTION_CODE;
272
273         while (par != end) {
274                 pos_type const siz = par->size();
275                 bool captionline = false;
276                 for (pos_type i = 0; i < siz; ++i) {
277                         if (i == 0 && par->isInset(i) && i + 1 == siz)
278                                 captionline = true;
279                         // ignore all struck out text and (caption) insets
280                         if (par->isDeleted(i)
281                             || (par->isInset(i) && par->getInset(i)->lyxCode() == CAPTION_CODE))
282                                 continue;
283                         if (par->isInset(i)) {
284                                 // Currently, this can only be a quote inset
285                                 // that is output as plain quote here, but
286                                 // we use more generic code anyway.
287                                 otexstringstream ots;
288                                 OutputParams rp = runparams;
289                                 rp.pass_thru = true;
290                                 par->getInset(i)->latex(ots, rp);
291                                 code += ots.str();
292                                 continue;
293                         }
294                         char_type c = par->getChar(i);
295                         // we can only output characters covered by the current
296                         // encoding!
297                         try {
298                                 if (runparams.encoding->encodable(c))
299                                         code += c;
300                                 else if (runparams.dryrun) {
301                                         code += "<" + _("LyX Warning: ")
302                                            + _("uncodable character") + " '";
303                                         code += docstring(1, c);
304                                         code += "'>";
305                                 } else
306                                         uncodable += c;
307                         } catch (EncodingException & /* e */) {
308                                 if (runparams.dryrun) {
309                                         code += "<" + _("LyX Warning: ")
310                                            + _("uncodable character") + " '";
311                                         code += docstring(1, c);
312                                         code += "'>";
313                                 } else
314                                         uncodable += c;
315                         }
316                 }
317                 ++par;
318                 // for the inline case, if there are multiple paragraphs
319                 // they are simply joined. Otherwise, expect latex errors.
320                 if (par != end && !isInline && !captionline)
321                         code += "\n";
322         }
323         if (isInline) {
324                 static const docstring delimiters =
325                                 from_utf8("!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm");
326
327                 size_t pos = delimiters.find_first_not_of(code);
328
329                 // This code piece contains all possible special character? !!!
330                 // Replace ! with a warning message and use ! as delimiter.
331                 if (pos == string::npos) {
332                         docstring delim_error = "<" + _("LyX Warning: ")
333                                 + _("no more lstline delimiters available") + ">";
334                         code = subst(code, from_ascii("!"), delim_error);
335                         pos = 0;
336                         if (!runparams.dryrun && !runparams.silent) {
337                                 // FIXME: warning should be passed to the error dialog
338                                 frontend::Alert::warning(_("Running out of delimiters"),
339                                 _("For inline program listings, one character must be reserved\n"
340                                   "as a delimiter. One of the listings, however, uses all available\n"
341                                   "characters, so none is left for delimiting purposes.\n"
342                                   "For the time being, I have replaced '!' by a warning, but you\n"
343                                   "must investigate!"));
344                         }
345                 }
346                 docstring const delim(1, delimiters[pos]);
347                 if (use_minted) {
348                         os << "\\mintinline";
349                         if (!param_string.empty())
350                                 os << "[" << from_utf8(param_string) << "]";
351                         os << "{" << ascii_lowercase(minted_language) << "}";
352                 } else {
353                         os << "\\lstinline";
354                         if (!param_string.empty())
355                                 os << "[" << from_utf8(param_string) << "]";
356                         else if (pos >= delimiters.find('Q'))
357                                 // We need to terminate the command before
358                                 // the delimiter
359                                 os << " ";
360                 }
361                 os << delim << code << delim;
362         } else if (use_minted) {
363                 OutputParams rp = runparams;
364                 rp.moving_arg = true;
365                 TexString caption = getCaption(rp);
366                 if (isfloat) {
367                         os << breakln << "\\begin{listing}";
368                         if (!float_placement.empty())
369                                 os << '[' << float_placement << "]";
370                 } else if (captionfirst && !caption.str.empty()) {
371                         os << breakln << "\\lyxmintcaption[t]{"
372                            << move(caption) << "}\n";
373                 }
374                 os << breakln << "\\begin{minted}";
375                 if (!param_string.empty())
376                         os << "[" << param_string << "]";
377                 os << "{" << ascii_lowercase(minted_language) << "}\n"
378                    << code << breakln << "\\end{minted}\n";
379                 if (isfloat) {
380                         if (!caption.str.empty())
381                                 os << "\\caption{" << move(caption) << "}\n";
382                         os << "\\end{listing}\n";
383                 } else if (!captionfirst && !caption.str.empty()) {
384                         os << breakln << "\\lyxmintcaption[b]{"
385                            << move(caption) << "}";
386                 }
387         } else {
388                 OutputParams rp = runparams;
389                 rp.moving_arg = true;
390                 TexString caption = getCaption(rp);
391                 os << breakln << "\\begin{lstlisting}";
392                 if (param_string.empty() && caption.str.empty())
393                         os << "\n";
394                 else {
395                         if (!runparams.nice)
396                                 os << safebreakln;
397                         os << "[";
398                         if (!caption.str.empty()) {
399                                 os << "caption={" << move(caption) << '}';
400                                 if (!param_string.empty())
401                                         os << ',';
402                         }
403                         os << from_utf8(param_string) << "]\n";
404                 }
405                 os << code << breakln << "\\end{lstlisting}\n";
406         }
407
408         if (encoding_switched){
409                 // Switch back
410                 switchEncoding(os.os(), buffer().params(),
411                                runparams, *save_enc, true, true);
412                 os << "\\egroup" << breakln;
413                 runparams.encoding = save_enc;
414         }
415
416         if (!uncodable.empty() && !runparams.silent) {
417                 // issue a warning about omitted characters
418                 // FIXME: should be passed to the error dialog
419                 if (fixedlstenc)
420                         frontend::Alert::warning(_("Uncodable characters in listings inset"),
421                                 bformat(_("The following characters in one of the program listings are\n"
422                                           "not representable in the current encoding and have been omitted:\n%1$s.\n"
423                                           "This is due to a restriction of the listings package, which does\n"
424                                           "not support your encoding '%2$s'.\n"
425                                           "Toggling 'Use non-TeX fonts' in Document > Settings...\n"
426                                           "might help."),
427                                 uncodable, _(runparams.encoding->guiName())));
428                 else
429                         frontend::Alert::warning(_("Uncodable characters in listings inset"),
430                                 bformat(_("The following characters in one of the program listings are\n"
431                                           "not representable in the current encoding and have been omitted:\n%1$s."),
432                                 uncodable));
433         }
434 }
435
436
437 docstring InsetListings::xhtml(XMLStream & os, OutputParams const & rp) const
438 {
439         odocstringstream ods;
440         XMLStream out(ods);
441
442         bool const isInline = params().isInline();
443         if (isInline)
444                 out << xml::CompTag("br");
445         else {
446                 out << xml::StartTag("div", "class='float-listings'");
447                 docstring caption = getCaptionHTML(rp);
448                 if (!caption.empty())
449                         out << xml::StartTag("div", "class='listings-caption'")
450                             << XMLStream::ESCAPE_NONE
451                             << caption << xml::EndTag("div");
452         }
453
454         InsetLayout const & il = getLayout();
455         string const & tag = il.htmltag();
456         string attr = "class ='listings";
457         string const lang = params().getParamValue("language");
458         if (!lang.empty())
459                 attr += " " + lang;
460         attr += "'";
461         out << xml::StartTag(tag, attr);
462         OutputParams newrp = rp;
463         newrp.html_disable_captions = true;
464         // We don't want to convert dashes here. That's the only conversion we
465         // do for XHTML, so this is safe.
466         newrp.pass_thru = true;
467         docstring def = InsetText::insetAsXHTML(out, newrp, InsetText::JustText);
468         out << xml::EndTag(tag);
469
470         if (isInline) {
471                 out << xml::CompTag("br");
472                 // escaping will already have been done
473                 os << XMLStream::ESCAPE_NONE << ods.str();
474         } else {
475                 out << xml::EndTag("div");
476                 // In this case, this needs to be deferred, but we'll put it
477                 // before anything the text itself deferred.
478                 def = ods.str() + '\n' + def;
479         }
480         return def;
481 }
482
483
484 void InsetListings::docbook(XMLStream & xs, OutputParams const & rp) const
485 {
486         InsetLayout const & il = getLayout();
487
488         // Forge the attributes.
489         string attrs;
490         if (!il.docbookattr().empty())
491                 attrs += " role=\"" + il.docbookattr() + "\"";
492         string const lang = params().getParamValue("language");
493         if (!lang.empty())
494                 attrs += " language=\"" + lang + "\"";
495         xs << xml::StartTag(il.docbooktag(), attrs);
496         xs.startDivision(false);
497
498         // Deal with the caption.
499         docstring caption = getCaptionDocBook(rp);
500         if (!caption.empty()) {
501                 xs << xml::StartTag("bridgehead");
502                 xs << XMLStream::ESCAPE_NONE;
503                 xs << caption;
504                 xs << xml::EndTag("bridgehead");
505         }
506
507         // Deal with the content of the listing.
508         OutputParams newrp = rp;
509         newrp.pass_thru = true;
510         newrp.docbook_make_pars = false;
511         newrp.par_begin = 0;
512         newrp.par_end = text().paragraphs().size();
513         newrp.docbook_in_listing = true;
514
515         docbookParagraphs(text(), buffer(), xs, newrp);
516
517         // Done with the listing.
518         xs.endDivision();
519         xs << xml::EndTag(il.docbooktag());
520 }
521
522
523 string InsetListings::contextMenuName() const
524 {
525         return "context-listings";
526 }
527
528
529 void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd)
530 {
531         switch (cmd.action()) {
532
533         case LFUN_INSET_MODIFY: {
534                 cur.recordUndoInset(this);
535                 InsetListings::string2params(to_utf8(cmd.argument()), params());
536                 break;
537         }
538
539         case LFUN_INSET_DIALOG_UPDATE:
540                 cur.bv().updateDialog("listings", params2string(params()));
541                 break;
542
543         default:
544                 InsetCaptionable::doDispatch(cur, cmd);
545                 break;
546         }
547 }
548
549
550 bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
551         FuncStatus & status) const
552 {
553         switch (cmd.action()) {
554                 case LFUN_INSET_MODIFY:
555                 case LFUN_INSET_DIALOG_UPDATE:
556                         status.setEnabled(true);
557                         return true;
558                 case LFUN_CAPTION_INSERT: {
559                         // the inset outputs at most one caption
560                         if (params().isInline() || getCaptionInset()) {
561                                 status.setEnabled(false);
562                                 return true;
563                         }
564                 }
565                 // fall through
566                 default:
567                         return InsetCaptionable::getStatus(cur, cmd, status);
568         }
569 }
570
571
572 docstring const InsetListings::buttonLabel(BufferView const & bv) const
573 {
574         // FIXME UNICODE
575         if (decoration() == InsetLayout::CLASSIC)
576                 return isOpen(bv) ? _("Listing") : getNewLabel(_("Listing"));
577         else
578                 return getNewLabel(_("Listing"));
579 }
580
581
582 void InsetListings::validate(LaTeXFeatures & features) const
583 {
584         features.useInsetLayout(getLayout());
585         string param_string = params().params();
586         if (buffer().params().use_minted) {
587                 features.require("minted");
588                 OutputParams rp = features.runparams();
589                 if (!params().isFloat() && !getCaption(rp).str.empty())
590                         features.require("lyxmintcaption");
591                 if (features.usePolyglossia() && features.hasRTLLanguage())
592                         // minted loads color, but color must be loaded before bidi
593                         // (i.e., polyglossia)
594                         features.require("color");
595         } else {
596                 features.require("listings");
597                 if (contains(param_string, "\\color"))
598                         features.require("color");
599         }
600         InsetCaptionable::validate(features);
601 }
602
603
604 bool InsetListings::showInsetDialog(BufferView * bv) const
605 {
606         bv->showDialog("listings", params2string(params()),
607                 const_cast<InsetListings *>(this));
608         return true;
609 }
610
611
612 TexString InsetListings::getCaption(OutputParams const & runparams) const
613 {
614         InsetCaption const * ins = getCaptionInset();
615         if (ins == 0)
616                 return TexString();
617
618         otexstringstream os;
619         ins->getArgs(os, runparams);
620         ins->getArgument(os, runparams);
621
622         // TODO: The code below should be moved to support, and then the test
623         //       in ../tests should be moved there as well.
624
625         // the caption may contain \label{} but the listings
626         // package prefer caption={}, label={}
627         TexString cap = os.release();
628         if (buffer().params().use_minted
629             || !contains(cap.str, from_ascii("\\label{")))
630                 return cap;
631         // convert from
632         //     blah1\label{blah2} blah3
633         // to
634         //     blah1 blah3},label={blah2
635         // to form options
636         //     caption={blah1 blah3},label={blah2}
637         //
638         // NOTE that } is not allowed in blah2.
639         regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)");
640         string const new_cap("$1$3},label={$2");
641         // Remove potential \protect'ion of \label.
642         docstring capstr = subst(cap.str, from_ascii("\\protect\\label"),
643                                  from_ascii("\\label"));
644         // TexString validity: the substitution preserves the number of newlines.
645         // Moreover we assume that $2 does not contain newlines, so that the texrow
646         // information remains accurate.
647         // Replace '\n' with an improbable character from Private Use Area-A
648         // and then return to '\n' after the regex replacement.
649         capstr = subst(capstr, char_type('\n'), 0xffffd);
650         cap.str = subst(from_utf8(regex_replace(to_utf8(capstr), reg, new_cap)),
651                         0xffffd, char_type('\n'));
652         return cap;
653 }
654
655
656 void InsetListings::string2params(string const & in,
657                                    InsetListingsParams & params)
658 {
659         params = InsetListingsParams();
660         if (in.empty())
661                 return;
662         istringstream data(in);
663         Lexer lex;
664         lex.setStream(data);
665         // discard "listings", which is only used to determine inset
666         lex.next();
667         params.read(lex);
668 }
669
670
671 string InsetListings::params2string(InsetListingsParams const & params)
672 {
673         ostringstream data;
674         data << "listings" << ' ';
675         params.write(data);
676         return data.str();
677 }
678
679
680 } // namespace lyx