mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
man.vim: Fix tagfunc to respect b:man_default_sects
Also, kudos to @zsugabubus for fixing a related issue in #12417 This also prevents any sorting of the paths from man. We need to respect the order we get from it otherwise you end up loading /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/share/man/man1/ls.1 on MacOS instead of /usr/share/man/man1/ls.1
This commit is contained in:
parent
4aaffc5f33
commit
adc3425a37
@ -52,7 +52,7 @@ function! man#open_page(count, count1, mods, ...) abort
|
||||
let ref = a:2.'('.a:1.')'
|
||||
endif
|
||||
try
|
||||
let [sect, name] = man#extract_sect_and_name_ref(ref)
|
||||
let [sect, name] = s:extract_sect_and_name_ref(ref)
|
||||
if a:count ==# a:count1
|
||||
" v:count defaults to 0 which is a valid section, and v:count1 defaults to
|
||||
" 1, also a valid section. If they are equal, count explicitly set.
|
||||
@ -83,7 +83,7 @@ endfunction
|
||||
|
||||
function! man#read_page(ref) abort
|
||||
try
|
||||
let [sect, name] = man#extract_sect_and_name_ref(a:ref)
|
||||
let [sect, name] = s:extract_sect_and_name_ref(a:ref)
|
||||
let path = s:verify_exists(sect, name)
|
||||
let [sect, name] = s:extract_sect_and_name_path(path)
|
||||
let page = s:get_page(path)
|
||||
@ -196,7 +196,7 @@ endfunction
|
||||
|
||||
" attempt to extract the name and sect out of 'name(sect)'
|
||||
" otherwise just return the largest string of valid characters in ref
|
||||
function! man#extract_sect_and_name_ref(ref) abort
|
||||
function! s:extract_sect_and_name_ref(ref) abort
|
||||
if a:ref[0] ==# '-' " try ':Man -pandoc' with this disabled.
|
||||
throw 'manpage name cannot start with ''-'''
|
||||
endif
|
||||
@ -315,7 +315,7 @@ function! s:error(msg) abort
|
||||
echohl None
|
||||
endfunction
|
||||
|
||||
" see man#extract_sect_and_name_ref on why tolower(sect)
|
||||
" see s:extract_sect_and_name_ref on why tolower(sect)
|
||||
function! man#complete(arg_lead, cmd_line, cursor_pos) abort
|
||||
let args = split(a:cmd_line)
|
||||
let cmd_offset = index(args, 'Man')
|
||||
@ -372,14 +372,26 @@ function! s:get_paths(sect, name, do_fallback) abort
|
||||
" callers must try-catch this, as some `man` implementations don't support `s:find_arg`
|
||||
try
|
||||
let mandirs = join(split(s:system(['man', s:find_arg]), ':\|\n'), ',')
|
||||
return globpath(mandirs,'man?/'.a:name.'*.'.a:sect.'*', 0, 1)
|
||||
let paths = globpath(mandirs, 'man?/'.a:name.'*.'.a:sect.'*', 0, 1)
|
||||
try
|
||||
" Prioritize the result from verify_exists as it obeys b:man_default_sects.
|
||||
let first = s:verify_exists(a:sect, a:name)
|
||||
let paths = filter(paths, 'v:val !=# first')
|
||||
let paths = [first] + paths
|
||||
catch
|
||||
endtry
|
||||
return paths
|
||||
catch
|
||||
if !a:do_fallback
|
||||
throw v:exception
|
||||
endif
|
||||
|
||||
" fallback to a single path, with the page we're trying to find
|
||||
return [s:verify_exists(a:sect, a:name)]
|
||||
" Fallback to a single path, with the page we're trying to find.
|
||||
try
|
||||
return [s:verify_exists(a:sect, a:name)]
|
||||
catch
|
||||
return []
|
||||
endtry
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
@ -418,7 +430,7 @@ function! man#init_pager() abort
|
||||
" know the correct casing, cf. `man glDrawArraysInstanced`).
|
||||
let ref = substitute(matchstr(getline(1), '^[^)]\+)'), ' ', '_', 'g')
|
||||
try
|
||||
let b:man_sect = man#extract_sect_and_name_ref(ref)[0]
|
||||
let b:man_sect = s:extract_sect_and_name_ref(ref)[0]
|
||||
catch
|
||||
let b:man_sect = ''
|
||||
endtry
|
||||
@ -430,7 +442,7 @@ function! man#init_pager() abort
|
||||
endfunction
|
||||
|
||||
function! man#goto_tag(pattern, flags, info) abort
|
||||
let [l:sect, l:name] = man#extract_sect_and_name_ref(a:pattern)
|
||||
let [l:sect, l:name] = s:extract_sect_and_name_ref(a:pattern)
|
||||
|
||||
let l:paths = s:get_paths(l:sect, l:name, v:true)
|
||||
let l:structured = []
|
||||
@ -440,9 +452,6 @@ function! man#goto_tag(pattern, flags, info) abort
|
||||
let l:structured += [{ 'name': l:n, 'path': l:path }]
|
||||
endfor
|
||||
|
||||
" sort by relevance - exact matches first, then the previous order
|
||||
call sort(l:structured, { a, b -> a.name ==? l:name ? -1 : b.name ==? l:name ? 1 : 0 })
|
||||
|
||||
if &cscopetag
|
||||
" return only a single entry so we work well with :cstag (#11675)
|
||||
let l:structured = l:structured[:0]
|
||||
|
Loading…
Reference in New Issue
Block a user