Monday, December 3, 2012

Re: how to execute ranger from gvim

On 2012-12-03, ping wrote:
>
> On 12/03/2012 01:44 PM, Gary Johnson wrote:

> > " RangerChooser()
> > "
> > " Ranger version 1.4.2 or later is required to run this function. That's when
> > " the --choosefile option was added.
> >
> > fun! RangerChooser(...)
> > let tmpfile = tempname() " Get the name of a temporary
> > " file.
> > if a:0 > 0 && a:1 != "" " If the user has supplied an
> > " argument,
> > let dir = a:1 " set dir to that argument,
> > elseif expand("%") " otherwise if the current
> > " buffer has a name,
> > let dir = "." " set dir to the current
> > " working directory.
> > else " Otherwise,
> > let dir = expand("%:p:h") " set dir to the directory
> > " containing the current
> > " buffer.

Setting dir that way doesn't make sense to me. Either I wasn't
thinking straight when I wrote it or I'm not thinking straight now.

> > endif
> > exe 'silent !ranger --choosefile='.tmpfile dir
> > " Execute ranger in the
> > " directory given by dir and
> > " put the selected file in
> > " tmpfile.
> > if filereadable(tmpfile) " If tmpfile is readable,
> > exe 'edit' readfile(tmpfile)[0]
> > " edit the file whose name
> > " is in the first line of
> > " tmpfile. (readfile()
> > " returns the contents of the
> > " file as a list of lines.
> > " List element 0 is the
> > " first line.
> > call delete(tmpfile) " Delete the temporary file.
> > endif
> > redraw! " The display may have been
> > " messed up by ranger, so
> > " redraw it.
> > endfun
> > "map ,r :call RangerChooser()<CR>
> > command -nargs=? RangerChooser call RangerChooser("<args>")

> that are really magic codes and great vim+ranger combination. It works, I don't
> quite understand exactly how it works though...

I annotated the function above.

HTH,
Gary

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment