[Vim-latex-cvs] vimfiles/ftplugin/latex-suite envmacros.vim,1.6,1.7
Brought to you by:
srinathava,
tmaas
From: <sri...@us...> - 2002-11-17 00:43:31
|
Update of /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite In directory usw-pr-cvs1:/tmp/cvs-serv11836 Modified Files: envmacros.vim Log Message: changed the Tex_itemize and such functions (the specialized environment functions) to all use IMAP_PutTexWithMovement(). This allows the user's placeholder settings to be respected and also filetype specific indentation to be preserved even from menus. Previously, a choice made from the menu used to insert the placeholders even if the user had g:Imap_UsePlaceHolders = 0. New functions SetUpEnvironmentsPrompt() and PromptForEnvironment() for providing a consistent prompt for the user input. These functions will also be used in the coming version in Tex_Change... so that the same prompt is used. General janitorial work. Code clean up and prettification. Please check and report any bugs. Index: envmacros.vim =================================================================== RCS file: /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite/envmacros.vim,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** envmacros.vim 15 Nov 2002 22:30:16 -0000 1.6 --- envmacros.vim 17 Nov 2002 00:43:27 -0000 1.7 *************** *** 3,7 **** " Author: Mikolaj Machowski " Created: Tue Apr 23 08:00 PM 2002 PST ! " Last Change: pi± lis 15 11:00 2002 C " " Description: mappings/menus for environments. --- 3,7 ---- " Author: Mikolaj Machowski " Created: Tue Apr 23 08:00 PM 2002 PST ! " Last Change: Sat Nov 16 04:00 PM 2002 PST " " Description: mappings/menus for environments. *************** *** 106,110 **** if g:Tex_Menus && g:Tex_EnvironmentMenus if wiz ! exe 'amenu '.location.' <plug><C-r>=Tex_MenuWizard("'.a:submenu.'", "'.a:name.'")<CR>' else exe 'amenu '.location." <plug><C-r>=IMAP_PutTextWithMovement('".a:irhs."')<CR>" --- 106,110 ---- if g:Tex_Menus && g:Tex_EnvironmentMenus if wiz ! exe 'amenu '.location.' <plug><C-r>=Tex_DoEnvironment("'.a:name.'")<CR>' else exe 'amenu '.location." <plug><C-r>=IMAP_PutTextWithMovement('".a:irhs."')<CR>" *************** *** 261,281 **** " ============================================================================== " Specialized functions for various environments " ============================================================================== " Tex_itemize: {{{ ! function! Tex_itemize(indent, env) ! exe 'normal i'.a:indent.'\begin{'.a:env."}\<cr>\\item \<cr>\\end{".a:env."}«»\<Up>" endfunction " }}} " Tex_description: {{{ ! function! Tex_description(indent, env) let itlabel = input('(Optional) Item label? ') if itlabel != '' let itlabel = '['.itlabel.']' endif ! exe 'normal i'.a:indent."\\begin{description}\<cr>\\item".itlabel." \<cr>\\end{description}«»\<Up>" endfunction " }}} " Tex_figure: {{{ ! function! Tex_figure(indent, env) let flto = input('Float to (htbp)? ') let caption = input('Caption? ') --- 261,288 ---- " ============================================================================== " Specialized functions for various environments + " + " All these functions are to be used as: + " + " inoremap <lhs> <C-r>=Tex_itemize('enumerate')<CR> + " nnoremap <lhs> i<C-r>=Tex_itemize('enumerate')<CR> + " + " and so on... " ============================================================================== " Tex_itemize: {{{ ! function! Tex_itemize(env) ! return IMAP_PutTextWithMovement('\begin{'.a:env."}\<cr>\\item «»\<cr>\\end{".a:env."}«»") endfunction " }}} " Tex_description: {{{ ! function! Tex_description(env) let itlabel = input('(Optional) Item label? ') if itlabel != '' let itlabel = '['.itlabel.']' endif ! return IMAP_PutTextWithMovement("\\begin{description}\<cr>\\item".itlabel." «»\<cr>\\end{description}«»") endfunction " }}} " Tex_figure: {{{ ! function! Tex_figure(env) let flto = input('Float to (htbp)? ') let caption = input('Caption? ') *************** *** 314,322 **** let figure = figure . centr let figure = figure . '\end{'.a:env.'}' ! exe 'normal i'.a:indent.figure."\<Esc>$" endfunction " }}} " Tex_table: {{{ ! function! Tex_table(indent, env) let flto = input('Float to (htbp)? ') let caption = input('Caption? ') --- 321,329 ---- let figure = figure . centr let figure = figure . '\end{'.a:env.'}' ! return IMAP_PutTextWithMovement(figure) endfunction " }}} " Tex_table: {{{ ! function! Tex_table(env) let flto = input('Float to (htbp)? ') let caption = input('Caption? ') *************** *** 354,362 **** endif let ret=ret.'\end{table}«»' ! exe 'normal i'.ret."\<Esc>?ä\<cr>:nohl\<cr>C" endfunction " }}} " Tex_tabular: {{{ ! function! Tex_tabular(indent, env) let pos = input('(Optional) Position (t b)? ') let format = input("Format ( l r c p{width} | @{text} )? ") --- 361,369 ---- endif let ret=ret.'\end{table}«»' ! return IMAP_PutTextWithMovement(ret) endfunction " }}} " Tex_tabular: {{{ ! function! Tex_tabular(env) let pos = input('(Optional) Position (t b)? ') let format = input("Format ( l r c p{width} | @{text} )? ") *************** *** 367,386 **** let format = '{'.format.'}' endif ! exe 'normal i'.a:indent.'\begin{'.a:env.'}'.pos.format."\<cr> \<cr>\\end{".a:env."}«»\<Up>" endfunction " }}} " Tex_eqnarray: {{{ ! function! Tex_eqnarray(indent, env) let label = input('Label? ') if label != '' let arrlabel = '\label{'.label."}\<cr> " else ! let arrlabel = ' ' endif ! exe 'normal i'.a:indent.'\begin{'.a:env."}\<cr>".arrlabel."\<cr>\\end{".a:env."}«»\<Up>" endfunction " }}} " Tex_list: {{{ ! function! Tex_list(indent, env) let label = input('Label (for \item)? ') if label != '' --- 374,393 ---- let format = '{'.format.'}' endif ! return IMAP_PutTextWithMovement('\begin{'.a:env.'}'.pos.format."\<cr> \<cr>\\end{".a:env."}«»") endfunction " }}} " Tex_eqnarray: {{{ ! function! Tex_eqnarray(env) let label = input('Label? ') if label != '' let arrlabel = '\label{'.label."}\<cr> " else ! let arrlabel = '' endif ! return IMAP_PutTextWithMovement('\begin{'.a:env."}\<cr>".arrlabel."«»\<cr>\\end{".a:env."}«»") endfunction " }}} " Tex_list: {{{ ! function! Tex_list(env) let label = input('Label (for \item)? ') if label != '' *************** *** 393,401 **** let label = '' endif ! exe 'normal i'.a:indent.'\begin{list}'.label."\<cr>\\item \<cr>\\end{list}«»\<Up>" endfunction " }}} " Tex_document: {{{ ! function! Tex_document(indent, env) let dstyle = input('Document style? ') let opts = input('(Optional) Options? ') --- 400,408 ---- let label = '' endif ! return IMAP_PutTextWithMovement('\begin{list}'.label."\<cr>\\item \<cr>\\end{list}«»") endfunction " }}} " Tex_document: {{{ ! function! Tex_document(env) let dstyle = input('Document style? ') let opts = input('(Optional) Options? ') *************** *** 406,414 **** let foo = foo.'['.opts.']'.'{'.dstyle.'}' endif ! exe 'normal i'.a:indent.foo."\<cr>\<cr>\\begin{document}\<cr>\<cr>\\end{document}\<Up>" endfunction " }}} " Tex_minipage: {{{ ! function! Tex_minipage(indent, env) let foo = '\begin{minipage}' let pos = input('(Optional) Position (t b)? ') --- 413,421 ---- let foo = foo.'['.opts.']'.'{'.dstyle.'}' endif ! return IMAP_PutTextWithMovement(foo."\<cr>\<cr>\\begin{document}\<cr>«»\<cr>\\end{document}") endfunction " }}} " Tex_minipage: {{{ ! function! Tex_minipage(env) let foo = '\begin{minipage}' let pos = input('(Optional) Position (t b)? ') *************** *** 419,427 **** let foo = foo.'['.pos.']{'.width.'}' endif ! exe 'normal i'.a:indent.foo."\<cr> \<cr>\\end{minipage}«»\<Up>" endfunction " }}} " Tex_thebibliography: {{{ ! function! Tex_thebibliography(indent, env) " AUC Tex: "Label for BibItem: 99" let indent = input('Indent for BibItem? ') --- 426,434 ---- let foo = foo.'['.pos.']{'.width.'}' endif ! return IMAP_PutTextWithMovement(foo."\<cr>«»\<cr>\\end{minipage}«»") endfunction " }}} " Tex_thebibliography: {{{ ! function! Tex_thebibliography(env) " AUC Tex: "Label for BibItem: 99" let indent = input('Indent for BibItem? ') *************** *** 434,466 **** endif let bar = bar.'{'.key.'}' ! exe 'normal i'.a:indent.'\begin{thebibliography}'.foo."\<cr>".bar." \<cr>\\end{thebibliography}«»\<Up>" endfunction " }}} ! " Merged contributions from Carl Mueller ! " asdf is a fake argument to recognize if call is coming from keyboard or from ! " menu ! inoremap <F5> <C-O>:call Tex_FFive_intelligent()<cr> ! noremap <F5> :call Tex_FFive_intelligent()<cr> ! function! Tex_FFive_intelligent() " {{{ let start_line = line('.') let pos = line('.').' | normal! '.virtcol('.').'|' if search('\\documentclass', 'bW') && search('\\begin{document}') let begin_line = search('\\begin{document}') if start_line < begin_line exe pos ! call Tex_package_from_line() else exe pos ! call Tex_DoEnvironment('asdf') endif elseif search('\\documentclass') exe pos ! call Tex_package_from_line() else exe pos ! call Tex_DoEnvironment('asdf') endif ! endfunction " }}} function! Tex_package_from_line() " {{{ " Function Tex_PutPackage is defined in packages.vim --- 441,561 ---- endif let bar = bar.'{'.key.'}' ! return IMAP_PutTextWithMovement('\begin{thebibliography}'.foo."\<cr>".bar." \<cr>\\end{thebibliography}«»\<Up>") endfunction " }}} ! " ============================================================================== ! " Contributions / suggestions from Carl Mueller (auctex.vim) ! " ============================================================================== ! let s:common_environments = 'equation,equation*,eqnarray,eqnarray*,[,$$,align,align*' ! ! " SetUpEnvironmentsPrompt: sets up a prompt string using s:common_environments {{{ ! " Description: ! " ! function! SetUpEnvironmentsPrompt() ! let num_common = GetListCount(s:common_environments) ! ! let i = 1 ! let s:common_env_prompt = "\n" ! ! while i < num_common ! ! let env1 = Tex_Strntok(s:common_environments, ',', i) ! let env2 = Tex_Strntok(s:common_environments, ',', i + 1) ! ! let s:common_env_prompt = s:common_env_prompt."(".i.") ".env1."\t".( strlen(env1) < 4 ? "\t" : "" )."(".(i+1).") ".env2."\n" ! ! let i = i + 2 ! endwhile ! let s:common_env_prompt = s:common_env_prompt."\n".'Enter number or name of environment :' ! endfunction " }}} ! " PromptForEnvironment: prompts for an environment {{{ ! " Description: ! function! PromptForEnvironment(ask) ! ! if !exists('s:common_env_prompt') ! call SetUpEnvironmentsPrompt() ! endif ! ! let inp = input(a:ask.s:common_env_prompt) ! if inp =~ '^[0-9]$' ! let env = Tex_Strntok(s:common_environments, ',', inp) ! else ! let env = inp ! endif ! ! return env ! endfunction " }}} ! " Tex_DoEnvironment: fast insertion of environments {{{ ! " Description: ! " The menus call this function with an argument (the name of the environment ! " to insert). The maps call this without any arguments. In this case, it ! " prompts for an environment to enter if the current line is empty. If ! " called without arguments and there is a word on the current line, then use ! " that as the name of a new environment. ! function! Tex_DoEnvironment(...) ! let l = getline('.') ! if a:0 < 1 ! let env = matchstr(l, '^\s*\zs.*') ! if env == '' ! let env = PromptForEnvironment('Choose which environment to insert :') ! if env != '' ! return Tex_PutEnvironment(env) ! endif ! else ! let ind = matchstr(l, '^\s*\ze') ! normal 0D ! return Tex_PutEnvironment(ind, env) ! endif ! else ! return Tex_PutEnvironment(a:1) ! endif ! endfunction " }}} ! " Tex_PutEnvironment: calls various specialized functions {{{ ! " Description: ! " Based on input argument, it calls various specialized functions. ! function! Tex_PutEnvironment(env) ! if a:env =~ "theorem\\|lemma\\|equation\\|eqnarray\\|align\\|multline" ! return Tex_eqnarray(a:env) ! elseif a:env =~ "enumerate\\|itemize\\|theindex\\|trivlist" ! return Tex_itemize(a:env) ! elseif a:env =~ "table\\|table*" ! return Tex_table(a:env) ! elseif a:env =~ "tabular\\|tabular*\\|array\\|array*" ! return Tex_tabular(a:env) ! elseif exists('*Tex_'.a:env) ! exe 'return Tex_'.a:env.'(a:env)' ! else ! return IMAP_PutTextWithMovement('\begin{'.a:env."}\<cr>«»\<cr>\\end{".a:env."}«»") ! endif ! endfunction " }}} ! ! inoremap <F5> <C-r>=Tex_FastEnvironmentInsert()<cr> ! nnoremap <F5> i<C-r>=Tex_FastEnvironmentInsert()<cr> ! ! function! Tex_FastEnvironmentInsert() " {{{ ! let start_line = line('.') let pos = line('.').' | normal! '.virtcol('.').'|' + if search('\\documentclass', 'bW') && search('\\begin{document}') let begin_line = search('\\begin{document}') if start_line < begin_line exe pos ! return Tex_package_from_line() else exe pos ! return Tex_DoEnvironment() endif elseif search('\\documentclass') exe pos ! return Tex_package_from_line() else exe pos ! return Tex_DoEnvironment() endif ! endfunction ! ! " }}} function! Tex_package_from_line() " {{{ " Function Tex_PutPackage is defined in packages.vim *************** *** 470,515 **** let pack = input('Package? ') if pack != '' ! call Tex_PutPackage(pack) endif return 0 else normal 0D ! call Tex_PutPackage(pack) ! endif ! endfunction " }}} ! ! ! function! Tex_DoEnvironment(env) " {{{ ! let l = getline('.') ! if a:env == 'asdf' ! let env = matchstr(l, '^\s*\zs.*') ! if env == '' ! let env = input('Environment? ') ! if env != '' ! call Tex_PutEnvironment(l, env) ! endif ! else ! let ind = matchstr(l, '^\s*\ze') ! normal 0D ! call Tex_PutEnvironment(ind, env) ! endif ! else ! call Tex_PutEnvironment(l, a:env) ! endif ! startinsert ! endfunction " }}} ! function! Tex_PutEnvironment(indent, env) " {{{ ! if a:env =~ "theorem\\|lemma\\|equation\\|eqnarray\\|align\\|multline" ! call Tex_eqnarray(a:indent, a:env) ! elseif a:env =~ "enumerate\\|itemize\\|theindex\\|trivlist" ! call Tex_itemize(a:indent, a:env) ! elseif a:env =~ "table\\|table*" ! call Tex_table(a:indent, a:env) ! elseif a:env =~ "tabular\\|tabular*\\|array\\|array*" ! call Tex_tabular(a:indent, a:env) ! elseif exists('*Tex_'.a:env) ! exe 'call Tex_'.a:env.'(a:indent, a:env)' ! else ! exe 'normal i'.a:indent.'\begin{'.a:env."}\<cr> \<cr>\\end{".a:env."}«»\<Up>" endif endfunction " }}} --- 565,574 ---- let pack = input('Package? ') if pack != '' ! return Tex_PutPackage(pack) endif return 0 else normal 0D ! return Tex_PutPackage(pack) endif endfunction " }}} *************** *** 530,534 **** let s:math_environment = 'eqnarray,eqnarray*,align,align*,equation,equation*,[,$$' let s:item_environment = 'list,trivlist,enumerate,itemize,theindex' ! function Tex_change_environment() " {{{ let env_line = searchpair("\\[\\|begin{", '', "\\]\\|end{", "bn") if env_line != 0 --- 589,593 ---- let s:math_environment = 'eqnarray,eqnarray*,align,align*,equation,equation*,[,$$' let s:item_environment = 'list,trivlist,enumerate,itemize,theindex' ! function! Tex_change_environment() " {{{ let env_line = searchpair("\\[\\|begin{", '', "\\]\\|end{", "bn") if env_line != 0 *************** *** 660,662 **** " vim:fdm=marker:nowrap:noet - --- 719,720 ---- |