Re: lyx-remote script?
On 1.07.04, G. Milde wrote: I wrote a simple shell script that seems to do the trick. There is an error when the filename is relative and pwd != LyX's working dir. The attached python version solves this. Günter -- G.Milde at web.de #!/usr/bin/env python # -*- coding: iso-8859-1 -*- Open a file in a running LyX or start LyX with the file Needs the LyX-Server running (Set EditPreferencesPathsServer-pipe) Test the LyX-Server with lyx -dbg 4096. # TODO: a function for nonblocking opening of a file/pipe # a function for reading a nonblocking pipe with select # a lyxclient object (see /usr/share/pybliographer/Pyblio/LyX.py) import sys, os # --- Customizable values --- # the server pipe path (.in and .out will be added) lyxpipe = os.environ.get(LYXPIPE, ~/.lyx/lyxpipe) # the lyx-function we want to use (see lfuns in the LyX-Wiki) lfun = file-open # --- Preparation --- # normalize the path and convert ~-constructs pipename = os.path.abspath(os.path.expanduser(lyxpipe)) inpipename = pipename+.in outpipename = pipename+.out # --- open the server pipe --- # the built in file() function doesnot allow nonblocking mode # inpipe = file(lyxpipe+'.in', 'w', 0) # -- use os.open # instead of advance tests we catch exceptions (no pipe, lefover pipe) try: inpipe_fd = os.open(inpipename, os.O_WRONLY|os.O_NONBLOCK) except OSError, exception: # print \nerror opening + inpipename if exception.errno == 2: print serverpipe + inpipename + doesnot exist: print wrong path or no running LyX elif exception.errno == 6: print pipe exists but not open for reading print assume leftover from a crashed lyx - deleting it os.remove(inpipename) os.remove(outpipename) else: raise print starting a new lyx session os.execvp(lyx, sys.argv) # convert to built in file object inpipe = os.fdopen(inpipe_fd, 'w', 0) # Send a LYXCMD for every filename argument for arg in sys.argv[1:]: arg = os.path.abspath(arg) # close the LYXCMD line with a '\n' or it will be ignored! inpipe.write(LYXCMD:lyx-remote:%s:%s\n%(lfun,arg)) # response = outpipe.read() # print response inpipe.close()
Re: lyx-remote script?
G. Milde wrote: I wrote a simple shell script that seems to do the trick. Thanks to Kornel Benko and Jean-Pierre Chretien for their tips. A python version proved more complicated because of the possible blocking of writes/reads to/from named pipes. More on this later. (Are there people interested in a Python sampleclient?) Yes. Me. I see you have posted it in a separate mail. Looks very elegant. Given that the lyxserver doesn't work on Win32 machines anyway, I think that this script is a perfectly sufficient solution to the given problem. I'm currently v. busy, but remind me again in one week's time if I haven't followed up on this. I think that you script could go in the repository quite nicely. * Customization.lyx gives a wrong debug number for the server: ... starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx -dbg 4096 Got that. Fixed in cvs. -- Angus
Re: lyx-remote script?
Angus == Angus Leeming [EMAIL PROTECTED] writes: * Customization.lyx gives a wrong debug number for the server: ... starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx -dbg 4096 Angus Got that. Fixed in cvs. Please... Use -dbg lyxserver instead, it is a bit less cryptic. JMarc
Re: lyx-remote script?
Jean-Marc Lasgouttes wrote: Angus == Angus Leeming [EMAIL PROTECTED] writes: * Customization.lyx gives a wrong debug number for the server: ... starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx -dbg 4096 Angus Got that. Fixed in cvs. Please... Use -dbg lyxserver instead, it is a bit less cryptic. Done. -- Angus
Re: lyx-remote script?
On 1.07.04, G. Milde wrote: I wrote a simple shell script that seems to do the trick. There is an error when the filename is relative and pwd != LyX's working dir. The attached python version solves this. Günter -- G.Milde at web.de #!/usr/bin/env python # -*- coding: iso-8859-1 -*- Open a file in a running LyX or start LyX with the file Needs the LyX-Server running (Set EditPreferencesPathsServer-pipe) Test the LyX-Server with lyx -dbg 4096. # TODO: a function for nonblocking opening of a file/pipe # a function for reading a nonblocking pipe with select # a lyxclient object (see /usr/share/pybliographer/Pyblio/LyX.py) import sys, os # --- Customizable values --- # the server pipe path (.in and .out will be added) lyxpipe = os.environ.get(LYXPIPE, ~/.lyx/lyxpipe) # the lyx-function we want to use (see lfuns in the LyX-Wiki) lfun = file-open # --- Preparation --- # normalize the path and convert ~-constructs pipename = os.path.abspath(os.path.expanduser(lyxpipe)) inpipename = pipename+.in outpipename = pipename+.out # --- open the server pipe --- # the built in file() function doesnot allow nonblocking mode # inpipe = file(lyxpipe+'.in', 'w', 0) # -- use os.open # instead of advance tests we catch exceptions (no pipe, lefover pipe) try: inpipe_fd = os.open(inpipename, os.O_WRONLY|os.O_NONBLOCK) except OSError, exception: # print \nerror opening + inpipename if exception.errno == 2: print serverpipe + inpipename + doesnot exist: print wrong path or no running LyX elif exception.errno == 6: print pipe exists but not open for reading print assume leftover from a crashed lyx - deleting it os.remove(inpipename) os.remove(outpipename) else: raise print starting a new lyx session os.execvp(lyx, sys.argv) # convert to built in file object inpipe = os.fdopen(inpipe_fd, 'w', 0) # Send a LYXCMD for every filename argument for arg in sys.argv[1:]: arg = os.path.abspath(arg) # close the LYXCMD line with a '\n' or it will be ignored! inpipe.write(LYXCMD:lyx-remote:%s:%s\n%(lfun,arg)) # response = outpipe.read() # print response inpipe.close()
Re: lyx-remote script?
G. Milde wrote: I wrote a simple shell script that seems to do the trick. Thanks to Kornel Benko and Jean-Pierre Chretien for their tips. A python version proved more complicated because of the possible blocking of writes/reads to/from named pipes. More on this later. (Are there people interested in a Python sampleclient?) Yes. Me. I see you have posted it in a separate mail. Looks very elegant. Given that the lyxserver doesn't work on Win32 machines anyway, I think that this script is a perfectly sufficient solution to the given problem. I'm currently v. busy, but remind me again in one week's time if I haven't followed up on this. I think that you script could go in the repository quite nicely. * Customization.lyx gives a wrong debug number for the server: ... starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx -dbg 4096 Got that. Fixed in cvs. -- Angus
Re: lyx-remote script?
Angus == Angus Leeming [EMAIL PROTECTED] writes: * Customization.lyx gives a wrong debug number for the server: ... starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx -dbg 4096 Angus Got that. Fixed in cvs. Please... Use -dbg lyxserver instead, it is a bit less cryptic. JMarc
Re: lyx-remote script?
Jean-Marc Lasgouttes wrote: Angus == Angus Leeming [EMAIL PROTECTED] writes: * Customization.lyx gives a wrong debug number for the server: ... starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx -dbg 4096 Angus Got that. Fixed in cvs. Please... Use -dbg lyxserver instead, it is a bit less cryptic. Done. -- Angus
Re: "lyx-remote" script?
On 1.07.04, G. Milde wrote: > > I wrote a simple shell script that seems to do the trick. There is an error when the filename is relative and pwd != LyX's working dir. The attached python version solves this. Günter -- G.Milde at web.de #!/usr/bin/env python # -*- coding: iso-8859-1 -*- """Open a file in a running LyX or start LyX with the file Needs the LyX-Server running (Set Edit>Preferences>Paths>Server-pipe) Test the LyX-Server with lyx -dbg 4096. """ # TODO: a function for nonblocking opening of a file/pipe # a function for reading a nonblocking pipe with select # a lyxclient object (see /usr/share/pybliographer/Pyblio/LyX.py) import sys, os # --- Customizable values --- # the server pipe path (".in" and ".out" will be added) lyxpipe = os.environ.get("LYXPIPE", "~/.lyx/lyxpipe") # the lyx-function we want to use (see lfuns in the LyX-Wiki) lfun = "file-open" # --- Preparation --- # normalize the path and convert ~-constructs pipename = os.path.abspath(os.path.expanduser(lyxpipe)) inpipename = pipename+".in" outpipename = pipename+".out" # --- open the server pipe --- # the built in file() function doesnot allow nonblocking mode # inpipe = file(lyxpipe+'.in', 'w', 0) # --> use os.open # instead of advance tests we catch exceptions (no pipe, lefover pipe) try: inpipe_fd = os.open(inpipename, os.O_WRONLY|os.O_NONBLOCK) except OSError, exception: # print "\nerror opening " + inpipename if exception.errno == 2: print "serverpipe " + inpipename + " doesnot exist:" print "wrong path or no running LyX" elif exception.errno == 6: print "pipe exists but not open for reading" print "assume leftover from a crashed lyx -> deleting it" os.remove(inpipename) os.remove(outpipename) else: raise print "starting a new lyx session" os.execvp("lyx", sys.argv) # convert to built in file object inpipe = os.fdopen(inpipe_fd, 'w', 0) # Send a LYXCMD for every filename argument for arg in sys.argv[1:]: arg = os.path.abspath(arg) # close the LYXCMD line with a '\n' or it will be ignored! inpipe.write("LYXCMD:lyx-remote:%s:%s\n"%(lfun,arg)) # response = outpipe.read() # print response inpipe.close()
Re: "lyx-remote" script?
G. Milde wrote: > I wrote a simple shell script that seems to do the trick. Thanks to > Kornel Benko and Jean-Pierre Chretien for their tips. > > A python version proved more complicated because of the possible blocking > of writes/reads to/from named pipes. More on this later. (Are there > people interested in a Python sampleclient?) Yes. Me. I see you have posted it in a separate mail. Looks very elegant. Given that the lyxserver doesn't work on Win32 machines anyway, I think that this script is a perfectly sufficient solution to the given problem. I'm currently v. busy, but remind me again in one week's time if I haven't followed up on this. I think that you script could go in the repository quite nicely. > * Customization.lyx gives a wrong debug number for the server: > ... starting LyX as lyx -dbg 8192 >should become > ... starting LyX as lyx -dbg 4096 Got that. Fixed in cvs. -- Angus
Re: "lyx-remote" script?
> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes: >> * Customization.lyx gives a wrong debug number for the server: ... >> starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx >> -dbg 4096 Angus> Got that. Fixed in cvs. Please... Use "-dbg lyxserver" instead, it is a bit less cryptic. JMarc
Re: "lyx-remote" script?
Jean-Marc Lasgouttes wrote: >> "Angus" == Angus Leeming <[EMAIL PROTECTED]> >> writes: > > >>> * Customization.lyx gives a wrong debug number for the server: ... >>> starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx >>> -dbg 4096 > > Angus> Got that. Fixed in cvs. > > Please... Use "-dbg lyxserver" instead, it is a bit less cryptic. Done. -- Angus
Re: lyx-remote script?
I wrote a simple shell script that seems to do the trick. Thanks to Kornel Benko and Jean-Pierre Chretien for their tips. A python version proved more complicated because of the possible blocking of writes/reads to/from named pipes. More on this later. (Are there people interested in a Python sampleclient?) BTW: I found 2 documentation errors in LyX 1.3.3 * The German de_Customization.lyx misses the section about the lyxserver. * Customization.lyx gives a wrong debug number for the server: ... starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx -dbg 4096 Günter -- G.Milde at web.de
Re: lyx-remote script?
I wrote a simple shell script that seems to do the trick. Thanks to Kornel Benko and Jean-Pierre Chretien for their tips. A python version proved more complicated because of the possible blocking of writes/reads to/from named pipes. More on this later. (Are there people interested in a Python sampleclient?) BTW: I found 2 documentation errors in LyX 1.3.3 * The German de_Customization.lyx misses the section about the lyxserver. * Customization.lyx gives a wrong debug number for the server: ... starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx -dbg 4096 Günter -- G.Milde at web.de
Re: "lyx-remote" script?
I wrote a simple shell script that seems to do the trick. Thanks to Kornel Benko and Jean-Pierre Chretien for their tips. A python version proved more complicated because of the possible blocking of writes/reads to/from named pipes. More on this later. (Are there people interested in a Python sampleclient?) BTW: I found 2 documentation errors in LyX 1.3.3 * The German de_Customization.lyx misses the section about the lyxserver. * Customization.lyx gives a wrong debug number for the server: ... starting LyX as lyx -dbg 8192 should become ... starting LyX as lyx -dbg 4096 Günter -- G.Milde at web.de
Re: lyx-remote script?
Date: Tue, 15 Jun 2004 08:14:16 +0200 From: G. Milde [EMAIL PROTECTED] To: LyX Users List [EMAIL PROTECTED] Subject: lyx-remote script? Dear Lyxers, I would like to see a script, that * opens a file in a LyX session, if there is an open one, or * starts LyX with the file, if there is no LyX running. I thought about checking for ~.lyxpipe, if it exists send an open file command there, if not start LyX with file. The lyxpipe files may be there alone if LyX has been killed unexpectedly, so this test in not enough robust. You need to check if there is an active LyX with ps, e.g. in Perl if ((-e $ENV{HOME}/.lyxpipe.in) (grep(/lyx/,`ps -u $ENV{USER}`))) { # open a buffer through the pipe } else { `$0 $ARGV[0]` } I'm unfamiliar with file loading in buffers with the LyX server, the commented line should be repaced by the correct syntax. -- Jean-Pierre
Re: lyx-remote script?
G. Milde [EMAIL PROTECTED] writes: I would like to see a script, that * opens a file in a LyX session, if there is an open one, or * starts LyX with the file, if there is no LyX running. Years ago, when I first ported LyX-1.3.x to X11 on the Mac, I wrote a script that does this. The script is actually for use with an Applescript that responds to a file dropped on it, but it should work as well from the command line. See if http://www.18james.com/code/lyx-remote does part of what you need. -- Ronald Florence ron.18james.com
Re: lyx-remote script?
Date: Tue, 15 Jun 2004 08:14:16 +0200 From: G. Milde [EMAIL PROTECTED] To: LyX Users List [EMAIL PROTECTED] Subject: lyx-remote script? Dear Lyxers, I would like to see a script, that * opens a file in a LyX session, if there is an open one, or * starts LyX with the file, if there is no LyX running. I thought about checking for ~.lyxpipe, if it exists send an open file command there, if not start LyX with file. The lyxpipe files may be there alone if LyX has been killed unexpectedly, so this test in not enough robust. You need to check if there is an active LyX with ps, e.g. in Perl if ((-e $ENV{HOME}/.lyxpipe.in) (grep(/lyx/,`ps -u $ENV{USER}`))) { # open a buffer through the pipe } else { `$0 $ARGV[0]` } I'm unfamiliar with file loading in buffers with the LyX server, the commented line should be repaced by the correct syntax. -- Jean-Pierre
Re: lyx-remote script?
G. Milde [EMAIL PROTECTED] writes: I would like to see a script, that * opens a file in a LyX session, if there is an open one, or * starts LyX with the file, if there is no LyX running. Years ago, when I first ported LyX-1.3.x to X11 on the Mac, I wrote a script that does this. The script is actually for use with an Applescript that responds to a file dropped on it, but it should work as well from the command line. See if http://www.18james.com/code/lyx-remote does part of what you need. -- Ronald Florence ron.18james.com
Re: "lyx-remote" script?
>>Date: Tue, 15 Jun 2004 08:14:16 +0200 >>From: "G. Milde" <[EMAIL PROTECTED]> >>To: LyX Users List <[EMAIL PROTECTED]> >>Subject: "lyx-remote" script? >> >>Dear Lyxers, >> >>I would like to see a script, that >> * opens a file in a LyX session, if there is an open one, or >> * starts LyX with the file, if there is no LyX running. >> >>I thought about checking for ~.lyxpipe, >> if it exists send an open file command there, >> if not start LyX with file. The lyxpipe files may be there alone if LyX has been killed unexpectedly, so this test in not enough robust. You need to check if there is an active LyX with ps, e.g. in Perl if ((-e "$ENV{HOME}/.lyxpipe.in") && (grep(/lyx/,`ps -u $ENV{USER}`))) { # open a buffer through the pipe } else { `$0 $ARGV[0]` } I'm unfamiliar with file loading in buffers with the LyX server, the commented line should be repaced by the correct syntax. -- Jean-Pierre
Re: "lyx-remote" script?
"G. Milde" <[EMAIL PROTECTED]> writes: > I would like to see a script, that >* opens a file in a LyX session, if there is an open one, or >* starts LyX with the file, if there is no LyX running. Years ago, when I first ported LyX-1.3.x to X11 on the Mac, I wrote a script that does this. The script is actually for use with an Applescript that responds to a file dropped on it, but it should work as well from the command line. See if http://www.18james.com/code/lyx-remote does part of what you need. -- Ronald Florence ron.18james.com
lyx-remote script?
Dear Lyxers, I would like to see a script, that * opens a file in a LyX session, if there is an open one, or * starts LyX with the file, if there is no LyX running. I thought about checking for ~.lyxpipe, if it exists send an open file command there, if not start LyX with file. Is there already something like this? (Or could a LyX-guru write it on the fly?) Günter -- G.Milde at web.de
lyx-remote script?
Dear Lyxers, I would like to see a script, that * opens a file in a LyX session, if there is an open one, or * starts LyX with the file, if there is no LyX running. I thought about checking for ~.lyxpipe, if it exists send an open file command there, if not start LyX with file. Is there already something like this? (Or could a LyX-guru write it on the fly?) Günter -- G.Milde at web.de
"lyx-remote" script?
Dear Lyxers, I would like to see a script, that * opens a file in a LyX session, if there is an open one, or * starts LyX with the file, if there is no LyX running. I thought about checking for ~.lyxpipe, if it exists send an open file command there, if not start LyX with file. Is there already something like this? (Or could a LyX-guru write it on the fly?) Günter -- G.Milde at web.de