man.vim: check for -l flag #6766

This commit is contained in:
raichoo
2017-05-18 21:04:17 +02:00
committed by Justin M. Keyes
parent 060ce0e0bc
commit 3280765f2d

View File

@@ -1,16 +1,22 @@
" Maintainer: Anmol Sethi <anmol@aubble.com> " Maintainer: Anmol Sethi <anmol@aubble.com>
let s:man_find_arg = "-w" let s:find_arg = '-w'
let s:localfile_arg = v:true " Always use -l if possible. #6683
" TODO(nhooyr) Completion may work on SunOS; I'm not sure if `man -l` displays function! s:init() abort
" the list of searched directories. " TODO(nhooyr): Does `man -l` on SunOS list searched directories?
try try
if !has('win32') && $OSTYPE !~? 'cygwin\|linux' && system('uname -s') =~? 'SunOS' && system('uname -r') =~# '^5' if !has('win32') && $OSTYPE !~? 'cygwin\|linux' && system('uname -s') =~? 'SunOS' && system('uname -r') =~# '^5'
let s:man_find_arg = '-l' let s:find_arg = '-l'
endif endif
catch /E145:/ " Check for -l support.
" Ignore the error in restricted mode call s:get_page(s:get_path('', 'man')[0:-2])
endtry catch /E145:/
" Ignore the error in restricted mode
catch /command error .*/
let s:localfile_arg = v:false
endtry
endfunction
function! man#open_page(count, count1, mods, ...) abort function! man#open_page(count, count1, mods, ...) abort
if a:0 > 2 if a:0 > 2
@@ -88,10 +94,8 @@ endfunction
" Handler for s:system() function. " Handler for s:system() function.
function! s:system_handler(jobid, data, event) dict abort function! s:system_handler(jobid, data, event) dict abort
if a:event == 'stdout' if a:event is# 'stdout' || a:event is# 'stderr'
let self.stdout .= join(a:data, "\n") let self[a:event] .= join(a:data, "\n")
elseif a:event == 'stderr'
let self.stderr .= join(a:data, "\n")
else else
let self.exit_code = a:data let self.exit_code = a:data
endif endif
@@ -118,7 +122,7 @@ function! s:system(cmd, ...) abort
try try
call jobstop(jobid) call jobstop(jobid)
throw printf('command timed out: %s', join(a:cmd)) throw printf('command timed out: %s', join(a:cmd))
catch /^Vim\%((\a\+)\)\=:E900/ catch /^Vim(call):E900:/
endtry endtry
elseif res[0] == -2 elseif res[0] == -2
throw printf('command interrupted: %s', join(a:cmd)) throw printf('command interrupted: %s', join(a:cmd))
@@ -136,8 +140,7 @@ function! s:get_page(path) abort
" Force MANPAGER=cat to ensure Vim is not recursively invoked (by man-db). " Force MANPAGER=cat to ensure Vim is not recursively invoked (by man-db).
" http://comments.gmane.org/gmane.editors.vim.devel/29085 " http://comments.gmane.org/gmane.editors.vim.devel/29085
let cmd = ['env', 'MANPAGER=cat', 'MANWIDTH='.manwidth, 'man'] let cmd = ['env', 'MANPAGER=cat', 'MANWIDTH='.manwidth, 'man']
" Use -l everywhere except macOS. #6683 return s:system(cmd + (s:localfile_arg ? ['-l', a:path] : [a:path]))
return s:system(cmd + (has('mac') ? [a:path] : ['-l', a:path]))
endfunction endfunction
function! s:put_page(page) abort function! s:put_page(page) abort
@@ -201,14 +204,14 @@ endfunction
function! s:get_path(sect, name) abort function! s:get_path(sect, name) abort
if empty(a:sect) if empty(a:sect)
return s:system(['man', s:man_find_arg, a:name]) return s:system(['man', s:find_arg, a:name])
endif endif
" '-s' flag handles: " '-s' flag handles:
" - tokens like 'printf(echo)' " - tokens like 'printf(echo)'
" - sections starting with '-' " - sections starting with '-'
" - 3pcap section (found on macOS) " - 3pcap section (found on macOS)
" - commas between sections (for section priority) " - commas between sections (for section priority)
return s:system(['man', s:man_find_arg, '-s', a:sect, a:name]) return s:system(['man', s:find_arg, '-s', a:sect, a:name])
endfunction endfunction
function! s:verify_exists(sect, name) abort function! s:verify_exists(sect, name) abort
@@ -333,7 +336,7 @@ endfunction
function! s:complete(sect, psect, name) abort function! s:complete(sect, psect, name) abort
try try
let mandirs = join(split(s:system(['man', s:man_find_arg]), ':\|\n'), ',') let mandirs = join(split(s:system(['man', s:find_arg]), ':\|\n'), ',')
catch catch
call s:error(v:exception) call s:error(v:exception)
return return
@@ -375,3 +378,5 @@ function! man#init_pager() abort
endtry endtry
execute 'silent file man://'.fnameescape(ref) execute 'silent file man://'.fnameescape(ref)
endfunction endfunction
call s:init()