vimwiki-backup / vimwiki

Automatically exported from code.google.com/p/vimwiki
1 stars 1 forks source link

open schemes with program like utl.vim #328

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Let vimwiki open schemes like
- [[local:...]
- [[http:...]
- [[man:...]
....
etc
with programs like firefox, man, PDF viewer, libreoffice etc.

Just like script "utl.vim".
let user self define which program to open which scheme.

Original issue reported on code.google.com by numbch...@gmail.com on 25 May 2012 at 4:58

GoogleCodeExporter commented 9 years ago
Also let user define custom scheme is better.

Original comment by numbch...@gmail.com on 25 May 2012 at 4:59

GoogleCodeExporter commented 9 years ago
All known schemes are opened with vimwiki (local, http, file, ...)

Unknown(unregistered?) schemes should be passed to VimwikiWeblinkHandler user 
func.
We should probably rename it to VimwikiLinkHander

Original comment by habamax on 29 May 2012 at 3:27

GoogleCodeExporter commented 9 years ago
If it is possible, I hope author can implement same function like utl.vim. 
instead of opening them as text.
for example:
[[local:./LaTeX.pdf]]
I hope it can be opened by a PDF viewer instead of opening as text file.

Original comment by numbch...@gmail.com on 29 May 2012 at 3:54

GoogleCodeExporter commented 9 years ago
current implementation should be able to open link such as

file:///home/user/Documents/test.pdf

in an external viewer.

Original comment by habamax on 29 May 2012 at 5:08

GoogleCodeExporter commented 9 years ago
=> On [2012-05-29 17:08:37 +0000]:
 vimwiki@googlecode.com Said: 

This handler can not open filename contains space,
I tried link format like bellowing:
    file:///program/books/kk - cn.pdf
    file:///program/books/kk\ -\ cn.pdf
Both of them can not work.

Original comment by numbch...@gmail.com on 29 May 2012 at 11:59

GoogleCodeExporter commented 9 years ago
1. file:/// links should be without spaces
2. links are absolute, it means that you have to have /program/books/kk - 
cn.pdf (I doubt this path exists on linux)
3. you should use [[file:///absolute path to file/file name.pdf]]

It work for linux with current sources from hg.
But doesn't work for windows yet.

Original comment by habamax on 30 May 2012 at 6:25

GoogleCodeExporter commented 9 years ago
=> On [2012-05-30 06:25:23 +0000]:
 vimwiki@googlecode.com Said: 

When I use [[file:///./program/books/Clean\ Code\ -\ CN.pdf]]
Error:
    xdg-open: file '/./program/books/Clean\' does not exist'
When I use [[file:///./program/books/Clean Code - CN.pdf]]
    this relative path can not work.
When I use absolute path, then it work.
Why vimwiki have to use absolute path ?  It is really weird.
handler must support relative path.

ERROR: when I use absolute path, then vimwiki can find the file correctly.
But vimwiki open it with vim instead of pdf viewer.

Original comment by numbch...@gmail.com on 30 May 2012 at 6:47

GoogleCodeExporter commented 9 years ago
Relative paths doesn't work for [[file:///. Weird or not -- this is subject to 
discuss.
There is VimwikiLinkHandler user function, use it to do with [[file:/// 
whatever you want.

Opening in external program doesn't work for dev version posted here -- use 
sources from hg repository.

Original comment by habamax on 30 May 2012 at 7:38

GoogleCodeExporter commented 9 years ago
=> On [2012-05-30 07:38:21 +0000]:
 vimwiki@googlecode.com Said: 

I know say this is weird is not good for programmer. I read an article about
this. So, sorry for this. I was not that mean.
I think let vim get a relative path parameter to a function is not so hard.
That's why I think this is weird.

I think I'm using hg repository.
I'm using Vim-Addon-Manager.
and this is the output of its source.
    Source URL: https://code.google.com/p/vimwiki (type hg)

Original comment by numbch...@gmail.com on 30 May 2012 at 8:03

GoogleCodeExporter commented 9 years ago
Check the latest sources.

Have also a look into Issue 339

Original comment by habamax on 30 May 2012 at 6:28

GoogleCodeExporter commented 9 years ago
=> On [2012-05-30 18:28:07 +0000]:
 vimwiki@googlecode.com Said: 

Tested new sources, absolute can work find. Relative path still can not work.
Hope this can be solved in the future.

Original comment by numbch...@gmail.com on 31 May 2012 at 1:38

GoogleCodeExporter commented 9 years ago
Please see Issue 338, and try the latest sources (... once again!)

I have written a custom VimwikiLinkHandler() that should help.  You can paste 
it into your vimrc file.

Thx for your continued efforts!

Original comment by stu.andrews on 31 May 2012 at 2:50

GoogleCodeExporter commented 9 years ago
=> On [2012-05-31 02:50:51 +0000]:
 vimwiki@googlecode.com Said: 

In vimwiki file.
    [[file:///./program/books/Clean Code - CN.pdf]]
    [[file://./program/books/Clean Code - CN.pdf]]
    [[file://program/books/Clean Code - CN.pdf]]
The file is in ./program/books/Clean\ Code\ -\ CN.pdf.
All above links can not work.

I followed doc help, setup VimwikiLinkHandler() function like this:
    function! VimwikiLinkHandler(link)
        let browser = 'firefox'
        execute 'silent !xdg-open "'.browser.'" ' . a:link
    endfunction

Then got error:
    xdg-open: unexpected argument 'file:///./program/books/Clean'
    xdg-open: unexpected argument 'file://./program/books/Clean'
    xdg-open: unexpected argument 'file://program/books/Clean'

The [[local:./program/books/xxx.pdf]] scheme is find.
I think upper function need to be improved.
the `a:link` variable should be parsed.

Original comment by numbch...@gmail.com on 31 May 2012 at 3:48

GoogleCodeExporter commented 9 years ago
=> On [2012-05-31 02:50:51 +0000]:
 vimwiki@googlecode.com Said: 

I try to find out how you parse file:/// scheme in your source code.
I found this:
    " ensure there are three slashes after 'file:'
    let path = substitute(path, '\%(file://\)\?\zs'.'/\+', '/', 'g')
    " remove repeated /'s
    let subdir = substitute(subdir, '/\+', '/', 'g')
    let lnk = substitute(lnk, '/\+', '/', 'g')
    if vimwiki#u#is_windows()
        let lnk = substitute(lnk, '^/\ze[[:alpha:]]:', '', '')
    endif
    '"')"

I think I should add this into my custom function.

Original comment by numbch...@gmail.com on 31 May 2012 at 3:53

GoogleCodeExporter commented 9 years ago
I found one function to parse scheme link:
    let link = vimwiki#base#resolve_scheme(link, 0)
My custom function still can not work even I add this into my function.
I think vimwiki's vimwiki#base#resolve_scheme() can be more smart.

Original comment by numbch...@gmail.com on 31 May 2012 at 3:58

GoogleCodeExporter commented 9 years ago
I am not a wizard or telepathist.

What do you want to achieve?
Links with [[local: scheme use relative paths and now(!) are opened using 
system default application. Get the latest sources.

If you want further customization then
1. grab current sources from this HG repo using mercurial.
2. open doc/vimwiki.txt and find VimwikiLinkHandler function example
3. customize.

PS
I know nothing about vim-addon-manager so I don't know if it is ok to pull the 
latest sources from the repo using it.

Original comment by habamax on 31 May 2012 at 4:12

GoogleCodeExporter commented 9 years ago
And after all if it still doesn't work for you...
Then show us your custom VimwikiLinkHandler function.

Original comment by habamax on 31 May 2012 at 4:23

GoogleCodeExporter commented 9 years ago
=> On [2012-05-31 04:12:19 +0000]:
 vimwiki@googlecode.com Said: 

Hmm, the [[local:]] scheme can work, it's fine.
Sorry for this.

I did.

I think VAM is using the hg repo.

So it's find now.
Close this issue.

Original comment by numbch...@gmail.com on 31 May 2012 at 4:25

GoogleCodeExporter commented 9 years ago
=> On [2012-05-31 04:24:06 +0000]:
 vimwiki@googlecode.com Said: 

I have replied my custom function in my email.

Original comment by numbch...@gmail.com on 31 May 2012 at 4:38

GoogleCodeExporter commented 9 years ago
I misunderstand the [[file:///]] scheme, I thought [[file:///]] scheme is 
similar [[local:]], that's why I ask you [[file:///]] scheme still can not open 
links correctly. I read the "updated" issue338, you only changed [[local:]] 
behavior. I think this is enough. issue solved.

Original comment by numbch...@gmail.com on 31 May 2012 at 4:42

GoogleCodeExporter commented 9 years ago
ok, that is fine!

Original comment by habamax on 31 May 2012 at 5:01