diff options
Diffstat (limited to 'runtime/autoload/man.vim')
-rw-r--r-- | runtime/autoload/man.vim | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim index 77ccbdf888..41c2f5a405 100644 --- a/runtime/autoload/man.vim +++ b/runtime/autoload/man.vim @@ -1,5 +1,10 @@ " Maintainer: Anmol Sethi <anmol@aubble.com> +if exists('s:loaded_man') + finish +endif +let s:loaded_man = 1 + let s:find_arg = '-w' let s:localfile_arg = v:true " Always use -l if possible. #6683 let s:section_arg = '-s' @@ -144,8 +149,9 @@ function! s:system(cmd, ...) abort endfunction function! s:get_page(path) abort - " Respect $MANWIDTH or default to window width. - let manwidth = empty($MANWIDTH) ? winwidth(0) : $MANWIDTH + " Disable hard-wrap by using a big $MANWIDTH (max 1000 on some systems #9065). + " We use soft wrap: ftplugin/man.vim sets wrap/breakindent/…. + let manwidth = 999 " Force MANPAGER=cat to ensure Vim is not recursively invoked (by man-db). " http://comments.gmane.org/gmane.editors.vim.devel/29085 " Set MAN_KEEP_FORMATTING so Debian man doesn't discard backspaces. @@ -161,6 +167,11 @@ function! s:put_page(page) abort while getline(1) =~# '^\s*$' silent keepjumps 1delete _ endwhile + " XXX: nroff justifies text by filling it with whitespace. That interacts + " badly with our use of $MANWIDTH=999. Hack around this by using a fixed + " size for those whitespace regions. + silent! keeppatterns keepjumps %s/\s\{199,}/\=repeat(' ', 10)/g + 1 lua require("man").highlight_man_page() setlocal filetype=man endfunction @@ -381,15 +392,17 @@ function! man#init_pager() abort keepjumps 1 endif lua require("man").highlight_man_page() - " This is not perfect. See `man glDrawArraysInstanced`. Since the title is - " all caps it is impossible to tell what the original capitilization was. + " Guess the ref from the heading (which is usually uppercase, so we cannot + " 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] catch let b:man_sect = '' endtry - execute 'silent file man://'.fnameescape(ref) + if -1 == match(bufname('%'), 'man:\/\/') " Avoid duplicate buffers, E95. + execute 'silent file man://'.tolower(fnameescape(ref)) + endif endfunction call s:init() |