[LyX features/cleanup/updateMacros3] Now just use the Inset::updateMacros method.
Richard Kimberly Heck
rikiheck at lyx.org
Thu Nov 12 22:40:55 UTC 2020
The branch, cleanup/updateMacros3, has been updated.
- Log -----------------------------------------------------------------
commit 426674045cd849e1a041473350f00dad74a430fb
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 18:07:35 2020 -0500
Now just use the Inset::updateMacros method.
I did all this step by step so (a) I could check the output along
the way and (b) so it will be easier to isolate problems if those
should arise.
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 5776e16..aeb99c0 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -924,48 +924,13 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
// look for macros in each paragraph
while (it.pit() <= lastpit) {
Paragraph & par = it.paragraph();
-
// iterate over the insets of the current paragraph
for (auto const & insit : par.insetList()) {
it.pos() = insit.pos;
-
- if (InsetText * itext = insit.inset->asInsetText()) {
- // collect macros in inset
- it.push_back(CursorSlice(*insit.inset));
- itext->updateMacros(it, ourscope);
- it.pop_back();
- continue;
- }
-
- if (InsetTabular * itext = insit.inset->asInsetTabular()) {
- it.push_back(CursorSlice(*insit.inset));
- itext->updateMacros(it, ourscope);
- it.pop_back();
- continue;
- }
-
- // is it an external file?
- if (insit.inset->lyxCode() == INCLUDE_CODE) {
- insit.inset->updateMacros(it, ourscope);
- continue;
- }
-
- InsetMath * im = insit.inset->asInsetMath();
- if (im) {
- InsetMathHull * hull = im->asHullInset();
- if (hull)
- hull->updateMacros(it, ourscope);
- }
-
- if (insit.inset->lyxCode() != MATHMACRO_CODE)
- continue;
-
- // get macro data
- InsetMathMacroTemplate * macroTemplate =
- insit.inset->asInsetMath()->asMacroTemplate();
- macroTemplate->updateMacros(it, ourscope);
+ it.push_back(CursorSlice(*insit.inset));
+ insit.inset->updateMacros(it, ourscope);
+ it.pop_back();
}
-
// next paragraph
it.pit()++;
it.pos() = 0;
commit 8a8d0c5aab6e503df0f5cdadcf3967de003dbbe2
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 18:05:40 2020 -0500
nullptr
diff --git a/src/mathed/InsetMathMacroTemplate.cpp b/src/mathed/InsetMathMacroTemplate.cpp
index 84f8b73..a445b4d 100644
--- a/src/mathed/InsetMathMacroTemplate.cpp
+++ b/src/mathed/InsetMathMacroTemplate.cpp
@@ -481,7 +481,7 @@ void InsetMathMacroTemplate::updateMacros(DocIterator const & us, DocIterator co
void InsetMathMacroTemplate::updateToContext(MacroContext const & mc)
{
- redefinition_ = mc.get(name()) != 0;
+ redefinition_ = mc.get(name()) != nullptr;
}
@@ -564,7 +564,7 @@ void InsetMathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
Changer dummy2 = mi.base.font.changeStyle(TEXT_STYLE);
// valid macro?
- MacroData const * macro = 0;
+ MacroData const * macro = nullptr;
if (validName())
macro = mi.macrocontext.get(name());
@@ -687,7 +687,7 @@ void InsetMathMacroTemplate::shiftArguments(size_t from, int by)
int InsetMathMacroTemplate::maxArgumentInDefinition() const
{
// We don't have a buffer when pasting from the clipboard (bug 6014).
- Buffer const * macro_buffer = isBufferLoaded() ? &buffer() : 0;
+ Buffer const * macro_buffer = isBufferLoaded() ? &buffer() : nullptr;
int maxArg = 0;
DocIterator it = doc_iterator_begin(macro_buffer, this);
it.idx() = defIdx();
commit 09bf2ed724516e3d7faff91a7158b72da1bf5823
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 18:03:36 2020 -0500
Move updateMacros code into InsetMathMacroTemplate.
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 37a1c8e..5776e16 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -961,21 +961,9 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
continue;
// get macro data
- InsetMathMacroTemplate & macroTemplate =
- *insit.inset->asInsetMath()->asMacroTemplate();
- MacroContext mc(&buffer(), it);
- macroTemplate.updateToContext(mc);
-
- // valid?
- bool valid = macroTemplate.validMacro();
- // FIXME: Should be fixNameAndCheckIfValid() in fact,
- // then the BufferView's cursor will be invalid in
- // some cases which leads to crashes.
- if (!valid)
- continue;
-
- // register macro
- buffer().registerMacro(macroTemplate.name(), it, ourscope);
+ InsetMathMacroTemplate * macroTemplate =
+ insit.inset->asInsetMath()->asMacroTemplate();
+ macroTemplate->updateMacros(it, ourscope);
}
// next paragraph
diff --git a/src/mathed/InsetMathMacroTemplate.cpp b/src/mathed/InsetMathMacroTemplate.cpp
index 1152936..84f8b73 100644
--- a/src/mathed/InsetMathMacroTemplate.cpp
+++ b/src/mathed/InsetMathMacroTemplate.cpp
@@ -460,6 +460,25 @@ docstring InsetMathMacroTemplate::name() const
}
+void InsetMathMacroTemplate::updateMacros(DocIterator const & us, DocIterator const & scope)
+{
+ // This matches the previous code, but I am not sure why it
+ // should be like this.
+ DocIterator it = us;
+ it.pop_back();
+ MacroContext mc(&buffer(), it);
+ updateToContext(mc);
+ // FIXME: Should be fixNameAndCheckIfValid() in fact,
+ // then the BufferView's cursor will be invalid in
+ // some cases which leads to crashes.
+ if (!validMacro())
+ return;
+
+ // register macro
+ buffer().registerMacro(name(), it, scope);
+}
+
+
void InsetMathMacroTemplate::updateToContext(MacroContext const & mc)
{
redefinition_ = mc.get(name()) != 0;
diff --git a/src/mathed/InsetMathMacroTemplate.h b/src/mathed/InsetMathMacroTemplate.h
index 0940896..7c9a680 100644
--- a/src/mathed/InsetMathMacroTemplate.h
+++ b/src/mathed/InsetMathMacroTemplate.h
@@ -87,6 +87,8 @@ public:
/// decide whether its a redefinition
void updateToContext(MacroContext const & mc);
+ ///
+ void updateMacros(DocIterator const & us, DocIterator const & scope) override;
///
void draw(PainterInfo & pi, int x, int y) const override;
commit 96820abca07f52a968b7e11228a5676272f6231f
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 17:48:51 2020 -0500
Move updateMacros code to InsetInclude.
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index 75a41c3..eff6fb5 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -1400,6 +1400,16 @@ void InsetInclude::updateCommand()
}
+void InsetInclude::updateMacros(DocIterator const & us, DocIterator const & scope)
+{
+ buffer().setMacroLock();
+ loadIfNeeded();
+ buffer().clearMacroLock();
+ if (child_buffer_)
+ buffer().registerChild(child_buffer_, us, scope);
+}
+
+
void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
{
file_exist_ = includedFileExist();
diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h
index a254254..046f481 100644
--- a/src/insets/InsetInclude.h
+++ b/src/insets/InsetInclude.h
@@ -106,6 +106,8 @@ public:
///
void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
///
+ void updateMacros(DocIterator const & us, DocIterator const & scope) override;
+ ///
std::string contextMenuName() const override;
//@}
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 9d8b2ac..37a1c8e 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -946,15 +946,7 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
// is it an external file?
if (insit.inset->lyxCode() == INCLUDE_CODE) {
- // get buffer of external file
- InsetInclude const & incinset =
- static_cast<InsetInclude const &>(*insit.inset);
- buffer().setMacroLock();
- Buffer * child = incinset.loadIfNeeded();
- buffer().clearMacroLock();
- if (!child)
- continue;
- buffer().registerChild(child, it, ourscope);
+ insit.inset->updateMacros(it, ourscope);
continue;
}
commit 7bab06289480eb33a7fa411ef4b3add4ac97e058
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 17:43:57 2020 -0500
Move code to InsetMathHull::updateMacros.
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index e8deb3a..9d8b2ac 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -962,7 +962,7 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
if (im) {
InsetMathHull * hull = im->asHullInset();
if (hull)
- hull->recordLocation(it);
+ hull->updateMacros(it, ourscope);
}
if (insit.inset->lyxCode() != MATHMACRO_CODE)
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 43f4958..5464115 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -238,6 +238,13 @@ namespace {
} // namespace
+// FIXME This may or may not be the right place to do this.
+void InsetMathHull::updateMacros(DocIterator const & us, DocIterator const &)
+{
+ recordLocation(us);
+}
+
+
void InsetMathHull::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
{
if (!buffer_) {
diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h
index 0b085a1..ef77a75 100644
--- a/src/mathed/InsetMathHull.h
+++ b/src/mathed/InsetMathHull.h
@@ -50,6 +50,8 @@ public:
void setBuffer(Buffer &) override;
///
void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
+ /// This must be called by any subclass that overrides it!
+ void updateMacros(DocIterator const & us, DocIterator const & scope) override;
///
void addToToc(DocIterator const & di, bool output_active,
UpdateType utype, TocBackend & backend) const override;
commit 0507c0b967e5ff2208eb1b932da0b14a7b23d490
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 17:20:48 2020 -0500
Move updateMacros code into InsetTabular
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index e6c9892..75886f5 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -4813,6 +4813,19 @@ void InsetTabular::edit(Cursor & cur, bool front, EntryDirection)
}
+void InsetTabular::updateMacros(DocIterator const & us, DocIterator const & scope)
+{
+ DocIterator pos = us;
+ size_t const numcells = pos.nargs();
+ for (size_t c = 0; c < numcells; ++c, pos.top().forwardIdx()) {
+ shared_ptr<InsetTableCell> cp = cell(c);
+ // this test should be unnecessary, right?
+ if (cp)
+ cp->updateMacros(pos, scope);
+ }
+}
+
+
void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype, bool const /*deleted*/)
{
// In a longtable, tell captions what the current float is
diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h
index 2ee107a..c27fec0 100644
--- a/src/insets/InsetTabular.h
+++ b/src/insets/InsetTabular.h
@@ -1054,6 +1054,8 @@ public:
/// Update the counters of this inset and of its contents
void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
///
+ void updateMacros(DocIterator const & us, DocIterator const & scope) override;
+ ///
void addToToc(DocIterator const & di, bool output_active,
UpdateType utype, TocBackend & backend) const override;
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index fb581f2..e8deb3a 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -62,6 +62,7 @@
#include "mathed/InsetMathHull.h"
#include "mathed/MacroTable.h"
#include "mathed/InsetMathMacroTemplate.h"
+#include "insets/InsetTabular.h"
#include "support/convert.h"
#include "support/debug.h"
@@ -936,14 +937,10 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
continue;
}
- if (insit.inset->asInsetTabular()) {
- CursorSlice slice(*insit.inset);
- size_t const numcells = slice.nargs();
- for (; slice.idx() < numcells; slice.forwardIdx()) {
- it.push_back(slice);
- updateMacros(it, ourscope);
- it.pop_back();
- }
+ if (InsetTabular * itext = insit.inset->asInsetTabular()) {
+ it.push_back(CursorSlice(*insit.inset));
+ itext->updateMacros(it, ourscope);
+ it.pop_back();
continue;
}
commit 04f893b3f600bdf278273a6ba333b164e081bcc5
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 16:33:28 2020 -0500
Move some processing from the loop into the main InsetText routine.
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index c6fbfdb..7885046 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -571,6 +571,9 @@ public:
/// The boolean indicates whether we are preparing for output, e.g.,
/// of XHTML.
virtual void updateBuffer(ParIterator const &, UpdateType, bool const) {}
+ /// Note that \param us is expected to be a DocIterator pointing at this inset.
+ /// We will assert otherwise.
+ virtual void updateMacros(DocIterator const & /* us */, DocIterator const & /* scope */) {}
/// Updates the inset's dialog
virtual Buffer const * updateFrontend() const;
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 2a99b10..fb581f2 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -913,8 +913,13 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
{
LBUFERR(us.nextInset() == this);
DocIterator it = us;
- pit_type const lastpit = it.lastpit();
+ DocIterator ourscope = scope;
+ if (!producesOutput()) {
+ ourscope = us;
+ ++ourscope.pos();
+ }
+ pit_type const lastpit = it.lastpit();
// look for macros in each paragraph
while (it.pit() <= lastpit) {
Paragraph & par = it.paragraph();
@@ -923,20 +928,10 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
for (auto const & insit : par.insetList()) {
it.pos() = insit.pos;
- if (InsetText const * itext = insit.inset->asInsetText()) {
+ if (InsetText * itext = insit.inset->asInsetText()) {
// collect macros in inset
it.push_back(CursorSlice(*insit.inset));
- if (itext->producesOutput()) {
- // the simple case
- updateMacros(it, scope);
- } else {
- // We don't want macros declared in notes, comments, etc,
- // to affect anything outside them.
- // New scope which ends just behind the inset
- DocIterator new_scope = it;
- ++new_scope.pos();
- updateMacros(it, new_scope);
- }
+ itext->updateMacros(it, ourscope);
it.pop_back();
continue;
}
@@ -946,7 +941,7 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
size_t const numcells = slice.nargs();
for (; slice.idx() < numcells; slice.forwardIdx()) {
it.push_back(slice);
- updateMacros(it, scope);
+ updateMacros(it, ourscope);
it.pop_back();
}
continue;
@@ -962,7 +957,7 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
buffer().clearMacroLock();
if (!child)
continue;
- buffer().registerChild(child, it, scope);
+ buffer().registerChild(child, it, ourscope);
continue;
}
@@ -991,7 +986,7 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
continue;
// register macro
- buffer().registerMacro(macroTemplate.name(), it, scope);
+ buffer().registerMacro(macroTemplate.name(), it, ourscope);
}
// next paragraph
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index 9fdfb6f..079d0f4 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -173,7 +173,7 @@ public:
/// Update the counters of this inset and of its contents
void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
///
- void updateMacros(DocIterator const & us, DocIterator const & scope);
+ void updateMacros(DocIterator const & us, DocIterator const & scope) override;
///
void setMacrocontextPositionRecursive(DocIterator const & pos);
///
commit acec4a21f1360f8941d58cf00103abb4ce75e667
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 16:30:03 2020 -0500
nullptr
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index a947499..2a99b10 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -1187,7 +1187,7 @@ bool InsetText::showCompletionCursor() const
CompletionList const * InsetText::createCompletionList(Cursor const & cur) const
{
- return completionSupported(cur) ? text_.createCompletionList(cur) : 0;
+ return completionSupported(cur) ? text_.createCompletionList(cur) : nullptr;
}
commit 706451e6b28df0bc78b70d6211bddeecfc3e12d4
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 16:19:46 2020 -0500
Temporary script for testing math export.
diff --git a/runtest.sh b/runtest.sh
new file mode 100644
index 0000000..45ac23e
--- /dev/null
+++ b/runtest.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+/cvs/lyx/lyx-devel/build/bin/lyx2.4 -E pdflatex /cvs/lyx/lyx-devel/Math-Cleanup.tex lib/doc/Math.lyx
+if diff -q Math-Master.tex Math-Cleanup.tex; then
+ echo "No differences in LaTeX output!";
+else
+ echo "Differences in LaTeX output! Enter to see them....";
+ pause
+ diff -u Math-Master.tex Math-Cleanup.tex
+fi
commit 4a90913bf7ef08e49f5288ee34461eef2d0c7b1e
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Thu Nov 12 16:16:15 2020 -0500
Start moving updateMacros code into the insets.
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 859f9ce..c0a133f 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3855,6 +3855,37 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
}
+void Buffer::setMacroLock() const
+{
+ d->macro_lock = true;
+}
+
+
+void Buffer::clearMacroLock() const
+{
+ d->macro_lock = false;
+}
+
+
+void Buffer::registerChild(Buffer * child,
+ DocIterator const & pos, DocIterator const & scope) const
+{
+ // register its position, but only when it is
+ // included first in the buffer
+ d->children_positions.insert({child, pos});
+ // register child with its scope
+ d->position_to_children[pos] = Impl::ScopeBuffer(scope, child);
+}
+
+
+void Buffer::registerMacro(docstring const & name, DocIterator const & pos,
+ DocIterator const & scope)
+{
+ d->macro_table.addMacroDefinition(name, pos, scope,
+ MacroData(const_cast<Buffer *>(this), pos));
+}
+
+
void Buffer::updateMacros() const
{
if (d->macro_lock)
diff --git a/src/Buffer.h b/src/Buffer.h
index c8946d6..267bf94 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -597,6 +597,10 @@ public:
//
// Macro handling
//
+ ///
+ void setMacroLock() const;
+ ///
+ void clearMacroLock() const;
/// Collect macro definitions in paragraphs
void updateMacros() const;
/// Iterate through the whole buffer and try to resolve macros
@@ -614,10 +618,18 @@ public:
/// Return macro defined before the inclusion of the child
MacroData const * getMacro(docstring const & name, Buffer const & child, bool global = true) const;
+ ///
+ void registerMacro(docstring const & name, DocIterator const & pos,
+ DocIterator const & scope);
+
/// Collect user macro names at loading time
typedef std::set<docstring> UserMacroSet;
mutable UserMacroSet usermacros;
+ ///
+ void registerChild(Buffer * child,
+ DocIterator const & pos, DocIterator const & scope) const;
+
/// Replace the inset contents for insets which InsetCode is equal
/// to the passed \p inset_code. Handles undo.
void changeRefsIfUnique(docstring const & from, docstring const & to);
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index ec223fa..a947499 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -56,6 +56,13 @@
#include "frontends/alert.h"
#include "frontends/Painter.h"
+// These are only temporarily here, until the relevant code
+// is moved into these insets
+#include "insets/InsetInclude.h"
+#include "mathed/InsetMathHull.h"
+#include "mathed/MacroTable.h"
+#include "mathed/InsetMathMacroTemplate.h"
+
#include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
@@ -902,6 +909,98 @@ void InsetText::updateBuffer(ParIterator const & it, UpdateType utype, bool cons
}
+void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
+{
+ LBUFERR(us.nextInset() == this);
+ DocIterator it = us;
+ pit_type const lastpit = it.lastpit();
+
+ // look for macros in each paragraph
+ while (it.pit() <= lastpit) {
+ Paragraph & par = it.paragraph();
+
+ // iterate over the insets of the current paragraph
+ for (auto const & insit : par.insetList()) {
+ it.pos() = insit.pos;
+
+ if (InsetText const * itext = insit.inset->asInsetText()) {
+ // collect macros in inset
+ it.push_back(CursorSlice(*insit.inset));
+ if (itext->producesOutput()) {
+ // the simple case
+ updateMacros(it, scope);
+ } else {
+ // We don't want macros declared in notes, comments, etc,
+ // to affect anything outside them.
+ // New scope which ends just behind the inset
+ DocIterator new_scope = it;
+ ++new_scope.pos();
+ updateMacros(it, new_scope);
+ }
+ it.pop_back();
+ continue;
+ }
+
+ if (insit.inset->asInsetTabular()) {
+ CursorSlice slice(*insit.inset);
+ size_t const numcells = slice.nargs();
+ for (; slice.idx() < numcells; slice.forwardIdx()) {
+ it.push_back(slice);
+ updateMacros(it, scope);
+ it.pop_back();
+ }
+ continue;
+ }
+
+ // is it an external file?
+ if (insit.inset->lyxCode() == INCLUDE_CODE) {
+ // get buffer of external file
+ InsetInclude const & incinset =
+ static_cast<InsetInclude const &>(*insit.inset);
+ buffer().setMacroLock();
+ Buffer * child = incinset.loadIfNeeded();
+ buffer().clearMacroLock();
+ if (!child)
+ continue;
+ buffer().registerChild(child, it, scope);
+ continue;
+ }
+
+ InsetMath * im = insit.inset->asInsetMath();
+ if (im) {
+ InsetMathHull * hull = im->asHullInset();
+ if (hull)
+ hull->recordLocation(it);
+ }
+
+ if (insit.inset->lyxCode() != MATHMACRO_CODE)
+ continue;
+
+ // get macro data
+ InsetMathMacroTemplate & macroTemplate =
+ *insit.inset->asInsetMath()->asMacroTemplate();
+ MacroContext mc(&buffer(), it);
+ macroTemplate.updateToContext(mc);
+
+ // valid?
+ bool valid = macroTemplate.validMacro();
+ // FIXME: Should be fixNameAndCheckIfValid() in fact,
+ // then the BufferView's cursor will be invalid in
+ // some cases which leads to crashes.
+ if (!valid)
+ continue;
+
+ // register macro
+ buffer().registerMacro(macroTemplate.name(), it, scope);
+ }
+
+ // next paragraph
+ it.pit()++;
+ it.pos() = 0;
+ }
+}
+
+
void InsetText::toString(odocstream & os) const
{
os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index cefd44c..9fdfb6f 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -173,6 +173,8 @@ public:
/// Update the counters of this inset and of its contents
void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
///
+ void updateMacros(DocIterator const & us, DocIterator const & scope);
+ ///
void setMacrocontextPositionRecursive(DocIterator const & pos);
///
void toString(odocstream &) const override;
-----------------------------------------------------------------------
Summary of changes:
runtest.sh | 10 ++++++++
src/Buffer.cpp | 31 ++++++++++++++++++++++++++
src/Buffer.h | 12 ++++++++++
src/insets/Inset.h | 3 ++
src/insets/InsetInclude.cpp | 10 ++++++++
src/insets/InsetInclude.h | 2 +
src/insets/InsetTabular.cpp | 13 +++++++++++
src/insets/InsetTabular.h | 2 +
src/insets/InsetText.cpp | 38 ++++++++++++++++++++++++++++++++-
src/insets/InsetText.h | 2 +
src/mathed/InsetMathHull.cpp | 7 ++++++
src/mathed/InsetMathHull.h | 2 +
src/mathed/InsetMathMacroTemplate.cpp | 25 +++++++++++++++++++--
src/mathed/InsetMathMacroTemplate.h | 2 +
14 files changed, 155 insertions(+), 4 deletions(-)
create mode 100644 runtest.sh
hooks/post-receive
--
Repository for new features
More information about the lyx-cvs
mailing list