]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MacroTable.cpp
Fix bug 5802 (http://bugzilla.lyx.org/show_bug.cgi?id=5802)
[lyx.git] / src / mathed / MacroTable.cpp
index 188d3c0d89070ef362e3f1e72b9b86c14792e804..b2e50d119168f0d3698199faa22f68428779c6d4 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
 #include "InsetMathNest.h"
 
 #include "Buffer.h"
+#include "BufferList.h"
 #include "DocIterator.h"
 #include "InsetList.h"
 #include "Text.h"
 
 #include "support/debug.h"
-
-#include <boost/assert.hpp>
+#include "support/FileName.h"
+#include "support/lassert.h"
 
 #include <sstream>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
@@ -60,19 +62,27 @@ MacroData::MacroData(MathMacroTemplate const & macro)
          redefinition_(false), type_(MacroTypeNewcommand)
 {
        queryData(macro);
-}      
+}
 
 
 void MacroData::expand(vector<MathData> const & args, MathData & to) const
 {
        updateData();
 
-       InsetMathSqrt inset; // Hack. Any inset with a cell would do.
+       // Hack. Any inset with a cell would do.
+       static Buffer * buffer = 0;
+       if (!buffer) {
+               buffer = theBufferList().newBuffer(
+               FileName::tempName().absFilename() + "_macrodata.internal");
+               buffer->setUnnamed(true);
+       }
+       static InsetMathSqrt inset;
+
        // FIXME UNICODE
        asArray(display_.empty() ? definition_ : display_, inset.cell(0));
        //lyxerr << "MathData::expand: args: " << args << endl;
        //lyxerr << "MathData::expand: ar: " << inset.cell(0) << endl;
-       for (DocIterator it = doc_iterator_begin(inset); it; it.forwardChar()) {
+       for (DocIterator it = doc_iterator_begin(buffer, &inset); it; it.forwardChar()) {
                if (!it.nextInset())
                        continue;
                if (it.nextInset()->lyxCode() != MATHMACROARG_CODE)
@@ -107,7 +117,7 @@ vector<docstring> const &  MacroData::defaults() const
 void MacroData::unlock() const
 {
        --lockCount_;
-       BOOST_ASSERT(lockCount_ >= 0);
+       LASSERT(lockCount_ >= 0, /**/);
 }
 
 
@@ -123,7 +133,8 @@ void MacroData::queryData(MathMacroTemplate const & macro) const
        redefinition_ = macro.redefinition();
        type_ = macro.type();
        optionals_ = macro.numOptionals();
-       macro.getDefaults(defaults_);   
+       
+       macro.getDefaults(defaults_);
 }
 
 
@@ -132,7 +143,7 @@ void MacroData::updateData() const
        if (queried_)
                return;
 
-       BOOST_ASSERT(buffer_ != 0);
+       LASSERT(buffer_ != 0, /**/);
        
        // Try to fix position DocIterator. Should not do anything in theory.
        pos_.fixIfBroken();
@@ -161,9 +172,9 @@ void MacroData::write(odocstream & os, bool overwriteRedefinition) const
        }
                
        // output template
-       MathMacroTemplate const & tmpl 
-       = static_cast<MathMacroTemplate const &>(*inset);
-       WriteStream wi(os, false, true);
+       MathMacroTemplate const & tmpl =
+               static_cast<MathMacroTemplate const &>(*inset);
+       WriteStream wi(os, false, true, false);
        tmpl.write(wi, overwriteRedefinition);
 }
 
@@ -205,6 +216,13 @@ void MacroTable::insert(docstring const & def, string const & requires)
 }
 
 
+void MacroTable::getMacroNames(std::set<docstring> & names) const
+{
+       for (const_iterator it = begin(); it != end(); ++it)
+               names.insert(it->first);
+}
+
+
 void MacroTable::dump()
 {
        lyxerr << "\n------------------------------------------" << endl;