Skip to content

Commit

Permalink
special names, list of partial names
Browse files Browse the repository at this point in the history
  • Loading branch information
tom committed May 23, 2010
1 parent b16fb0d commit 6d69ce7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
69 changes: 44 additions & 25 deletions autoload/presets.vim
Expand Up @@ -3,8 +3,8 @@
" @GIT: http://github.com/tomtom/vimtlib/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-04-24.
" @Last Change: 2010-05-13.
" @Revision: 173
" @Last Change: 2010-05-16.
" @Revision: 190


let s:config_stack = []
Expand Down Expand Up @@ -71,6 +71,13 @@ if !exists('g:presets#sets')
endfor
unlet s:name s:size

let g:presets#sets['ruler'] = {
\ '10global': {
\ '10laststatus': 0,
\ '10ruler': 1,
\ },
\}

let g:presets#sets['plain'] = {
\ '10global': {
\ '10guioptions': substitute(&guioptions, '\C[mrlRLbT]', '', 'g'),
Expand Down Expand Up @@ -135,9 +142,12 @@ if !exists('*presets#Maximize')
endif


let s:special_names = ['show']


" :nodoc:
function! presets#Complete(ArgLead, CmdLine, CursorPos) "{{{3
let sets = keys(g:presets#sets)
let sets = sort(keys(g:presets#sets), 1) + s:special_names
if !empty(a:ArgLead)
let slen = len(a:ArgLead)
call filter(sets, 'strpart(v:val, 0, slen) ==# a:ArgLead')
Expand All @@ -147,31 +157,39 @@ endf


" Push the preset NAME onto the configuration stack.
"
" The following special NAMEs are supported:
" show ... list the names of the presets on the configuration stack
function! presets#Push(names) "{{{3
for name0 in split(a:names, '\s\+')
let names = presets#Complete(name0, '', 0)
" TLogVAR name0, names
" Exact match
if index(names, name0) != -1
let names = [name0]
" TLogVAR names
endif
if len(names) != 1
echoerr 'Presets: Ambivalent or unknown name: '. name0 .' ('. join(keys(g:presets#sets), ', ') .')'
else
let name = names[0]
" TLogVAR name, names
if has_key(g:presets#sets, name)
let set = g:presets#sets[name]
let previous = {}
call s:Set(set, previous, 0)
call add(s:config_stack, previous)
" redraw
if a:names == 'show'
let names = reverse(map(copy(s:config_stack), 'v:val._name'))
echom "Presets stack:" join(names, ', ')
else
for name0 in split(a:names, '\s\+')
let names = presets#Complete(name0, '', 0)
" TLogVAR name0, names
" Exact match
if index(names, name0) != -1
let names = [name0]
" TLogVAR names
endif
if len(names) != 1
echoerr 'Presets: Ambivalent or unknown name: '. name0 .' ('. join(keys(g:presets#sets), ', ') .')'
else
echoerr 'Presets: Unknown set: '. name
let name = names[0]
" TLogVAR name, names
if has_key(g:presets#sets, name)
let set = g:presets#sets[name]
let previous = {'_name': name}
call s:Set(set, previous, 0)
call add(s:config_stack, previous)
" redraw
else
echoerr 'Presets: Unknown set: '. name
endif
endif
endif
endfor
endfor
endif
endf


Expand Down Expand Up @@ -207,6 +225,7 @@ function! s:Set(preset, save, descending_order) "{{{3
let preset = g:presets#sets[name]
call s:Set(preset, a:save, a:descending_order)
endfor
elseif type[0] == '_'
else
if !has_key(a:save, type)
let a:save[type] = {}
Expand Down
5 changes: 4 additions & 1 deletion doc/presets.txt
Expand Up @@ -82,8 +82,11 @@ presets#Maximize()
You might need to redefine it if it doesn't work for you.

*presets#Push()*
presets#Push(name)
presets#Push(names)
Push the preset NAME onto the configuration stack.

The following special NAMEs are supported:
show ... list the names of the presets on the configuration stack

*presets#Pop()*
presets#Pop()
Expand Down
7 changes: 5 additions & 2 deletions plugin/presets.vim
Expand Up @@ -3,8 +3,8 @@
" @GIT: http://github.com/tomtom/vimtlib/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-04-24.
" @Last Change: 2010-05-09.
" @Revision: 20
" @Last Change: 2010-05-15.
" @Revision: 23
" GetLatestVimScripts: 0 0 :AutoInstall: presets.vim
" Quickly switch between vim configurations

Expand All @@ -25,6 +25,9 @@ set cpo&vim
"
" If no PRESET argument is given, pop the previous preset from the
" configuration stack.
"
" This command supports certain special names -- see |presets#Push()|
" for details.
command! -bang -nargs=? -complete=customlist,presets#Complete Preset
\ if empty(<q-args>) |
\ call presets#Pop() |
Expand Down

0 comments on commit 6d69ce7

Please sign in to comment.