Make a link to a file in relative way.

91 views
Skip to first unread message

smcho

unread,
Nov 11, 2010, 3:43:03 PM11/11/10
to leo-editor
Leo file is in file://localhost/A/C, so the relative path from leo
directory to the pdf is ../B.

My question is can I make the link in the relative way? I sometimes
move the whole directory, so it's not a good idea for me to store all
the link information absolute way.

For linking a pdf file within Leo, I use @url as follows.
@url file://localhost/A/B/hello.pdf

But
@url file://../B/hello.pdf

doesn't work.

Edward K. Ream

unread,
Nov 11, 2010, 6:25:54 PM11/11/10
to leo-e...@googlegroups.com
On Thu, Nov 11, 2010 at 2:43 PM, smcho <csmg...@gmail.com> wrote:

> My question is can I make the link in the relative way?

The following works:

@url 'file:./../doc/leoDocs.leo#Users Guide-->Basics-->Customizing Leo'

For reference, see the code in g.handleUrlInUrlNode. There is a
comment which says:

Most browsers should handle the following urls:
ftp://ftp.uu.net/public/whatever.
http://localhost/MySiteUnderDevelopment/index.html
file://home/me/todolist.html

I'm not sure how reliable that comment is :-)

Edward

smcho

unread,
Nov 12, 2010, 3:46:04 PM11/12/10
to leo-editor
I have a leo file in directory A/B, and put 15.pdf file in A.
I tried @url 'file:./../15.pdf', but it doesn't work.

The error message printed is as follows.

0:32: execution error: An error of type -2110 has occurred. (-2110)


On Nov 11, 5:25 pm, "Edward K. Ream" <edream...@gmail.com> wrote:

smcho

unread,
Nov 12, 2010, 4:16:02 PM11/12/10
to leo-editor
I find that file:// is used for absolute path, but one can use
file://abc/def/../cde to point to the relative path.
However in order to do that, I need to know current path.

Is there a way to make

file://<CURRENT_PATH>/../abc.pdf

so that Leo knows the CURRENT_PATH to fill it up to open the abc.pdf
file?

Edward K. Ream

unread,
Nov 12, 2010, 6:20:19 PM11/12/10
to leo-e...@googlegroups.com
On Fri, Nov 12, 2010 at 3:16 PM, smcho <csmg...@gmail.com> wrote:

> Is there a way to make
>
> file://<CURRENT_PATH>/../abc.pdf
>
> so that Leo knows the CURRENT_PATH to fill it up to open the abc.pdf
> file?

Yes. Use the {{exp}} form. Within @path and @<file> paths, {{exp}}
gets evaluated with the following symbols known: c, g, p, os and sys.
Example:

@file {{os.curdir}}/../abc.pdf

Not sure whether this works with @url.

This isn't documented anywhere at present. It's on the list to add before rc1.

Edward

smcho

unread,
Nov 12, 2010, 7:59:47 PM11/12/10
to leo-editor
>     @file {{os.curdir}}/../abc.pdf
I checked it works.

> Not sure whether this works with @url.
It doesn't work. When I run "os.curdir", I get '.', and I need to run
os.path.abspath(os.curdir) to get absolute path.
As @url requires abs path, there should be a way to run
os.path.abspath(os.curdir) to check if it works with @url.

Edward K. Ream

unread,
Nov 13, 2010, 2:02:28 PM11/13/10
to leo-e...@googlegroups.com
On Fri, Nov 12, 2010 at 6:59 PM, smcho <csmg...@gmail.com> wrote:

> there should be a way to run os.path.abspath(os.curdir) to check if it works with @url.

os is defined in {{exp}} so the following should work:

{{os.path.abspath(os.curdir)}}

Edward

smcho

unread,
Nov 13, 2010, 11:17:19 PM11/13/10
to leo-editor
Compared to this error message : 0:29: execution error: An error of
type -2110 has occurred. (-2110)
when I have 'file:./15.pdf', I got the following error.

0:47: execution error: File some object wasn’t found. (-43)

with this

file://localhost{{os.path.abspath(os.curdir)}}/15.pdf

It doesn't seem to work, and I can guess what went wrong if I know the
whole path.
Can I print out what the full path of "file://
localhost{{os.path.abspath(os.curdir)}}/15.pdf"?

On Nov 13, 1:02 pm, "Edward K. Ream" <edream...@gmail.com> wrote:

Edward K. Ream

unread,
Nov 14, 2010, 1:52:13 PM11/14/10
to leo-e...@googlegroups.com
On Fri, Nov 12, 2010 at 3:16 PM, smcho <csmg...@gmail.com> wrote:

> Is there a way to make
>
> file://<CURRENT_PATH>/../abc.pdf
>
> so that Leo knows the CURRENT_PATH to fill it up to open the abc.pdf
> file?

Yes. Use the {{exp}} form. Within @path and @<file> paths, {{exp}}


gets evaluated with the following symbols known: c, g, p, os and sys.
Example:

@file {{os.curdir}}/../abc.pdf

Not sure whether this works with @url.

I just added this to the documentation. See LeoDocs.leo, and search for "{{"

Edward

Reply all
Reply to author
Forward
0 new messages