]> git.lyx.org Git - features.git/commitdiff
Redo the getMacroDefinitions routine.
authorRichard Kimberly Heck <rikiheck@lyx.org>
Thu, 12 Nov 2020 03:47:57 +0000 (22:47 -0500)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Thu, 12 Nov 2020 03:47:57 +0000 (22:47 -0500)
src/Buffer.cpp

index 19012643e0a8d01bce94aca8a1a9ef2c6f523b72..859f9ce4e386c66378c5c9a89c0670404a59fa01 100644 (file)
@@ -215,14 +215,15 @@ public:
                typedef map<DocIterator, MacroDefinition> MacroDefList;
                typedef map<docstring, MacroDefList> MacroMap;
 
-               pair<bool, MacroDefList const &> getMacroDefinitions(docstring const & name) const
+               bool haveMacro(docstring const & name) const
+                       { return macro_map_.count(name) != 0; }
+               
+               // Will assert if there is no such macro, so call haveMacro first!
+               MacroDefList const & getMacroDefinitions(docstring const & name) const
                {
                        MacroMap::const_iterator it = macro_map_.find(name);
-                       if (it == macro_map_.end()) {
-                               static MacroDefList dummy;
-                               return {false, dummy};
-                       }
-                       return {true, it->second};
+                       LBUFERR(it != macro_map_.end());
+                       return it->second;
                }
 
                set<docstring> getMacroNames() const
@@ -3634,10 +3635,9 @@ MacroData const * Buffer::Impl::getBufferMacro(docstring const & name,
        MacroData const * bestData = nullptr;
 
        // find macro definitions for name
-       pair<bool, MacroTable::MacroDefList const &> mdl_pair = 
-               macro_table.getMacroDefinitions(name);
-       if (mdl_pair.first) {
-               MacroTable::MacroDefList const & mdl = mdl_pair.second;
+       if (macro_table.haveMacro(name)) {
+               MacroTable::MacroDefList const & mdl = 
+                       macro_table.getMacroDefinitions(name);
                // find last definition in front of pos
                MacroTable::MacroDefList::const_iterator it = 
                                greatest_below(mdl, pos);
@@ -3748,8 +3748,10 @@ MacroData const * Buffer::getMacro(docstring const & name,
 {
        // look where the child buffer is included first
        Impl::BufferPositionMap::iterator it = d->children_positions.find(&child);
-       if (it == d->children_positions.end())
+       if (it == d->children_positions.end()) {
+               LYXERR0("Querying parent for macro when we are not a child!");
                return nullptr;
+       }
 
        // check for macros at the inclusion position
        return getMacro(name, it->second, global);