Anton Lindqvist wrote:
> > > Hi,
> > > This patch adds a function with the declaration optiontype({option})
> > > which returns the type of the given option. I'm currently using it to
> > > achieve the following option toggle mapping:
> > >
> > > " :NMapChangeOption[!] {letter} {option} [enable]
> > > "
> > > " Create a normal mode option toggle mapping for {option}. The mapping
> > > key
> > > " sequence will be prefixed with 'co' followed by {letter}.
> > > "
> > > " By default the option will only be changed in the current buffer.
> > > Using [!]
> > > " will change the option globally.
> > > "
> > > " Boolean option example:
> > > "
> > > " :NMapChangeOption s spell
> > > "
> > > " Pressing 'cos' will toggle the spell option on and off.
> > > "
> > > " Non boolean option example:
> > > "
> > > " :NMapChangeOption y syntax ON
> > > "
> > > " The optional [enable] argument can be used for string and comma
> > > separated
> > > " list options. Pressing 'coy' will add/remove 'ON' from the syntax
> > > option.
> > > "
> > > " This functionality is borrowed from Tim Pope's unimpaired.vim plugin.
> > > command! -bang -complete=option -nargs=+ NMapChangeOption
> > > \ call s:NMapChangeOption(<bang>0, <f-args>)
> > > func! s:NMapChangeOption(global, letter, option, ...) abort
> > > let set = a:global ? 'set' : 'setlocal'
> > > let type = optiontype(a:option)
> > > if type == 0 " boolean
> > > let rhs = printf(':%s <C-R>=&%s ? "no" : ""<CR>%s<CR>',
> > > \ set, a:option, a:option)
> > > elseif type == 2 " comma separated list
> > > let rhs = printf(':%s %s<C-R>=&%s !~# "%s" ? "+=" : "-="<CR>%s<CR>',
> > > \ set, a:option, a:option, a:1, a:1)
> > > elseif type == 4 " string
> > > let rhs = printf(':%s %s<C-R>=&%s == "%s" ? "&" : "=%s"<CR><CR>',
> > > \ set, a:option, a:option, a:1, a:1)
> > > endif
> > > exe 'nnoremap co' . a:letter rhs
> > > endfunc
> > >
> > > NMapChangeOption c colorcolumn +1
> > > NMapChangeOption! h hlsearch
> > > NMapChangeOption l list
> > > NMapChangeOption! p paste
> > > NMapChangeOption s spell
> > > NMapChangeOption w wrap
> > > NMapChangeOption y syntax ON
> > >
> > > The patch includes tests and docs.
> >
> > I can see how this would be useful. But returning just a number is
> > limited. There are many more properties of an option, such as whether
> > it is window-local, was set or not, can be set from a modeline, etc.
> > Not that we need to add all those properties now, but I'm sure someone
> > will want to add them later. Perhaps using "optionproperties()" and
> > returning a Dictionary?
>
> Great feedback. Attached is a revised patch with you ideas applied.
> For now the 'optionproperties()' function returns a Dictionary with only
> one entry called 'type'.
Thanks. I wonder if "type" would just return bool/number/string. Then
for a string type there would be a subtype for comma/flaglist.
I suppose it depends on what you want to do if you want to know what
kind of string option it is. Also, if we later add another kind (colon
separate?) that is also a string, it would still be possible to
recognize the string if you don't care about the subtype.
--
hundred-and-one symptoms of being an internet addict:
126. You brag to all of your friends about your date Saturday night...but
you don't tell them it was only in a chat room.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.