mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 21:25:04 -07:00
fix(man.vim): filetype=man is too eager #15489
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
This commit is contained in:
parent
502a56867d
commit
b6b12ea7c3
@ -65,6 +65,7 @@ function! man#open_page(count, mods, ...) abort
|
|||||||
let b:man_sect = sect
|
let b:man_sect = sect
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Called when a man:// buffer is opened.
|
||||||
function! man#read_page(ref) abort
|
function! man#read_page(ref) abort
|
||||||
try
|
try
|
||||||
let [sect, name] = s:extract_sect_and_name_ref(a:ref)
|
let [sect, name] = s:extract_sect_and_name_ref(a:ref)
|
||||||
@ -121,6 +122,15 @@ function! s:system(cmd, ...) abort
|
|||||||
return opts.stdout
|
return opts.stdout
|
||||||
endfunction
|
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
|
function! s:get_page(path) abort
|
||||||
" Disable hard-wrap by using a big $MANWIDTH (max 1000 on some systems #9065).
|
" Disable hard-wrap by using a big $MANWIDTH (max 1000 on some systems #9065).
|
||||||
" Soft-wrap: ftplugin/man.vim sets wrap/breakindent/….
|
" Soft-wrap: ftplugin/man.vim sets wrap/breakindent/….
|
||||||
@ -134,9 +144,7 @@ function! s:get_page(path) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:put_page(page) abort
|
function! s:put_page(page) abort
|
||||||
setlocal modifiable
|
setlocal modifiable noreadonly noswapfile
|
||||||
setlocal noreadonly
|
|
||||||
setlocal noswapfile
|
|
||||||
silent keepjumps %delete _
|
silent keepjumps %delete _
|
||||||
silent put =a:page
|
silent put =a:page
|
||||||
while getline(1) =~# '^\s*$'
|
while getline(1) =~# '^\s*$'
|
||||||
@ -148,7 +156,7 @@ function! s:put_page(page) abort
|
|||||||
silent! keeppatterns keepjumps %s/\s\{199,}/\=repeat(' ', 10)/g
|
silent! keeppatterns keepjumps %s/\s\{199,}/\=repeat(' ', 10)/g
|
||||||
1
|
1
|
||||||
lua require("man").highlight_man_page()
|
lua require("man").highlight_man_page()
|
||||||
setlocal filetype=man
|
call s:set_options(v:false)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! man#show_toc() abort
|
function! man#show_toc() abort
|
||||||
@ -397,6 +405,7 @@ function! s:format_candidate(path, psect) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Called when Nvim is invoked as $MANPAGER.
|
||||||
function! man#init_pager() abort
|
function! man#init_pager() abort
|
||||||
" https://github.com/neovim/neovim/issues/6828
|
" https://github.com/neovim/neovim/issues/6828
|
||||||
let og_modifiable = &modifiable
|
let og_modifiable = &modifiable
|
||||||
@ -420,6 +429,7 @@ function! man#init_pager() abort
|
|||||||
execute 'silent file man://'.tolower(fnameescape(ref))
|
execute 'silent file man://'.tolower(fnameescape(ref))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
call s:set_options(v:true)
|
||||||
let &l:modifiable = og_modifiable
|
let &l:modifiable = og_modifiable
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -6,14 +6,6 @@ if exists('b:did_ftplugin') || &filetype !=# 'man'
|
|||||||
endif
|
endif
|
||||||
let b:did_ftplugin = 1
|
let b:did_ftplugin = 1
|
||||||
|
|
||||||
let s:pager = !exists('b:man_sect')
|
|
||||||
|
|
||||||
if s:pager
|
|
||||||
call man#init_pager()
|
|
||||||
endif
|
|
||||||
|
|
||||||
setlocal noswapfile buftype=nofile bufhidden=hide
|
|
||||||
setlocal nomodified readonly nomodifiable
|
|
||||||
setlocal noexpandtab tabstop=8 softtabstop=8 shiftwidth=8
|
setlocal noexpandtab tabstop=8 softtabstop=8 shiftwidth=8
|
||||||
setlocal wrap breakindent linebreak
|
setlocal wrap breakindent linebreak
|
||||||
|
|
||||||
@ -32,11 +24,7 @@ if !exists('g:no_plugin_maps') && !exists('g:no_man_maps')
|
|||||||
nnoremap <silent> <buffer> k gk
|
nnoremap <silent> <buffer> k gk
|
||||||
nnoremap <silent> <buffer> gO :call man#show_toc()<CR>
|
nnoremap <silent> <buffer> gO :call man#show_toc()<CR>
|
||||||
nnoremap <silent> <buffer> <2-LeftMouse> :Man<CR>
|
nnoremap <silent> <buffer> <2-LeftMouse> :Man<CR>
|
||||||
if s:pager
|
nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c
|
||||||
nnoremap <silent> <buffer> <nowait> q :lclose<CR>:q<CR>
|
|
||||||
else
|
|
||||||
nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if get(g:, 'ft_man_folding_enable', 0)
|
if get(g:, 'ft_man_folding_enable', 0)
|
||||||
|
@ -6,7 +6,7 @@ endif
|
|||||||
let g:loaded_man = 1
|
let g:loaded_man = 1
|
||||||
|
|
||||||
command! -bang -bar -range=-1 -complete=customlist,man#complete -nargs=* Man
|
command! -bang -bar -range=-1 -complete=customlist,man#complete -nargs=* Man
|
||||||
\ if <bang>0 | set ft=man |
|
\ if <bang>0 | call man#init_pager() |
|
||||||
\ else | call man#open_page(<count>, <q-mods>, <f-args>) | endif
|
\ else | call man#open_page(<count>, <q-mods>, <f-args>) | endif
|
||||||
|
|
||||||
augroup man
|
augroup man
|
||||||
|
@ -27,11 +27,7 @@ if &filetype != 'man'
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists('b:man_sect')
|
if get(b:, 'man_sect', '') =~# '^[023]'
|
||||||
call man#init_pager()
|
|
||||||
endif
|
|
||||||
|
|
||||||
if b:man_sect =~# '^[023]'
|
|
||||||
syntax case match
|
syntax case match
|
||||||
syntax include @c $VIMRUNTIME/syntax/c.vim
|
syntax include @c $VIMRUNTIME/syntax/c.vim
|
||||||
syntax match manCFuncDefinition display '\<\h\w*\>\ze\(\s\|\n\)*(' contained
|
syntax match manCFuncDefinition display '\<\h\w*\>\ze\(\s\|\n\)*(' contained
|
||||||
|
Loading…
Reference in New Issue
Block a user