Em Qui 02 Mar 2006 18:40, Jose' Matos escreveu:

Oi José!

> On Thursday 02 March 2006 21:32, João Luis Meloni Assirati wrote:
>
> Olá João, :-)
>  (Oi seria melhor ? ;-)

Está bem das duas maneiras. Gosto do modo português de falar, também :)
(Lars, keep reading, please :)

> >
> > I don't get it. What is the problem?
>
> class TexRow {
> ...
> int TexRow::getRowFromId(int id, int pos) const;
> ...
> }
>
> The use of TexRow classifier inside the class is wrong, since the function
> is declared there. The right syntax is:
>
> class TexRow {
> ...
> int getRowFromId(int id, int pos) const;
> ...
> }

Sorry, guys. I hadn't reallized that Lars post  was about the .h file. I 
understand now, it was a stupid error. Attached is the updated patch.

Thanks,
João.
Index: src/BufferView.h
===================================================================
--- src/BufferView.h	(revision 13280)
+++ src/BufferView.h	(working copy)
@@ -179,6 +179,8 @@
 	int offset_ref() const;
 	/// access to anchor
 	lyx::pit_type anchor_ref() const;
+	/// access to the texrow corresponding to the beginning of the view
+	int texrow_ref() const;
 
 	/// access to full cursor
 	LCursor & cursor();
Index: src/BufferView.C
===================================================================
--- src/BufferView.C	(revision 13280)
+++ src/BufferView.C	(working copy)
@@ -387,6 +387,13 @@
 }
 
 
+int BufferView::texrow_ref() const 
+{
+	return buffer()->texrow().getRowFromId(
+		buffer()->paragraphs()[anchor_ref()].id(), offset_ref());
+}
+
+
 int BufferView::offset_ref() const
 {
 	return pimpl_->offset_ref_;
Index: src/LaTeX.C
===================================================================
--- src/LaTeX.C	(revision 13280)
+++ src/LaTeX.C	(working copy)
@@ -383,7 +383,10 @@
 
 int LaTeX::startscript()
 {
-	string tmp = cmd + ' ' + QuoteName(file) + " > " + os::nulldev();
+	string tmp = cmd;
+	if (runparams.srcspecials)
+		tmp += ' ' + lyxrc.source_specials_switch;
+	tmp += ' ' + QuoteName(file) + " > " + os::nulldev();
 	Systemcall one;
 	return one.startscript(Systemcall::Wait, tmp);
 }
Index: src/buffer.C
===================================================================
--- src/buffer.C	(revision 13280)
+++ src/buffer.C	(working copy)
@@ -1280,7 +1280,7 @@
 
 	switch (func.action) {
 		case LFUN_EXPORT: {
-			bool const tmp = Exporter::Export(this, func.argument, false);
+			bool const tmp = Exporter::Export(this, func.argument, false, false);
 			if (result)
 				*result = tmp;
 			break;
Index: src/converter.h
===================================================================
--- src/converter.h	(revision 13280)
+++ src/converter.h	(working copy)
@@ -107,12 +107,13 @@
 	bool convert(Buffer const * buffer,
 		     std::string const & from_file, std::string const & to_file_base,
 		     std::string const & from_format, std::string const & to_format,
-                     std::string & to_file, bool try_default = false);
+		     std::string & to_file, bool try_default = false,
+		     bool for_preview = false);
 	///
 	bool convert(Buffer const * buffer,
 		     std::string const & from_file, std::string const & to_file_base,
 		     std::string const & from_format, std::string const & to_format,
-                     bool try_default = false);
+                     bool try_default = false, bool for_preview = false);
 	///
 	void update(Formats const & formats);
 	///
Index: src/converter.C
===================================================================
--- src/converter.C	(revision 13280)
+++ src/converter.C	(working copy)
@@ -281,7 +281,8 @@
 bool Converters::convert(Buffer const * buffer,
 			 string const & from_file, string const & to_file_base,
 			 string const & from_format, string const & to_format,
-			 string & to_file, bool try_default)
+			 string & to_file, bool try_default,
+			 bool for_preview)
 {
 	string const to_ext = formats.extension(to_format);
 	to_file = ChangeExtension(to_file_base, to_ext);
@@ -323,6 +324,8 @@
 	}
 	OutputParams runparams;
 	runparams.flavor = getFlavor(edgepath);
+	runparams.srcspecials = (for_preview && to_format == "dvi");
+	runparams.latexfile = from_file;
 	string path = OnlyPath(from_file);
 	Path p(path);
 
@@ -515,11 +518,11 @@
 bool Converters::convert(Buffer const * buffer,
 			 string const & from_file, string const & to_file_base,
 			 string const & from_format, string const & to_format,
-                         bool try_default)
+                         bool try_default, bool for_preview)
 {
 	string to_file;
 	return convert(buffer, from_file, to_file_base, from_format, to_format,
-		       to_file, try_default);
+		       to_file, try_default, for_preview);
 }
 
 
@@ -576,7 +579,7 @@
 	runparams.document_language = buffer.params().language->babel();
 
 	// do the LaTeX run(s)
-	string const name = buffer.getLatexName();
+	string const name = runparams.latexfile;
 	LaTeX latex(command, runparams, name, buffer.filePath());
 	TeXErrors terr;
 	showMessage show(buffer);
Index: src/exporter.h
===================================================================
--- src/exporter.h	(revision 13280)
+++ src/exporter.h	(working copy)
@@ -19,6 +19,7 @@
 
 
 class Buffer;
+class BufferView;
 class Format;
 
 class Exporter {
@@ -26,14 +27,15 @@
 	///
 	static
 	bool Export(Buffer * buffer, std::string const & format,
-		    bool put_in_tempdir, std::string & result_file);
+		    bool put_in_tempdir, bool for_preview,
+		    std::string & result_file);
 	///
 	static
 	bool Export(Buffer * buffer, std::string const & format,
-		    bool put_in_tempdir);
+		    bool put_in_tempdir, bool for_preview);
 	///
 	static
-	bool Preview(Buffer * buffer, std::string const & format);
+	bool Preview(BufferView * bv, std::string const & format);
 	///
 	static
 	bool IsExportable(Buffer const & buffer, std::string const & format);
Index: src/exporter.C
===================================================================
--- src/exporter.C	(revision 13280)
+++ src/exporter.C	(working copy)
@@ -19,6 +19,7 @@
 #include "exporter.h"
 
 #include "buffer.h"
+#include "BufferView.h"
 #include "buffer_funcs.h"
 #include "bufferparams.h"
 #include "converter.h"
@@ -137,7 +138,8 @@
 
 
 bool Exporter::Export(Buffer * buffer, string const & format,
-		      bool put_in_tempdir, string & result_file)
+		      bool put_in_tempdir, bool for_preview,
+		      string & result_file)
 {
 	string backend_format;
 	OutputParams runparams;
@@ -173,6 +175,11 @@
 		backend_format = format;
 
 	string filename = buffer->getLatexName(false);
+	if(for_preview && format == "dvi") {
+		filename = ChangeExtension(filename, "");
+		filename += "_pre";
+		filename = ChangeExtension(filename, "tex");
+	}
 	filename = AddName(buffer->temppath(), filename);
 	filename = ChangeExtension(filename,
 				   formats.extension(backend_format));
@@ -208,7 +215,8 @@
 	}
 
 	if (!converters.convert(buffer, filename, filename,
-				backend_format, format, result_file))
+				backend_format, format, result_file,
+				false, for_preview))
 		return false;
 
 	if (!put_in_tempdir) {
@@ -252,19 +260,20 @@
 
 
 bool Exporter::Export(Buffer * buffer, string const & format,
-		      bool put_in_tempdir)
+		      bool put_in_tempdir, bool for_preview)
 {
 	string result_file;
-	return Export(buffer, format, put_in_tempdir, result_file);
+	return Export(buffer, format, put_in_tempdir, for_preview, result_file);
 }
 
 
-bool Exporter::Preview(Buffer * buffer, string const & format)
+bool Exporter::Preview(BufferView * bv, string const & format)
 {
-	string result_file;
-	if (!Export(buffer, format, true, result_file))
-		return false;
-	return formats.view(*buffer, result_file, format);
+ 	string result_file;
+ 	if (!Export(bv->buffer(), format, true,
+ 		    !lyxrc.source_specials_switch.empty(), result_file))
+ 		return false;
+ 	return formats.view(*bv, result_file, format);
 }
 
 
Index: src/format.h
===================================================================
--- src/format.h	(revision 13280)
+++ src/format.h	(working copy)
@@ -16,6 +16,7 @@
 #include <string>
 
 class Buffer;
+class BufferView;
 
 class Format {
 public:
@@ -108,7 +109,7 @@
 	///
 	void setViewer(std::string const & name, std::string const & command);
 	///
-	bool view(Buffer const & buffer, std::string const & filename,
+	bool view(BufferView const & bv, std::string const & filename,
 		  std::string const & format_name) const;
 	///
 	bool edit(Buffer const & buffer, std::string const & filename,
Index: src/format.C
===================================================================
--- src/format.C	(revision 13280)
+++ src/format.C	(working copy)
@@ -12,6 +12,7 @@
 
 #include "format.h"
 #include "buffer.h"
+#include "BufferView.h"
 #include "bufferparams.h"
 #include "lyxrc.h"
 #include "debug.h"
@@ -23,6 +24,8 @@
 #include "support/filetools.h"
 #include "support/path.h"
 #include "support/systemcall.h"
+#include "support/convert.h"
+#include "support/filetools.h"
 
 using lyx::support::bformat;
 using lyx::support::compare_ascii_no_case;
@@ -35,6 +38,7 @@
 using lyx::support::QuoteName;
 using lyx::support::subst;
 using lyx::support::Systemcall;
+using lyx::support::ChangeExtension;
 
 using std::string;
 using std::distance;
@@ -46,6 +50,8 @@
 string const token_from("$$i");
 string const token_path("$$p");
 string const token_socket("$$a");
+string const token_srcfile("$$s");
+string const token_srcline("$$l");
 
 
 class FormatNamesEqual : public std::unary_function<Format, bool> {
@@ -213,7 +219,7 @@
 }
 
 
-bool Formats::view(Buffer const & buffer, string const & filename,
+bool Formats::view(BufferView const & bv, string const & filename,
 		   string const & format_name) const
 {
 	if (filename.empty())
@@ -234,15 +240,31 @@
 
 	string command = LibScriptSearch(format->viewer());
 
-	if (format_name == "dvi" &&
-	    !lyxrc.view_dvi_paper_option.empty()) {
-		command += ' ' + lyxrc.view_dvi_paper_option;
-		string paper_size = buffer.params().paperSizeName();
-		if (paper_size == "letter")
-			paper_size = "us";
-		command += ' ' + paper_size;
-		if (buffer.params().orientation == ORIENTATION_LANDSCAPE)
-			command += 'r';
+	if (format_name == "dvi") {
+		if (!lyxrc.view_dvi_paper_option.empty()) {
+			command += ' ' + lyxrc.view_dvi_paper_option;
+			string paper_size = bv.buffer()->params().paperSizeName();
+			if (paper_size == "letter")
+				paper_size = "us";
+			command += ' ' + paper_size;
+			if (bv.buffer()->params().orientation == ORIENTATION_LANDSCAPE)
+				command += 'r';
+		}
+		if (!lyxrc.dvi_fwsearch_switch.empty()) {
+			if (lyxrc.dvi_fwsearch_switch == "auto") {
+				if (format->viewer() == "xdvi") {
+					command += " -sourceposition '$$l $$s'";
+				} else if (format->viewer() == "kdvi") {
+					command += " --unique 'file:$$i#src:$$l$$s'";
+				} else {
+					lyxerr << "Cannot handle 'auto' \\dvi_fwsearch_switch for viewer "
+					       << format->viewer() << ". "
+					       << "Please specify a switch." << std::endl;
+				}
+			} else {
+				command += ' ' + lyxrc.dvi_fwsearch_switch;
+			}
+		}
 	}
 
 	if (!contains(command, token_from))
@@ -252,8 +274,11 @@
 			QuoteName(OnlyFilename(filename)));
 	command = subst(command, token_path, QuoteName(OnlyPath(filename)));
 	command = subst(command, token_socket, QuoteName(lyxsocket->address()));
+	command = subst(command, token_srcfile,
+			QuoteName(ChangeExtension(filename, "tex")));
+	command = subst(command, token_srcline, convert<string>(bv.texrow_ref()));
 	lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
-	buffer.message(_("Executing command: ") + command);
+	bv.buffer()->message(_("Executing command: ") + command);
 
 	Path p(OnlyPath(filename));
 	Systemcall one;
Index: src/lyxfunc.C
===================================================================
--- src/lyxfunc.C	(revision 13280)
+++ src/lyxfunc.C	(working copy)
@@ -824,17 +824,17 @@
 		}
 
 		case LFUN_UPDATE:
-			Exporter::Export(owner->buffer(), argument, true);
+			Exporter::Export(owner->buffer(), argument, true, true);
 			view()->showErrorList(BufferFormat(*owner->buffer()));
 			break;
 
 		case LFUN_PREVIEW:
-			Exporter::Preview(owner->buffer(), argument);
-			view()->showErrorList(BufferFormat(*owner->buffer()));
-			break;
+			Exporter::Preview(view(), argument);
+                        view()->showErrorList(BufferFormat(*owner->buffer()));
+                        break;
 
 		case LFUN_BUILDPROG:
-			Exporter::Export(owner->buffer(), "program", true);
+			Exporter::Export(owner->buffer(), "program", true, false);
 			view()->showErrorList(_("Build"));
 			break;
 
@@ -847,7 +847,7 @@
 			if (argument == "custom")
 				owner->getDialogs().show("sendto");
 			else {
-				Exporter::Export(owner->buffer(), argument, false);
+				Exporter::Export(owner->buffer(), argument, false, false);
 				view()->showErrorList(BufferFormat(*owner->buffer()));
 			}
 			break;
@@ -881,7 +881,7 @@
 
 			} else {
 				Exporter::Export(buffer, format_name, true,
-						 filename);
+						 false, filename);
 			}
 
 			// Substitute $$FName for filename
@@ -916,7 +916,7 @@
 
 			Buffer * buffer = owner->buffer();
 
-			if (!Exporter::Export(buffer, "dvi", true)) {
+			if (!Exporter::Export(buffer, "dvi", true, false)) {
 				showPrintError(buffer->fileName());
 				break;
 			}
@@ -1131,10 +1131,8 @@
 			}
 
 			view()->setCursorFromRow(row);
-
 			view()->center();
-			// see BufferView_pimpl::center()
-			view()->updateScrollbar();
+			view()->update();
 			break;
 		}
 
@@ -1985,6 +1983,7 @@
 				package().document_dir() = lyxrc.document_path;
 			}
 		}
+	case LyXRC::RC_DVI_FWSEARCH_SWITCH:
 	case LyXRC::RC_ESC_CHARS:
 	case LyXRC::RC_FONT_ENCODING:
 	case LyXRC::RC_FORMAT:
@@ -2051,6 +2050,7 @@
 	case LyXRC::RC_SERVERPIPE:
 	case LyXRC::RC_SET_COLOR:
 	case LyXRC::RC_SHOW_BANNER:
+	case LyXRC::RC_SOURCE_SPECIALS_SWITCH:
 	case LyXRC::RC_SPELL_COMMAND:
 	case LyXRC::RC_TEMPDIRPATH:
 	case LyXRC::RC_TEMPLATEPATH:
Index: src/lyxrc.h
===================================================================
--- src/lyxrc.h	(revision 13280)
+++ src/lyxrc.h	(working copy)
@@ -58,6 +58,7 @@
 		RC_DIALOGS_ICONIFY_WITH_MAIN,
 		RC_DISPLAY_GRAPHICS,
 		RC_DOCUMENTPATH,
+		RC_DVI_FWSEARCH_SWITCH,
 		RC_ESC_CHARS,
 		RC_FONT_ENCODING,
 		RC_FORMAT,
@@ -120,6 +121,7 @@
 		RC_SERVERPIPE,
 		RC_SET_COLOR,
 		RC_SHOW_BANNER,
+		RC_SOURCE_SPECIALS_SWITCH,
 		RC_SPELL_COMMAND,
 		RC_TEMPDIRPATH,
 		RC_TEMPLATEPATH,
@@ -384,6 +386,13 @@
 	 *  The string is input, stored and output in native format.
 	 */
 	std::string path_prefix;
+	/** Command line option to pass to latex for generation of
+	 *  dvi with source information
+	 */
+	std::string source_specials_switch;
+	/** Command line option to pass to dvi viewer for forward search
+	 */
+	std::string dvi_fwsearch_switch;
 };
 
 
Index: src/lyxrc.C
===================================================================
--- src/lyxrc.C	(revision 13280)
+++ src/lyxrc.C	(working copy)
@@ -87,6 +87,7 @@
 	{ "\\dialogs_iconify_with_main", LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN },
 	{ "\\display_graphics", LyXRC::RC_DISPLAY_GRAPHICS },
 	{ "\\document_path", LyXRC::RC_DOCUMENTPATH },
+	{ "\\dvi_fwsearch_switch", LyXRC::RC_DVI_FWSEARCH_SWITCH },
 	{ "\\escape_chars", LyXRC::RC_ESC_CHARS },
 	{ "\\font_encoding", LyXRC::RC_FONT_ENCODING },
 	{ "\\format", LyXRC::RC_FORMAT },
@@ -155,6 +156,7 @@
 	{ "\\serverpipe", LyXRC::RC_SERVERPIPE },
 	{ "\\set_color", LyXRC::RC_SET_COLOR },
 	{ "\\show_banner", LyXRC::RC_SHOW_BANNER },
+	{ "\\source_specials_switch", LyXRC::RC_SOURCE_SPECIALS_SWITCH },
 	{ "\\spell_command", LyXRC::RC_SPELL_COMMAND },
 	{ "\\tempdir_path", LyXRC::RC_TEMPDIRPATH },
 	{ "\\template_path", LyXRC::RC_TEMPLATEPATH },
@@ -1153,6 +1155,16 @@
 				path_prefix = lexrc.getString();
 			break;
 
+		case RC_SOURCE_SPECIALS_SWITCH:
+			if (lexrc.next())
+				source_specials_switch = lexrc.getString();
+			break;
+
+		case RC_DVI_FWSEARCH_SWITCH:
+			if (lexrc.next())
+				dvi_fwsearch_switch = lexrc.getString();
+			break;
+
 		case RC_LAST: break; // this is just a dummy
 		}
 	}
@@ -1985,6 +1997,16 @@
 	case RC_VIEWER:
 		// Ignore it
 
+	case RC_SOURCE_SPECIALS_SWITCH:
+		if (ignore_system_lyxrc ||
+		    source_specials_switch != system_lyxrc.source_specials_switch)
+			os << "\\source_specials_switch " << '"' << source_specials_switch << '"' << '\n';
+
+	case RC_DVI_FWSEARCH_SWITCH:
+		if (ignore_system_lyxrc ||
+		    dvi_fwsearch_switch != system_lyxrc.dvi_fwsearch_switch)
+			os << "\\dvi_fwsearch_switch " << '"' << dvi_fwsearch_switch << '"' << '\n';
+
 		os << "\n#\n"
 		   << "# CONVERTERS SECTION ##########################\n"
 		   << "#\n\n";
@@ -2165,6 +2187,10 @@
 		str = _("The default path for your documents. An empty value selects the directory LyX was started from.");
 		break;
 
+	case RC_DVI_FWSEARCH_SWITCH:
+		str = _("DVI viewer command line switch to enable dvi forward search.");
+		break;
+
 	case RC_ESC_CHARS:
 	case RC_USE_ESC_CHARS:
 		str = _("Specify additional chars that can be part of a word.");
@@ -2396,6 +2422,10 @@
 		str = _("De-select if you don't want the startup banner.");
 		break;
 
+	case RC_SOURCE_SPECIALS_SWITCH:
+		str = _("LaTeX command line switch to enable source information in the dvi.");
+		break;
+
 	case RC_SPELL_COMMAND:
 		str = _("What command runs the spellchecker?");
 		break;
Index: src/outputparams.h
===================================================================
--- src/outputparams.h	(revision 13280)
+++ src/outputparams.h	(working copy)
@@ -97,6 +97,14 @@
 	 *  if this flag is true, since they may not exist.
 	 */
 	bool inComment;
+
+	/** Whether to insert or not source specials.
+	 */
+	bool srcspecials;
+
+	/** Name of the file latex will run on
+	 */
+	std::string latexfile;
 };
 
 #endif // NOT OUTPUTPARAMS_H
Index: src/outputparams.C
===================================================================
--- src/outputparams.C	(revision 13280)
+++ src/outputparams.C	(working copy)
@@ -18,7 +18,7 @@
 	: flavor(LATEX), nice(false), moving_arg(false),
 	  local_font(0), free_spacing(false), use_babel(false),
 	  linelen(0), depth(0),
-	  exportdata(new ExportData),
+	  exportdata(new ExportData), srcspecials(false),
 	  inComment(false)
 {}
 
Index: src/texrow.h
===================================================================
--- src/texrow.h	(revision 13280)
+++ src/texrow.h	(working copy)
@@ -46,6 +46,9 @@
 	 */
 	bool getIdFromRow(int row, int & id, int & pos) const;
 
+	/// getRowFromId - find the closest row for a given (id, pos) pair
+	int getRowFromId(int id, int pos) const;
+
 	/// Returns the number of rows contained
 	int rows() const { return count; }
 
Index: src/texrow.C
===================================================================
--- src/texrow.C	(revision 13280)
+++ src/texrow.C	(working copy)
@@ -78,6 +78,39 @@
 }
 
 
+int TexRow::getRowFromId(int id, int pos) const
+{
+	RowList::const_iterator cit = rowlist.begin();
+	RowList::const_iterator rowlist_end = rowlist.end();
+	int diff_id = abs(cit->id() - id);
+	int best_id = cit->id();
+	int diff_pos = abs(cit->pos() - pos);
+	int best_row = cit->rownumber();
+	for (++cit; cit != rowlist_end; ++cit) {
+		int new_diff_id = abs(cit->id() - id);
+		int new_best_id = cit->id();
+		int new_diff_pos = abs(cit->pos() - pos);
+		if (new_diff_id < diff_id) {
+			diff_id = new_diff_id;
+			best_id = new_best_id;
+			diff_pos = new_diff_pos;
+			best_row = cit->rownumber();
+		} else if (new_diff_id == diff_id) {
+			if (new_best_id > best_id) {
+				best_id = new_best_id;
+				diff_pos = new_diff_pos;
+				best_row = cit->rownumber();
+			} else if ((new_best_id == best_id)
+				   && (new_diff_pos < diff_pos)) {
+				diff_pos = new_diff_pos;
+				best_row = cit->rownumber();
+			}
+		}
+	}
+	return best_row;
+}
+
+
 TexRow & TexRow::operator+=(TexRow const & tr)
 {
 	rowlist.insert(rowlist.end(), tr.rowlist.begin(), tr.rowlist.end());
Index: src/insets/ExternalSupport.C
===================================================================
--- src/insets/ExternalSupport.C	(revision 13280)
+++ src/insets/ExternalSupport.C	(working copy)
@@ -315,7 +315,7 @@
 		support::ChangeExtension(to_file, string());
 	/* bool const success = */
 		converters.convert(&buffer, temp_file, to_file_base,
-				   from_format, to_format, true);
+				   from_format, to_format, true, false);
 	// return success
 }
 
Index: src/insets/insetgraphics.C
===================================================================
--- src/insets/insetgraphics.C	(revision 13280)
+++ src/insets/insetgraphics.C	(working copy)
@@ -708,7 +708,7 @@
 		<< "\tfile to convert = " << temp_file << '\n'
 		<< "\t from " << from << " to " << to << '\n';
 
-	if (converters.convert(&buf, temp_file, temp_file, from, to, true)) {
+	if (converters.convert(&buf, temp_file, temp_file, from, to, true, false)) {
 		runparams.exportdata->addExternalFile("latex",
 				to_file, output_to_file);
 		runparams.exportdata->addExternalFile("dvi",

Reply via email to