#include "ParagraphParameters.h"
#include "ParIterator.h"
#include "PDFOptions.h"
-#include "Session.h"
#include "sgml.h"
#include "TexRow.h"
#include "TexStream.h"
namespace {
-int const LYX_FORMAT = 318;
+int const LYX_FORMAT = 321;
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
typedef pair<DocIterator, MacroData> ScopeMacro;
typedef map<DocIterator, ScopeMacro> PositionScopeMacroMap;
typedef map<docstring, PositionScopeMacroMap> NamePositionScopeMacroMap;
+ /// map from the macro name to the position map,
+ /// which maps the macro definition position to the scope and the MacroData.
NamePositionScopeMacroMap macros;
bool macro_lock;
typedef map<Buffer const * const, DocIterator> BufferPositionMap;
typedef pair<DocIterator, Buffer const *> ScopeBuffer;
typedef map<DocIterator, ScopeBuffer> PositionScopeBufferMap;
+ /// position of children buffers in this buffer
BufferPositionMap children_positions;
+ /// map from children inclusion positions to their scope and their buffer
PositionScopeBufferMap position_to_children;
/// Container for all sort of Buffer dependant errors.
LYXERR(Debug::PARSER, "Handling document header token: `"
<< token << '\'');
- string unknown = params().readToken(lex, token, d->filename.onlyPath());
+ string unknown = params().readToken(lex, token, d->filename.onlyPath(),
+ d->temppath);
if (!unknown.empty()) {
if (unknown[0] != '\\' && token == "\\textclass") {
Alert::warning(_("Unknown document class"),
// Enable embeded files, which will set temp path and move
// inconsistent inzip files if needed.
- embeddedFiles().enable(params().embedded, *this, false);
+ try {
+ embeddedFiles().validate(*this);
+ embeddedFiles().enable(params().embedded, *this, false);
+ } catch (ExceptionMessage const & message) {
+ Alert::error(message.title_, message.details_);
+ Alert::warning(_("Failed to read embedded files"),
+ _("Due to most likely a bug, LyX failed to locate all embedded "
+ "file. If you unzip the LyX file, you should be able to see and "
+ "open content.lyx which is your main text. You may also be able "
+ "to recover some embedded files. Please report this bug to the "
+ "lyx-devel mailing list."));
+ return false;
+ }
updateMacros();
updateMacroInstances();
}
if (!retval) {
- message(str + _(" could not write file!."));
+ message(str + _(" could not write file!"));
return false;
}
removeAutosaveFile(d->filename.absFilename());
if (params().embedded) {
- message(str + _(" writing embedded files!."));
+ message(str + _(" writing embedded files."));
// if embedding is enabled, write file.lyx and all the embedded files
// to the zip file fname.
if (!d->embedded_files.writeFile(fname, *this)) {
- message(str + _(" could not write embedded files!."));
+ message(str + _(" could not write embedded files!"));
return false;
}
}
}
-void Buffer::updateEnvironmentMacros(DocIterator & it, pit_type lastpit,
- DocIterator & scope) const
+void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const
{
- Paragraph & par = it.paragraph();
- depth_type depth = par.params().depth();
- Length const & leftIndent = par.params().leftIndent();
+ pit_type lastpit = it.lastpit();
// look for macros in each paragraph
while (it.pit() <= lastpit) {
Paragraph & par = it.paragraph();
- // increased depth?
- if ((par.params().depth() > depth
- || par.params().leftIndent() != leftIndent)
- && par.layout().isEnvironment()) {
- updateBlockMacros(it, scope);
- continue;
- }
-
// iterate over the insets of the current paragraph
InsetList const & insets = par.insetList();
InsetList::const_iterator iit = insets.begin();
// collect macros in inset
it.push_back(CursorSlice(*iit->inset));
- updateInsetMacros(it, newScope ? insetScope : scope);
+ updateMacros(it, newScope ? insetScope : scope);
it.pop_back();
continue;
}
}
-void Buffer::updateBlockMacros(DocIterator & it, DocIterator & scope) const
-{
- Paragraph & par = it.paragraph();
-
- // set scope for macros in this paragraph:
- // * either the "old" outer scope
- // * or the scope ending after the environment
- if (par.layout().isEnvironment()) {
- // find end of environment block,
- DocIterator envEnd = it;
- pit_type n = it.lastpit() + 1;
- depth_type depth = par.params().depth();
- Length const & length = par.params().leftIndent();
- // looping through the paragraph, basically until
- // the layout changes or the depth gets smaller.
- // (the logic of output_latex.cpp's TeXEnvironment)
- do {
- envEnd.pit()++;
- if (envEnd.pit() == n)
- break;
- } while (par.layout() == envEnd.paragraph().layout()
- || depth < envEnd.paragraph().params().depth()
- || length != envEnd.paragraph().params().leftIndent());
-
- // collect macros from environment block
- updateEnvironmentMacros(it, envEnd.pit() - 1, envEnd);
- } else {
- // collect macros from paragraph
- updateEnvironmentMacros(it, it.pit(), scope);
- }
-}
-
-
-void Buffer::updateInsetMacros(DocIterator & it, DocIterator & scope) const
-{
- // look for macros in each paragraph
- pit_type n = it.lastpit() + 1;
- while (it.pit() < n)
- updateBlockMacros(it, scope);
-}
-
-
void Buffer::updateMacros() const
{
if (d->macro_lock)
DocIterator it = par_iterator_begin();
DocIterator outerScope = it;
outerScope.pit() = outerScope.lastpit() + 2;
- updateInsetMacros(it, outerScope);
+ updateMacros(it, outerScope);
}