mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 09:48:19 +00: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:
@@ -52,7 +52,7 @@ function! man#open_page(count, count1, mods, ...) abort
|
|||||||
let ref = a:2.'('.a:1.')'
|
let ref = a:2.'('.a:1.')'
|
||||||
endif
|
endif
|
||||||
try
|
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
|
if a:count ==# a:count1
|
||||||
" v:count defaults to 0 which is a valid section, and v:count1 defaults to
|
" 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.
|
" 1, also a valid section. If they are equal, count explicitly set.
|
||||||
@@ -83,7 +83,7 @@ endfunction
|
|||||||
|
|
||||||
function! man#read_page(ref) abort
|
function! man#read_page(ref) abort
|
||||||
try
|
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 path = s:verify_exists(sect, name)
|
||||||
let [sect, name] = s:extract_sect_and_name_path(path)
|
let [sect, name] = s:extract_sect_and_name_path(path)
|
||||||
let page = s:get_page(path)
|
let page = s:get_page(path)
|
||||||
@@ -196,7 +196,7 @@ endfunction
|
|||||||
|
|
||||||
" attempt to extract the name and sect out of 'name(sect)'
|
" attempt to extract the name and sect out of 'name(sect)'
|
||||||
" otherwise just return the largest string of valid characters in ref
|
" 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.
|
if a:ref[0] ==# '-' " try ':Man -pandoc' with this disabled.
|
||||||
throw 'manpage name cannot start with ''-'''
|
throw 'manpage name cannot start with ''-'''
|
||||||
endif
|
endif
|
||||||
@@ -315,7 +315,7 @@ function! s:error(msg) abort
|
|||||||
echohl None
|
echohl None
|
||||||
endfunction
|
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
|
function! man#complete(arg_lead, cmd_line, cursor_pos) abort
|
||||||
let args = split(a:cmd_line)
|
let args = split(a:cmd_line)
|
||||||
let cmd_offset = index(args, 'Man')
|
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`
|
" callers must try-catch this, as some `man` implementations don't support `s:find_arg`
|
||||||
try
|
try
|
||||||
let mandirs = join(split(s:system(['man', s:find_arg]), ':\|\n'), ',')
|
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
|
catch
|
||||||
if !a:do_fallback
|
if !a:do_fallback
|
||||||
throw v:exception
|
throw v:exception
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" fallback to a single path, with the page we're trying to find
|
" Fallback to a single path, with the page we're trying to find.
|
||||||
return [s:verify_exists(a:sect, a:name)]
|
try
|
||||||
|
return [s:verify_exists(a:sect, a:name)]
|
||||||
|
catch
|
||||||
|
return []
|
||||||
|
endtry
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -418,7 +430,7 @@ function! man#init_pager() abort
|
|||||||
" know the correct casing, cf. `man glDrawArraysInstanced`).
|
" know the correct casing, cf. `man glDrawArraysInstanced`).
|
||||||
let ref = substitute(matchstr(getline(1), '^[^)]\+)'), ' ', '_', 'g')
|
let ref = substitute(matchstr(getline(1), '^[^)]\+)'), ' ', '_', 'g')
|
||||||
try
|
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
|
catch
|
||||||
let b:man_sect = ''
|
let b:man_sect = ''
|
||||||
endtry
|
endtry
|
||||||
@@ -430,7 +442,7 @@ function! man#init_pager() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! man#goto_tag(pattern, flags, info) abort
|
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:paths = s:get_paths(l:sect, l:name, v:true)
|
||||||
let l:structured = []
|
let l:structured = []
|
||||||
@@ -440,9 +452,6 @@ function! man#goto_tag(pattern, flags, info) abort
|
|||||||
let l:structured += [{ 'name': l:n, 'path': l:path }]
|
let l:structured += [{ 'name': l:n, 'path': l:path }]
|
||||||
endfor
|
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
|
if &cscopetag
|
||||||
" return only a single entry so we work well with :cstag (#11675)
|
" return only a single entry so we work well with :cstag (#11675)
|
||||||
let l:structured = l:structured[:0]
|
let l:structured = l:structured[:0]
|
||||||
|
Reference in New Issue
Block a user