controlling leo to jump to specific line

56 views
Skip to first unread message

Josef

unread,
Jul 24, 2012, 4:40:59 AM7/24/12
to leo-e...@googlegroups.com
When editing LaTeX, I use synctex (e.g.: \synctex=1) to be able to jump forward to the appropriate line in the pdf viewer and back from the viewer to the line in the editor. Under Linux this seems to work currently only for very few setups and I got it working with Emacs and Okular.
I wish this feature would be available in Leo. Backward jumping is more important than forward: I use this feature heavily while proof-reading the PDF: it is just much quicker to shift-click on a line and end up in the right line in the source than searching through the sources until one finds the right line.
To do so, I would need to be able to tell Okular how to jump into a particular source line of a particular file in Leo (via command line). Ideally this should not open a new Leo instance, but direct an already open Leo to the appropriate line. For Emacs I would enter this line in the Okular "Editor" setting:

emacsclient -a emacs --no-wait +%l %f
 
Is there a way to do this in Leo? It should start Leo only if Leo is not open yet, and jump to the line (%l) in the file (%f).

forward-jumping would require to call Okular with the right command line parameters. For Emacs these are:

okular --unique %o#src:%n%b

I am not sure what the parameters mean: I copied them from
http://mathieu.3maisons.org/wordpress/how-to-configure-emacs-and-auctex-to-work-with-a-pdf-viewer#comment-15

- Josef

Terry Brown

unread,
Jul 24, 2012, 8:17:03 AM7/24/12
to leo-e...@googlegroups.com
On Tue, 24 Jul 2012 01:40:59 -0700 (PDT)
Josef <joe...@gmx.net> wrote:

> To do so, I would need to be able to tell Okular how to jump into a
> particular source line of a particular file in Leo (via command line).
> Ideally this should not open a new Leo instance, but direct an already open
> Leo to the appropriate line. For Emacs I would enter this line in the
> Okular "Editor" setting:
>
> emacsclient -a emacs --no-wait +%l %f

A small python script controlling Leo through the leoserver interface
could do this. The one below (also somewhere in the contrib repo.?) is
one I wrote to open files in Leo, or select the file again if it's
already loaded, it would just need the line selection part added.


#!/usr/bin/python
import sys
sys.path.append("/home/tbrown/Package/leo/bzr/leo.repo/trunk")
from leo.external import lproto
import os

addr = open(os.path.expanduser('~/.leo/leoserv_sockname')).read()
pc = lproto.LProtoClient(addr)
pc.send("""
import os
fn = %s
c = g.app.commanders()[0]
h = "@edit "+fn
n = g.findNodeAnywhere(c, h)
if not n:
n = c.rootPosition().insertAfter()
n.moveToRoot(c.rootPosition())
n.h = h
if os.path.isfile(fn):
n.b = file(fn).read()
c.selectPosition(n)
c.redraw()
c.bringToFront()
""" % repr(os.path.join(os.getcwd(), sys.argv[1])) )

Josef

unread,
Jul 29, 2012, 2:14:02 PM7/29/12
to leo-e...@googlegroups.com, terry_...@yahoo.com
Hi Terry,

it took me a while to figure out that the leoserver is provided by the leoremote package. Still, even when with that package loaded I get

Traceback (most recent call last):
  File "openLeo.py", line 7, in <module>

    addr = open(os.path.expanduser('~/.leo/leoserv_sockname')).read()
IOError: [Errno 2] No such file or directory: '/home/dalcolmo/.leo/leoserv_sockname'

What do I need to do to put leo into server mode? - Josef


Terry Brown

unread,
Jul 29, 2012, 4:21:52 PM7/29/12
to leo-e...@googlegroups.com
Do you have it enabled as a plugin in Leo as well as being on the path
of the python running on the script? Needs adding to the
@enabled-plugins node in @settings in myLeoSettings.leo

Cheers -Terry

Josef

unread,
Jul 30, 2012, 4:46:20 AM7/30/12
to leo-e...@googlegroups.com, terry_...@yahoo.com
I have the leoremote plugin enabled, but still Leo does not create any socket on ~/.leo, e.g. I see no "file" ~/.leo.leoserv_sockname,
hence

>     addr = open(os.path.expanduser('~/.leo/leoserv_sockname')).read()

fails. I also do not understand why the leoremote.py file has to be on the Python path (of the external script). I did add the Leo dir do the Python path, so the lproto.py is found.

- Josef
 

Josef

unread,
Jul 30, 2012, 5:07:06 AM7/30/12
to leo-e...@googlegroups.com, terry_...@yahoo.com
Ah! I overlooked the answer in the leoremote doc: I had to execute the command leoserv-start (in the doc it says leoserve-start, which fails: note the different spelling!).

Now I just need to figure out how to execute the leoserv-start command automatically when Leo starts. And then I need to start Leo from the script, if no Leo instance exists yet (and wait until the socket is open).

- Josef

Josef

unread,
Jul 30, 2012, 5:12:44 AM7/30/12
to leo-e...@googlegroups.com, terry_...@yahoo.com


Now I just need to figure out how to execute the leoserv-start command automatically when Leo starts. And then I need to start Leo from the script, if no Leo instance exists yet (and wait until the socket is open).


I just realized, there is a problem when multiple Leo instances are created: if Leo opens a socket automatically upon startup, there will be a collision on ~/.leo/leoserv_sockname. Did anyone already deal with this problem? I suppose it means one must also make sure that no more than 1 Leo instance may exist at any time.

- Josef
Reply all
Reply to author
Forward
0 new messages