Re: Turning abbreviations on and off

2006-09-27 Thread Luc Hermitte
Hello,

* On Mon, Sep 25, 2006 at 02:41:51PM +0200, Marius Roets [EMAIL PROTECTED] 
wrote:
 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.

A while back, I implemented a plugin specialised in toggling almost
everything like the definitions from a VimL function.

It seems I haven't released the lastest version on sourceforge. However
you can obtain it from here:
http://hermitte.free.fr/vim/ressources/Triggers.tar.gz
The documentation can be found there:
http://hermitte.free.fr/vim/general.php#expl_triggers

 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.

Won't you be more interrested in definitions local to projects ?
I.e. all files under a directory will have some specialized mappings,
abbreviations,  And files under another directory will have other
specialized abbreviation ...
This issue has been discussed here a couple or week, may be less.

HTH,

-- 
Luc Hermitte
http://hermitte.free.fr/vim/


Re: Turning abbreviations on and off

2006-09-25 Thread Yakov Lerner

On 9/25/06, Marius Roets [EMAIL PROTECTED] wrote:

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
... 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.


How about this:

function! MyAbbrevs()
  iabbrev buffer then THEN
  iabbrev buffer else ELSE
  let g:myabbrev_set=1
endfunc

function! UnsetMyAbbrev()
  iunabbrev bufferthen
  iunabbrev bufferelse
  let g:myabbrev_set=0
endfunc

function! ToggleMyAbbrev()
  if exists(g:myabbrev_set)  g:myabbrev_set
   call UnsetMyAbbrev()
  else
   call MyAbbrevs()
  endif
endfunc

call MyAbbrevs()  initial setting
nmap F5 :call ToggleMyAbbrev()cr

Yakov


Re: Turning abbreviations on and off

2006-09-25 Thread Benji Fisher
On Mon, Sep 25, 2006 at 12:58:51PM +, Yakov Lerner wrote:
 On 9/25/06, Marius Roets [EMAIL PROTECTED] wrote:
 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
 ... 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.
 
 How about this:
 
 function! MyAbbrevs()
   iabbrev buffer then THEN
   iabbrev buffer else ELSE
   let g:myabbrev_set=1
 endfunc
 
 function! UnsetMyAbbrev()
   iunabbrev bufferthen
   iunabbrev bufferelse
   let g:myabbrev_set=0
 endfunc
 
 function! ToggleMyAbbrev()
   if exists(g:myabbrev_set)  g:myabbrev_set
call UnsetMyAbbrev()
   else
call MyAbbrevs()
   endif
 endfunc
 
 call MyAbbrevs()  initial setting
 nmap F5 :call ToggleMyAbbrev()cr
 
 Yakov

 You forgot to set g:myabbrev_set to 0 or 1 in the ToggleMyAbbrev()
function.  Easily fixed.

 Here is another way to do it, using the new Dictionary type
introduced in vim 7.0.  I have not tested this!  I also use a single
function, with an argument, instead of three, and I think it makes more
sense to use a buffer-local variable to keep track of the state.  This
version has the advantage that if you add an abbreviation, you do not have to 
remember to add the unabbreviation in a different place.

let s:abbs = {'then': 'THEN', 'else': 'ELSE'}

 Set action to 's' for set, 'u' for unset, or 't' for toggle.
fun! MyAbbrevs(action)
  if (s:action == 's') ||
\ (s:action == 't'  exists(b:myabbrev_set)  b:myabbrev_set)
for [lhs, rhs] in items(s:abbs)
  execute 'iabbrev buffer' lhs rhs
endfor
let b:myabbrev_set = 1
return 0
  elseif (s:action == 'u' || s:action == 't')
for lhs in keys(s:abbs)
  execute 'iunabbrev buffer' lhs
endfor
let b:myabbrev_set = 0
return 0
  else   unrecognized parameter
return 1
  endif
endfun

HTH --Benji Fisher


Re: Turning abbreviations on and off

2006-09-25 Thread A.J.Mechelynck

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-RMyAbbrev(then)CR
iabbr else C-RMyabbrev(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.