Hello again, This patch implements Inverse DVI search for lyx. It needs my previous patch for the socket lyxserver. To use it, define
xdvi -editor 'lyxclient -a $$s -g %f %l' as the viewer for the DVI format and latex --src-specials as the latex->DVI converter. As with the previous, I will provide Changelog entries if this patch gets accepted. Regards, João.
Index: src/format.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/format.C,v retrieving revision 1.19 diff -u -r1.19 format.C --- src/format.C 2003/10/06 15:42:15 1.19 +++ src/format.C 2003/10/08 05:11:12 @@ -16,6 +16,7 @@ #include "lyxrc.h" #include "debug.h" #include "gettext.h" +#include "LyXSocket.h" #include "frontends/Alert.h" //to be removed? @@ -36,11 +37,13 @@ using std::string; +extern LyXServerSocket * lyxsocket; namespace { string const token_from("$$i"); string const token_path("$$p"); +string const token_socket("$$s"); } //namespace anon @@ -196,7 +199,7 @@ command = subst(command, token_from, QuoteName(OnlyFilename(filename))); command = subst(command, token_path, QuoteName(OnlyPath(filename))); - + command = subst(command, token_socket, QuoteName(lyxsocket->address())); lyxerr[Debug::FILES] << "Executing command: " << command << std::endl; buffer.message(_("Executing command: ") + command); Index: src/bufferlist.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/bufferlist.C,v retrieving revision 1.134 diff -u -r1.134 bufferlist.C --- src/bufferlist.C 2003/10/06 15:42:06 1.134 +++ src/bufferlist.C 2003/10/08 05:11:16 @@ -37,6 +37,7 @@ using lyx::support::MakeDisplayPath; using lyx::support::OnlyFilename; using lyx::support::removeAutosaveFile; +using lyx::support::prefixIs; using std::endl; using std::find; @@ -326,6 +327,17 @@ find_if(bstore.begin(), bstore.end(), lyx::compare_memfun(&Buffer::fileName, s)); return it != bstore.end() ? (*it) : 0; +} + + +Buffer * BufferList::getBufferFromTmp(string const & s) +{ + BufferStorage::iterator it = bstore.begin(); + BufferStorage::iterator end = bstore.end(); + for (; it < end; ++it) + if (prefixIs(s, (*it)->temppath())) + return *it; + return 0; } Index: src/bufferlist.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/bufferlist.h,v retrieving revision 1.45 diff -u -r1.45 bufferlist.h --- src/bufferlist.h 2003/10/07 06:45:24 1.45 +++ src/bufferlist.h 2003/10/08 05:11:18 @@ -68,6 +68,8 @@ Buffer * getBuffer(std::string const &); /// returns a pointer to the buffer with the given number. Buffer * getBuffer(unsigned int); + /// returns a pointer to the buffer whose temppath matches the string + Buffer * BufferList::getBufferFromTmp(std::string const &); /// reset current author for all buffers void setCurrentAuthor(std::string const & name, std::string const & email); Index: src/lyxfunc.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxfunc.C,v retrieving revision 1.509 diff -u -r1.509 lyxfunc.C --- src/lyxfunc.C 2003/10/07 07:42:11 1.509 +++ src/lyxfunc.C 2003/10/08 05:11:25 @@ -73,6 +73,7 @@ #include "support/path_defines.h" #include "support/tostr.h" #include "support/std_sstream.h" +#include "support/os.h" using bv_funcs::apply_freefont; using bv_funcs::changeDepth; @@ -104,6 +105,8 @@ using lyx::support::token; using lyx::support::trim; using lyx::support::user_lyxdir; +using lyx::support::prefixIs; +using lyx::support::os::getTmpDir; using std::endl; using std::make_pair; @@ -1364,14 +1367,20 @@ int row; istringstream istr(argument.c_str()); istr >> file_name >> row; - // 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)); + if (prefixIs(file_name, getTmpDir())) { + // Needed by inverse dvi search. If it is a file + // in tmpdir, call the apropriated function + view()->buffer(bufferlist.getBufferFromTmp(file_name)); } else { - view()->loadLyXFile(s); + // 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)); + } else { + view()->loadLyXFile(s); + } } view()->setCursorFromRow(row);