[netrw] How to use netrw#Call() to create custom mappings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[netrw] How to use netrw#Call() to create custom mappings

Pablo Giménez Pizarro
Hello.
I want to customize some of the shortcuts in Netrw.
I have seen it provides a global variable which is a dictionary of key mappings and function calls.
I paste here  a snippet from the help:
Example: Clear netrw's marked file list via a mapping on gu >
    " ExampleUserMap: {{{2
    fun! ExampleUserMap(islocal)
      call netrw#Modify("netrwmarkfilelist",[])
      call netrw#Modify('netrwmarkfilemtch_{bufnr("%")}',"")
      let retval= ["refresh"]
      return retval
    endfun

    let g:Netrw_UserMaps= [["gu","ExampleUserMap"]]

What I am trying to do is to use this mechanism to map u to browse up dir rather than -, so I did the next:
function! utils#UserNetrwBrowseUpDir( islocal )
    call netrw#Call("NetrwBrowseUpDir", 1)
endfunction

let g:Netrw_UserMaps= [["u","utils#UserNetrwBrowseUpDir"]]

Well the mapping is working, using netrw#Call() I can call internal functions in netrw.vim,
but I got an error in NetrwBrowseUpDir( islocal ), basically the argument is passed as a list whereas it should be a number.
This is netrw#Call() 
fun! netrw#Call(funcname,...)
  if a:0 > 0
   exe "call s:".a:funcname."(".string(a:000).")"
  else
   exe "call s:".a:funcname."()"
  endif
endfun

I don't know how I have to pass my argument to netrw#Call()  in order to be passed as a single integer to  NetrwBrowseUpDir() .

Thanks and sorry for the long email.

P
--
Un saludo
Best Regards
Pablo Giménez

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [netrw] How to use netrw#Call() to create custom mappings

Andy Wokula
Am 11.12.2017 um 03:16 schrieb Pablo Giménez:

> Hello.
> I want to customize some of the shortcuts in Netrw.
> I have seen it provides a global variable which is a dictionary of key mappings and function calls.
> I paste here  a snippet from the help:
> Example: Clear netrw's marked file list via a mapping on gu >
>      " ExampleUserMap: {{{2
>      fun! ExampleUserMap(islocal)
>        call netrw#Modify("netrwmarkfilelist",[])
>        call netrw#Modify('netrwmarkfilemtch_{bufnr("%")}',"")
>        let retval= ["refresh"]
>        return retval
>      endfun
>
>      let g:Netrw_UserMaps= [["gu","ExampleUserMap"]]
>
> What I am trying to do is to use this mechanism to map u to browse up dir rather than -, so I did the next:
> function! utils#UserNetrwBrowseUpDir( islocal )
>      call netrw#Call("NetrwBrowseUpDir", 1)
> endfunction
>
> let g:Netrw_UserMaps= [["u","utils#UserNetrwBrowseUpDir"]]
>
> Well the mapping is working, using netrw#Call() I can call internal functions in netrw.vim,
> but I got an error in NetrwBrowseUpDir( islocal ), basically the argument is passed as a list whereas it should be a number.
> This is netrw#Call()
> fun! netrw#Call(funcname,...)
>    if a:0 > 0
>     exe "call s:".a:funcname."(".string(a:000).")"
>    else
>     exe "call s:".a:funcname."()"
>    endif
> endfun
>
> I don't know how I have to pass my argument to netrw#Call()  in order to be passed as a single integer to NetrwBrowseUpDir() .
>
> Thanks and sorry for the long email.
> **//___^**//___^
> P
> --
> Un saludo
> Best Regards
> Pablo Giménez

Looks like netrw#Call() is unusable, it should be defined as

fun! netrw#Call(funcname, args)
   return call('s:'. a:funcname, a:args)
endfun

Then it can be used like call() and you can do
   call netrw#Call("NetrwBrowseUpDir", [1])

--
Andy

https://github.com/vim/vim/blob/de04654ddc865af94ef04b1738b335a924be7923/runtime/autoload/netrw.vim#L10856

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [netrw] How to use netrw#Call() to create custom mappings

Charles E Campbell Jr
In reply to this post by Pablo Giménez Pizarro
Pablo Giménez wrote:

> Hello.
> I want to customize some of the shortcuts in Netrw.
> I have seen it provides a global variable which is a dictionary of key
> mappings and function calls.
> I paste here  a snippet from the help:
> Example: Clear netrw's marked file list via a mapping on gu >
>     " ExampleUserMap: {{{2
>     fun! ExampleUserMap(islocal)
>       call netrw#Modify("netrwmarkfilelist",[])
>       call netrw#Modify('netrwmarkfilemtch_{bufnr("%")}',"")
>       let retval= ["refresh"]
>       return retval
>     endfun
>
>     let g:Netrw_UserMaps= [["gu","ExampleUserMap"]]
>
> What I am trying to do is to use this mechanism to map u to browse up
> dir rather than -, so I did the next:
> function! utils#UserNetrwBrowseUpDir( islocal )
>     call netrw#Call("NetrwBrowseUpDir", 1)
> endfunction
>
> let g:Netrw_UserMaps= [["u","utils#UserNetrwBrowseUpDir"]]
>
> Well the mapping is working, using netrw#Call() I can call internal
> functions in netrw.vim,
> but I got an error in NetrwBrowseUpDir( islocal ), basically the
> argument is passed as a list whereas it should be a number.
> This is netrw#Call()
> fun! netrw#Call(funcname,...)
>   if a:0 > 0
>    exe "call s:".a:funcname."(".string(a:000).")"
>   else
>    exe "call s:".a:funcname."()"
>   endif
> endfun
>
> I don't know how I have to pass my argument to netrw#Call()  in order
> to be passed as a single integer to  NetrwBrowseUpDir() .
>
> Thanks and sorry for the long email.
>
Hello:

Please try the attached script (goup.vim); it uses netrw#Call with
"NetrwBrowseUpDir".  You may need to use
http://www.drchip.org/astronaut/vim/index.html#NETRW 's version of
netrw.  There's a problem with that version that I'm trying to address
under Windows, though, so be forewarned.
To use goup.vim:

  :e .

which should go up one directory.

The next step: try unbud.vim.

  :so unbud.vim
  :e .
  u

which also should go up one directory.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

goup.vim (102 bytes) Download Attachment
unbud.vim (216 bytes) Download Attachment