aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnmol Sethi <hi@nhooyr.io>2020-06-12 23:43:53 -0400
committerAnmol Sethi <hi@nhooyr.io>2020-06-13 02:55:40 -0400
commitadc3425a3777c55080b7b5cdd37b02e858c5807c (patch)
treed4d706ff5b2f754ce182bc3e2a066dfe386604b7
parent4aaffc5f339c248c12d2b9d87880bb73c714f369 (diff)
downloadrneovim-adc3425a3777c55080b7b5cdd37b02e858c5807c.tar.gz
rneovim-adc3425a3777c55080b7b5cdd37b02e858c5807c.tar.bz2
rneovim-adc3425a3777c55080b7b5cdd37b02e858c5807c.zip
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
-rw-r--r--runtime/autoload/man.vim33
1 files changed, 21 insertions, 12 deletions
diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim
index 215df9484a..930db3ceb7 100644
--- a/runtime/autoload/man.vim
+++ b/runtime/autoload/man.vim
@@ -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]