Saturday, January 6, 2018

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

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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment