" These commands create the option window.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2006 Oct 10
" 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
exe "norm! \<C-W>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 = line(".")
let line = getline(lnum)
while line[0] == "\t"
let lnum = lnum - 1
let line = getline(lnum)
endwhile
" <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()
exe "norm! \<C-W>p"
if exists("b:current_syntax") && b:current_syntax == "help"
exe "norm! \<C-W>j"
if winnr() == thiswin
exe "norm! \<C-W>j"
endif
endif
else
let local = 0
endif
if local && (winnr() == thiswin || (exists("b:current_syntax")
\ && b:current_syntax == "help"))
echo "Don't know in which window"
let local = -1
endif
return local
endfun
" Update a "set" line in the option window
fun! <SID>Update(lnum, line, local, thiswin)
" get the new value of the option and update the option window line
if match(a:line, "=") >= 0
let name = substitute(a:line, '^ \tset \([^=]*\)=.*', '\1', "")
else
let name = substitute(a:line, '^ \tset \(no\)\=\([a-z]*\).*', '\2', "")
endif
if name == "pt" && &pt =~ "\x80"
let val = <SID>PTvalue()
else
exe "let val = substitute(&" . name . ', "[ \\t\\\\\"|]", "\\\\\\0", "g")'
endif
if a:local
exe "norm! " . a:thiswin . "\<C-W>w"
endif
if match(a:line, "=") >= 0 || (val != "0" && val != "1")
call setline(a:lnum, " \tset " . name . "=" . val)
else
if