]> git.lyx.org Git - lyx.git/blob - src/factory.cpp
typos
[lyx.git] / src / factory.cpp
1 /**
2  * \file factory.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "factory.h"
14
15 #include "Buffer.h"
16 #include "BufferParams.h"
17 #include "FloatList.h"
18 #include "FuncRequest.h"
19 #include "Lexer.h"
20 #include "LyX.h"
21 #include "TextClass.h"
22
23 #include "insets/InsetBibitem.h"
24 #include "insets/InsetBibtex.h"
25 #include "insets/InsetBox.h"
26 #include "insets/InsetBranch.h"
27 #include "insets/InsetCaption.h"
28 #include "insets/InsetCitation.h"
29 #include "insets/InsetFlex.h"
30 #include "insets/InsetERT.h"
31 #include "insets/InsetListings.h"
32 #include "insets/InsetExternal.h"
33 #include "insets/InsetFloat.h"
34 #include "insets/InsetFloatList.h"
35 #include "insets/InsetFoot.h"
36 #include "insets/InsetGraphics.h"
37 #include "insets/InsetHyperlink.h"
38 #include "insets/InsetInclude.h"
39 #include "insets/InsetIndex.h"
40 #include "insets/InsetInfo.h"
41 #include "insets/InsetIPA.h"
42 #include "insets/InsetIPAMacro.h"
43 #include "insets/InsetLabel.h"
44 #include "insets/InsetLine.h"
45 #include "insets/InsetMarginal.h"
46 #include "insets/InsetNewline.h"
47 #include "insets/InsetNewpage.h"
48 #include "insets/InsetNomencl.h"
49 #include "insets/InsetNote.h"
50 #include "insets/InsetArgument.h"
51 #include "insets/InsetPhantom.h"
52 #include "insets/InsetPreview.h"
53 #include "insets/InsetRef.h"
54 #include "insets/InsetScript.h"
55 #include "insets/InsetSpace.h"
56 #include "insets/InsetTabular.h"
57 #include "insets/InsetTOC.h"
58 #include "insets/InsetVSpace.h"
59 #include "insets/InsetWrap.h"
60
61 #include "mathed/MathMacroTemplate.h"
62 #include "mathed/InsetMathHull.h"
63
64 #include "frontends/alert.h"
65
66 #include "support/debug.h"
67 #include "support/lstrings.h"
68 #include "support/ExceptionMessage.h"
69
70 #include "support/lassert.h"
71
72 #include <sstream>
73
74 using namespace std;
75 using namespace lyx::support;
76
77 namespace lyx {
78
79 namespace Alert = frontend::Alert;
80
81
82 Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
83 {
84         try {
85
86                 switch (cmd.action()) {
87
88                 case LFUN_NEWPAGE_INSERT: {
89                         string const name = cmd.getArg(0);
90                         InsetNewpageParams inp;
91                         if (name.empty() || name == "newpage")
92                                 inp.kind = InsetNewpageParams::NEWPAGE;
93                         else if (name == "pagebreak")
94                                 inp.kind = InsetNewpageParams::PAGEBREAK;
95                         else if (name == "clearpage")
96                                 inp.kind = InsetNewpageParams::CLEARPAGE;
97                         else if (name == "cleardoublepage")
98                                 inp.kind = InsetNewpageParams::CLEARDOUBLEPAGE;
99                         return new InsetNewpage(inp);
100                 }
101
102                 case LFUN_FLEX_INSERT: {
103                         string s = cmd.getArg(0);
104                         return new InsetFlex(buf, s);
105                 }
106
107                 case LFUN_NOTE_INSERT: {
108                         string arg = cmd.getArg(0);
109                         if (arg.empty())
110                                 arg = "Note";
111                         return new InsetNote(buf, arg);
112                 }
113
114                 case LFUN_BOX_INSERT: {
115                         string arg = cmd.getArg(0);
116                         if (arg.empty())
117                                 arg = "Boxed";
118                         return new InsetBox(buf, arg);
119                 }
120
121                 case LFUN_BRANCH_INSERT: {
122                         docstring arg = cmd.argument();
123                         if (arg.empty())
124                                 arg = from_ascii("none");
125                         return new InsetBranch(buf, InsetBranchParams(arg));
126                 }
127
128                 case LFUN_PHANTOM_INSERT: {
129                         string arg = cmd.getArg(0);
130                         if (arg.empty())
131                                 arg = "Phantom";
132                         return new InsetPhantom(buf, arg);
133                 }
134
135                 case LFUN_IPAMACRO_INSERT: {
136                         string const arg1 = cmd.getArg(0);
137                         string const arg2 = cmd.getArg(1);
138                         if (arg1 != "deco") {
139                                 LYXERR0("LFUN_IPAMACRO_INSERT: wrong argument");
140                                 return 0;
141                         }
142                         return new InsetIPADeco(buf, arg2);
143                 }
144
145                 case LFUN_ERT_INSERT:
146                         return new InsetERT(buf);
147
148                 case LFUN_LISTING_INSERT:
149                         return new InsetListings(buf);
150
151                 case LFUN_FOOTNOTE_INSERT:
152                         return new InsetFoot(buf);
153
154                 case LFUN_MARGINALNOTE_INSERT:
155                         return new InsetMarginal(buf);
156
157                 case LFUN_ARGUMENT_INSERT: {
158                         string arg = cmd.getArg(0);
159                         if (arg.empty()) {
160                                 LYXERR0("argument-insert needs an argument!");
161                                 return 0;
162                         }
163                         return new InsetArgument(buf, arg);
164                 }
165
166                 case LFUN_FLOAT_INSERT: {
167                         string argument = to_utf8(cmd.argument());
168                         if (!argument.empty()) {
169                                 if (!contains(argument, "sideways")) {
170                                         if (!contains(argument, "wide"))
171                                                 argument += "\nwide false";
172                                         argument += "\nsideways false";
173                                 }
174                         }
175                         return new InsetFloat(buf, argument);
176                 }
177
178                 case LFUN_FLOAT_WIDE_INSERT: {
179                         string argument = to_utf8(cmd.argument());
180                         if (!argument.empty()) {
181                                 if (!contains(argument, "sideways")) {
182                                         if (!contains(argument, "wide"))
183                                                 argument += "\nwide true";
184                                         argument += "\nsideways false";
185                                 }
186                         }
187                         InsetFloat * fl = new InsetFloat(buf, argument);
188                         fl->setWide(true);
189                         return fl;
190                 }
191
192                 case LFUN_WRAP_INSERT: {
193                         string const argument = to_utf8(cmd.argument());
194                         if (argument == "figure" || argument == "table")
195                                 return new InsetWrap(buf, argument);
196                         lyxerr << "Non-existent wrapfig type: " << argument << endl;
197                         return 0;
198                 }
199
200                 case LFUN_INDEX_INSERT: {
201                         docstring arg = cmd.argument();
202                         return new InsetIndex(buf, InsetIndexParams(arg));
203                 }
204
205                 case LFUN_IPA_INSERT:
206                         return new InsetIPA(buf);
207
208                 case LFUN_NOMENCL_INSERT: {
209                         InsetCommandParams icp(NOMENCL_CODE);
210                         icp["symbol"] = cmd.argument();
211                         return new InsetNomencl(buf, icp);
212                 }
213
214                 case LFUN_TABULAR_INSERT: {
215                         if (cmd.argument().empty())
216                                 return 0;
217                         istringstream ss(to_utf8(cmd.argument()));
218                         int r = 0, c = 0;
219                         ss >> r >> c;
220                         if (r <= 0)
221                                 r = 2;
222                         if (c <= 0)
223                                 c = 2;
224                         return new InsetTabular(buf, r, c);
225                 }
226
227                 case LFUN_CAPTION_INSERT:
228                         return new InsetCaption(buf);
229
230                 case LFUN_INDEX_PRINT:  {
231                         InsetCommandParams icp(INDEX_PRINT_CODE);
232                         icp["type"] = cmd.argument();
233                         return new InsetPrintIndex(buf, icp);
234                 }
235
236                 case LFUN_NOMENCL_PRINT: {
237                         InsetCommandParams icp(NOMENCL_PRINT_CODE);
238                         icp["set_width"] = from_ascii("auto");
239                         return new InsetPrintNomencl(buf, icp);
240                 }
241
242                 case LFUN_INFO_INSERT: {
243                         InsetInfo * inset = new InsetInfo(buf, to_utf8(cmd.argument()));
244                         inset->updateInfo();
245                         return inset;
246                 }
247
248                 case LFUN_PREVIEW_INSERT:
249                         return new InsetPreview(buf);
250
251                 case LFUN_SCRIPT_INSERT: {
252                         InsetScriptParams isp;
253                         InsetScript::string2params("script script " + to_utf8(cmd.argument()), isp);
254                         return new InsetScript(buf, isp);
255                 }
256
257                 case LFUN_INSET_INSERT: {
258                         string const name = cmd.getArg(0);
259                         InsetCode code = insetCode(name);
260                         switch (code) {
261                         case NO_CODE:
262                                 lyxerr << "No such inset '" << name << "'.";
263                                 return 0;
264                         
265                         case BIBITEM_CODE: {
266                                 InsetCommandParams icp(code);
267                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
268                                 return new InsetBibitem(buf, icp);
269                         }
270                         
271                         case BIBTEX_CODE: {
272                                 InsetCommandParams icp(code);
273                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
274                                 return new InsetBibtex(buf, icp);
275                         }
276                         
277                         case CITE_CODE: {
278                                 InsetCommandParams icp(code);
279                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
280                                 return new InsetCitation(buf, icp);
281                         }
282                         
283                         case ERT_CODE: {
284                                 return new InsetERT(buf,
285                                         InsetERT::string2params(to_utf8(cmd.argument())));
286                         }
287                         
288                         case EXTERNAL_CODE: {
289                                 InsetExternalParams iep;
290                                 InsetExternal::string2params(to_utf8(cmd.argument()), *buf, iep);
291                                 auto_ptr<InsetExternal> inset(new InsetExternal(buf));
292                                 inset->setBuffer(*buf);
293                                 inset->setParams(iep);
294                                 return inset.release();
295                         }
296                         
297                         case GRAPHICS_CODE: {
298                                 InsetGraphicsParams igp;
299                                 InsetGraphics::string2params(to_utf8(cmd.argument()), *buf, igp);
300                                 auto_ptr<InsetGraphics> inset(new InsetGraphics(buf));
301                                 inset->setParams(igp);
302                                 return inset.release();
303                         }
304                         
305                         case HYPERLINK_CODE: {
306                                 InsetCommandParams icp(code);
307                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
308                                 return new InsetHyperlink(buf, icp);
309                         }
310                         
311                         case INCLUDE_CODE: {
312                                 InsetCommandParams icp(code);
313                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
314                                 return new InsetInclude(buf, icp);
315                         }
316                         
317                         case INDEX_CODE: {
318                                 docstring arg = cmd.argument();
319                                 return new InsetIndex(buf, InsetIndexParams(arg));
320                         }
321                         
322                         case INDEX_PRINT_CODE:  {
323                                 InsetCommandParams icp(code);
324                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
325                                 return new InsetPrintIndex(buf, icp);
326                         }
327                         
328                         case LABEL_CODE: {
329                                 InsetCommandParams icp(code);
330                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
331                                 return new InsetLabel(buf, icp);
332                         }
333                         
334                         case LINE_CODE: {
335                                 InsetCommandParams icp(code);
336                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
337                                 return new InsetLine(buf, icp);
338                         }
339                                 
340                         case LISTINGS_CODE: {
341                                 InsetListingsParams par;
342                                 InsetListings::string2params(to_utf8(cmd.argument()), par);
343                                 return new InsetListings(buf, par);
344                         }
345                         
346                         case NOMENCL_CODE: {
347                                 InsetCommandParams icp(code);
348                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
349                                 return new InsetNomencl(buf, icp);
350                         }
351                         
352                         case REF_CODE: {
353                                 InsetCommandParams icp(code);
354                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
355                                 return new InsetRef(buf, icp);
356                         }
357
358                         case SCRIPT_CODE: {
359                                 InsetScriptParams isp;
360                                 InsetScript::string2params(to_utf8(cmd.argument()), isp);
361                                 return new InsetScript(buf, isp);
362                         }
363
364                         case SPACE_CODE: {
365                                 InsetSpaceParams isp;
366                                 InsetSpace::string2params(to_utf8(cmd.argument()), isp);
367                                 return new InsetSpace(isp);
368                         }
369                         
370                         case TOC_CODE: {
371                                 InsetCommandParams icp(code);
372                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
373                                 return new InsetTOC(buf, icp);
374                         }
375                         
376                         case VSPACE_CODE: {
377                                 VSpace vspace;
378                                 InsetVSpace::string2params(to_utf8(cmd.argument()), vspace);
379                                 return new InsetVSpace(vspace);
380                         }
381
382                         case PREVIEW_CODE:
383                                 return new InsetPreview(buf);
384                         
385                         default:
386                                 lyxerr << "Inset '" << name << "' not permitted with LFUN_INSET_INSERT."
387                                                 << endl;
388                                 return 0;
389                         
390                         }
391                 } //end LFUN_INSET_INSERT
392
393                 case LFUN_SPACE_INSERT: {
394                         string const name = cmd.getArg(0);
395                         string const len = cmd.getArg(1);
396                         if (name.empty()) {
397                                 lyxerr << "LyX function 'space-insert' needs an argument." << endl;
398                                 break;
399                         }
400                         InsetSpaceParams isp;
401                         // The tests for isp.math might be disabled after a file format change
402                         if (name == "normal")
403                                 isp.kind = InsetSpaceParams::NORMAL;
404                         else if (name == "protected")
405                                 isp.kind = InsetSpaceParams::PROTECTED;
406                         else if (name == "visible")
407                                 isp.kind = InsetSpaceParams::VISIBLE;
408                         else if (name == "thin")
409                                 isp.kind = InsetSpaceParams::THIN;
410                         else if (isp.math && name == "med")
411                                 isp.kind = InsetSpaceParams::MEDIUM;
412                         else if (isp.math && name == "thick")
413                                 isp.kind = InsetSpaceParams::THICK;
414                         else if (name == "quad")
415                                 isp.kind = InsetSpaceParams::QUAD;
416                         else if (name == "qquad")
417                                 isp.kind = InsetSpaceParams::QQUAD;
418                         else if (name == "enspace")
419                                 isp.kind = InsetSpaceParams::ENSPACE;
420                         else if (name == "enskip")
421                                 isp.kind = InsetSpaceParams::ENSKIP;
422                         else if (name == "negthinspace")
423                                 isp.kind = InsetSpaceParams::NEGTHIN;
424                         else if (name == "negmedspace")
425                                 isp.kind = InsetSpaceParams::NEGMEDIUM;
426                         else if (name == "negthickspace")
427                                 isp.kind = InsetSpaceParams::NEGTHICK;
428                         else if (name == "hfill")
429                                 isp.kind = InsetSpaceParams::HFILL;
430                         else if (name == "hfill*")
431                                 isp.kind = InsetSpaceParams::HFILL_PROTECTED;
432                         else if (name == "dotfill")
433                                 isp.kind = InsetSpaceParams::DOTFILL;
434                         else if (name == "hrulefill")
435                                 isp.kind = InsetSpaceParams::HRULEFILL;
436                         else if (name == "hspace") {
437                                 if (len.empty() || !isValidGlueLength(len)) {
438                                         lyxerr << "LyX function 'space-insert hspace' "
439                                                << "needs a valid length argument." << endl;
440                                         break;
441                                 }
442                                 isp.kind = InsetSpaceParams::CUSTOM;
443                                 isp.length = GlueLength(len);
444                         }
445                         else if (name == "hspace*") {
446                                 if (len.empty() || !isValidGlueLength(len)) {
447                                         lyxerr << "LyX function 'space-insert hspace*' "
448                                                << "needs a valid length argument." << endl;
449                                         break;
450                                 }
451                                 isp.kind = InsetSpaceParams::CUSTOM_PROTECTED;
452                                 isp.length = GlueLength(len);
453                         }
454                         else {
455                                 lyxerr << "Wrong argument for LyX function 'space-insert'." << endl;
456                                 break;
457                         }
458                         return new InsetSpace(isp);
459                 }
460                 break;
461
462                 default:
463                         break;
464                 }
465
466         } catch (ExceptionMessage const & message) {
467                 if (message.type_ == ErrorException) {
468                         // This should never happen!
469                         Alert::error(message.title_, message.details_);
470                         lyx_exit(1);
471                 } else if (message.type_ == WarningException) {
472                         Alert::warning(message.title_, message.details_);
473                         return 0;
474                 }
475         }
476
477         return 0;
478 }
479
480
481 Inset * createInset(Buffer * buf, FuncRequest const & cmd)
482 {
483         Inset * inset = createInsetHelper(buf, cmd);
484         if (inset)
485                 inset->setBuffer(*buf);
486         return inset;
487 }
488
489
490 Inset * readInset(Lexer & lex, Buffer * buf)
491 {
492         // consistency check
493         if (lex.getString() != "\\begin_inset")
494                 LYXERR0("Buffer::readInset: Consistency check failed.");
495
496         auto_ptr<Inset> inset;
497
498         string tmptok;
499         lex >> tmptok;
500
501         // test the different insets
502         
503         // FIXME It would be better if we did not have this branch and could
504         // just do one massive switch for all insets. But at present, it's
505         // easier to do it this way, and we can't do the massive switch until
506         // the conversion mentioned below.  Note that if we do want to do a
507         // single switch, we need to remove this "CommandInset" line---or
508         // replace it with a single "InsetType" line that would be used in all
509         // insets.
510         if (tmptok == "CommandInset") {
511                 lex.next();
512                 string const insetType = lex.getString();
513                 lex.pushToken(insetType);
514                 
515                 InsetCode const code = insetCode(insetType);
516                 
517                 //FIXME If we do the one massive switch, we cannot do this here, since
518                 //we do not know in advance that we're dealing with a command inset.
519                 //Worst case, we could put it in each case below. Better, we could
520                 //pass the lexer to the constructor and let the params be built there.
521                 InsetCommandParams inscmd(code);
522                 inscmd.read(lex);
523
524                 switch (code) {
525                         case BIBITEM_CODE:
526                                 inset.reset(new InsetBibitem(buf, inscmd));
527                                 break;
528                         case BIBTEX_CODE:
529                                 inset.reset(new InsetBibtex(buf, inscmd));
530                                 break;
531                         case CITE_CODE: 
532                                 inset.reset(new InsetCitation(buf, inscmd));
533                                 break;
534                         case HYPERLINK_CODE:
535                                 inset.reset(new InsetHyperlink(buf, inscmd));
536                                 break;
537                         case INCLUDE_CODE:
538                                 inset.reset(new InsetInclude(buf, inscmd));
539                                 break;
540                         case INDEX_PRINT_CODE:
541                                 inset.reset(new InsetPrintIndex(buf, inscmd));
542                                 break;
543                         case LABEL_CODE:
544                                 inset.reset(new InsetLabel(buf, inscmd));
545                                 break;
546                         case LINE_CODE:
547                                 inset.reset(new InsetLine(buf, inscmd));
548                                 break;
549                         case NOMENCL_CODE:
550                                 inset.reset(new InsetNomencl(buf, inscmd));
551                                 break;
552                         case NOMENCL_PRINT_CODE:
553                                 inset.reset(new InsetPrintNomencl(buf, inscmd));
554                                 break;
555                         case REF_CODE:
556                                 if (inscmd["name"].empty() && inscmd["reference"].empty())
557                                         return 0;
558                                 inset.reset(new InsetRef(buf, inscmd));
559                                 break;
560                         case TOC_CODE:
561                                 inset.reset(new InsetTOC(buf, inscmd));
562                                 break;
563                         case NO_CODE:
564                         default:
565                                 lyxerr << "unknown CommandInset '" << insetType
566                                                         << "'" << endl;
567                                 while (lex.isOK() && lex.getString() != "\\end_inset")
568                                         lex.next();
569                                 return 0;
570                 }
571                 inset->setBuffer(*buf);
572         } else { 
573                 // FIXME This branch should be made to use inset codes
574                 // as the preceding branch does. Unfortunately, that
575                 // will take some doing. It requires converting the
576                 // representation of the insets in LyX files so that
577                 // they use the inset names listed in Inset.cpp. Then,
578                 // as above, the inset names can be translated to
579                 // inset codes using insetCode(). And the insets'
580                 // write() routines should use insetName() rather than
581                 // hardcoding it.
582                 if (tmptok == "Quotes") {
583                         inset.reset(new InsetQuotes(buf));
584                 } else if (tmptok == "External") {
585                         inset.reset(new InsetExternal(buf));
586                 } else if (tmptok == "FormulaMacro") {
587                         inset.reset(new MathMacroTemplate(buf));
588                 } else if (tmptok == "Formula") {
589                         inset.reset(new InsetMathHull(buf));
590                 } else if (tmptok == "Graphics") {
591                         inset.reset(new InsetGraphics(buf));
592                 } else if (tmptok == "Note") {
593                         inset.reset(new InsetNote(buf, tmptok));
594                 } else if (tmptok == "Box") {
595                         inset.reset(new InsetBox(buf, tmptok));
596                 } else if (tmptok == "Flex") {
597                         lex.eatLine();
598                         string s = lex.getString();
599                         inset.reset(new InsetFlex(buf, s));
600                 } else if (tmptok == "Branch") {
601                         inset.reset(new InsetBranch(buf, InsetBranchParams()));
602                 } else if (tmptok == "Phantom") {
603                         inset.reset(new InsetPhantom(buf, tmptok));
604                 } else if (tmptok == "ERT") {
605                         inset.reset(new InsetERT(buf));
606                 } else if (tmptok == "listings") {
607                         inset.reset(new InsetListings(buf));
608                 } else if (tmptok == "script") {
609                         inset.reset(new InsetScript(buf));
610                 } else if (tmptok == "space") {
611                         inset.reset(new InsetSpace);
612                 } else if (tmptok == "Tabular") {
613                         inset.reset(new InsetTabular(buf));
614                 } else if (tmptok == "Text") {
615                         inset.reset(new InsetText(buf));
616                 } else if (tmptok == "VSpace") {
617                         inset.reset(new InsetVSpace);
618                 } else if (tmptok == "Foot") {
619                         inset.reset(new InsetFoot(buf));
620                 } else if (tmptok == "Marginal") {
621                         inset.reset(new InsetMarginal(buf));
622                 } else if (tmptok == "Newpage") {
623                         inset.reset(new InsetNewpage);
624                 } else if (tmptok == "Newline") {
625                         inset.reset(new InsetNewline);
626                 } else if (tmptok == "Argument") {
627                         inset.reset(new InsetArgument(buf, tmptok));
628                 } else if (tmptok == "Float") {
629                         inset.reset(new InsetFloat(buf, string()));
630                 } else if (tmptok == "Wrap") {
631                         lex.next();
632                         string tmptok = lex.getString();
633                         inset.reset(new InsetWrap(buf, tmptok));
634                 } else if (tmptok == "Caption") {
635                         inset.reset(new InsetCaption(buf));
636                 } else if (tmptok == "Index") {
637                         inset.reset(new InsetIndex(buf, InsetIndexParams()));
638                 } else if (tmptok == "FloatList") {
639                         inset.reset(new InsetFloatList(buf));
640                 } else if (tmptok == "Info") {
641                         inset.reset(new InsetInfo(buf));
642                 } else if (tmptok == "IPA") {
643                         inset.reset(new InsetIPA(buf));
644                 } else if (tmptok == "IPADeco") {
645                         inset.reset(new InsetIPADeco(buf, tmptok));
646                 } else if (tmptok == "Preview") {
647                         inset.reset(new InsetPreview(buf));
648                 } else {
649                         lyxerr << "unknown Inset type '" << tmptok
650                                << "'" << endl;
651                         while (lex.isOK() && lex.getString() != "\\end_inset")
652                                 lex.next();
653                         return 0;
654                 }
655
656                 // Set the buffer reference for proper parsing of some insets
657                 // (InsetCollapsable for example)
658                 inset->setBuffer(*buf);
659                 inset->read(lex);
660                 // Set again the buffer for insets that are created inside this inset
661                 // (InsetMathHull for example).
662                 inset->setBuffer(*buf);
663         }
664         return inset.release();
665 }
666
667
668 } // namespace lyx