[Vim-latex-cvs] vimfiles/plugin imaps.vim,1.5,1.6
Brought to you by:
srinathava,
tmaas
From: <sri...@us...> - 2002-12-02 13:09:19
|
Update of /cvsroot/vim-latex/vimfiles/plugin In directory sc8-pr-cvs1:/tmp/cvs-serv12338 Modified Files: imaps.vim Log Message: A very difficult fix for the encoding problem... Bug: When 'encoding' is set to utf8, then macros dont work. i.e, typing () results in (ä)«» with the cursor placed at the end. Cause: The behavior of vim changes according to the current encoding. Solution: 1. When latex-suite is first called, temporarily set encoding to latin1, source all the files and then reset it to the original value. This ensures that the scripts rely on a consistent encoding scheme. 2. Whenever we do encoding specific stuff, then switch back to latin1, do our stuff and then switch back. This is complicated by the fact that while inserting text (using the Imap_PutText...() function), we need to insert the placeholders in the curret locale, not latin1, otherwise the user will see things like <ab> and <bb> instead of « and ». Therefore, the jump function needs to account for the fact that the characters are no longer in latin1... TODO: Document these changes asap otherwise I will completeley forget why I did what I did... Index: imaps.vim =================================================================== RCS file: /cvsroot/vim-latex/vimfiles/plugin/imaps.vim,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** imaps.vim 12 Nov 2002 18:24:01 -0000 1.5 --- imaps.vim 2 Dec 2002 13:09:16 -0000 1.6 *************** *** 5,9 **** " Description: insert mode template expander with cursor placement " while preserving filetype indentation. ! " Last Change: Mon Nov 04 02:00 PM 2002 PST " " Documentation: {{{ --- 5,9 ---- " Description: insert mode template expander with cursor placement " while preserving filetype indentation. ! " Last Change: Mon Dec 02 04:00 AM 2002 PST " " Documentation: {{{ *************** *** 271,274 **** --- 271,277 ---- function! IMAP_PutTextWithMovement(text) + let s:oldenc = &encoding + let &encoding='latin1' + let text = a:text *************** *** 330,334 **** let movement = movement.":call SAImaps_RemoveLastHistoryItem()\<cr>" " BNF 12 Nov 2002: Functions never add more than one item to the searcg ! " history. I do not recall where this is documented... " let movement = movement.":call SAImaps_RemoveLastHistoryItem()\<cr>" --- 333,337 ---- let movement = movement.":call SAImaps_RemoveLastHistoryItem()\<cr>" " BNF 12 Nov 2002: Functions never add more than one item to the searcg ! " history. " let movement = movement.":call SAImaps_RemoveLastHistoryItem()\<cr>" *************** *** 341,349 **** " otherwise enter select mode... else ! let movement = movement."vf".phe."\<C-g>" end end return initial.text.movement endfunction --- 344,354 ---- " otherwise enter select mode... else ! let movement = movement."v/".iconv(phe, 'latin1', s:oldenc)."\<CR>\<C-g>" end end + let &encoding = s:oldenc return initial.text.movement + endfunction *************** *** 355,358 **** --- 360,366 ---- " modified by SA to use optional place holder characters. function! IMAP_Jumpfunc() + let s:oldenc = &encoding + setglobal encoding=latin1 + let phs = '«' let phe = '»' *************** *** 370,388 **** endif ! if !search(phs.'.\{-}'.phe,'W') "no more marks echomsg "no marks found\n" return "\<CR>" else ! if getline('.')[col('.')] == phe ! return "\<Del>\<Del>" else if col('.') > 1 ! return "\<Esc>lvf".phe."\<C-g>" else ! return "\<C-\>\<C-n>vf".phe."\<C-g>" endif endif endif endfunction " map only if there is no mapping already. allows for user customization. if !hasmapto('IMAP_Jumpfunc') --- 378,406 ---- endif ! let phsc = iconv(phs, 'latin1', s:oldenc) ! let phec = iconv(phe, 'latin1', s:oldenc) ! ! if !search(phsc.'.\{-}'.phec,'W') "no more marks echomsg "no marks found\n" return "\<CR>" else ! if strpart ( ! \ getline('.'), ! \ col('.') + strlen(phsc) - 1, ! \ strlen(phec) ! \ ! \ ) == phec ! ! return substitute(phsc.phec, '.', "\<Del>", 'g')."\<C-r>=RestoreEncoding()\<CR>" else if col('.') > 1 ! return "\<Esc>lv/".phec."\<CR>\<Esc>:call RestoreEncoding()\<CR>gv\<C-g>" else ! return "\<C-\>\<C-n>v/".phe."\<CR>\<Esc>:call RestoreEncoding()\<CR>gv\<C-g>" endif endif endif endfunction + " map only if there is no mapping already. allows for user customization. if !hasmapto('IMAP_Jumpfunc') *************** *** 391,394 **** --- 409,418 ---- end " }}} + " RestoreEncoding: restores file encoding to what it was originally {{{ + " Description: + function! RestoreEncoding() + let &g:encoding = s:oldenc + return '' + endfunction " }}} nmap <silent> <script> <plug>«SelectRegion» `<v`> |