Marius Roets wrote:
Hi everybody,

I have a in my plsql.vim filetype plugin a lot of abbreviations to the
effect of :
iabbrev <buffer> then THEN
iabbrev <buffer> else ELSE
...
etc.

The idea is that some companies' coding standards expect me to use
capitalized keywords. Personally I hate capitalized keywords (it
reminds me of BASIC programming). So I was wondering if there was a
way where I could turn a set of abbreviations on and off, on the fly,
without reloading the buffer.

Thanks
Marius


iabbr then <C-R>MyAbbrev("then")<CR>
iabbr else <C-R>Myabbrev("else")<CR>
" etc.

function MyAbbrev(string)
        if exists("b:allcaps")
                let l:allcaps = b:allcaps
        elseif exists("g:allcaps")
                let l:allcaps = g:allcaps
        else
                let l:allcaps = 0
        endif
        if l:allcaps
                return toupper(a:string)
        else
                return a:string
        endif
endfunction

Set it buffer-by-buffer by setting b:allcaps to TRUE (nonzero) or FALSE (zero).
Buffers where b:allcaps is undefined will use the global value of g:allcaps, if defined. When neither b:allcaps (for the current buffer) nor g:allcaps (global) are defined, we fallback to "not all caps".

The function can be replaced by a single expression making heavy use of the ?: i.e. (ifexpr?thenvalue:elsevalue) ternary operator but I believe the result wouldn't be as legible.


Best regards,
Tony.

Reply via email to