]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
FindAdv: Amend ec387b6d: Handle search for '{' and '}'
[lyx.git] / src / Buffer.cpp
index 5ef7c91c9d09d42345c1fdd2e571bc37150a4bee..01469dbc9065718fa0476c7cef0f770496143e67 100644 (file)
@@ -21,6 +21,7 @@
 #include "BufferParams.h"
 #include "Bullet.h"
 #include "Chktex.h"
+#include "ColorSet.h"
 #include "Converter.h"
 #include "Counters.h"
 #include "Cursor.h"
@@ -1006,7 +1007,7 @@ int Buffer::readHeader(Lexer & lex)
 
        params().shell_escape = theSession().shellescapeFiles().find(absFileName());
 
-       params().makeDocumentClass();
+       params().makeDocumentClass(isClone(), isInternal());
 
        return unknown_tokens;
 }
@@ -1471,7 +1472,7 @@ bool Buffer::save() const
        // proper location once that has been done successfully. that
        // way we preserve the original file if something goes wrong.
        string const justname = fileName().onlyFileNameWithoutExt();
-       auto tempfile = make_unique<TempFile>(fileName().onlyPath(),
+       auto tempfile = lyx::make_unique<TempFile>(fileName().onlyPath(),
                                              justname + "-XXXXXX.lyx");
        bool const symlink = fileName().isSymLink();
        if (!symlink)
@@ -2938,7 +2939,12 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                                undo().recordUndoBufferParams(CursorData());
                                branch_list.add(branch_name);
                                branch = branch_list.find(branch_name);
-                               string const x11hexname = X11hexname(branch->color());
+                               string x11hexname;
+                               string const bcolor = branch->color();
+                               if (bcolor.size() == 7 && bcolor[0] == '#')
+                                       x11hexname = bcolor;
+                               else
+                                       x11hexname = lcolor.getX11HexName(lcolor.getFromLyXName(bcolor));
                                docstring const str = branch_name + ' ' + from_ascii(x11hexname);
                                lyx::dispatch(FuncRequest(LFUN_SET_COLOR, str));
                                dr.setError(false);
@@ -4056,18 +4062,29 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
        // Some macros rely on font encoding
        runparams.main_fontenc = params().main_font_encoding();
 
+       // Use the right wrapping for the comment at the beginning of the generated
+       // snippet, so that it is either valid LaTeX or valid XML (including HTML and DocBook).
+       docstring comment_start = from_ascii("% ");
+       docstring comment_end = from_ascii("");
+       if (runparams.flavor == Flavor::Html || runparams.flavor == Flavor::DocBook5) {
+               comment_start = from_ascii("<!-- ");
+               comment_end = from_ascii(" -->");
+       }
+
        if (output == CurrentParagraph) {
                runparams.par_begin = par_begin;
                runparams.par_end = par_end;
                if (par_begin + 1 == par_end) {
-                       os << "% "
+                       os << comment_start
                           << bformat(_("Preview source code for paragraph %1$d"), par_begin)
+                          << comment_end
                           << "\n\n";
                } else {
-                       os << "% "
+                       os << comment_start
                           << bformat(_("Preview source code from paragraph %1$s to %2$s"),
                                        convert<docstring>(par_begin),
                                        convert<docstring>(par_end - 1))
+                          << comment_end
                           << "\n\n";
                }
                // output paragraphs
@@ -4117,13 +4134,14 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
                                d->ignore_parent = false;
                }
        } else {
-               os << "% ";
+               os << comment_start;
                if (output == FullSource)
                        os << _("Preview source code");
                else if (output == OnlyPreamble)
                        os << _("Preview preamble");
                else if (output == OnlyBody)
                        os << _("Preview body");
+               os << comment_end;
                os << "\n\n";
                if (runparams.flavor == Flavor::LyX) {
                        ostringstream ods;
@@ -4137,9 +4155,9 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
                } else if (runparams.flavor == Flavor::Html) {
                        writeLyXHTMLSource(os, runparams, output);
                } else if (runparams.flavor == Flavor::Text) {
-                       if (output == OnlyPreamble) {
+                       if (output == OnlyPreamble)
                                os << "% "<< _("Plain text does not have a preamble.");
-                       else
+                       else
                                writePlaintextFile(*this, os, runparams);
                } else if (runparams.flavor == Flavor::DocBook5) {
                        writeDocBookSource(os, runparams, output);
@@ -5353,6 +5371,12 @@ void Buffer::Impl::updateStatistics(DocIterator & from, DocIterator & to, bool s
                                }
                                else if (ins && ins->isSpace())
                                        ++blank_count_;
+                               else if (ins) {
+                                       pair<int, int> words = ins->isWords();
+                                       char_count_ += words.first;
+                                       word_count_ += words.second;
+                                       inword = false;
+                               }
                                else {
                                        char_type const c = par.getChar(pos);
                                        if (isPrintableNonspace(c))