Not all accessors did update the data previously. Therefore it could happen
that document export from the command line would output \newcommand, and from
GUI it would output \renewcommand for the same macro, simply because in the
GUI case the data was updated as a side effect of the GUI thread reading some
other member.
I also removed the mutable flag for requires_, since this member is always
set on construction and does not need any lazy update.
redefinition_(false), type_(MacroTypeNewcommand)
{}
redefinition_(false), type_(MacroTypeNewcommand)
{}
MacroData::MacroData(Buffer * buf, DocIterator const & pos)
: buffer_(buf), pos_(pos), queried_(false), numargs_(0),
optionals_(0), lockCount_(0), redefinition_(false),
type_(MacroTypeNewcommand)
{
}
MacroData::MacroData(Buffer * buf, DocIterator const & pos)
: buffer_(buf), pos_(pos), queried_(false), numargs_(0),
optionals_(0), lockCount_(0), redefinition_(false),
type_(MacroTypeNewcommand)
{
}
MacroData::MacroData(Buffer * buf, MathMacroTemplate const & macro)
: buffer_(buf), queried_(false), numargs_(0), optionals_(0), lockCount_(0),
redefinition_(false), type_(MacroTypeNewcommand)
MacroData::MacroData(Buffer * buf, MathMacroTemplate const & macro)
: buffer_(buf), queried_(false), numargs_(0), optionals_(0), lockCount_(0),
redefinition_(false), type_(MacroTypeNewcommand)
-vector<docstring> const & MacroData::defaults() const
+vector<docstring> const & MacroData::defaults() const
{
updateData();
return defaults_;
{
updateData();
return defaults_;
redefinition_ = macro.redefinition();
type_ = macro.type();
optionals_ = macro.numOptionals();
redefinition_ = macro.redefinition();
type_ = macro.type();
optionals_ = macro.numOptionals();
macro.getDefaults(defaults_);
}
macro.getDefaults(defaults_);
}
return;
LBUFERR(buffer_);
return;
LBUFERR(buffer_);
// Try to fix position DocIterator. Should not do anything in theory.
pos_.fixIfBroken();
// Try to fix position DocIterator. Should not do anything in theory.
pos_.fixIfBroken();
// find macro template
Inset * inset = pos_.nextInset();
if (inset == 0 || inset->lyxCode() != MATHMACRO_CODE) {
lyxerr << "BUG: No macro template found by MacroData" << endl;
return;
}
// find macro template
Inset * inset = pos_.nextInset();
if (inset == 0 || inset->lyxCode() != MATHMACRO_CODE) {
lyxerr << "BUG: No macro template found by MacroData" << endl;
return;
}
// query the data from the macro template
// query the data from the macro template
- queryData(static_cast<MathMacroTemplate const &>(*inset));
+ queryData(static_cast<MathMacroTemplate const &>(*inset));
int MacroData::write(odocstream & os, bool overwriteRedefinition) const
{
int MacroData::write(odocstream & os, bool overwriteRedefinition) const
{
lyxerr << "BUG: No macro template found by MacroData" << endl;
return 0;
}
lyxerr << "BUG: No macro template found by MacroData" << endl;
return 0;
}
// output template
MathMacroTemplate const & tmpl =
static_cast<MathMacroTemplate const &>(*inset);
// output template
MathMacroTemplate const & tmpl =
static_cast<MathMacroTemplate const &>(*inset);
MacroTypeNewcommandx,
MacroTypeDef
};
MacroTypeNewcommandx,
MacroTypeDef
};
///
class MacroData {
public:
///
class MacroData {
public:
///
std::vector<docstring> const & defaults() const;
///
///
std::vector<docstring> const & defaults() const;
///
- std::string const & requires() const { updateData(); return requires_; }
+ std::string const & requires() const { return requires_; }
- std::string & requires() { updateData(); return requires_; }
-
+ std::string & requires() { return requires_; }
+
/// lock while being drawn to avoid recursions
int lock() const { return ++lockCount_; }
/// is it being drawn?
bool locked() const { return lockCount_ != 0; }
///
void unlock() const;
/// lock while being drawn to avoid recursions
int lock() const { return ++lockCount_; }
/// is it being drawn?
bool locked() const { return lockCount_ != 0; }
///
void unlock() const;
-
- ///
- bool redefinition() const { return redefinition_; }
- ///
- void setRedefinition(bool redefined) { redefinition_ = redefined; }
- MacroType type() const { return type_; }
+ bool redefinition() const { updateData(); return redefinition_; }
+
- MacroType & type() { return type_; }
-
+ MacroType type() const { updateData(); return type_; }
+
/// output as TeX macro, only works for lazy MacroData!!!
int write(odocstream & os, bool overwriteRedefinition) const;
/// output as TeX macro, only works for lazy MacroData!!!
int write(odocstream & os, bool overwriteRedefinition) const;
bool operator==(MacroData const & x) const {
updateData();
x.updateData();
bool operator==(MacroData const & x) const {
updateData();
x.updateData();
- return definition_ == x.definition_
+ return definition_ == x.definition_
&& numargs_ == x.numargs_
&& display_ == x.display_
&& requires_ == x.requires_
&& numargs_ == x.numargs_
&& display_ == x.display_
&& requires_ == x.requires_
Buffer const * buffer_;
/// The position of the definition in the buffer.
/// There is no guarantee it stays valid if the buffer
Buffer const * buffer_;
/// The position of the definition in the buffer.
/// There is no guarantee it stays valid if the buffer
- /// changes. But it (normally) exists only until the
+ /// changes. But it (normally) exists only until the
/// next Buffer::updateMacros call where new MacroData
/// objects are created for each macro definition.
/// next Buffer::updateMacros call where new MacroData
/// objects are created for each macro definition.
- /// In the worst case, it is invalidated and the MacroData
+ /// In the worst case, it is invalidated and the MacroData
/// returns its defaults values and the user sees unfolded
/// macros.
mutable DocIterator pos_;
/// returns its defaults values and the user sees unfolded
/// macros.
mutable DocIterator pos_;
///
mutable docstring display_;
///
///
mutable docstring display_;
///
- mutable std::string requires_;
///
mutable size_t optionals_;
///
///
mutable size_t optionals_;
///
///
class MacroSet : public std::set<MacroData const *> {};
///
class MacroSet : public std::set<MacroData const *> {};
/// A lookup table of macro definitions.
/**
* This contains a table of "global" macros that are always accessible,
/// A lookup table of macro definitions.
/**
* This contains a table of "global" macros that are always accessible,
public:
/// construct context for the insets at pos
MacroContext(Buffer const * buf, DocIterator const & pos);
public:
/// construct context for the insets at pos
MacroContext(Buffer const * buf, DocIterator const & pos);
/// Lookup macro
MacroData const * get(docstring const & name) const;
/// Lookup macro
MacroData const * get(docstring const & name) const;
private:
///
Buffer const * buf_;
private:
///
Buffer const * buf_;