[Vim-latex-cvs] vimfiles/ftplugin/tex brackets.vim,1.8,1.9
Brought to you by:
srinathava,
tmaas
From: <sri...@us...> - 2003-10-09 23:58:16
|
Update of /cvsroot/vim-latex/vimfiles/ftplugin/tex In directory sc8-pr-cvs1:/tmp/cvs-serv20763 Modified Files: brackets.vim Log Message: New: Johannes Tanzler's Tex_InsertItem function to insert an \item command with extra options depending on the surrounding environment. Index: brackets.vim =================================================================== RCS file: /cvsroot/vim-latex/vimfiles/ftplugin/tex/brackets.vim,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** brackets.vim 31 Dec 2002 19:15:37 -0000 1.8 --- brackets.vim 9 Oct 2003 23:58:13 -0000 1.9 *************** *** 2,6 **** " Author: Carl Mueller " (incorporated into latex-suite by Srinath Avadhanula) - " Last Change: Tue Dec 31 11:00 AM 2002 PST " Description: " This ftplugin provides the following maps: --- 2,5 ---- *************** *** 22,25 **** --- 21,28 ---- " 3. q<M-l> \lefteqn{} " otherwise insert \label{} + " . <M-i> inserts \item commands at the current cursor location depending on + " the surrounding environment. For example, inside itemize, it will + " insert a simple \item, but within a description, it will insert + " \item[<+label+>] etc. " " These functions make it extremeley easy to do all the \left \right stuff in *************** *** 53,56 **** --- 56,60 ---- inoremap <silent> <Plug>Tex_MathCal <C-r>=Tex_MathCal()<CR> inoremap <silent> <Plug>Tex_LeftRight <C-r>=Tex_LeftRight()<CR> + inoremap <Plug>Tex_InsertItem <Esc>a<C-r>=Tex_InsertItem()<CR> " Provide mappings only if the user hasn't provided a map already or if the *************** *** 67,70 **** --- 71,77 ---- imap <buffer> <silent> <M-l> <Plug>Tex_LeftRight endif + if !hasmapto("\<Plug>Tex_InsertItem") + inoremap <M-i> <C-R>=Tex_InsertItem()<CR> + endif " }}} *************** *** 158,161 **** --- 165,216 ---- endif endfunction " }}} + " Tex_InsertItem: insert item into a list {{{ + " Description: a polymorphic function which inserts various formatted \item + " commands depending on the environment surrounding the cursor. If outside a + " list, then do nothing. + " + " (C) 2003 by Johannes Tanzler, <joh...@ao...> + " modifications by Srinath Avadhanula + function! Tex_InsertItem() + " Remember where we are. + let curpos = line('.').' | normal! |'.virtcol('.') + let curline = line('.') + + " Get one of the relevant environments before this line. + let env_line = search( + \ '^\s*\\begin{\(itemize\|enumerate\|theindex\|description\|labeling\|thebibliography\)', 'bW') + " If none found then return. + if env_line == 0 + return '' + endif + " We are at the beginning of the environment. + let env = matchstr(getline(env_line), '{\zs.\{-}\ze}') + call Tex_Debug("env = ".env, "bra") + " search forward for the end of the environment. If the end of the + " environment occurs before where we originally were, means we were + " outside (after the end) of the environment. In this do nothing. + let env_line_end = search('^\s*\\end{'.env) + + call Tex_Debug("env_line = ".env_line.', env_line_end = '.env_line_end, "bra") + if env_line_end < curline + exec curpos + return '' + endif + + exec curpos + + if env =~ '\(itemize\|enumerate\|theindex\)' + return IMAP_PutTextWithMovement("\\item ") + elseif env =~ '\(description\|labeling\)' + if env =~ 'labeling' | let add = '\sfb ' | else | let add = '' | endif + return IMAP_PutTextWithMovement("\\item[" . add . "<+label+>] <++>") + elseif env =~ '\(thebibliography\)' + return IMAP_PutTextWithMovement("\\item[<+biblabel+>]{<+bibkey+>}<++>") + else + return "" + endif + endfunction + + " }}} " vim:fdm=marker |