]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathMacro.cpp
Only set buffer if it is not null.
[lyx.git] / src / mathed / InsetMathMacro.cpp
index 15b5d29d9c1ef11f4a9ccaaa1d7b9890987d221c..f1a84cd57343da6d5b8c8b29a8e741bd62d4d546 100644 (file)
@@ -39,7 +39,7 @@
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
-#include "support/RefChanger.h"
+#include "support/Changer.h"
 #include "support/textutils.h"
 
 #include <ostream>
@@ -91,7 +91,7 @@ public:
                // macro arguments are in macros
                LATTEST(mathMacro_->nesting() > 0);
                /// The macro nesting can change display of insets. Change it locally.
-               Changer chg = make_change(mi.base.macro_nesting,
+               Changer chg = changeVar(mi.base.macro_nesting,
                                          mathMacro_->nesting() == 1 ? 0 : mathMacro_->nesting());
 
                MathRow::Element e_beg(mi, MathRow::BEGIN);
@@ -205,7 +205,7 @@ public:
                : name_(name), displayMode_(DISPLAY_INIT),
                  expanded_(buf), definition_(buf), attachedArgsNum_(0),
                  optionals_(0), nextFoldMode_(true), macroBackup_(buf),
-                 macro_(0), needsUpdate_(false), isUpdating_(false),
+                 macro_(nullptr), needsUpdate_(false), isUpdating_(false),
                  appetite_(9), nesting_(0), limits_(AUTO_LIMITS)
        {
        }
@@ -307,7 +307,11 @@ InsetMathMacro::InsetMathMacro(Buffer * buf, docstring const & name)
 InsetMathMacro::InsetMathMacro(InsetMathMacro const & that)
        : InsetMathNest(that), d(new Private(*that.d))
 {
-       setBuffer(*that.buffer_);
+       // FIXME This should not really be necessary, but when we are
+       // initializing the table of global macros, we create macros
+       // with no associated Buffer.
+       if (that.buffer_)
+               setBuffer(*that.buffer_);
        d->updateChildren(this);
 }
 
@@ -344,7 +348,7 @@ bool InsetMathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
                return InsetMath::addToMathRow(mrow, mi);
 
        /// The macro nesting can change display of insets. Change it locally.
-       Changer chg = make_change(mi.base.macro_nesting, d->nesting_);
+       Changer chg = changeVar(mi.base.macro_nesting, d->nesting_);
 
        MathRow::Element e_beg(mi, MathRow::BEGIN);
        e_beg.inset = this;
@@ -569,7 +573,7 @@ InsetMath::marker_type InsetMathMacro::marker(BufferView const * bv) const
 void InsetMathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        /// The macro nesting can change display of insets. Change it locally.
-       Changer chg = make_change(mi.base.macro_nesting, d->nesting_);
+       Changer chg = changeVar(mi.base.macro_nesting, d->nesting_);
 
        // set edit mode for which we will have calculated metrics. But only
        d->editing_[mi.base.bv] = editMode(mi.base.bv);
@@ -649,7 +653,7 @@ void InsetMathMacro::updateMacro(MacroContext const & mc)
                        d->needsUpdate_ = true;
                }
        } else {
-               d->macro_ = 0;
+               d->macro_ = nullptr;
        }
 }
 
@@ -684,7 +688,7 @@ void InsetMathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc,
        UpdateLocker locker(*this);
 
        // known macro?
-       if (d->macro_ == 0)
+       if (d->macro_ == nullptr)
                return;
 
        // remember nesting level of this macro
@@ -837,7 +841,7 @@ void InsetMathMacro::setDisplayMode(InsetMathMacro::DisplayMode mode, int appeti
 
 InsetMathMacro::DisplayMode InsetMathMacro::computeDisplayMode() const
 {
-       if (d->nextFoldMode_ == true && d->macro_ && !d->macro_->locked())
+       if (d->nextFoldMode_ && d->macro_ && !d->macro_->locked())
                return DISPLAY_NORMAL;
        else
                return DISPLAY_UNFOLDED;
@@ -859,10 +863,10 @@ bool InsetMathMacro::validName() const
 
        // valid characters?
        if (n.size() > 1) {
-               for (size_t i = 0; i<n.size(); ++i) {
-                       if (!(n[i] >= 'a' && n[i] <= 'z')
-                           && !(n[i] >= 'A' && n[i] <= 'Z')
-                           && n[i] != '*')
+               for (char_type c : n) {
+                       if (!(c >= 'a' && c <= 'z')
+                           && !(c >= 'A' && c <= 'Z')
+                           && c != '*')
                                return false;
                }
        }
@@ -1172,10 +1176,10 @@ void InsetMathMacro::write(WriteStream & os) const
                // contains macros with optionals.
                bool braced = false;
                size_type last = cell(i).size() - 1;
-               if (cell(i).size() && cell(i)[last]->asUnknownInset()) {
+               if (!cell(i).empty() && cell(i)[last]->asUnknownInset()) {
                        latexkeys const * l = in_word_set(cell(i)[last]->name());
                        braced = (l && l->inset == "big");
-               } else if (cell(i).size() && cell(i)[0]->asScriptInset()) {
+               } else if (!cell(i).empty() && cell(i)[0]->asScriptInset()) {
                        braced = cell(i)[0]->asScriptInset()->nuc().empty();
                } else {
                        for (size_type j = 0; j < cell(i).size(); ++j) {