Mercurial > vim
changeset 36403:cb45908672c2 draft
runtime(netrw): improve netrw's open-handling further
Commit: https://github.com/vim/vim/commit/70197885a8957071e4ab6816141ce6e8026635c6
Author: Enno <Konfekt@users.noreply.github.com>
Date: Mon Oct 28 20:47:25 2024 +0100
runtime(netrw): improve netrw's open-handling further
closes: https://github.com/vim/vim/issues/15956
Signed-off-by: Enno <Konfekt@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 28 Oct 2024 21:00:03 +0100 |
parents | d01cd046b864 |
children | b9ffc41b32b4 |
files | runtime/plugin/netrwPlugin.vim |
diffstat | 1 files changed, 20 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/plugin/netrwPlugin.vim +++ b/runtime/plugin/netrwPlugin.vim @@ -35,17 +35,18 @@ set cpo&vim " Commands Launch/URL {{{2 " surpress output of command; use bang for GUI applications -" set up redirection (avoids browser messages) -" by default if not set, g:netrw_suppress_gx_mesg is true -if get(g:, 'netrw_suppress_gx_mesg', 1) - if &srr =~# "%s" - let s:redir = printf(&srr, has("win32") ? "nul" : "/dev/null") - else - let s:redir= &srr .. (has("win32") ? "nul" : "/dev/null") +func s:redir() + " set up redirection (avoids browser messages) + " by default if not set, g:netrw_suppress_gx_mesg is true + if get(g:, 'netrw_suppress_gx_mesg', 1) + if &srr =~# "%s" + return printf(&srr, has("win32") ? "nul" : "/dev/null") + else + return &srr .. (has("win32") ? "nul" : "/dev/null") + endif endif -else - let s:redir= "" -endif + return '' +endfunc if has('unix') if has('win32unix') @@ -60,26 +61,26 @@ if has('unix') " Adding "" //b` sets void title, hides cmd window and blocks path conversion " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/ command -complete=shellcmd -nargs=1 -bang Launch - \ exe 'silent !start "" //b' trim(<q-args>) s:redir | redraw! + \ exe 'silent !start "" //b' trim(<q-args>) s:redir() | redraw! else " imitate /usr/bin/start script for other environments and hope for the best command -complete=shellcmd -nargs=1 -bang Launch - \ exe 'silent !cmd //c start "" //b' trim(<q-args>) s:redir | redraw! + \ exe 'silent !cmd //c start "" //b' trim(<q-args>) s:redir() | redraw! endif elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL command -complete=shellcmd -nargs=1 -bang Launch execute ':silent !'.. \ ((<q-args> =~? '\v<\f+\.(exe|com|bat|cmd)>') ? \ 'cmd.exe /c start "" /b' trim(<q-args>) : - \ 'nohup ' trim(<q-args>) s:redir '&') + \ 'nohup ' trim(<q-args>) s:redir() '&') \ | redraw! else command -complete=shellcmd -nargs=1 -bang Launch - \ exe ':silent ! nohup' trim(<q-args>) s:redir '&' | redraw! + \ exe ':silent ! nohup' trim(<q-args>) s:redir() '&' | redraw! endif elseif has('win32') command -complete=shellcmd -nargs=1 -bang Launch \ exe 'silent !'.. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c') - \ 'start /b ' trim(<q-args>) s:redir | redraw! + \ 'start /b ' trim(<q-args>) s:redir() | redraw! endif if exists(':Launch') == 2 " Git Bash @@ -95,17 +96,15 @@ if exists(':Launch') == 2 " MacOS elseif executable('open') let s:cmd = 'open' - else - let s:cmd = '' endif - function s:Open(cmd, file) - if empty(a:cmd) && !exists('g:netrw_browsex_viewer') + function s:Open(file) + if !exists('s:cmd') && !exists('g:netrw_browsex_viewer') echoerr "No program to open this path found. See :help Open for more information." else - Launch cmd shellescape(a:file, 1) + exe 'Launch' s:cmd shellescape(a:file, 1) endif endfunction - command -complete=file -nargs=1 Open call s:Open(s:cmd, <q-args>) + command -complete=file -nargs=1 Open call s:Open(<q-args>) endif if !exists('g:netrw_regex_url')