diff options
author | Hugues Hiegel <hugues.hiegel@advisorsla.com> | 2018-11-07 10:34:07 +0100 |
---|---|---|
committer | Hugues Hiegel <hugues.hiegel@advisorsla.com> | 2018-11-07 10:34:07 +0100 |
commit | 2f6eca0dc513d474765290f1a5a4c02aed549be0 (patch) | |
tree | ba0d3ec8462f470e2fe451ab1075e6a4f5b52a9d /autoload/l9/tempvariables.vim | |
parent | a647d34ce197a451b2dac7ad2fa62533a790fa6e (diff) |
Plein de trucs en vrac... J’ai honte..
Diffstat (limited to 'autoload/l9/tempvariables.vim')
-rw-r--r-- | autoload/l9/tempvariables.vim | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/autoload/l9/tempvariables.vim b/autoload/l9/tempvariables.vim new file mode 100644 index 0000000..ee847ee --- /dev/null +++ b/autoload/l9/tempvariables.vim @@ -0,0 +1,60 @@ +"============================================================================= +" Copyright (C) 2010 Takeshi NISHIDA +" +"============================================================================= +" LOAD GUARD {{{1 + +if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, []) + finish +endif + +" }}}1 +"============================================================================= +" TEMPORARY VARIABLES {{{1 + +" +let s:origMap = {} + +" set temporary variables +function l9#tempvariables#set(group, name, value) + if !exists('s:origMap[a:group]') + let s:origMap[a:group] = {} + endif + if !exists('s:origMap[a:group][a:name]') + let s:origMap[a:group][a:name] = eval(a:name) + endif + execute 'let ' . a:name . ' = a:value' +endfunction + +" set temporary variables +function l9#tempvariables#setList(group, variables) + for [name, value] in a:variables + call l9#tempvariables#set(a:group, name, value) + unlet value " to avoid E706 + endfor +endfunction + +" get temporary variables +function l9#tempvariables#getList(group) + if !exists('s:origMap[a:group]') + return [] + endif + return map(keys(s:origMap[a:group]), '[v:val, eval(v:val)]') +endfunction + +" restore original variables and clean up. +function l9#tempvariables#end(group) + if !exists('s:origMap[a:group]') + return + endif + for [name, value] in items(s:origMap[a:group]) + execute 'let ' . name . ' = value' + unlet value " to avoid E706 + endfor + unlet s:origMap[a:group] +endfunction + +" }}}1 +"============================================================================= +" vim: set fdm=marker: + |