[Vim-latex-cvs] vimfiles/plugin imaps.vim,1.9.2.2,1.9.2.3
Brought to you by:
srinathava,
tmaas
|
From: <ma...@us...> - 2002-12-14 14:22:26
|
Update of /cvsroot/vim-latex/vimfiles/plugin
In directory sc8-pr-cvs1:/tmp/cvs-serv30280/plugin
Modified Files:
Tag: b-newimaps
imaps.vim
Log Message:
I simplified the Tex_IMAP() wrapper for the new IMAP() function and made
some other minor improvements.
Index: imaps.vim
===================================================================
RCS file: /cvsroot/vim-latex/vimfiles/plugin/imaps.vim,v
retrieving revision 1.9.2.2
retrieving revision 1.9.2.3
diff -C2 -d -r1.9.2.2 -r1.9.2.3
*** imaps.vim 14 Dec 2002 10:48:24 -0000 1.9.2.2
--- imaps.vim 14 Dec 2002 14:22:23 -0000 1.9.2.3
***************
*** 8,12 ****
" while preserving filetype indentation.
"
! " Last Change: Sat Dec 14 02:00 AM 2002 PST
"
" Documentation: {{{
--- 8,12 ----
" while preserving filetype indentation.
"
! " Last Change: Sat Dec 14 09:00 AM 2002 EST
"
" Documentation: {{{
***************
*** 98,104 ****
" ==============================================================================
" {{{
- " A lot of back-spaces, to be used by IMAP(). If needed, more will be added
- " automatically.
- let s:backsp = substitute("0123456789", '\d', "\<bs>", 'g')
" s:LHS_{ft}_{char} will be generated automatically. It will look like
" s:LHS_tex_o = 'fo\|foo\|boo' and contain all mapped sequences ending in "o".
--- 98,101 ----
***************
*** 135,142 ****
function! IMAP(ft, lhs, ...)
let lastLHSChar = a:lhs[strlen(a:lhs)-1]
- " Make sure that s:backsp is long enough:
- while strlen(s:backsp) < strlen(a:lhs)
- let s:backsp = s:backsp . s:backsp
- endwhile
" Add a:lhs to the list of left-hand sides that end with lastLHSChar:
if !exists("s:LHS_" . a:ft . "_" . s:Hash(lastLHSChar))
--- 132,135 ----
***************
*** 146,154 ****
\ s:LHS_{a:ft}_{s:Hash(lastLHSChar)}
endif
" Build up the right-hand side:
let rhs = ""
! let phs = s:PlaceHolderStart()
! let phe = s:PlaceHolderEnd()
! let i = 1 " counter for arguments
let template = 0 " flag: is the current argument a <+template+> ?
while i <= a:0
--- 139,148 ----
\ s:LHS_{a:ft}_{s:Hash(lastLHSChar)}
endif
+
" Build up the right-hand side:
let rhs = ""
! let phs = s:PlaceHolderStart() " default <+
! let phe = s:PlaceHolderEnd() " default +>
! let i = 1 " counter for arguments
let template = 0 " flag: is the current argument a <+template+> ?
while i <= a:0
***************
*** 176,180 ****
" It has been changed in order to retain backwards compatibility (of
" sorts) while still using the new IMAP
! " It could also be used for convinience in places where specifying multiple
" arguments might be tedious.
"
--- 170,174 ----
" It has been changed in order to retain backwards compatibility (of
" sorts) while still using the new IMAP
! " It could also be used for convenience in places where specifying multiple
" arguments might be tedious.
"
***************
*** 184,189 ****
"
" The last 2 optional arguments specify the placeholder characters in the rhs.
! " See s:PlaceHolderStart() and s:PlaceHolderEnd for how they are chosen if the
! " the optional arguments are unspecified.
function! Tex_IMAP(lhs, rhs, ft, ...)
--- 178,183 ----
"
" The last 2 optional arguments specify the placeholder characters in the rhs.
! " See s:PlaceHolderStart() and s:PlaceHolderEnd() for how they are chosen if
! " the the optional arguments are unspecified.
function! Tex_IMAP(lhs, rhs, ft, ...)
***************
*** 198,241 ****
let phe = '+>'
endif
" break up the rhs into multiple chunks
let remainingString = a:rhs
! let callString = 'call IMAP(a:ft, a:lhs, arg_1'
let i = 1
! while remainingString != ''
! let firstPart = matchstr(remainingString, '^.\{-}\ze\('.phs.'\|$\)')
! let secondPart = matchstr(remainingString,
! \ phs.'\zs.\{-}\ze'.phe,
! \ strlen(firstPart))
! let arg_{i} = firstPart
! " we have already appended one argument. Do this only from next time
! " on.
! if i > 1
! let callString = callString.', arg_'.i
! endif
!
! " if firstPart is smaller than the total string, then there is a
! " placeholder. Therefore append the placeholder as an argument
! if strlen(firstPart) < strlen(remainingString)
! let i = i + 1
!
! let arg_{i} = secondPart
! let callString = callString.', arg_'.i
! endif
!
! " find out the part remaining.
! let remainingString = strpart(remainingString,
! \ strlen(firstPart) +
! \ strlen(secondPart) +
! \ strlen(phs) + strlen(phe))
!
if i >= 20
echomsg 'getting more than 20 placeholders!'
echomsg 'input rhs = '.a:rhs
endif
-
- let i = i + 1
endwhile
" Finally, we end up with a string like:
--- 192,228 ----
let phe = '+>'
endif
+ let startpat = escape(phs, '\')
+ let endpat = escape(phe, '\')
+
+ " This might not work in all cases, but it is a good idea.
+ " Problem: \ or " or ' in a:rhs ...
+ " " Change 'ba<++>bar' into '"ba", "", "bar"'
+ " let args = '"' . escape(a:rhs, '\"') . '"'
+ " let args = substitute(args, '\V' . startpat . '\|' . endpat, '","', "g")
+ " let callString = 'call IMAP(a:ft, a:lhs,' . args . ')'
" break up the rhs into multiple chunks
let remainingString = a:rhs
! let callString = 'call IMAP(a:ft, a:lhs'
! " Use \V so that we do not have to worry about magic characters.
! let pat = '\V' . '\(\.\{-}\)' .startpat. '\(\.\{-}\)' .endpat. '\(\.\*\)'
let i = 1
! while remainingString =~ pat
! let arg_{i} = substitute(remainingString, pat, '\1', '')
! let callString = callString.', arg_'.i
! let arg_{i+1} = substitute(remainingString, pat, '\2', '')
! let callString = callString.', arg_'.(i+1)
! let remainingString = substitute(remainingString, pat, '\3', '')
! let i = i+2
if i >= 20
echomsg 'getting more than 20 placeholders!'
echomsg 'input rhs = '.a:rhs
endif
endwhile
+ if strlen(remainingString)
+ let arg_{i} = remainingString
+ let callString = callString.', arg_'.i
+ endif
" Finally, we end up with a string like:
***************
*** 243,247 ****
let callString = callString.')'
- echomsg callString
exec callString
endfunction
--- 230,233 ----
***************
*** 619,625 ****
" variable, or the global one, or the default.
fun! s:PlaceHolderStart()
! if exists("b:Imap_PlaceHolderStart")
return b:Imap_PlaceHolderStart
! elseif exists("g:Imap_PlaceHolderStart")
return g:Imap_PlaceHolderStart
else
--- 605,611 ----
" variable, or the global one, or the default.
fun! s:PlaceHolderStart()
! if exists("b:Imap_PlaceHolderStart") && strlen(b:Imap_PlaceHolderEnd)
return b:Imap_PlaceHolderStart
! elseif exists("g:Imap_PlaceHolderStart") && strlen(g:Imap_PlaceHolderEnd)
return g:Imap_PlaceHolderStart
else
***************
*** 627,633 ****
endfun
fun! s:PlaceHolderEnd()
! if exists("b:Imap_PlaceHolderEnd")
return b:Imap_PlaceHolderEnd
! elseif exists("g:Imap_PlaceHolderEnd")
return g:Imap_PlaceHolderEnd
else
--- 613,619 ----
endfun
fun! s:PlaceHolderEnd()
! if exists("b:Imap_PlaceHolderEnd") && strlen(b:Imap_PlaceHolderEnd)
return b:Imap_PlaceHolderEnd
! elseif exists("g:Imap_PlaceHolderEnd") && strlen(g:Imap_PlaceHolderEnd)
return g:Imap_PlaceHolderEnd
else
|