The branch, cleanup/updateMacros3, has been updated.
  discards  7bd31f68133a6a22251ce9524ff345edefaf9081 (commit)
  discards  1be4f14958484f26f4c2a0af2169ae4cc5ee894c (commit)
  discards  dec071d1c616fa8da02e01952f059cad7defa594 (commit)
  discards  1af03ec53c5c770c81769b9be08e2608c06814dc (commit)
  discards  8f206260326e536a9ba1676b1390914b1bae85b9 (commit)
  discards  dae691e319adabbaa3d47957b0a6c725b7f6126f (commit)
  discards  a5b0f8a4c62a6722d9c5934a9a9f3f5dd79c4c4f (commit)
  discards  cb89b7bf05bc37e7c3212b1eb624b994482137f5 (commit)
  discards  c3e83d6dac3f646439cec99ba18a782eeb4ea0bb (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (7bd31f68133a6a22251ce9524ff345edefaf9081)
            \
             N -- N -- N (28366c68086a54544076d619d4c9c2343bbee230)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

- Log -----------------------------------------------------------------

commit 28366c68086a54544076d619d4c9c2343bbee230
Author: Richard Kimberly Heck <[email protected]>
Date:   Wed Nov 11 11:58:30 2020 -0500

    MacroScope --> MacroDefinition

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index e6d1c91..e50fd5c 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -200,9 +200,9 @@ public:
        mutable TocBackend toc_backend;
 
        /// macro tables
-       struct ScopeMacro {
-               ScopeMacro() {}
-               ScopeMacro(DocIterator const & s, MacroData const & m)
+       struct MacroDefinition {
+               MacroDefinition() {}
+               MacroDefinition(DocIterator const & s, MacroData const & m)
                        : scope(s), macro(m) {}
                // The SCOPE is really just the last position at which the macro
                // is in force. This will be the end of the file (if there are 
no
@@ -211,7 +211,7 @@ public:
                DocIterator scope;
                MacroData macro;
        };
-       typedef map<DocIterator, ScopeMacro> PositionScopeMacroMap;
+       typedef map<DocIterator, MacroDefinition> PositionScopeMacroMap;
        typedef map<docstring, PositionScopeMacroMap> MacroMap;
        /// map from the macro name to the position map,
        /// which maps the macro definition position to the scope and the 
MacroData.
@@ -3811,7 +3811,7 @@ void Buffer::Impl::updateMacros(DocIterator & it, 
DocIterator & scope)
                        // FIXME (Abdel), I don't understand why we pass 'it' 
here
                        // instead of 'macroTemplate' defined above... is this 
correct?
                        macros[macroTemplate.name()][it] =
-                               Impl::ScopeMacro(scope, 
MacroData(const_cast<Buffer *>(owner_), it));
+                               Impl::MacroDefinition(scope, 
MacroData(const_cast<Buffer *>(owner_), it));
                }
 
                // next paragraph

commit 27a4f5a486032e4e53dfa4df86e7fa5ccfdcce28
Author: Richard Kimberly Heck <[email protected]>
Date:   Wed Nov 11 11:57:05 2020 -0500

    Renaming

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index cf341d5..e6d1c91 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -1971,7 +1971,7 @@ Buffer::ExportStatus Buffer::writeLaTeXSource(otexstream 
& os,
 
                // get parent macros (if this buffer has a parent) which will be
                // written at the document begin further down.
-               MacroSet parentMacros;
+               MacroDataSet parentMacros;
                listParentMacros(parentMacros, features);
 
                // Write the preamble
@@ -3938,7 +3938,7 @@ void Buffer::listMacroNames(MacroNameSet & macros) const
 }
 
 
-void Buffer::listParentMacros(MacroSet & macros, LaTeXFeatures & features) 
const
+void Buffer::listParentMacros(MacroDataSet & macros, LaTeXFeatures & features) 
const
 {
        Buffer const * const pbuf = d->parent();
        if (!pbuf)
diff --git a/src/Buffer.h b/src/Buffer.h
index 2dbc16c..c8946d6 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -45,7 +45,7 @@ class LaTeXFeatures;
 class Language;
 class MacroData;
 class MacroNameSet;
-class MacroSet;
+class MacroDataSet;
 class OutputParams;
 class otexstream;
 class ParagraphList;
@@ -605,7 +605,7 @@ public:
        /// List macro names of this buffer, the parent and the children
        void listMacroNames(MacroNameSet & macros) const;
        /// Collect macros of the parent and its children in front of this 
buffer.
-       void listParentMacros(MacroSet & macros, LaTeXFeatures & features) 
const;
+       void listParentMacros(MacroDataSet & macros, LaTeXFeatures & features) 
const;
 
        /// Return macro defined before pos (or in the master buffer)
        MacroData const * getMacro(docstring const & name, DocIterator const & 
pos, bool global = true) const;
diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h
index 0d5e4a2..c0e3aa6 100644
--- a/src/mathed/MacroTable.h
+++ b/src/mathed/MacroTable.h
@@ -158,7 +158,7 @@ private:
 ///
 class MacroNameSet : public std::set<docstring> {};
 ///
-class MacroSet : public std::set<MacroData const *> {};
+class MacroDataSet : public std::set<MacroData const *> {};
 
 
 /// A lookup table of macro definitions.

commit 03bf9eb619872200aa977f0ab93add8e93a4c2d4
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon Nov 9 17:29:27 2020 -0500

    Renaming

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 1183842..cf341d5 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3690,7 +3690,7 @@ MacroData const * Buffer::getMacro(docstring const & name,
        }
 
        if (global) {
-               data = MacroTable::get().getMacro(name);
+               data = GlobalMacros::get().getMacro(name);
                if (data != nullptr)
                        return data;
        }
diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index 600562f..c051c8e 100644
--- a/src/mathed/InsetMathMacro.cpp
+++ b/src/mathed/InsetMathMacro.cpp
@@ -938,7 +938,7 @@ MacroData const * InsetMathMacro::macroBackup() const
 {
        if (macro())
                return &d->macroBackup_;
-       if (MacroData const * data = MacroTable::get().getMacro(name()))
+       if (MacroData const * data = GlobalMacros::get().getMacro(name()))
                return data;
        return nullptr;
 }
@@ -957,7 +957,7 @@ void InsetMathMacro::validate(LaTeXFeatures & features) 
const
                features.require(d->required_);
        else if (!d->macro_) {
                // Update requires for known global macros.
-               MacroData const * data = MacroTable::get().getMacro(name());
+               MacroData const * data = GlobalMacros::get().getMacro(name());
                if (data && !data->required().empty())
                        features.require(data->required());
        }
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 19aa745..ee4cf77 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -2106,7 +2106,7 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
 
        // fill in global macros
        macros.clear();
-       MacroTable::get().getMacroNames(macros, false);
+       GlobalMacros::get().getMacroNames(macros, false);
        //lyxerr << "Globals completion macros: ";
        for (it = macros.begin(); it != macros.end(); ++it) {
                //lyxerr << "\\" + *it << " ";
diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp
index 2bc427b..e6daac6 100644
--- a/src/mathed/MacroTable.cpp
+++ b/src/mathed/MacroTable.cpp
@@ -215,22 +215,22 @@ int MacroData::write(odocstream & os, bool 
overwriteRedefinition) const
 //
 /////////////////////////////////////////////////////////////////////
 
-MacroTable & MacroTable::get()
+GlobalMacros & GlobalMacros::get()
 {
-       static MacroTable theGlobalMacros;
+       static GlobalMacros theGlobalMacros;
        return theGlobalMacros;
 }
 
 
-MacroData const * MacroTable::getMacro(docstring const & name) const
+MacroData const * GlobalMacros::getMacro(docstring const & name) const
 {
        const_iterator it = find(name);
        return it == end() ? 0 : &it->second;
 }
 
 
-MacroTable::iterator
-MacroTable::insert(docstring const & name, MacroData const & data)
+GlobalMacros::iterator
+GlobalMacros::insert(docstring const & name, MacroData const & data)
 {
        //lyxerr << "MacroTable::insert: " << to_utf8(name) << endl;
        iterator it = find(name);
@@ -243,8 +243,8 @@ MacroTable::insert(docstring const & name, MacroData const 
& data)
 }
 
 
-MacroTable::iterator
-MacroTable::insert(Buffer * buf, docstring const & definition)
+GlobalMacros::iterator
+GlobalMacros::insert(Buffer * buf, docstring const & definition)
 {
        //lyxerr << "MacroTable::insert, def: " << to_utf8(def) << endl;
        InsetMathMacroTemplate mac(buf);
@@ -254,7 +254,7 @@ MacroTable::insert(Buffer * buf, docstring const & 
definition)
 }
 
 
-void MacroTable::getMacroNames(std::set<docstring> & names, bool gethidden) 
const
+void GlobalMacros::getMacroNames(std::set<docstring> & names, bool gethidden) 
const
 {
        for (const_iterator it = begin(); it != end(); ++it)
                if (gethidden || !it->second.hidden())
@@ -262,7 +262,7 @@ void MacroTable::getMacroNames(std::set<docstring> & names, 
bool gethidden) cons
 }
 
 
-void MacroTable::dump()
+void GlobalMacros::dump()
 {
        lyxerr << "\n------------------------------------------" << endl;
        for (const_iterator it = begin(); it != end(); ++it)
diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h
index a6996da..0d5e4a2 100644
--- a/src/mathed/MacroTable.h
+++ b/src/mathed/MacroTable.h
@@ -168,15 +168,15 @@ class MacroSet : public std::set<MacroData const *> {};
  * hack to display certain contents nicely.
  *
  **/
-class MacroTable : public std::map<docstring, MacroData>
+class GlobalMacros : public std::map<docstring, MacroData>
 {
 public:
        /// We are a singleton
-       MacroTable() = default;
-       MacroTable(MacroTable const &) = delete;
-       void operator=(MacroTable const &) = delete;
+       GlobalMacros() = default;
+       GlobalMacros(GlobalMacros const &) = delete;
+       void operator=(GlobalMacros const &) = delete;
        /// the global list: our unique instance
-       static MacroTable & get();
+       static GlobalMacros & get();
        /// Parse full "\\def..." or "\\newcommand..." or ...
        iterator insert(Buffer * buf, docstring const & definition);
        /// Insert pre-digested macro definition
diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp
index f956973..49baa5d 100644
--- a/src/mathed/MathFactory.cpp
+++ b/src/mathed/MathFactory.cpp
@@ -202,7 +202,7 @@ void initSymbols()
                                        required = "";
                        } else
                                htmlname = xmlname = "";
-                       MacroTable::iterator it = MacroTable::get().insert(
+                       GlobalMacros::iterator it = GlobalMacros::get().insert(
                                        0, from_utf8(macro));
                        if (!extra.empty() || !htmlname.empty() || 
!xmlname.empty() || !required.empty()) {
                                MathWordList::iterator wit = 
theMathWordList.find(it->first);

commit 51ea1be83dfca904054625ced88ce5a2f59ce32f
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon Nov 9 17:27:57 2020 -0500

    Some comments, and some conditional code to dump the macro table.
    
    (cherry picked from commit 30415c80f7934580ce2e1fdf0b5f84b5faeba9da)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 3d2729c..1183842 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -204,17 +204,21 @@ public:
                ScopeMacro() {}
                ScopeMacro(DocIterator const & s, MacroData const & m)
                        : scope(s), macro(m) {}
+               // The SCOPE is really just the last position at which the macro
+               // is in force. This will be the end of the file (if there are 
no
+               // children) unless it is in (say) a note, or an inactive 
branch,
+               // in which case it will be the end of that construct.
                DocIterator scope;
                MacroData macro;
        };
        typedef map<DocIterator, ScopeMacro> PositionScopeMacroMap;
-       typedef map<docstring, PositionScopeMacroMap> NamePositionScopeMacroMap;
+       typedef map<docstring, PositionScopeMacroMap> MacroMap;
        /// map from the macro name to the position map,
        /// which maps the macro definition position to the scope and the 
MacroData.
-       NamePositionScopeMacroMap macros;
+       MacroMap macros;
 
        /// Each child Buffer is listed in this map, together with where
-       /// it is included in this Buffer.
+       /// it is first included in this Buffer.
        typedef map<Buffer const * const, DocIterator> BufferPositionMap;
        BufferPositionMap children_positions;
        /// We also have a map from the positions where Buffers are included
@@ -3599,9 +3603,9 @@ MacroData const * Buffer::Impl::getBufferMacro(docstring 
const & name,
        MacroData const * bestData = nullptr;
 
        // find macro definitions for name
-       NamePositionScopeMacroMap::const_iterator nameIt = macros.find(name);
+       MacroMap::const_iterator nameIt = macros.find(name);
        if (nameIt != macros.end()) {
-               // find last definition in front of pos or at pos itself
+               // find last definition in front of pos
                PositionScopeMacroMap::const_iterator it
                        = greatest_below(nameIt->second, pos);
                if (it != nameIt->second.end()) {
@@ -3821,9 +3825,22 @@ void Buffer::updateMacros() const
 {
        if (d->macro_lock)
                return;
-
+#if 0
+       LYXERR0("Starting macro dump");
+       for (auto const & m : d->macros) {
+               LYXERR0(m.first);
+               for (auto const & m1 : m.second) {
+                       LYXERR0(m1.first);
+                       LYXERR0("Scope: " << m1.second.scope);
+                       LYXERR0("Def: " << m1.second.macro.definition());
+                       LYXERR0("");
+               }
+       }
+       LYXERR0("Ending macro dump");
+       LYXERR0("");
        LYXERR(Debug::MACROS, "updateMacro of " << d->filename.onlyFileName());
-
+#endif
+       
        // start with empty table
        d->macros.clear();
        d->children_positions.clear();

commit a9fc72242ff85f6030c8ad1637d70308d54cbcb3
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon Nov 9 16:59:04 2020 -0500

    More comments and minor code cleanup

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 7e72619..3d2729c 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -220,7 +220,10 @@ public:
        /// We also have a map from the positions where Buffers are included
        /// to those Buffers and their scope (whose point RKH does not yet 
        /// understand).
-       // FIXME Surely one of these is enough?
+       // FIXME Surely one of these is enough? The difference is that
+       // children_positions has one entry for each child Buffer, whereas
+       // position_to_children has one entry for each InsetInclude (and the
+       // same Buffer could be included twice).
        struct ScopeBuffer {
                ScopeBuffer() = default;
                ScopeBuffer(DocIterator const & s, Buffer const * b)
@@ -614,6 +617,10 @@ void Buffer::cloneWithChildren(BufferMap & bufmap, 
CloneList_ptr clones) const
                return;
 
        Buffer * buffer_clone = new Buffer(fileName().absFileName(), false, 
this);
+       if (!buffer_clone) {
+               LYXERR0("Buffer creation failed!");
+               LBUFERR(false);
+       }
 
        // The clone needs its own DocumentClass, since running updateBuffer() 
will
        // modify it, and we would otherwise be sharing it with the original 
Buffer.
@@ -629,27 +636,32 @@ void Buffer::cloneWithChildren(BufferMap & bufmap, 
CloneList_ptr clones) const
        buffer_clone->d->macro_lock = true;
        buffer_clone->d->children_positions.clear();
 
-       // FIXME (Abdel 09/01/2010): this is too complicated. The whole 
children_positions and
-       // math macro caches need to be rethought and simplified.
-       // I am not sure wether we should handle Buffer cloning here or in 
BufferList.
-       // Right now BufferList knows nothing about buffer clones.
+       // clone the children and update the information in the InsetIncludes
        for (auto const & p : d->position_to_children) {
-               DocIterator dit = p.first.clone(buffer_clone);
+               // location of child in old Buffer
+               DocIterator const & olddit = p.first;
+               // a DocIterator that points to the same location in this new 
Buffer
+               DocIterator dit = olddit.clone(buffer_clone);
                dit.setBuffer(buffer_clone);
+               // the child in the old Buffer
                Buffer * child = const_cast<Buffer *>(p.second.buffer);
-
+               // clone the child
                child->cloneWithChildren(bufmap, clones);
+               // we now need to find the child we just created (or the 
previously
+               // created one, if it was already cloned).
                BufferMap::iterator const bit = bufmap.find(child);
                LASSERT(bit != bufmap.end(), continue);
                Buffer * child_clone = bit->second;
 
+               // the Buffer for this include inset is now the cloned child
                Inset * inset = dit.nextInset();
                LASSERT(inset && inset->lyxCode() == INCLUDE_CODE, continue);
                InsetInclude * inset_inc = static_cast<InsetInclude *>(inset);
                inset_inc->setChildBuffer(child_clone);
+               // set us as its parent
                child_clone->d->setParent(buffer_clone);
                // FIXME Do we need to do this now, or can we wait until we run 
updateMacros()?
-               buffer_clone->setChild(dit, child_clone);
+               d->children_positions[child_clone] = dit;
        }
        buffer_clone->d->macro_lock = false;
 }
@@ -795,12 +807,6 @@ Undo & Buffer::undo()
 }
 
 
-void Buffer::setChild(DocIterator const & dit, Buffer * child)
-{
-       d->children_positions[child] = dit;
-}
-
-
 string Buffer::latexName(bool const no_path) const
 {
        FileName latex_name =
diff --git a/src/Buffer.h b/src/Buffer.h
index a917c6e..2dbc16c 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -223,7 +223,7 @@ public:
        double fontScalingFactor() const;
 
 private:
-       ///
+       /// map from Buffers to their clones
        typedef std::map<Buffer const *, Buffer *> BufferMap;
        ///
        void cloneWithChildren(BufferMap &, CloneList_ptr) const;
@@ -648,8 +648,6 @@ public:
        /// This function is called when the buffer is changed.
        void changed(bool update_metrics) const;
        ///
-       void setChild(DocIterator const & dit, Buffer * child);
-       ///
        void updateTocItem(std::string const &, DocIterator const &) const;
        /// This function is called when the buffer structure is changed.
        void structureChanged() const;

commit 65d92093285cf06c7d7bfc8c6a0ded687aa42ce6
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon Nov 9 16:37:18 2020 -0500

    Surely we do not need to clear objects that are about to be destroyed
    
    (cherry picked from commit efe55ba6a700ed9eec836d9bc23fd5756cfdcd47)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index bcba8d2..7e72619 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -557,10 +557,6 @@ Buffer::~Buffer()
                        } else
                                cloned_buffers.erase(it);
                }
-               // FIXME Do we really need to do this right before we delete d?
-               // clear references to children in macro tables
-               d->children_positions.clear();
-               d->position_to_children.clear();
        } else {
                // loop over children
                for (auto const & p : d->children_positions) {
@@ -583,11 +579,6 @@ Buffer::~Buffer()
                        Alert::warning(_("Attempting to close changed 
document!"), msg);
                }
 
-               // FIXME Do we really need to do this right before we delete d?
-               // clear references to children in macro tables
-               d->children_positions.clear();
-               d->position_to_children.clear();
-
                if (!d->temppath.destroyDirectory()) {
                        LYXERR0(bformat(_("Could not remove the temporary 
directory %1$s"),
                                from_utf8(d->temppath.absFileName())));

commit e53ef4d3667007e07caecee04dcb45715f45b200
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon Nov 9 16:36:20 2020 -0500

    More comments and minor cleanup

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 5379d9f..bcba8d2 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -213,18 +213,21 @@ public:
        /// which maps the macro definition position to the scope and the 
MacroData.
        NamePositionScopeMacroMap macros;
 
-       /// positions of child buffers in the buffer
+       /// Each child Buffer is listed in this map, together with where
+       /// it is included in this Buffer.
+       typedef map<Buffer const * const, DocIterator> BufferPositionMap;
+       BufferPositionMap children_positions;
+       /// We also have a map from the positions where Buffers are included
+       /// to those Buffers and their scope (whose point RKH does not yet 
+       /// understand).
+       // FIXME Surely one of these is enough?
        struct ScopeBuffer {
-               ScopeBuffer() : buffer(nullptr) {}
+               ScopeBuffer() = default;
                ScopeBuffer(DocIterator const & s, Buffer const * b)
                        : scope(s), buffer(b) {}
                DocIterator scope;
                Buffer const * buffer;
        };
-       /// position of children buffers in this buffer
-       typedef map<Buffer const * const, DocIterator> BufferPositionMap;
-       BufferPositionMap children_positions;
-       /// map from children inclusion positions to their scope and their 
buffer
        typedef map<DocIterator, ScopeBuffer> PositionScopeBufferMap;
        PositionScopeBufferMap position_to_children;
 
@@ -5461,9 +5464,9 @@ bool Buffer::saveAs(FileName const & fn)
 
 void Buffer::checkChildBuffers()
 {
-       for (auto const & bit : d->children_positions) {
-               DocIterator dit = bit.second;
-               Buffer * cbuf = const_cast<Buffer *>(bit.first);
+       for (auto const & kid : d->children_positions) {
+               DocIterator const & dit = kid.second;
+               Buffer * cbuf = const_cast<Buffer *>(kid.first);
                if (!cbuf || !theBufferList().isLoaded(cbuf))
                        continue;
                Inset * inset = dit.nextInset();
@@ -5475,7 +5478,9 @@ void Buffer::checkChildBuffers()
                                onlyPath(absFileName())).absFileName();
                if (oldloc == newloc)
                        continue;
-               // the location of the child file is incorrect.
+               // the location of the child file is incorrect. e.g., it
+               // had a relative path which does not now point to the correct
+               // file (after saveAs, usually).
                cbuf->setParent(nullptr);
                inset_inc->setChildBuffer(nullptr);
        }

commit 163c1d010d3bce6971ca89652d888c0b518a8be2
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon Nov 9 15:56:01 2020 -0500

    Some comments and some minor re-organization

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 1416970..5379d9f 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -214,7 +214,6 @@ public:
        NamePositionScopeMacroMap macros;
 
        /// positions of child buffers in the buffer
-       typedef map<Buffer const * const, DocIterator> BufferPositionMap;
        struct ScopeBuffer {
                ScopeBuffer() : buffer(nullptr) {}
                ScopeBuffer(DocIterator const & s, Buffer const * b)
@@ -222,10 +221,11 @@ public:
                DocIterator scope;
                Buffer const * buffer;
        };
-       typedef map<DocIterator, ScopeBuffer> PositionScopeBufferMap;
        /// position of children buffers in this buffer
+       typedef map<Buffer const * const, DocIterator> BufferPositionMap;
        BufferPositionMap children_positions;
        /// map from children inclusion positions to their scope and their 
buffer
+       typedef map<DocIterator, ScopeBuffer> PositionScopeBufferMap;
        PositionScopeBufferMap position_to_children;
 
        /// Contains the old buffer filePath() while saving-as, or the
diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h
index ab3c6b4..a6996da 100644
--- a/src/mathed/MacroTable.h
+++ b/src/mathed/MacroTable.h
@@ -112,6 +112,10 @@ private:
        void updateData() const;
        ///
        Buffer const * buffer_;
+       // FIXME This is probably a large part of why updateMacros is 
+       // so expensive. We are, it would seem, recreating these objects
+       // from scratch each time through. That seems unnecessary, if what
+       // usually needs updating is just the pos_ member.
        /// 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
@@ -121,13 +125,20 @@ private:
        /// returns its defaults values and the user sees unfolded
        /// macros.
        mutable DocIterator pos_;
-       ///
+       /// flag that tells us whether our cached info is valid. used
+       /// with lazy version.
        mutable bool queried_ = false;
-       ///
+       // At the moment, it seems to me as if most of the other members
+       // could be replaced by a pointer to the associated macro (and so
+       // that one eliminated. I.e.:
+       //    InsetMathMacroTemplate const * const ourmacro_;
+       //    docstring definition() { return ourmacro_->definition(); }
+       // etc.
+       /// the macro definition
        mutable docstring definition_;
        ///
        mutable size_t numargs_ = 0;
-       ///
+       /// what we use (a kind of LyX macro) for display in the work area
        mutable docstring display_;
        ///
        latexkeys const * sym_ = nullptr;

commit 1ff570f37e295975a6d92d8b7c3ac6c12943e4d6
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon Nov 9 15:39:20 2020 -0500

    Properly implement the singleton pattern

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 9562cb8..1416970 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3686,7 +3686,7 @@ MacroData const * Buffer::getMacro(docstring const & name,
        }
 
        if (global) {
-               data = MacroTable::globalMacros().get(name);
+               data = MacroTable::get().getMacro(name);
                if (data != nullptr)
                        return data;
        }
diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index 57294c0..600562f 100644
--- a/src/mathed/InsetMathMacro.cpp
+++ b/src/mathed/InsetMathMacro.cpp
@@ -938,7 +938,7 @@ MacroData const * InsetMathMacro::macroBackup() const
 {
        if (macro())
                return &d->macroBackup_;
-       if (MacroData const * data = MacroTable::globalMacros().get(name()))
+       if (MacroData const * data = MacroTable::get().getMacro(name()))
                return data;
        return nullptr;
 }
@@ -957,7 +957,7 @@ void InsetMathMacro::validate(LaTeXFeatures & features) 
const
                features.require(d->required_);
        else if (!d->macro_) {
                // Update requires for known global macros.
-               MacroData const * data = MacroTable::globalMacros().get(name());
+               MacroData const * data = MacroTable::get().getMacro(name());
                if (data && !data->required().empty())
                        features.require(data->required());
        }
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index ada0400..19aa745 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -2106,7 +2106,7 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
 
        // fill in global macros
        macros.clear();
-       MacroTable::globalMacros().getMacroNames(macros, false);
+       MacroTable::get().getMacroNames(macros, false);
        //lyxerr << "Globals completion macros: ";
        for (it = macros.begin(); it != macros.end(); ++it) {
                //lyxerr << "\\" + *it << " ";
diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp
index 218c849..2bc427b 100644
--- a/src/mathed/MacroTable.cpp
+++ b/src/mathed/MacroTable.cpp
@@ -215,14 +215,14 @@ int MacroData::write(odocstream & os, bool 
overwriteRedefinition) const
 //
 /////////////////////////////////////////////////////////////////////
 
-MacroTable & MacroTable::globalMacros()
+MacroTable & MacroTable::get()
 {
        static MacroTable theGlobalMacros;
        return theGlobalMacros;
 }
 
 
-MacroData const * MacroTable::get(docstring const & name) const
+MacroData const * MacroTable::getMacro(docstring const & name) const
 {
        const_iterator it = find(name);
        return it == end() ? 0 : &it->second;
diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h
index 77b306f..ab3c6b4 100644
--- a/src/mathed/MacroTable.h
+++ b/src/mathed/MacroTable.h
@@ -160,19 +160,22 @@ class MacroSet : public std::set<MacroData const *> {};
 class MacroTable : public std::map<docstring, MacroData>
 {
 public:
+       /// We are a singleton
+       MacroTable() = default;
+       MacroTable(MacroTable const &) = delete;
+       void operator=(MacroTable const &) = delete;
+       /// the global list: our unique instance
+       static MacroTable & get();
        /// Parse full "\\def..." or "\\newcommand..." or ...
        iterator insert(Buffer * buf, docstring const & definition);
        /// Insert pre-digested macro definition
        iterator insert(docstring const & name, MacroData const & data);
        ///
-       MacroData const * get(docstring const & name) const;
+       MacroData const * getMacro(docstring const & name) const;
        ///
        void dump();
        ///
        void getMacroNames(std::set<docstring> & names, bool gethidden) const;
-
-       /// the global list
-       static MacroTable & globalMacros();
 };
 
 
diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp
index 54fe012..f956973 100644
--- a/src/mathed/MathFactory.cpp
+++ b/src/mathed/MathFactory.cpp
@@ -202,7 +202,7 @@ void initSymbols()
                                        required = "";
                        } else
                                htmlname = xmlname = "";
-                       MacroTable::iterator it = 
MacroTable::globalMacros().insert(
+                       MacroTable::iterator it = MacroTable::get().insert(
                                        0, from_utf8(macro));
                        if (!extra.empty() || !htmlname.empty() || 
!xmlname.empty() || !required.empty()) {
                                MathWordList::iterator wit = 
theMathWordList.find(it->first);

commit 0e0c5c5d4c4109981e1ef4b3105c37bc1a97f17c
Author: Richard Kimberly Heck <[email protected]>
Date:   Fri Nov 6 11:41:20 2020 -0500

    The isMacroScope method is just !producesOutput (or should be).
    
    So remove that, and restructure the code a bit.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 23f6315..9562cb8 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3730,19 +3730,20 @@ void Buffer::Impl::updateMacros(DocIterator & it, 
DocIterator & scope)
                for (auto const & insit : par.insetList()) {
                        it.pos() = insit.pos;
 
-                       // is it a nested text inset?
-                       if (insit.inset->asInsetText()) {
-                               // Inset needs its own scope?
-                               InsetText const * itext = 
insit.inset->asInsetText();
-                               bool newScope = itext->isMacroScope();
-
-                               // scope which ends just behind the inset
-                               DocIterator insetScope = it;
-                               ++insetScope.pos();
-
+                       if (InsetText const * itext = 
insit.inset->asInsetText()) {
                                // collect macros in inset
                                it.push_back(CursorSlice(*insit.inset));
-                               updateMacros(it, newScope ? insetScope : scope);
+                               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;
                        }
diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp
index a70ff27..17e8007 100644
--- a/src/insets/InsetBranch.cpp
+++ b/src/insets/InsetBranch.cpp
@@ -381,13 +381,6 @@ string InsetBranch::contextMenuName() const
 }
 
 
-bool InsetBranch::isMacroScope() const
-{
-       // Its own scope if not selected by buffer
-       return !producesOutput();
-}
-
-
 string InsetBranch::params2string(InsetBranchParams const & params)
 {
        ostringstream data;
diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h
index 6106ce5..2746485 100644
--- a/src/insets/InsetBranch.h
+++ b/src/insets/InsetBranch.h
@@ -104,8 +104,6 @@ private:
        ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const 
override;
        ///
-       bool isMacroScope() const override;
-       ///
        docstring toolTip(BufferView const & bv, int x, int y) const override;
        ///
        bool usePlainLayout() const override { return false; }
diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp
index fa84c61..5717feb 100644
--- a/src/insets/InsetNote.cpp
+++ b/src/insets/InsetNote.cpp
@@ -198,16 +198,6 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const 
& cmd,
 }
 
 
-bool InsetNote::isMacroScope() const
-{
-       // LyX note has no latex output
-       if (params_.type == InsetNoteParams::Note)
-               return true;
-
-       return InsetCollapsible::isMacroScope();
-}
-
-
 void InsetNote::latex(otexstream & os, OutputParams const & runparams_in) const
 {
        if (params_.type == InsetNoteParams::Note)
diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h
index aeab8f0..b698505 100644
--- a/src/insets/InsetNote.h
+++ b/src/insets/InsetNote.h
@@ -79,8 +79,6 @@ private:
        /// show the note dialog
        bool showInsetDialog(BufferView * bv) const override;
        ///
-       bool isMacroScope() const override;
-       ///
        void latex(otexstream &, OutputParams const &) const override;
        ///
        int plaintext(odocstringstream & ods, OutputParams const & op,
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index d571806..cefd44c 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -156,8 +156,6 @@ public:
        ///
        bool allowSpellCheck() const override { return getLayout().spellcheck() 
&& !getLayout().isPassThru(); }
        ///
-       virtual bool isMacroScope() const { return false; }
-       ///
        bool allowMultiPar() const override { return getLayout().isMultiPar(); }
        ///
        bool isInTitle() const override { return intitle_context_; }

-----------------------------------------------------------------------

Summary of changes:
 src/Buffer.cpp |   41 +++++++++++++++++++++--------------------
 1 files changed, 21 insertions(+), 20 deletions(-)


hooks/post-receive
-- 
Repository for new features
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to