" These commands create the option window.
"
" Maintainer: The Vim Project <https://github.com/vim/vim>
" Last Change: 2025 Apr 06
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
" If there already is an option window, jump to that one.
let buf = bufnr('option-window')
if buf >= 0
let winids = win_findbuf(buf)
if len(winids) > 0
if win_gotoid(winids[0]) == 1
finish
endif
endif
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
func <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
endfunc
" function to be called when <Space> is hit in the option-window
func <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
endfunc
let s:local_to_window = gettext('(local to window)')
let s:local_to_buffer = gettext('(local to buffer)')
let s:global_or_local = gettext('(global or local to buffer)')
" find the window in which the option applies
" returns 0 for global option, 1 for local option, -1 for error
func <SID>Find(lnum)
let line = getline(a:lnum - 1)
if line =~ s:local_to_window || line =~ s:local_to_buffer
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 && (winnr() == thiswin || (exists("b:current_syntax")
\ && b:current_syntax == "help"))
echo "Don't know in which window"
let local = -1
endif
return local
endfunc
" Update a "set" line in the option window
func <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
let val = escape(eval('&' . name), " \t\\\"|")
if a:local
exe a:thiswin . "wincmd w"
endif
if match(a:line, "=") >= 0 || (val != "0" && val != "1")
call setline(a:lnum, " \tset " . name . "=" . val)
else
if val
call setline(a:lnum, " \tset " . name . "\tno" . name)
else
call setline(a:lnum, " \tset no" . name . "\t" . name)
endif
endif
set nomodified
endfunc
" Reset 'title' and 'icon' to make it work faster.
" Reset 'undolevels' to avoid undo'ing until the buffer is empty.
let s:old_title = &title
let s:
|