Let us be not too insane :-) and provide a different solution using mappings and netrw public API.
Beware that the code is neither complete nor was tested properly!
" our custom delete routine
function! g:MyNetrw_DoDelete(flist)
echom 'Deleting ' a:flist
endfunction
" setup netrw mappings (:h g:Netrw_UserMaps)
let g:Netrw_UserMaps = [['D', 'g:MyNetrw_D'], ["\<Del>", 'g:MyNetrw_D']]
" unfortunately, the visual mode is not supported by Netrw_UserMaps,
" so implement it with the help of augroup/autocmd
" (although netrw is very peculiar about its mappings,
" it seems to work okay too)
augroup MyNetrw | au!
autocmd FileType netrw vnoremap <buffer>D :call g:MyNetrw_vD()<CR>
augroup end
" implement normal mode deletion
function! g:MyNetrw_D(islocal)
if a:islocal
" get selected file list (:h netrw-mf)
let l:flist = netrw#Expose('netrwmarkfilelist')
if l:flist is# 'n/a'
" no selection -- get name under cursor
let l:flist = [b:netrw_curdir . '/' . netrw#GX()]
else
" remove selection as files will be deleted soon
call netrw#Call('NetrwUnmarkAll')
endif
" do delete and refresh view
call g:MyNetrw_DoDelete(l:flist)
return 'refresh'
endif
" this is to handle remote deletion
" hope it works...
call netrw#Call('RemotePathAnalysis', b:netrw_curdir)
let l:usermach = netrw#Expose('user') . '@' . netrw#Expose('machine')
let l:path = netrw#Expose('path')
call netrw#Call('NetrwRemoteRm', l:usermach, l:path)
endfunction
" implement delete over Visual range
function! g:MyNetrw_vD() range
if isdirectory(b:netrw_curdir)
" assume it's local dir
" get all file names over selected lines
let l:flist = []
for l:lnum in range(a:firstline, a:lastline)
execute l:lnum
call add(l:flist, b:netrw_curdir . '/' . netrw#GX())
endfor
" do delete and then refresh view
call g:MyNetrw_DoDelete(l:flist)
call netrw#Call('NetrwRefresh', 1, b:netrw_curdir)
return
endif
" remote delete over visual range -- NOT IMPLEMENTED
" Note: call() cannot supply non-trivial range,
" so we have to process line range manually (sigh),
" and then call `s:NetrwRemoteRmFile()` in a loop
endfunction