diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2021-08-26 02:19:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-26 02:19:52 -0700 |
commit | 2548a9e18037339c4c502d971bdeaf909b82a739 (patch) | |
tree | 26d64f77b584c2976334cc9cdfc29ea75afe605a /runtime/autoload | |
parent | 8d62f5fd58d421edb39b66fd8b350325120b3cd6 (diff) | |
download | rneovim-2548a9e18037339c4c502d971bdeaf909b82a739.tar.gz rneovim-2548a9e18037339c4c502d971bdeaf909b82a739.tar.bz2 rneovim-2548a9e18037339c4c502d971bdeaf909b82a739.zip |
fix(man.vim): filetype=man is too eager #15488
Problem:
"set filetype=man" assumes the user wants :Man features, this does extra
stuff like renaming the buffer as "man://".
Solution:
- old entrypoint was ":set filetype=man", but this is too presumptuous #15487
- make the entrypoints more explicit:
1. when the ":Man" command is run
2. when a "man://" buffer is opened
- remove the tricky b:man_sect checks in ftplugin/man.vim and syntax/man.vim
- MANPAGER is supported via ":Man!", as documented.
fixes #15487
Diffstat (limited to 'runtime/autoload')
-rw-r--r-- | runtime/autoload/man.vim | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim index 4f556e6e87..8bf95651b7 100644 --- a/runtime/autoload/man.vim +++ b/runtime/autoload/man.vim @@ -65,6 +65,7 @@ function! man#open_page(count, mods, ...) abort let b:man_sect = sect endfunction +" Called when a man:// buffer is opened. function! man#read_page(ref) abort try let [sect, name] = s:extract_sect_and_name_ref(a:ref) @@ -121,6 +122,15 @@ function! s:system(cmd, ...) abort return opts.stdout endfunction +function! s:set_options(pager) abort + setlocal filetype=man + setlocal noswapfile buftype=nofile bufhidden=hide + setlocal nomodified readonly nomodifiable + if a:pager + nnoremap <silent> <buffer> <nowait> q :lclose<CR>:q<CR> + endif +endfunction + function! s:get_page(path) abort " Disable hard-wrap by using a big $MANWIDTH (max 1000 on some systems #9065). " Soft-wrap: ftplugin/man.vim sets wrap/breakindent/…. @@ -134,9 +144,7 @@ function! s:get_page(path) abort endfunction function! s:put_page(page) abort - setlocal modifiable - setlocal noreadonly - setlocal noswapfile + setlocal modifiable noreadonly noswapfile silent keepjumps %delete _ silent put =a:page while getline(1) =~# '^\s*$' @@ -148,7 +156,7 @@ function! s:put_page(page) abort silent! keeppatterns keepjumps %s/\s\{199,}/\=repeat(' ', 10)/g 1 lua require("man").highlight_man_page() - setlocal filetype=man + call s:set_options(v:false) endfunction function! man#show_toc() abort @@ -397,6 +405,7 @@ function! s:format_candidate(path, psect) abort endif endfunction +" Called when Nvim is invoked as $MANPAGER. function! man#init_pager() abort " https://github.com/neovim/neovim/issues/6828 let og_modifiable = &modifiable @@ -420,6 +429,7 @@ function! man#init_pager() abort execute 'silent file man://'.tolower(fnameescape(ref)) endif + call s:set_options(v:true) let &l:modifiable = og_modifiable endfunction |