Hello,

Here is a patch that I would like to discuss. It brings some improvements to the source view panel and it fixes <http://www.lyx.org/trac/ticket/6501> (Cursor in "LaTeX Source" pane does not follow cursor in Editor window).

I use a unique_ptr because it was the best way to do. Because of this, the patch has to be compiled with CXXFLAGS="-std=c++11". Fortunately it was easy to fix the LyX source to have a compilation with c++11.

Is there a reason for not using c++11? I don't mind rewriting the patch in such a way that it works in the current environment. Just tell me what you prefer instead. (auto_ptr is too limited here and I don't want to put a raw pointer in the interface. shared_ptr would certainly work but on the other hand I don't see why we would forbid ourselves from using c++11 features.) Anyway it would be good to fix the source code for c++11 compilation even if we don't make c++11 mandatory.


As for the improvements themselves, please have a look at the description of the patch below if you would like to test the new features. Note that the patch is independant of my earlier patch adding QTimers.

Also is there an expert of TexRow? I am thinking of a further improvement along the lines of <http://www.lyx.org/trac/ticket/4725#comment:1> (ability to view source of only the current selection) which seems quite simple to do at least partially.


Guillaume
>From f64ed67aa44725e3c270b01c64dcd080916b0f39 Mon Sep 17 00:00:00 2001
From: gadmm <ga...@free.fr>
Date: Tue, 4 Aug 2015 23:16:40 +0100
Subject: [PATCH] Improve the display of the source (bugs #6501,#7359).

Also fixes compilation with CXXFLAGS="-std=c++11". Must configure
with the latter to have a compilation.

* Selection highlighting has been broken since a conflict with
  reverse-search was repaired (at 00a62b7c), now fixed.

* The selection highlighting was off, for LaTeX formats (in full
  source view), and meaningless, for non LaTeX formats.

* (regression at cc00b9aa) force_getcontent_ was always true
  therefore the code to detect changes in the generated source
  was dead. The  consequence is that the source view would jump to
  the beginning at each updateView() even if no change occurred.
  cc00b9aa was meant to fix #5600, which I cannot reproduce so I
  removed force_get_contents_, which appears meaningless.
  * Fixed the thread-unsafety of crc_ (there was
  no bug only because it was part of the dead code).

* Various improvements:
  *  When the position-to-line conversion is unavailable (LyXHTML,
     LyX source, etc.) we focus on the first difference instead.
  *  Get some space around the cursor
  *  Respect the scrollbars
  *  Highlight with QTextEdit::ExtraSelections instead of
     cursor selection (the latter used to break syntax highlighting
     of the TeX code... which was not so much of an issue because
     the wrong part was selected)
---
 src/Buffer.cpp                       |  25 ++---
 src/Buffer.h                         |   7 +-
 src/Compare.cpp                      |   4 +-
 src/CutAndPaste.cpp                  |   8 +-
 src/Text.cpp                         |   8 +-
 src/Text2.cpp                        |   4 +-
 src/Text3.cpp                        |   4 +-
 src/frontends/qt4/GuiApplication.cpp |   2 +-
 src/frontends/qt4/GuiApplication.h   |   2 +-
 src/frontends/qt4/GuiViewSource.cpp  | 177 ++++++++++++++++++++++++++---------
 src/frontends/qt4/GuiViewSource.h    |  14 ++-
 src/output_docbook.cpp               |   4 +-
 src/output_latex.cpp                 |   6 +-
 13 files changed, 186 insertions(+), 79 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 2a67292..0fb12a6 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3509,11 +3509,12 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to)
 	}
 }
 
-
-void Buffer::getSourceCode(odocstream & os, string const & format,
+// returns a null pointer if id-to-row conversion is unsupported
+unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
 			   pit_type par_begin, pit_type par_end,
 			   OutputWhat output, bool master) const
 {
+	unique_ptr<TexRow> texrow(nullptr);
 	OutputParams runparams(&params().encoding());
 	runparams.nice = true;
 	runparams.flavor = params().getOutputFlavor(format);
@@ -3567,12 +3568,12 @@ void Buffer::getSourceCode(odocstream & os, string const & format,
 			LaTeXFeatures features(*this, params(), runparams);
 			params().validate(features);
 			runparams.use_polyglossia = features.usePolyglossia();
-			TexRow texrow;
-			texrow.reset();
-			texrow.newline();
-			texrow.newline();
+			texrow.reset(new TexRow());
+			texrow->reset();
+			texrow->newline();
+			texrow->newline();
 			// latex or literate
-			otexstream ots(os, texrow);
+			otexstream ots(os, *texrow);
 
 			// the real stuff
 			latexParagraphs(*this, text(), ots, runparams);
@@ -3610,15 +3611,17 @@ void Buffer::getSourceCode(odocstream & os, string const & format,
 				writeDocBookSource(os, absFileName(), runparams, output);
 		} else {
 			// latex or literate
-			d->texrow.reset();
-			d->texrow.newline();
-			d->texrow.newline();
-			otexstream ots(os, d->texrow);
+			texrow.reset(new TexRow());
+			texrow->reset();
+			texrow->newline();
+			texrow->newline();
+			otexstream ots(os, *texrow);
 			if (master)
 				runparams.is_child = true;
 			writeLaTeXSource(ots, string(), runparams, output);
 		}
 	}
+	return texrow;
 }
 
 
diff --git a/src/Buffer.h b/src/Buffer.h
index b50d5f4..2ed7d62 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -618,9 +618,10 @@ public:
 
 	/// get source code (latex/docbook) for some paragraphs, or all paragraphs
 	/// including preamble
-	void getSourceCode(odocstream & os, std::string const & format,
-			   pit_type par_begin, pit_type par_end, OutputWhat output,
-			   bool master) const;
+	/// returns a null pointer if Id to Row conversion is unsupported
+	std::unique_ptr<TexRow> getSourceCode(odocstream & os,
+			std::string const & format, pit_type par_begin,
+			pit_type par_end, OutputWhat output, bool master) const;
 
 	/// Access to error list.
 	/// This method is used only for GUI visualisation of Buffer related
diff --git a/src/Compare.cpp b/src/Compare.cpp
index 048feba..983442d 100644
--- a/src/Compare.cpp
+++ b/src/Compare.cpp
@@ -422,8 +422,8 @@ static void getParagraphList(DocRange const & range,
 	pit_type startpit = range.from.pit();
 	pit_type endpit = range.to.pit();
 	ParagraphList const & ps_ = range.text()->paragraphs();
-	ParagraphList tmp_pars(next(ps_.begin(), startpit),
-		next(ps_.begin(), endpit + 1));
+	ParagraphList tmp_pars(lyx::next(ps_.begin(), startpit),
+						   lyx::next(ps_.begin(), endpit + 1));
 
 	// Remove the end of the last paragraph; afterwards, remove the
 	// beginning of the first paragraph. Keep this order - there may only
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 0bfd3ad..9cf8367 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -387,7 +387,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
 
 	// Paste it!
 	if (empty) {
-		pars.insert(next(pars.begin(), pit),
+		pars.insert(lyx::next(pars.begin(), pit),
 			    insertion.begin(),
 			    insertion.end());
 
@@ -395,7 +395,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
 		mergeParagraph(buffer.params(), pars,
 			       pit + insertion.size() - 1);
 	} else {
-		pars.insert(next(pars.begin(), pit + 1),
+		pars.insert(lyx::next(pars.begin(), pit + 1),
 			    insertion.begin(),
 			    insertion.end());
 
@@ -599,8 +599,8 @@ void copySelectionHelper(Buffer const & buf, Text const & text,
 	LASSERT(startpit != endpit || start <= end, return);
 
 	// Clone the paragraphs within the selection.
-	ParagraphList copy_pars(next(pars.begin(), startpit),
-				next(pars.begin(), endpit + 1));
+	ParagraphList copy_pars(lyx::next(pars.begin(), startpit),
+							lyx::next(pars.begin(), endpit + 1));
 
 	// Remove the end of the last paragraph; afterwards, remove the
 	// beginning of the first paragraph. Keep this order - there may only
diff --git a/src/Text.cpp b/src/Text.cpp
index e30cd74..2bf665f 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -135,7 +135,7 @@ void breakParagraphConservative(BufferParams const & bparams,
 	ParagraphList & pars, pit_type par_offset, pos_type pos)
 {
 	// create a new paragraph
-	Paragraph & tmp = *pars.insert(next(pars.begin(), par_offset + 1),
+	Paragraph & tmp = *pars.insert(lyx::next(pars.begin(), par_offset + 1),
 				       Paragraph());
 	Paragraph & par = pars[par_offset];
 
@@ -661,7 +661,7 @@ static void breakParagraph(Text & text, pit_type par_offset, pos_type pos,
 	ParagraphList & pars = text.paragraphs();
 	// create a new paragraph, and insert into the list
 	ParagraphList::iterator tmp =
-		pars.insert(next(pars.begin(), par_offset + 1),
+		pars.insert(lyx::next(pars.begin(), par_offset + 1),
 			    Paragraph());
 
 	Paragraph & par = pars[par_offset];
@@ -1638,14 +1638,14 @@ bool Text::backspacePos0(Cursor & cur)
 	if (cur.lastpos() == 0
 	    || (cur.lastpos() == 1 && par.isSeparator(0))) {
 		cur.recordUndo(prevcur.pit());
-		plist.erase(next(plist.begin(), cur.pit()));
+		plist.erase(lyx::next(plist.begin(), cur.pit()));
 		needsUpdate = true;
 	}
 	// is previous par empty?
 	else if (prevcur.lastpos() == 0
 		 || (prevcur.lastpos() == 1 && prevpar.isSeparator(0))) {
 		cur.recordUndo(prevcur.pit());
-		plist.erase(next(plist.begin(), prevcur.pit()));
+		plist.erase(lyx::next(plist.begin(), prevcur.pit()));
 		needsUpdate = true;
 	}
 	// Pasting is not allowed, if the paragraphs have different
diff --git a/src/Text2.cpp b/src/Text2.cpp
index 9e6ec8e..c3d696e 100644
--- a/src/Text2.cpp
+++ b/src/Text2.cpp
@@ -906,7 +906,7 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
 		               min(old.pit() + 1, old.lastpit()));
 		ParagraphList & plist = old.text()->paragraphs();
 		bool const soa = oldpar.params().startOfAppendix();
-		plist.erase(next(plist.begin(), old.pit()));
+		plist.erase(lyx::next(plist.begin(), old.pit()));
 		// do not lose start of appendix marker (bug 4212)
 		if (soa && old.pit() < pit_type(plist.size()))
 			plist[old.pit()].params().startOfAppendix(true);
@@ -970,7 +970,7 @@ void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool tra
 			continue;
 
 		if (par.empty() || (par.size() == 1 && par.isLineSeparator(0))) {
-			pars_.erase(next(pars_.begin(), pit));
+			pars_.erase(lyx::next(pars_.begin(), pit));
 			--pit;
 			--last;
 			continue;
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 7f94185..c542baa 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -376,7 +376,7 @@ static void outline(OutlineOp mode, Cursor & cur)
 	ParagraphList & pars = buf.text().paragraphs();
 	ParagraphList::iterator const bgn = pars.begin();
 	// The first paragraph of the area to be copied:
-	ParagraphList::iterator start = next(bgn, pit);
+	ParagraphList::iterator start = lyx::next(bgn, pit);
 	// The final paragraph of area to be copied:
 	ParagraphList::iterator finish = start;
 	ParagraphList::iterator const end = pars.end();
@@ -814,7 +814,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		ParagraphList & pars = buf.text().paragraphs();
 		ParagraphList::iterator bgn = pars.begin();
 		// The first paragraph of the area to be selected:
-		ParagraphList::iterator start = next(bgn, pit);
+		ParagraphList::iterator start = lyx::next(bgn, pit);
 		// The final paragraph of area to be selected:
 		ParagraphList::iterator finish = start;
 		ParagraphList::iterator end = pars.end();
diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp
index fe34509..dc5ecdd 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -3085,7 +3085,7 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
 }
 #elif defined(QPA_XCB)
 bool GuiApplication::nativeEventFilter(const QByteArray & eventType,
-				       void * message, long *) Q_DECL_OVERRIDE
+				       void * message, long *) //Q_DECL_OVERRIDE
 {
 	if (!current_view_ || eventType != "xcb_generic_event_t")
 		return false;
diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h
index 344a862..82f5898 100644
--- a/src/frontends/qt4/GuiApplication.h
+++ b/src/frontends/qt4/GuiApplication.h
@@ -108,7 +108,7 @@ public:
 #ifdef Q_WS_X11
 	bool x11EventFilter(XEvent * ev);
 #elif defined(QPA_XCB)
-	virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
+	virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result) Q_DECL_OVERRIDE;
 #endif
 	//@}
 
diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp
index 3fcaed9..0bf772f 100644
--- a/src/frontends/qt4/GuiViewSource.cpp
+++ b/src/frontends/qt4/GuiViewSource.cpp
@@ -17,13 +17,11 @@
 #include "LaTeXHighlighter.h"
 #include "qt_helpers.h"
 
-#include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Cursor.h"
 #include "Format.h"
 #include "Paragraph.h"
-#include "TexRow.h"
 
 #include "support/debug.h"
 #include "support/lassert.h"
@@ -33,6 +31,7 @@
 #include <boost/crc.hpp>
 
 #include <QBoxLayout>
+#include <QScrollBar>
 #include <QSettings>
 #include <QTextCursor>
 #include <QTextDocument>
@@ -46,7 +45,7 @@ namespace frontend {
 ViewSourceWidget::ViewSourceWidget()
 	:	bv_(0), document_(new QTextDocument(this)),
 		highlighter_(new LaTeXHighlighter(document_)),
-		force_getcontent_(true)
+		crc_(0)
 {
 	setupUi(this);
 
@@ -88,18 +87,16 @@ static size_t crcCheck(docstring const & s)
 }
 
 
-/** get the source code of selected paragraphs, or the whole document
-	\param fullSource get full source code
-	\return true if the content has changed since last call.
- */
-static bool getContent(BufferView const * view, Buffer::OutputWhat output,
-		       QString & qstr, string const & format, bool force_getcontent,
-		       bool master)
+pair<bool, unique_ptr<TexRow> >
+ViewSourceWidget::getContent(BufferView const * view,
+			Buffer::OutputWhat output, QString & qstr, string const & format,
+			bool master)
 {
 	// get the *top* level paragraphs that contain the cursor,
 	// or the selected text
 	pit_type par_begin;
 	pit_type par_end;
+	bool changed = false;
 
 	if (!view->cursor().selection()) {
 		par_begin = view->cursor().bottom().pit();
@@ -111,26 +108,21 @@ static bool getContent(BufferView const * view, Buffer::OutputWhat output,
 	if (par_begin > par_end)
 		swap(par_begin, par_end);
 	odocstringstream ostr;
-	view->buffer().getSourceCode(ostr, format, par_begin, par_end + 1,
-				     output, master);
+	unique_ptr<TexRow> texrow = view->buffer().getSourceCode(ostr, format,
+								    par_begin, par_end + 1, output, master);
 	docstring s = ostr.str();
-	// FIXME THREAD
-	// Could this be private to this particular dialog? We could have
-	// more than one of these, in different windows.
-	static size_t crc = 0;
 	size_t newcrc = crcCheck(s);
-	if (newcrc == crc && !force_getcontent)
-		return false;
-	crc = newcrc;
-	qstr = toqstr(s);
-	return true;
+	if (newcrc != crc_) {
+		crc_ = newcrc;
+		qstr = toqstr(s);
+		changed = true;
+	}
+	return make_pair(changed, std::move(texrow));
 }
 
 
 void ViewSourceWidget::setBufferView(BufferView const * bv)
 {
-	if (bv_ != bv)
-		force_getcontent_ = true;
 	bv_ = bv;
 	setEnabled(bv ?  true : false);
 }
@@ -172,27 +164,127 @@ void ViewSourceWidget::updateView()
 	else if (contentsCO->currentIndex() == 3)
 		output = Buffer::OnlyBody;
 
-	if (getContent(bv_, output, content, format,
-		      force_getcontent_, masterPerspectiveCB->isChecked()))
+	pair<bool, unique_ptr<TexRow> > res = getContent(bv_, output, content,
+								format, masterPerspectiveCB->isChecked());
+	bool changed = res.first;
+	unique_ptr<TexRow> texrow = std::move(res.second);
+
+	// will try to get that much space around the cursor
+	const int v_margin = 3;
+	const int h_margin = 10;
+	// will try to preserve this
+	const int h_scroll = viewSourceTV->horizontalScrollBar()->value();
+
+	if (changed) {
+		QString old = document_->toPlainText();
 		document_->setPlainText(content);
+		if (!texrow) {
+			// position-to-row is unavailable
+			// we jump to the first modification
+			const QChar * oc = old.constData();
+			const QChar * nc = content.constData();
+			int pos = 0;
+			while (*oc != '\0' && *nc != '\0' && *oc == *nc) {
+				++oc;
+				++nc;
+				++pos;
+			}
+			QTextCursor c = QTextCursor(viewSourceTV->document());
+			//get some space below the cursor
+			c.setPosition(pos);
+			c.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,v_margin);
+			viewSourceTV->setTextCursor(c);
+			//get some space on the right of the cursor
+			viewSourceTV->horizontalScrollBar()->setValue(h_scroll);
+			c.setPosition(pos);
+			const int block = c.blockNumber();
+			for (int i = h_margin; i && block == c.blockNumber(); --i) {
+				c.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor);
+			}
+			c.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor);
+			viewSourceTV->setTextCursor(c);
+			//back to the position
+			c.setPosition(pos);
+			//c.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,1);
+			viewSourceTV->setTextCursor(c);
+		}
+	}
 
-	CursorSlice beg = bv_->cursor().selectionBegin().bottom();
-	CursorSlice end = bv_->cursor().selectionEnd().bottom();
-	int const begrow = bv_->buffer().texrow().
-		getRowFromIdPos(beg.paragraph().id(), beg.pos());
-	int endrow = bv_->buffer().texrow().
-		getRowFromIdPos(end.paragraph().id(), end.pos());
-	int const nextendrow = bv_->buffer().texrow().
-		getRowFromIdPos(end.paragraph().id(), end.pos() + 1);
-	if (endrow != nextendrow)
-		endrow = nextendrow - 1;
-
-	QTextCursor c = QTextCursor(viewSourceTV->document());
-	c.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, begrow);
-	c.select(QTextCursor::BlockUnderCursor);
-	c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor,
-		endrow - begrow + 1);
-	viewSourceTV->setTextCursor(c);
+	if (texrow) {
+		// Use the available position-to-row conversion to highlight
+		// the current selection in the source
+		//
+		// FIXME:
+		// * it is currently impossible to highlight the very last line
+		//   of a document, because TexRow gives the wrong data.
+		// * we currently only compute the top-level position, which
+		//   makes it impossible to highlight inside an inset. It is not
+		//   a limitation of TexRow,  but replacing bottom() with top()
+		//   works partially and causes segfaults with math. Solving
+		//   this could be seen as a solution to #4725.
+		CursorSlice beg = bv_->cursor().selectionBegin().bottom();
+		CursorSlice end = bv_->cursor().selectionEnd().bottom();
+		int const beg_par = beg.paragraph().id();
+		int const end_par = end.paragraph().id();
+		int const beg_pos = beg.pos();
+		int const end_pos = end.pos();
+		int beg_row, end_row, next_end_row;
+		if (beg_par != end_par || beg_pos != end_pos) {
+			beg_row = texrow->getRowFromIdPos(beg_par, beg_pos);
+			end_row = texrow->getRowFromIdPos(end_par, max(0, end_pos - 1));
+			next_end_row = texrow->getRowFromIdPos(end_par, end_pos);
+		} else {
+			end_row = beg_row = texrow->getRowFromIdPos(beg_par, beg_pos);
+			next_end_row = texrow->getRowFromIdPos(beg_par, beg_pos + 1);
+		}
+		if (end_row != next_end_row)
+			end_row = next_end_row - 1;
+
+		QTextCursor c = QTextCursor(viewSourceTV->document());
+
+		c.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor,
+					   beg_row - 1);
+		const int beg_sel = c.position();
+		//get some space above the cursor
+		c.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor,
+					   v_margin);
+		viewSourceTV->setTextCursor(c);
+		c.setPosition(beg_sel, QTextCursor::MoveAnchor);
+
+		c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor,
+					   end_row - beg_row +1);
+		const int end_sel = c.position();
+		//get some space below the cursor
+		c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor,
+					   v_margin - 1);
+		viewSourceTV->setTextCursor(c);
+		c.setPosition(end_sel, QTextCursor::KeepAnchor);
+
+		viewSourceTV->setTextCursor(c);
+
+		//the real highlighting is done with an ExtraSelection
+		QTextCharFormat format;
+		QPalette palette = viewSourceTV->palette();
+		//Alternative:
+		//  QColor bg = palette.color(QPalette::Active,QPalette::Highlight);
+		//  bg.setAlpha(64);
+		//  format.setBackground(QBrush(bg));
+		//Other alternatives:
+		//format.setBackground(palette.light());
+		//format.setBackground(palette.alternateBase());
+		format.setBackground(palette.toolTipBase());
+		format.setProperty(QTextFormat::FullWidthSelection, true);
+		QTextEdit::ExtraSelection sel;
+		sel.format = format;
+		sel.cursor = c;
+		viewSourceTV->setExtraSelections(
+			QList<QTextEdit::ExtraSelection>() << sel);
+
+		//clean up
+		c.clearSelection();
+		viewSourceTV->setTextCursor(c);
+		viewSourceTV->horizontalScrollBar()->setValue(h_scroll);
+	}
 }
 
 
@@ -289,6 +381,7 @@ QString GuiViewSource::title() const
 {
 	switch (docType()) {
 		case LATEX:
+			//FIXME: this is shown for LyXHTML source, LyX source, etc.
 			return qt_("LaTeX Source");
 		case DOCBOOK:
 			return qt_("DocBook Source");
diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h
index c600269..fac9e2c 100644
--- a/src/frontends/qt4/GuiViewSource.h
+++ b/src/frontends/qt4/GuiViewSource.h
@@ -16,11 +16,15 @@
 
 #include "ui_ViewSourceUi.h"
 
+#include "Buffer.h"
 #include "DockView.h"
+#include "TexRow.h"
 
 #include <QDockWidget>
 #include <QString>
 
+using namespace std;
+
 class QTextDocument;
 
 namespace lyx {
@@ -53,6 +57,12 @@ public Q_SLOTS:
 	void contentsChanged();
 
 private:
+	/// Get the source code of selected paragraphs, or the whole document
+	/// returns <b,t> where b is true if the content has changed since last
+	/// call, and if TexRow is unavailable for the format then t is null.
+	pair<bool, unique_ptr<TexRow> > getContent(BufferView const * view,
+			Buffer::OutputWhat output, QString & qstr, string const & format,
+			bool master);
 	///
 	BufferView const * bv_;
 	///
@@ -60,9 +70,9 @@ private:
 	/// LaTeX syntax highlighter
 	LaTeXHighlighter * highlighter_;
 	///
-	bool force_getcontent_;
-	///
 	QString view_format_;
+	///
+	size_t crc_;
 };
 
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 48b2f60..ac1a2d3 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -328,8 +328,8 @@ void docbookParagraphs(Text const & text,
 
 	// if only part of the paragraphs will be outputed
 	if (runparams.par_begin !=  runparams.par_end) {
-		par = next(paragraphs.begin(), runparams.par_begin);
-		pend = next(paragraphs.begin(), runparams.par_end);
+		par = lyx::next(paragraphs.begin(), runparams.par_begin);
+		pend = lyx::next(paragraphs.begin(), runparams.par_end);
 		// runparams will be passed to nested paragraphs, so
 		// we have to reset the range parameters.
 		const_cast<OutputParams&>(runparams).par_begin = 0;
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 80cb990..8112fe0 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -472,9 +472,9 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi
 	// get the first paragraph in sequence with this layout and depth
 	pit_type offset = 0;
 	while (true) {
-		if (prev(pit, offset) == pars.begin())
+		if (lyx::prev(pit, offset) == pars.begin())
 			break;
-		ParagraphList::const_iterator priorpit = prev(pit, offset + 1);
+		ParagraphList::const_iterator priorpit = lyx::prev(pit, offset + 1);
 		if (priorpit->layout() == current_layout
 		    && priorpit->params().depth() == current_depth)
 			++offset;
@@ -482,7 +482,7 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi
 			break;
 	}
 
-	ParagraphList::const_iterator spit = prev(pit, offset);
+	ParagraphList::const_iterator spit = lyx::prev(pit, offset);
 
 	for (; spit != pars.end(); ++spit) {
 		if (spit->layout() != current_layout || spit->params().depth() < current_depth)
-- 
2.1.4

Reply via email to