" These commands create the option window.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2017 Aug 01
" If there already is an option window, jump to that one.
if bufwinnr("option-window") > 0
let s:thiswin = winnr()
while 1
if @% == "option-window"
finish
endif
wincmd w
if s:thiswin == winnr()
break
endif
endwhile
endif
" Make sure the '<' flag is not included in 'cpoptions', otherwise <CR> would
" not be recognized. See ":help 'cpoptions'".
let s:cpo_save = &cpo
set cpo&vim
" function to be called when <CR> is hit in the option-window
fun! <SID>CR()
" If on a continued comment line, go back to the first comment line
let lnum = search("^[^\t]", 'bWcn')
let line = getline(lnum)
" <CR> on a "set" line executes the option line
if match(line, "^ \tset ") >= 0
" For a local option: go to the previous window
" If this is a help window, go to the window below it
let thiswin = winnr()
let local = <SID>Find(lnum)
if local >= 0
exe line
call <SID>Update(lnum, line, local, thiswin)
endif
" <CR> on a "option" line shows help for that option
elseif match(line, "^[a-z]") >= 0
let name = substitute(line, '\([^\t]*\).*', '\1', "")
exe "help '" . name . "'"
" <CR> on an index line jumps to the group
elseif match(line, '^ \=[0-9]') >= 0
exe "norm! /" . line . "\<CR>zt"
endif
endfun
" function to be called when <Space> is hit in the option-window
fun! <SID>Space()
let lnum = line(".")
let line = getline(lnum)
" <Space> on a "set" line refreshes the option line
if match(line, "^ \tset ") >= 0
" For a local option: go to the previous window
" If this is a help window, go to the window below it
let thiswin = winnr()
let local = <SID>Find(lnum)
if local >= 0
call <SID>Update(lnum, line, local, thiswin)
endif
endif
endfun
" find the window in which the option applies
" returns 0 for global option, 1 for local option, -1 for error
fun! <SID>Find(lnum)
if getline(a:lnum - 1) =~ "(local to"
let local = 1
let thiswin = winnr()
wincmd p
if exists("b:current_syntax") && b:current_syntax == "help"
wincmd j
if winnr() == thiswin
wincmd j
endif
endif
else
let local = 0
endif
if local &