Hello,

I updated my patchs on inverse dvi search. Please have a look at it.

inverse-search.diff: enhance the behavior of the function
server-goto-file-row and create new function in the class BufferList
(getBufferFromTmppath) to identify a buffer by its temporary path.

lyx-client.diff: create a new command line switch -client to lyx. It has
the form

lyx -client <line> <file>

and try to communicate with a running lyx through lyxpipes and send a

LYXCMD:lyxclient:server-goto-file-row:<file> <line>

string to it.

To configure lyx to use inverse search (qt frontend):
1. Enable (to whatever name) LyxServer pipes in Edit->Preferences->Paths
2. Add the flag --src-specials to latex command in
   Edit->Preferences->Converters->[Latex->Dvi]->Converter
   (I changed 'latex $$i' to 'latex --src-specials $$i')
3. Edit->Preferences->File formats->DVI->Viewer and add the option

      -editor '/path/to/lyx -client %l %f'

to xdvi command (or simply

      -editor 'lyx -client %l %f'

when lyx be in the path).

ATTENTION: my tetex distribution has a broken xdvi wrapper script. For me,
it was nececessary to substitute xdvi by

      xdvi.real -editor '/path/to/lyx -client %l %f'


It would be cool if the 'configure' script also could detect whether latex
supports --src-specials and xdvi supports -editor, and also to make use
of lyxpipes by default. What do you think about it?

If you have any questions or suggestions on my patches, please let me
know.

Regards,
João.
Index: src/lyxfunc.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.413
diff -u -r1.413 lyxfunc.C
--- src/lyxfunc.C	2003/03/10 22:12:05	1.413
+++ src/lyxfunc.C	2003/03/11 14:17:15
@@ -1293,11 +1293,17 @@
 		// Must replace extension of the file to be .lyx and get full path
 		string const s(ChangeExtension(file_name, ".lyx"));
 
-		// Either change buffer or load the file
-		if (bufferlist.exists(s)) {
-			view()->buffer(bufferlist.getBuffer(s));
+		// Check wether the path is in the temp dir
+		if (prefixIs(s, system_tempdir)) {
+			lyxerr[Debug::INFO] << "Gotofilerow in tmpdir" << endl;
+			view()->buffer(bufferlist.getBufferFromTmppath(s));
 		} else {
-			view()->buffer(bufferlist.loadLyXFile(s));
+			// Either change buffer or load the file
+			if (bufferlist.exists(s)) {
+				view()->buffer(bufferlist.getBuffer(s));
+			} else {
+				view()->buffer(bufferlist.loadLyXFile(s));
+			}
 		}
 
 		view()->setCursorFromRow(row);
Index: src/bufferlist.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/bufferlist.C,v
retrieving revision 1.97
diff -u -r1.97 bufferlist.C
--- src/bufferlist.C	2003/03/04 09:27:27	1.97
+++ src/bufferlist.C	2003/03/11 14:17:15
@@ -417,6 +417,21 @@
 }
 
 
+Buffer * BufferList::getBufferFromTmppath(string const & s)
+{
+	BufferStorage::iterator it = bstore.begin();
+	BufferStorage::iterator end = bstore.end();
+	for (; it != end; ++it) {
+		if (prefixIs(s, (*it)->tmppath)) {
+			string::size_type tmppath_s = (*it)->tmppath.size();
+			if(s.size() == tmppath_s || s.at(tmppath_s) == '/')
+				return *it;
+		}
+	}
+	return 0;
+}
+
+
 Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
 {
 	// get a free buffer
Index: src/bufferlist.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/bufferlist.h,v
retrieving revision 1.37
diff -u -r1.37 bufferlist.h
--- src/bufferlist.h	2003/03/02 12:16:00	1.37
+++ src/bufferlist.h	2003/03/11 14:17:15
@@ -82,6 +82,9 @@
 	/// returns a pointer to the buffer with the given number.
 	Buffer * getBuffer(unsigned int);
 
+	/// returns a pointer to the buffer with the given tmppath
+	Buffer * getBufferFromTmppath(string const & s);
+
 	/// reset current author for all buffers
 	void setCurrentAuthor(string const & name, string const & email);
 
Index: src/lyx_main.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyx_main.C,v
retrieving revision 1.137
diff -u -r1.137 lyx_main.C
--- src/lyx_main.C	2003/02/28 09:49:44	1.137
+++ src/lyx_main.C	2003/03/11 14:15:53
@@ -42,6 +42,7 @@
 #include "BoostFormat.h"
 #include <boost/function.hpp>
 
+#include <fstream>
 #include <cstdlib>
 #include <csignal>
 
@@ -74,6 +75,34 @@
 // convenient to have it here.
 boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
+namespace
+{
+
+void clientSendCmd(string const & cmd)
+{
+	if (lyxrc.lyxpipes.empty()) {
+		lyxerr << _("Lyx is not configured to communicate with pipes.");
+		exit(1);
+	}
+	string outpipe(lyxrc.lyxpipes + ".in");
+	if (IsFileWriteable(outpipe) != 1) {
+		lyxerr << _("No pipe to communicate with lyx. Is lyx running?");
+		exit(1);
+	}
+	string inpipe(lyxrc.lyxpipes + ".out");
+	string ans;
+
+	ofstream out(outpipe.c_str(), ios::app);
+	ifstream in(inpipe.c_str(), ios::in);
+
+	out << cmd << endl;
+	out.close();
+	in >> ans;
+	lyxerr[Debug::INFO] << ans << endl;
+	in.close();
+}
+
+} // namespace anon
 
 LyX::LyX(int & argc, char * argv[])
 {
@@ -116,6 +145,18 @@
 	init(want_gui);
 	lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
 
+	// If called as client, send the command to the server and exit.
+	if (!client_command.empty()) {
+		clientSendCmd(client_command);
+		exit(0);
+	}
+
+	os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
+	system_tempdir = os::getTmpDir();
+	if (lyxerr.debugging(Debug::INIT)) {
+		lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
+	}
+
 	if (want_gui) {
 		lyx_gui::parse_lyxrc();
 	}
@@ -209,7 +250,6 @@
 
 }
 
-
 void LyX::init(bool gui)
 {
 	signal(SIGHUP, error_handler);
@@ -464,12 +504,6 @@
 		lyxrc.print();
 	}
 
-	os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
-	system_tempdir = os::getTmpDir();
-	if (lyxerr.debugging(Debug::INIT)) {
-		lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
-	}
-
 	lyxerr[Debug::INIT] << "Reading lastfiles `"
 			    << lyxrc.lastfiles << "'..." << endl;
 	lastfiles.reset(new LastFiles(lyxrc.lastfiles,
@@ -477,7 +511,6 @@
 				      lyxrc.num_lastfiles));
 }
 
-
 void LyX::defaultKeyBindings(kb_keymap  * kbmap)
 {
 	kbmap->bind("Right", LFUN_RIGHT);
@@ -761,6 +794,7 @@
 
 bool is_gui = true;
 string batch;
+string client;
 
 /// return the the number of arguments consumed
 typedef boost::function<int(string const &, string const &)> cmd_helper;
@@ -882,6 +916,17 @@
 	return 2;
 }
 
+int parse_client(string const & row, string const & file)
+{
+	if (row.empty()) {
+		lyxerr << _("Missing row number after --client switch") << endl;
+		exit(1);
+	}
+	client = "LYXCMD:lyxclient:server-goto-file-row:" + file + ' ' + row;
+	is_gui = false;
+	return 1;
+}
+
 } // namespace anon
 
 
@@ -902,6 +947,7 @@
 	cmdmap["--export"] = parse_export;
 	cmdmap["-i"] = parse_import;
 	cmdmap["--import"] = parse_import;
+	cmdmap["-client"] = parse_client;
 
 	for (int i = 1; i < argc; ++i) {
 		std::map<string, cmd_helper>::const_iterator it
@@ -925,6 +971,7 @@
 	}
 
 	batch_command = batch;
+	client_command = client;
 
 	return is_gui;
 }
Index: src/lyx_main.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyx_main.h,v
retrieving revision 1.33
diff -u -r1.33 lyx_main.h
--- src/lyx_main.h	2003/02/13 16:52:29	1.33
+++ src/lyx_main.h	2003/03/11 14:15:53
@@ -65,6 +65,8 @@
 	bool first_start;
 	/// the parsed command line batch command if any
 	string batch_command;
+	/// the parsed command line client command if any
+	string client_command;
 };
 
 #endif // LYX_MAIN_H

Reply via email to