PageRenderTime 246ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 1ms

/vim/ftplugin/latex-suite/envmacros.vim

https://bitbucket.org/vertespain/config
Vim Script | 1166 lines | 841 code | 100 blank | 225 comment | 193 complexity | df19e946e497c9738b2adb4892a461d2 MD5 | raw file
  1. "=============================================================================
  2. " File: envmacros.vim
  3. " Author: Mikolaj Machowski
  4. " Created: Tue Apr 23 08:00 PM 2002 PST
  5. " CVS Header: $Id: envmacros.vim 1051 2009-06-02 18:33:54Z tmaas $
  6. " Description: mappings/menus for environments.
  7. "=============================================================================
  8. if !g:Tex_EnvironmentMaps && !g:Tex_EnvironmentMenus
  9. finish
  10. endif
  11. exe 'so '.fnameescape(expand('<sfile>:p:h').'/wizardfuncs.vim')
  12. nmap <silent> <script> <plug> i
  13. imap <silent> <script> <C-o><plug> <Nop>
  14. " Define environments for IMAP evaluation " {{{
  15. let s:figure = "\\begin{figure}[<+htpb+>]\<cr>\\begin{center}\<cr>\\psfig{figure=<+eps file+>}\<cr>\\end{center}\<cr>\\caption{<+caption text+>}\<cr>\\label{fig:<+label+>}\<cr>\\end{figure}<++>"
  16. let s:figure_graphicx = "\\begin{figure}[<+htpb+>]\<cr>\\begin{center}\<cr>\\includegraphics{<+file+>}\<cr>\\end{center}\<cr>\\caption{<+caption text+>}\<cr>\\label{fig:<+label+>}\<cr>\\end{figure}<++>"
  17. let s:minipage = "\\begin{minipage}[<+tb+>]{<+width+>}\<cr><++>\<cr>\\end{minipage}<++>"
  18. let s:picture = "\\begin{picture}(<+width+>, <+height+>)(<+xoff+>,<+yoff+>)\<cr>\\put(<+xoff+>,<+yoff+>){\\framebox(<++>,<++>){<++>}}\<cr>\\end{picture}<++>"
  19. let s:list = "\\begin{list}{<+label+>}{<+spacing+>}\<cr>\\item <++>\<cr>\\end{list}<++>"
  20. let s:table = "\\begin{table}\<cr>\\centering\<cr>\\begin{tabular}{<+dimensions+>}\<cr><++>\<cr>\\end{tabular}\<cr>\\caption{<+Caption text+>}\<cr>\\label{tab:<+label+>}\<cr>\\end{table}<++>"
  21. let s:array = "\\left<++>\<cr>\\begin{array}{<+dimension+>}\<cr><+elements+>\<cr>\\end{array}\<cr>\\right<++>"
  22. let s:description ="\\begin{description}\<cr>\\item[<+label+>]<++>\<cr>\\end{description}<++>"
  23. let s:document = "\\documentclass[<+options+>]{<+class+>}\<cr>\<cr>\\begin{document}\<cr><++>\<cr>\\end{document}"
  24. let s:tabular = "\\begin{tabular}[<+hbtp+>]{<+format+>}\<cr><++>\<cr>\\end{tabular}"
  25. let s:tabular_star = "\\begin{tabular*}[<+hbtp+>]{<+format+>}\<cr><++>\<cr>\\end{tabular*}"
  26. " }}}
  27. " define environments with special behavior in line wise selection. {{{
  28. if !exists('s:vis_center_left')
  29. let s:vis_center_left = '\centerline{'
  30. let s:vis_center_right = '}'
  31. let s:vis_verbatim_left = '\verb\|'
  32. let s:vis_verbatim_right = '\|'
  33. let s:vis_flushright_left = '{\raggedright '
  34. let s:vis_flushright_right = '}'
  35. let s:vis_fushleft_left = '{\raggedleft '
  36. let s:vis_fushleft_right = '}'
  37. let s:vis_lrbox_left = '\sbox{'
  38. let s:vis_lrbox_right = '}'
  39. endif
  40. " }}}
  41. " Tex_EnvMacros: sets up maps and menus for environments {{{
  42. " Description:
  43. function! <SID>Tex_EnvMacros(lhs, submenu, name)
  44. let extra = ''
  45. if a:submenu =~ 'Lists'
  46. let extra = '\item '
  47. endif
  48. let vright = ''
  49. let vleft = ''
  50. if exists('s:vis_'.a:name.'_right')
  51. let vright = s:vis_{a:name}_right
  52. let vleft = s:vis_{a:name}_left
  53. endif
  54. let vrhs = "\<C-\\>\<C-N>:call VEnclose('".vleft."', '".vright."', '\\begin{".a:name."}', '\\end{".a:name."}')\<CR>"
  55. let location = g:Tex_EnvMenuLocation.a:submenu.a:name.'<tab>'
  56. if a:lhs != ''
  57. let vlhs = g:Tex_Leader2.substitute(tolower(a:lhs), '^.', '', '')
  58. let location = location.a:lhs.'\ ('.vlhs.')'
  59. if g:Tex_EnvironmentMaps && !exists('s:doneOnce')
  60. call IMAP(a:lhs, "\<C-r>=Tex_PutEnvironment('".a:name."')\<CR>", 'tex')
  61. exec 'vnoremap <silent> '.vlhs.' '.vrhs
  62. endif
  63. endif
  64. if g:Tex_Menus && g:Tex_EnvironmentMenus && has("gui_running")
  65. exe 'amenu '.location.' <plug><C-r>=Tex_DoEnvironment("'.a:name.'")<CR>'
  66. exe 'vmenu '.location.' '.vrhs
  67. endif
  68. endfunction
  69. " }}}
  70. " Tex_SpecialMacros: macros with special right hand sides {{{
  71. " Description:
  72. function! <SID>Tex_SpecialMacros(lhs, submenu, name, irhs, ...)
  73. let wiz = 1
  74. if a:0 > 0 && a:1 == 0
  75. let wiz = 0
  76. endif
  77. let location = g:Tex_EnvMenuLocation.a:submenu.a:name
  78. let vright = ''
  79. let vleft = ''
  80. if exists('s:vis_'.a:name.'_right')
  81. let vright = s:vis_{a:name}_right
  82. let vleft = s:vis_{a:name}_left
  83. endif
  84. let vrhs = "\<C-\\>\<C-N>:call VEnclose('".vleft."', '".vright."', '\\begin{".a:name."}', '\\end{".a:name."}')\<CR>"
  85. if a:lhs != ''
  86. let vlhs = g:Tex_Leader2.substitute(tolower(a:lhs), '^.', '', '')
  87. let location = location.'<tab>'.a:lhs.'\ ('.vlhs.')'
  88. if g:Tex_EnvironmentMaps && !exists('s:doneOnce')
  89. call IMAP(a:lhs, a:irhs, 'tex')
  90. exec 'vnoremap '.vlhs.' '.vrhs
  91. endif
  92. endif
  93. if g:Tex_Menus && g:Tex_EnvironmentMenus
  94. if wiz
  95. exe 'amenu '.location.' <plug><C-r>=Tex_DoEnvironment("'.a:name.'")<CR>'
  96. else
  97. exe 'amenu '.location." <plug><C-r>=IMAP_PutTextWithMovement('".a:irhs."')<CR>"
  98. endif
  99. exe 'vmenu '.location.' '.vrhs
  100. endif
  101. endfunction " }}}
  102. " Tex_SectionMacros: creates section maps and menus {{{
  103. " Description:
  104. function! <SID>Tex_SectionMacros(lhs, name)
  105. let vlhs = g:Tex_Leader2.substitute(tolower(a:lhs), '^.', '', '')
  106. let vrhs = "\<C-\\>\<C-N>:call VEnclose('\\".a:name."{', '}', '', '')<CR>"
  107. if g:Tex_SectionMaps && !exists('s:doneOnce')
  108. exe 'vnoremap '.vlhs.' '.vrhs
  109. call IMAP (a:lhs, "\\".a:name.'{<++>}<++>', 'tex')
  110. endif
  111. if g:Tex_Menus && g:Tex_SectionMenus
  112. let location = g:Tex_EnvMenuLocation.'Sections.'.a:name.'<tab>'.a:lhs.'\ ('.vlhs.')'
  113. let advlocation = g:Tex_EnvMenuLocation.'Sections.Advanced.'.a:name
  114. let irhs = "\<C-r>=IMAP_PutTextWithMovement('\\".a:name."{<++>}<++>')\<CR>"
  115. let advirhs = "\<C-r>=Tex_InsSecAdv('".a:name."')\<CR>"
  116. let advvrhs = "\<C-\\>\<C-N>:call Tex_VisSecAdv('".a:name."')\<CR>"
  117. exe 'amenu '.advlocation.' <plug>'.advirhs
  118. exe 'vnoremenu '.advlocation." ".advvrhs
  119. exe 'amenu '.location.' <plug>'.irhs
  120. exe 'vnoremenu '.location." ".vrhs
  121. endif
  122. endfunction " }}}
  123. " NewEnvironments {{{
  124. call s:Tex_SpecialMacros('', '', 'newenvironment', '\newenvironment{<++>}[<++>][<++>]{<++>}{<++>}<++>', 0)
  125. call s:Tex_SpecialMacros('', '', 'newenvironment*', '\newenvironment*{<++>}[<++>][<++>]{<++>}{<++>}<++>', 0)
  126. call s:Tex_SpecialMacros('', '', 'renewenvironment', '\renewenvironment{<++>}[<++>][<++>]{<++>}{<++>}<++>', 0)
  127. call s:Tex_SpecialMacros('', '', 'renewenvironment*', '\renewenvironment*{<++>}[<++>][<++>]{<++>}{<++>}<++>', 0)
  128. call s:Tex_SpecialMacros('', '', '-sepenv0-', ' :', 0)
  129. " }}}
  130. " Environments specific commands {{{
  131. call s:Tex_SpecialMacros('', 'Env&Commands.&Lists.', '&item', '\item', 0)
  132. call s:Tex_SpecialMacros('', 'Env&Commands.&Lists.', 'i&tem[]', '\item[<++>]<++>', 0)
  133. call s:Tex_SpecialMacros('', 'Env&Commands.&Lists.', '&bibitem{}', '\bibitem{<++>}<++>', 0)
  134. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', '\\&=', '\=', 0)
  135. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', '\\&>', '\>', 0)
  136. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', '&\\\\', '\\', 0)
  137. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', '\\&+', '\+', 0)
  138. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', '\\&-', '\-', 0)
  139. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', "\\\'", "\\\'", 0)
  140. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', '\\&`', '\`', 0)
  141. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', '\\&kill', '\kill', 0)
  142. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', '&makron\ \\CHAR=', '\<++>=<++>', 0)
  143. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', "&aigu\ \\CHAR\'", "\\<++>\'<++>", 0)
  144. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', '&grave\ \\CHAR`', '\<++>`<++>', 0)
  145. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', 'p&ushtabs', '\pushtabs', 0)
  146. call s:Tex_SpecialMacros('', 'Env&Commands.&Tabbing.', 'p&optabs', '\poptabs', 0)
  147. call s:Tex_SpecialMacros('', 'EnvCommands.&Tabular.', '&hline', '\hline', 0)
  148. call s:Tex_SpecialMacros('', 'EnvCommands.&Tabular.', '&cline', '\cline', 0)
  149. call s:Tex_SpecialMacros('', 'EnvCommands.&Tabular.', '&\&', '&', 0)
  150. call s:Tex_SpecialMacros('', 'EnvCommands.&Tabular.', '&\\\\', '\\', 0)
  151. call s:Tex_SpecialMacros('', 'EnvCommands.&Tabular.', '&multicolumn{}{}{}', '\multicolumn{<++>}{<++>}{<++>}<++>', 0)
  152. call s:Tex_SpecialMacros('', 'EnvCommands.Le&tter.', '&makelabels', '\makelabels', 0)
  153. call s:Tex_SpecialMacros('', 'EnvCommands.Le&tter.', '&address', '\address', 0)
  154. call s:Tex_SpecialMacros('', 'EnvCommands.Le&tter.', '&signature', '\signature', 0)
  155. call s:Tex_SpecialMacros('', 'EnvCommands.Le&tter.', '&date', '\date', 0)
  156. call s:Tex_SpecialMacros('', 'EnvCommands.Le&tter.', '-sepenva4-', ' :', 0)
  157. call s:Tex_SpecialMacros('', 'EnvCommands.Le&tter.', '&opening{}', '\opening{<++>}<++>', 0)
  158. call s:Tex_SpecialMacros('', 'EnvCommands.Le&tter.', '&closing{}', '\closing{<++>}<++>', 0)
  159. call s:Tex_SpecialMacros('', 'EnvCommands.Le&tter.', '&ps{}', '\ps{<++>}<++>', 0)
  160. call s:Tex_SpecialMacros('', 'EnvCommands.Le&tter.', 'cc&{}', '\cc{<++>}<++>', 0)
  161. call s:Tex_SpecialMacros('', 'EnvCommands.&Slides.', '&onlyslides{}', '\onlyslides{<++>}<++>', 0)
  162. call s:Tex_SpecialMacros('', 'EnvCommands.&Slides.', '&onlynotes{}', '\onlynotes{<++>}<++>', 0)
  163. call s:Tex_SpecialMacros('', 'EnvCommands.&Slides.', '-sepenva5-', ' :', 0)
  164. call s:Tex_SpecialMacros('', 'EnvCommands.&Slides.', '&invisible', '\invisible', 0)
  165. call s:Tex_SpecialMacros('', 'EnvCommands.&Slides.', '&visible', '\visible', 0)
  166. call s:Tex_SpecialMacros('', 'EnvCommands.&Slides.', '&settime', '\settime', 0)
  167. call s:Tex_SpecialMacros('', 'EnvCommands.&Slides.', '&addtime', '\addtime', 0)
  168. call s:Tex_SpecialMacros('', '', '-sepenv0-', ' :', 0)
  169. " }}}
  170. " Lists {{{
  171. call s:Tex_SpecialMacros('ELI', '&Lists.', 'list', s:list)
  172. call s:Tex_SpecialMacros('EDE', '&Lists.', 'description', s:description)
  173. call s:Tex_EnvMacros('EEN', '&Lists.', 'enumerate')
  174. call s:Tex_EnvMacros('EIT', '&Lists.', 'itemize')
  175. call s:Tex_EnvMacros('ETI', '&Lists.', 'theindex')
  176. call s:Tex_EnvMacros('ETL', '&Lists.', 'trivlist')
  177. " }}}
  178. " Tables {{{
  179. call s:Tex_SpecialMacros('ETE', '&Tables.', 'table', s:table)
  180. call s:Tex_EnvMacros('ETG', '&Tables.', 'tabbing')
  181. call s:Tex_EnvMacros('', '&Tables.', 'table*')
  182. call s:Tex_EnvMacros('', '&Tables.', 'table2')
  183. call s:Tex_SpecialMacros('ETR', '&Tables.', 'tabular', s:tabular)
  184. call s:Tex_SpecialMacros('', '&Tables.', 'tabular*', s:tabular_star)
  185. " }}}
  186. " Math {{{
  187. call s:Tex_EnvMacros('EAR', '&Math.', 'array')
  188. call s:Tex_EnvMacros('EDM', '&Math.', 'displaymath')
  189. call s:Tex_EnvMacros('EEA', '&Math.', 'eqnarray')
  190. call s:Tex_EnvMacros('', '&Math.', 'eqnarray*')
  191. call s:Tex_EnvMacros('EEQ', '&Math.', 'equation')
  192. call s:Tex_EnvMacros('EMA', '&Math.', 'math')
  193. " }}}
  194. " Structure {{{
  195. call s:Tex_SpecialMacros('EAR', 'Math.', 'array', s:array)
  196. call s:Tex_EnvMacros('EAB', '&Structure.', 'abstract')
  197. call s:Tex_EnvMacros('EAP', '&Structure.', 'appendix')
  198. call s:Tex_EnvMacros('ECE', '&Structure.', 'center')
  199. call s:Tex_EnvMacros('EDO', '&Structure.', 'document')
  200. call s:Tex_EnvMacros('EFC', '&Structure.', 'filecontents')
  201. call s:Tex_EnvMacros('', '&Structure.', 'filecontents*')
  202. call s:Tex_EnvMacros('EFL', '&Structure.', 'flushleft')
  203. call s:Tex_EnvMacros('EFR', '&Structure.', 'flushright')
  204. call s:Tex_EnvMacros('EQN', '&Structure.', 'quotation')
  205. call s:Tex_EnvMacros('EQE', '&Structure.', 'quote')
  206. call s:Tex_EnvMacros('ESP', '&Structure.', 'sloppypar')
  207. call s:Tex_EnvMacros('ETI', '&Structure.', 'theindex')
  208. call s:Tex_EnvMacros('ETP', '&Structure.', 'titlepage')
  209. call s:Tex_EnvMacros('EVM', '&Structure.', 'verbatim')
  210. call s:Tex_EnvMacros('', '&Structure.', 'verbatim*')
  211. call s:Tex_EnvMacros('EVE', '&Structure.', 'verse')
  212. call s:Tex_EnvMacros('ETB', '&Structure.', 'thebibliography')
  213. call s:Tex_SpecialMacros('', '&Structure.', '-sepstruct0-', ':', 0)
  214. call s:Tex_EnvMacros('ENO', '&Structure.', 'note')
  215. call s:Tex_EnvMacros('EOV', '&Structure.', 'overlay')
  216. call s:Tex_EnvMacros('ESL', '&Structure.', 'slide')
  217. " }}}
  218. " Sections {{{
  219. call s:Tex_SectionMacros('SPA', 'part')
  220. call s:Tex_SectionMacros('SCH', 'chapter')
  221. call s:Tex_SectionMacros('SSE', 'section')
  222. call s:Tex_SectionMacros('SSS', 'subsection')
  223. call s:Tex_SectionMacros('SS2', 'subsubsection')
  224. call s:Tex_SectionMacros('SPG', 'paragraph')
  225. call s:Tex_SectionMacros('SSP', 'subparagraph')
  226. " }}}
  227. " Miscellaneous {{{
  228. call s:Tex_SpecialMacros('', '', '-sepenv1-', ' :', 0)
  229. call s:Tex_SpecialMacros('EFI', '', 'figure', "\<C-r>=Tex_PutEnvironment('figure')\<CR>")
  230. call s:Tex_EnvMacros('', '', 'figure*')
  231. call s:Tex_EnvMacros('ELR', '', 'lrbox')
  232. call s:Tex_SpecialMacros('EMP', '', 'minipage', s:minipage)
  233. call s:Tex_SpecialMacros('EPI', '', 'picture', s:picture)
  234. " }}}
  235. if g:Tex_CatchVisMapErrors
  236. exe 'vnoremap '.g:Tex_Leader2." :\<C-u>call ExecMap('".g:Tex_Leader2."', 'v')\<CR>"
  237. endif
  238. " ==============================================================================
  239. " Specialized functions for various environments
  240. "
  241. " All these functions are to be used as:
  242. "
  243. " inoremap <lhs> <C-r>=Tex_itemize('enumerate')<CR>
  244. " nnoremap <lhs> i<C-r>=Tex_itemize('enumerate')<CR>
  245. "
  246. " and so on...
  247. " ==============================================================================
  248. " Tex_itemize: {{{
  249. function! Tex_itemize(env)
  250. return IMAP_PutTextWithMovement('\begin{'.a:env."}\<cr>\\item <++>\<cr>\\end{".a:env."}<++>")
  251. endfunction
  252. " }}}
  253. " Tex_description: {{{
  254. function! Tex_description(env)
  255. if g:Tex_UseMenuWizard == 1
  256. let itlabel = input('(Optional) Item label? ')
  257. if itlabel != ''
  258. let itlabel = '['.itlabel.']'
  259. endif
  260. return IMAP_PutTextWithMovement("\\begin{description}\<cr>\\item".itlabel." <++>\<cr>\\end{description}<++>")
  261. else
  262. return IMAP_PutTextWithMovement(s:description)
  263. endif
  264. endfunction
  265. " }}}
  266. " Tex_figure: {{{
  267. function! Tex_figure(env)
  268. if g:Tex_UseMenuWizard == 1
  269. let flto = input('Float to (htbp)? ')
  270. let caption = input('Caption? ')
  271. let center = input('Center ([y]/n)? ')
  272. let label = input('Label (for use with \ref)? ')
  273. " additional to AUC Tex since my pics are usually external files
  274. let pic = input('Name of Pic-File? ')
  275. if flto != ''
  276. let flto = '['.flto."]\<cr>"
  277. else
  278. let flto = "\<cr>"
  279. endif
  280. if pic != ''
  281. let pic = '\input{'.pic."}\<cr>"
  282. else
  283. let pic = "<++>\<cr>"
  284. endif
  285. if caption != ''
  286. let caption = '\caption{'.caption."}\<cr>"
  287. endif
  288. if label != ''
  289. let label = '\label{fig:'.label."}\<cr>"
  290. endif
  291. if center == 'y'
  292. let centr = '\begin{center}' . "\<cr>"
  293. let centr = centr . pic
  294. let centr = centr . caption
  295. let centr = centr . label
  296. let centr = centr . '\end{center}' . "\<cr>"
  297. else
  298. let centr = pic
  299. let centr = centr . caption
  300. let centr = centr . label
  301. endif
  302. let figure = '\begin{'.a:env.'}'.flto
  303. let figure = figure . centr
  304. let figure = figure . '\end{'.a:env.'}'
  305. return IMAP_PutTextWithMovement(figure)
  306. else
  307. if g:Tex_package_detected =~ '\<graphicx\>'
  308. return IMAP_PutTextWithMovement(s:figure_graphicx)
  309. else
  310. return IMAP_PutTextWithMovement(s:figure)
  311. endif
  312. endif
  313. endfunction
  314. " }}}
  315. " Tex_table: {{{
  316. function! Tex_table(env)
  317. if g:Tex_UseMenuWizard == 1
  318. let flto = input('Float to (htbp)? ')
  319. let caption = input('Caption? ')
  320. let center = input('Center (y/n)? ')
  321. let label = input('Label? ')
  322. if flto != ''
  323. let flto ='['.flto."]\<cr>"
  324. else
  325. let flto = ''
  326. endif
  327. let ret='\begin{table}'.flto
  328. if center == 'y'
  329. let ret=ret."\\begin{center}\<cr>"
  330. endif
  331. let foo = '\begin{tabular}'
  332. let pos = input('(Optional) Position (t b)? ')
  333. if pos != ''
  334. let foo = foo.'['.pos.']'
  335. else
  336. let foo = foo."\<cr>"
  337. endif
  338. let format = input("Format ( l r c p{width} | @{text} )? ")
  339. if format == ''
  340. let format = '<++>'
  341. endif
  342. let ret = ret.foo.'{'.format."}\<cr><++>\<cr>\\end{tabular}<++>\<cr>"
  343. if center == 'y'
  344. let ret=ret."\\end{center}\<cr>"
  345. endif
  346. if caption != ''
  347. let ret=ret.'\caption{'.caption."}\<cr>"
  348. endif
  349. if label != ''
  350. let ret=ret.'\label{tab:'.label."}\<cr>"
  351. endif
  352. let ret=ret.'\end{table}<++>'
  353. return IMAP_PutTextWithMovement(ret)
  354. else
  355. return IMAP_PutTextWithMovement(s:table)
  356. endif
  357. endfunction
  358. " }}}
  359. " Tex_tabular: {{{
  360. function! Tex_tabular(env)
  361. if g:Tex_UseMenuWizard == 1
  362. let pos = input('(Optional) Position (t b)? ')
  363. let format = input("Format ( l r c p{width} | @{text} )? ")
  364. if pos != ''
  365. let pos = '['.pos.']'
  366. endif
  367. if format != ''
  368. let format = '{'.format.'}'
  369. endif
  370. return IMAP_PutTextWithMovement('\begin{'.a:env.'}'.pos.format."\<cr> \<cr>\\end{".a:env.'}<++>')
  371. else
  372. return IMAP_PutTextWithMovement('\begin{'.a:env.'}[<+position+>]{<+format+>}'."\<cr><++>\<cr>\\end{".a:env.'}<++>')
  373. endif
  374. endfunction
  375. " }}}
  376. " Tex_eqnarray: {{{
  377. function! Tex_eqnarray(env)
  378. if g:Tex_UseMenuWizard == 1
  379. if a:env !~ '\*'
  380. let label = input('Label? ')
  381. if label != ''
  382. let arrlabel = '\label{'.label."}\<cr>"
  383. else
  384. let arrlabel = ''
  385. endif
  386. else
  387. let arrlabel = ''
  388. endif
  389. else
  390. if a:env !~ '\*'
  391. let arrlabel = "\\label{<++>}\<cr>"
  392. else
  393. let arrlabel = ""
  394. endif
  395. endif
  396. return IMAP_PutTextWithMovement('\begin{'.a:env."}\<cr><++>\<cr>".arrlabel."\\end{".a:env."}<++>")
  397. endfunction
  398. " }}}
  399. " Tex_list: {{{
  400. function! Tex_list(env)
  401. if g:Tex_UseMenuWizard == 1
  402. let label = input('Label (for \item)? ')
  403. if label != ''
  404. let label = '{'.label.'}'
  405. let addcmd = input('Additional commands? ')
  406. if addcmd != ''
  407. let label = label . '{'.addcmd.'}'
  408. endif
  409. else
  410. let label = ''
  411. endif
  412. return IMAP_PutTextWithMovement('\begin{list}'.label."\<cr>\\item \<cr>\\end{list}<++>")
  413. else
  414. return IMAP_PutTextWithMovement(s:list)
  415. endif
  416. endfunction
  417. " }}}
  418. " Tex_document: {{{
  419. function! Tex_document(env)
  420. if g:Tex_UseMenuWizard == 1
  421. let dstyle = input('Document style? ')
  422. let opts = input('(Optional) Options? ')
  423. let foo = '\documentclass'
  424. if opts == ''
  425. let foo = foo.'{'.dstyle.'}'
  426. else
  427. let foo = foo.'['.opts.']'.'{'.dstyle.'}'
  428. endif
  429. return IMAP_PutTextWithMovement(foo."\<cr>\<cr>\\begin{document}\<cr><++>\<cr>\\end{document}")
  430. else
  431. return IMAP_PutTextWithMovement(s:document)
  432. endif
  433. endfunction
  434. " }}}
  435. " Tex_minipage: {{{
  436. function! Tex_minipage(env)
  437. if g:Tex_UseMenuWizard == 1
  438. let foo = '\begin{minipage}'
  439. let pos = input('(Optional) Position (t b)? ')
  440. let width = input('Width? ')
  441. if pos == ''
  442. let foo = foo.'{'.width.'}'
  443. else
  444. let foo = foo.'['.pos.']{'.width.'}'
  445. endif
  446. return IMAP_PutTextWithMovement(foo."\<cr><++>\<cr>\\end{minipage}<++>")
  447. else
  448. return IMAP_PutTextWithMovement(s:minipage)
  449. endif
  450. endfunction
  451. " }}}
  452. " Tex_thebibliography: {{{
  453. function! Tex_thebibliography(env)
  454. if g:Tex_UseMenuWizard == 1
  455. " AUC Tex: "Label for BibItem: 99"
  456. let indent = input('Indent for BibItem? ')
  457. let foo = '{'.indent.'}'
  458. let biblabel = input('(Optional) Bibitem label? ')
  459. let key = input('Add key? ')
  460. let bar = '\bibitem'
  461. if biblabel != ''
  462. let bar = bar.'['.biblabel.']'
  463. endif
  464. let bar = bar.'{'.key.'}'
  465. return IMAP_PutTextWithMovement('\begin{thebibliography}'.foo."\<cr>".bar." \<cr>\\end{thebibliography}<++>\<Up>")
  466. else
  467. return IMAP_PutTextWithMovement(
  468. \ "\\begin{thebibliography}\<CR>".
  469. \ "\\bibitem[<+biblabel+>]{<+bibkey+>} <++>\<CR>".
  470. \ "<++>\<CR>".
  471. \ "\\end{thebibliography}<++>")
  472. endif
  473. endfunction
  474. " }}}
  475. " ==============================================================================
  476. " Contributions / suggestions from Carl Mueller (auctex.vim)
  477. " ==============================================================================
  478. " PromptForEnvironment: prompts for an environment {{{
  479. " Description:
  480. function! PromptForEnvironment(ask)
  481. return Tex_ChooseFromPrompt(
  482. \ a:ask."\n" .
  483. \ Tex_CreatePrompt(g:Tex_PromptedEnvironments, 2, ",") .
  484. \ "\nEnter name or number of environment :",
  485. \ g:Tex_PromptedEnvironments, ",")
  486. endfunction " }}}
  487. " Tex_DoEnvironment: fast insertion of environments {{{
  488. " Description:
  489. " The menus call this function with an argument (the name of the environment
  490. " to insert). The maps call this without any arguments. In this case, it
  491. " prompts for an environment to enter if the current line is empty. If
  492. " called without arguments and there is a word on the current line, then use
  493. " that as the name of a new environment.
  494. function! Tex_DoEnvironment(...)
  495. if a:0 < 1
  496. let env = matchstr(getline('.'), '^\s*\zs\w*\*\=\ze\s*$')
  497. " If in current line is more than one word or in visual mode
  498. " ignore contents of line and prompt for environment
  499. if env == '' || (exists('s:isvisual') && s:isvisual == 'yes')
  500. let env = PromptForEnvironment('Choose which environment to insert: ')
  501. if env != ''
  502. return Tex_PutEnvironment(env)
  503. else
  504. return ''
  505. endif
  506. else
  507. " delete the word on the line into the blackhole register.
  508. normal! 0"_D
  509. return Tex_PutEnvironment(env)
  510. endif
  511. else
  512. return Tex_PutEnvironment(a:1)
  513. endif
  514. endfunction " }}}
  515. " Tex_PutEnvironment: calls various specialized functions {{{
  516. " Description:
  517. " Based on input argument, it calls various specialized functions.
  518. function! Tex_PutEnvironment(env)
  519. if exists("s:isvisual") && s:isvisual == "yes"
  520. let s:isvisual = 'no'
  521. if a:env == '\['
  522. return VEnclose('', '', '\[', '\]')
  523. elseif a:env == '$$'
  524. return VEnclose('', '', '$$', '$$')
  525. endif
  526. return VEnclose('\begin{'.a:env.'}', '\end{'.a:env.'}', '\begin{'.a:env.'}', '\end{'.a:env.'}')
  527. else
  528. " The user can define something like
  529. " let g:Tex_Env_theorem = "\\begin{theorem}\<CR><++>\<CR>\\end{theorem}"
  530. " This will effectively over-write the default definition of the
  531. " theorem environment which uses a \label.
  532. if exists("b:Tex_Env_{'".a:env."'}")
  533. return IMAP_PutTextWithMovement(b:Tex_Env_{a:env})
  534. elseif exists("g:Tex_Env_{'".a:env."'}")
  535. return IMAP_PutTextWithMovement(g:Tex_Env_{a:env})
  536. elseif a:env =~ 'equation*\|eqnarray*\|theorem\|lemma\|equation\|eqnarray\|align\*\|align\>\|multline'
  537. let g:aa = a:env
  538. return Tex_eqnarray(a:env)
  539. elseif a:env =~ "enumerate\\|itemize\\|theindex\\|trivlist"
  540. return Tex_itemize(a:env)
  541. elseif a:env =~ "table\\|table*"
  542. return Tex_table(a:env)
  543. elseif a:env =~ "tabular\\|tabular*\\|array\\|array*"
  544. return Tex_tabular(a:env)
  545. elseif exists('*Tex_'.a:env)
  546. exe 'return Tex_'.a:env.'(a:env)'
  547. elseif a:env == '$$'
  548. return IMAP_PutTextWithMovement('$$<++>$$')
  549. elseif a:env == '\['
  550. return IMAP_PutTextWithMovement("\\[\<CR><++>\<CR>\\]<++>")
  551. else
  552. " Look in supported packages if exists template for environment
  553. " given in the line
  554. if exists('g:Tex_package_supported') && g:Tex_package_supported != ''
  555. let i = 1
  556. while Tex_Strntok(g:Tex_package_supported, ',', i) != ''
  557. let checkpack = Tex_Strntok(g:Tex_package_supported, ',', i)
  558. if g:TeX_package_{checkpack} =~ 'e..:'.a:env
  559. if a:env =~ '*'
  560. " Don't allow * to be treated as wildcard
  561. let aenv = substitute(a:env, '*', '\\*', '')
  562. else
  563. let aenv = a:env
  564. endif
  565. let envcommand = matchstr(g:TeX_package_{checkpack}, '\zse..:'.aenv.'[^,]\{-}\ze,')
  566. return Tex_ProcessPackageCommand(envcommand)
  567. endif
  568. let i = i + 1
  569. endwhile
  570. endif
  571. endif
  572. " If nothing before us managed to create an environment, then just
  573. " create a bare-bones environment from the name.
  574. return IMAP_PutTextWithMovement('\begin{'.a:env."}\<cr><++>\<cr>\\end{".a:env."}<++>")
  575. endif
  576. endfunction " }}}
  577. " Mapping the <F5> key to insert/prompt for an environment/package {{{
  578. " and <S-F5> to prompt/replace an environment
  579. "
  580. " g:Tex_PromptedEnvironments is a variable containing a comma seperated list
  581. " of environments. This list defines the prompt which latex-suite sets up when
  582. " the user presses <F5> on an empty line.
  583. "
  584. " Leaving this empty is equivalent to disabling the feature.
  585. if g:Tex_PromptedEnvironments != ''
  586. let b:DoubleDollars = 0
  587. " Provide only <plug>s here. main.vim will create the actual maps.
  588. inoremap <silent> <Plug>Tex_FastEnvironmentInsert <C-r>=Tex_FastEnvironmentInsert("no")<cr>
  589. nnoremap <silent> <Plug>Tex_FastEnvironmentInsert i<C-r>=Tex_FastEnvironmentInsert("no")<cr>
  590. vnoremap <silent> <Plug>Tex_FastEnvironmentInsert <C-\><C-N>:call Tex_FastEnvironmentInsert("yes")<CR>
  591. inoremap <silent> <Plug>Tex_FastEnvironmentChange <C-O>:call Tex_ChangeEnvironments()<CR>
  592. nnoremap <silent> <Plug>Tex_FastEnvironmentChange :call Tex_ChangeEnvironments()<CR>
  593. " Tex_FastEnvironmentInsert: maps <F5> to prompt for env and insert it " {{{
  594. " Description:
  595. " This function calculates whether we are in the preamble. If we are
  596. " then inserts a \usepackage line by either reading in a word from the
  597. " current line or prompting to type in one. If not in the preamble, then
  598. " inserts a environment template either by reading in a word from the
  599. " current line or prompting the user to choose one.
  600. "
  601. function! Tex_FastEnvironmentInsert(isvisual)
  602. let start_line = line('.')
  603. let pos = Tex_GetPos()
  604. let s:isvisual = a:isvisual
  605. " decide if we are in the preamble of the document. If we are then
  606. " insert a package, otherwise insert an environment.
  607. "
  608. if search('\\documentclass', 'bW') && search('\\begin{document}')
  609. " If there is a \documentclass line and a \begin{document} line in
  610. " the file, then a part of the file is the preamble.
  611. " search for where the document begins.
  612. let begin_line = search('\\begin{document}')
  613. " if the document begins after where we are presently, then we are
  614. " in the preamble.
  615. if start_line < begin_line
  616. " return to our original location and insert a package
  617. " statement.
  618. call Tex_SetPos(pos)
  619. return Tex_package_from_line()
  620. else
  621. " we are after the preamble. insert an environment.
  622. call Tex_SetPos(pos)
  623. return Tex_DoEnvironment()
  624. endif
  625. elseif search('\\documentclass')
  626. " if there is only a \documentclass but no \begin{document}, then
  627. " the entire file is a preamble. Put a package.
  628. call Tex_SetPos(pos)
  629. return Tex_package_from_line()
  630. else
  631. " no \documentclass, put an environment.
  632. call Tex_SetPos(pos)
  633. return Tex_DoEnvironment()
  634. endif
  635. endfunction
  636. " }}}
  637. " Tex_package_from_line: puts a \usepackage line in the current line. " {{{
  638. " Description:
  639. "
  640. function! Tex_package_from_line()
  641. " Function Tex_PutPackage is defined in packages.vim
  642. " Ignores <F5> in Visual mode
  643. if s:isvisual == "yes"
  644. return 0
  645. else
  646. let l = getline(".")
  647. let pack = matchstr(l, '^\s*\zs.*')
  648. normal! 0"_D
  649. return Tex_pack_one(pack)
  650. endif
  651. endfunction
  652. " }}}
  653. " Tex_ChangeEnvironments: calls Change() to change the environment {{{
  654. " Description:
  655. " Finds out which environment the cursor is positioned in and changes
  656. " that to the chosen new environment. This function knows the changes
  657. " which need to be made to change one env to another and calls
  658. " Change() with the info.
  659. "
  660. function! Tex_ChangeEnvironments()
  661. let env_line = searchpair('$$\|\\[\|begin{', '', '$$\|\\]\|end{', "bn")
  662. if env_line != 0
  663. if getline(env_line) !~ 'begin{'
  664. let env_name = '['
  665. else
  666. let env_name = matchstr(getline(env_line), 'begin{\zs.\{-}\ze}')
  667. endif
  668. endif
  669. if !exists('env_name')
  670. echomsg "You are not inside environment"
  671. return 0
  672. endif
  673. exe 'echomsg "You are within a '.env_name.' environment."'
  674. let change_env = PromptForEnvironment('What do you want to change it to? ')
  675. if change_env == 'eqnarray'
  676. call <SID>Change('eqnarray', 1, '', env_name =~ '\*$')
  677. elseif change_env == 'align'
  678. call <SID>Change('align', 1, '', env_name =~ '\*$')
  679. elseif change_env == 'eqnarray*'
  680. call <SID>Change('eqnarray*', 0, '\\nonumber', 0)
  681. elseif change_env == 'align*'
  682. call <SID>Change('align*', 0, '\\nonumber', 0)
  683. elseif change_env == 'equation*'
  684. call <SID>Change('equation*', 0, '&\|\\lefteqn{\|\\nonumber\|\\\\', 0)
  685. elseif change_env == ''
  686. return 0
  687. else
  688. call <SID>Change(change_env, 0, '', '')
  689. return 0
  690. endif
  691. endfunction
  692. " }}}
  693. " Change: changes the current env to the new env {{{
  694. " Description:
  695. " This function needs to know the changes which need to be made while
  696. " going from an old environment to a new one. This info, it gets from
  697. " Tex_ChangeEnvironments
  698. "
  699. " env : name of the new environment.
  700. " label : if 1, then insert a \label at the end of the environment.
  701. " otherwise, delete any \label line found.
  702. " delete : a pattern which is to be deleted from the original environment.
  703. " for example, going to a eqnarray* environment means we need to
  704. " delete \label's.
  705. " putInNonumber : whether we need to put a \nonumber before the end of the
  706. " environment.
  707. function! s:Change(env, label, delete, putInNonumber)
  708. let start_line = line('.')
  709. let start_col = virtcol('.')
  710. if a:env == '['
  711. if b:DoubleDollars == 0
  712. let first = '\\['
  713. let second = '\\]'
  714. else
  715. let first = '$$'
  716. let second = '$$'
  717. endif
  718. else
  719. let first = '\\begin{' . a:env . '}'
  720. let second = '\\end{' . a:env . '}'
  721. endif
  722. if b:DoubleDollars == 0
  723. let bottom = searchpair('\\\[\|\\begin{','','\\\]\|\\end{','')
  724. s/\\\]\|\\end{.\{-}}/\=second/
  725. let top = searchpair('\\\[\|\\begin{','','\\\]\|\\end{','b')
  726. s/\\\[\|\\begin{.\{-}}/\=first/
  727. else
  728. let bottom = search('\$\$\|\\end{')
  729. s/\$\$\|\\end{.\{-}}/\=second/
  730. let top = search('\$\$\|\\begin{','b')
  731. s/\$\$\|\\begin{.\{-}}/\=first/
  732. end
  733. if a:delete != ''
  734. exe 'silent '. top . "," . bottom . 's/' . a:delete . '//e'
  735. endif
  736. if a:putInNonumber == 1
  737. exe top
  738. call search('\\end\|\\\\')
  739. if line('.') != bottom
  740. exe '.+1,' . bottom . 's/\\\\/\\nonumber\\\\/e'
  741. exe (bottom-1) . 's/\s*$/ \\nonumber/'
  742. endif
  743. endif
  744. if a:label == 1
  745. exe top
  746. if search("\\label", "W") > bottom
  747. exe top
  748. let local_label = input('Label? ')
  749. if local_label != ''
  750. put = '\label{'.local_label.'}'
  751. endif
  752. normal $
  753. endif
  754. else
  755. exe 'silent '.top . ',' . bottom . ' g/\\label/delete'
  756. endif
  757. if exists('local_label') && local_label != ''
  758. exe start_line + 1.' | normal! '.start_col.'|'
  759. else
  760. exe start_line.' | normal! '.start_col.'|'
  761. endif
  762. endfunction " }}}
  763. endif
  764. " }}}
  765. " Map <S-F1> through <S-F4> to insert environments {{{
  766. if g:Tex_HotKeyMappings != ''
  767. " SetUpHotKeys: maps <F1> through <F4> to insert environments
  768. " Description:
  769. function! <SID>SetUpHotKeys()
  770. let i = 1
  771. let envname = Tex_Strntok(g:Tex_HotKeyMappings, ',', i)
  772. while envname != ''
  773. exec 'inoremap <silent> <buffer> <S-F'.i.'> <C-r>=Tex_PutEnvironment("'.envname.'")<CR>'
  774. let i = i + 1
  775. let envname = Tex_Strntok(g:Tex_HotKeyMappings, ',', i)
  776. endwhile
  777. endfunction
  778. endif
  779. " }}}
  780. " Tex_SetFastEnvironmentMaps: function for setting up the <F5> and <S-F1>-<S-F4> keys {{{
  781. " Description: This function is made public so it can be called by the
  782. " SetTeXOptions() function in main.vim
  783. function! Tex_SetFastEnvironmentMaps()
  784. if g:Tex_PromptedEnvironments != ''
  785. call Tex_MakeMap("<F5>", "<Plug>Tex_FastEnvironmentInsert", 'i', '<silent> <buffer>')
  786. call Tex_MakeMap("<F5>", "<Plug>Tex_FastEnvironmentInsert", 'n', '<silent> <buffer>')
  787. call Tex_MakeMap("<F5>", "<Plug>Tex_FastEnvironmentInsert", 'v', '<silent> <buffer>')
  788. call Tex_MakeMap("<S-F5>", "<Plug>Tex_FastEnvironmentChange", 'i', '<silent> <buffer>')
  789. call Tex_MakeMap("<S-F5>", "<Plug>Tex_FastEnvironmentChange", 'n', '<silent> <buffer>')
  790. endif
  791. if g:Tex_HotKeyMappings != ''
  792. call s:SetUpHotKeys()
  793. endif
  794. endfunction " }}}
  795. " ==============================================================================
  796. " Contributions / Tex_InsertItem() from Johannes Tanzler
  797. " ==============================================================================
  798. " Tex_GetCurrentEnv: gets the current environment in which the cursor lies {{{
  799. " Description: handles cases such as:
  800. "
  801. " \begin{itemize}
  802. " \item first item
  803. " \item second item
  804. " \begin{description}
  805. " \item first desc
  806. " \item second
  807. " % Tex_GetCurrentEnv will return "description" when called from here
  808. " \end{description}
  809. " \item third item
  810. " % Tex_GetCurrentEnv will return "itemize" when called from here
  811. " \end{itemize}
  812. " % Tex_GetCurrentEnv will return "" when called from here
  813. "
  814. " Author: Alan Schmitt
  815. function! Tex_GetCurrentEnv()
  816. let pos = Tex_GetPos()
  817. let i = 0
  818. while 1
  819. let env_line = search('^[^%]*\\\%(begin\|end\){', 'bW')
  820. if env_line == 0
  821. " we reached the beginning of the file, so we return the empty string
  822. call Tex_SetPos(pos)
  823. return ''
  824. endif
  825. if match(getline(env_line), '^[^%]*\\begin{') == -1
  826. " we found a \\end, so we keep searching
  827. let i = i + 1
  828. continue
  829. else
  830. " we found a \\begin which has not been \\end'ed. we are done.
  831. if i == 0
  832. let env = matchstr(getline(env_line), '\\begin{\zs.\{-}\ze}')
  833. call Tex_SetPos(pos)
  834. return env
  835. else
  836. " this \\begin closes a \\end, continue searching.
  837. let i = i - 1
  838. continue
  839. endif
  840. endif
  841. endwhile
  842. endfunction
  843. " }}}
  844. " Tex_InsertItem: insert \item into a list {{{
  845. " Description: Find last \begin line, extract env name, return to the start
  846. " position and insert proper \item, depending on env name.
  847. " Env names are stored in g: variables it can be used by
  848. " package files.
  849. TexLet g:Tex_ItemStyle_itemize = '\item '
  850. TexLet g:Tex_ItemStyle_enumerate = '\item '
  851. TexLet g:Tex_ItemStyle_theindex = '\item '
  852. TexLet g:Tex_ItemStyle_thebibliography = '\bibitem[<+biblabel+>]{<+bibkey+>} <++>'
  853. TexLet g:Tex_ItemStyle_description = '\item[<+label+>] <++>'
  854. function! Tex_InsertItem()
  855. " Get current enclosing environment
  856. let env = Tex_GetCurrentEnv()
  857. if exists('g:Tex_ItemStyle_'.env)
  858. return IMAP_PutTextWithMovement(g:Tex_ItemStyle_{env})
  859. else
  860. return ''
  861. endif
  862. endfunction
  863. " }}}
  864. " Tex_SetItemMaps: sets the \item inserting maps for current buffer {{{
  865. inoremap <script> <silent> <Plug>Tex_InsertItemOnThisLine <C-r>=Tex_InsertItem()<CR>
  866. inoremap <script> <silent> <Plug>Tex_InsertItemOnNextLine <ESC>o<C-R>=Tex_InsertItem()<CR>
  867. function! Tex_SetItemMaps()
  868. if !hasmapto("<Plug>Tex_InsertItem", "i")
  869. imap <buffer> <M-i> <Plug>Tex_InsertItemOnThisLine
  870. endif
  871. if !hasmapto("<Plug>Tex_InsertItemOnNextLine", "i")
  872. imap <buffer> <C-CR> <Plug>Tex_InsertItemOnNextLine
  873. endif
  874. endfunction " }}}
  875. " ==============================================================================
  876. " Implementation of Fast Environment commands for LaTeX commands
  877. " ==============================================================================
  878. " Define certain commonly used command definitions {{{
  879. TexLet g:Tex_Com_{'newtheorem'} = '\newtheorem{<+name+>}{<+caption+>}[<+within+>]'
  880. TexLet g:Tex_Com_{'frac'} = '\frac{<+n+>}{<+d+>}<++>'
  881. " }}}
  882. " PromptForCommand: prompts for a command {{{
  883. " Description:
  884. function! PromptForCommand(ask)
  885. let common_com_prompt =
  886. \ Tex_CreatePrompt(g:Tex_PromptedCommands, 2, ',') . "\n" .
  887. \ "Enter number or command name :"
  888. let inp = input(a:ask."\n".common_com_prompt)
  889. if inp =~ '^[0-9]\+$'
  890. let com = Tex_Strntok(g:Tex_PromptedCommands, ',', inp)
  891. else
  892. let com = inp
  893. endif
  894. return com
  895. endfunction " }}}
  896. " Tex_DoCommand: fast insertion of commands {{{
  897. " Description:
  898. "
  899. function! Tex_DoCommand(isvisual)
  900. " If the current line is empty or if a visual selection has been made,
  901. " prompt for a new environment.
  902. if getline('.') == '' || a:isvisual == 'yes'
  903. let com = PromptForCommand('Choose a command to insert: ')
  904. if com != ''
  905. return Tex_PutCommand(com, a:isvisual)
  906. else
  907. return ''
  908. endif
  909. else
  910. " We want to find out the word under the cursor without issuing
  911. " any movement commands.
  912. let presline = getline('.')
  913. let c = col('.')
  914. let wordbef = matchstr(strpart(presline, 0, c-1), '\k\+\*\?$')
  915. let wordaft = matchstr(strpart(presline, c-1), '^\k\+\*\?')
  916. let word = wordbef . wordaft
  917. call Tex_Debug("Tex_DoCommand: wordbef = [".wordbef."], wordaft = [".wordaft."], word = [".word."]", 'env')
  918. " We use \<Del> instead of \<Bs> because \<Bs> does not work
  919. " unless bs=2
  920. if word != ''
  921. return substitute(wordbef, '.', "\<Left>", 'g')
  922. \ . substitute(word, '.', "\<Del>", 'g')
  923. \ . Tex_PutCommand(word, a:isvisual)
  924. else
  925. let cmd = PromptForCommand('Choose a command to insert: ')
  926. if cmd != ''
  927. return Tex_PutCommand(cmd, a:isvisual)
  928. else
  929. return ''
  930. endif
  931. endif
  932. endif
  933. endfunction " }}}
  934. " Tex_PutCommand: calls various specialized functions {{{
  935. " Description:
  936. " Based on input argument, it calls various specialized functions.
  937. function! Tex_PutCommand(com, isvisual)
  938. if a:isvisual == "yes"
  939. if a:com == '$'
  940. return VEnclose('$', '$', '$', '$')
  941. elseif a:com == '\\('
  942. return VEnclose('\\(', '\\)', '\\(', '\\)')
  943. else
  944. return VEnclose("\\".a:com.'{', '}', "\\".a:com.'{', '}')
  945. endif
  946. else
  947. if exists('b:Tex_Com_{"'.a:com.'"}')
  948. return IMAP_PutTextWithMovement(b:Tex_Com_{a:com})
  949. elseif exists('g:Tex_Com_{"'.a:com.'"}')
  950. return IMAP_PutTextWithMovement(g:Tex_Com_{a:com})
  951. elseif a:com == '$'
  952. return IMAP_PutTextWithMovement('$<++>$')
  953. else
  954. return IMAP_PutTextWithMovement("\\".a:com.'{<++>}<++>')
  955. endif
  956. endif
  957. endfunction " }}}
  958. " Mapping the <F7> key to prompt/insert for command {{{
  959. " and <S-F7> to prompt/replace command
  960. "
  961. " g:Tex_PromptedCommands is a variable containing a comma seperated list
  962. " of commands.
  963. "
  964. " Leaving this empty is equivalent to disabling the feature.
  965. if g:Tex_PromptedCommands != ''
  966. let b:DoubleDollars = 0
  967. inoremap <silent> <Plug>Tex_FastCommandInsert <C-r>=Tex_DoCommand('no')<cr>
  968. nnoremap <silent> <Plug>Tex_FastCommandInsert i<C-r>=Tex_DoCommand('no')<cr>
  969. vnoremap <silent> <Plug>Tex_FastCommandInsert <C-\><C-N>:call Tex_DoCommand('yes')<CR>
  970. inoremap <silent> <Plug>Tex_FastCommandChange <C-O>:call Tex_ChangeCommand('no')<CR>
  971. nnoremap <silent> <Plug>Tex_FastCommandChange :call Tex_ChangeCommand('no')<CR>
  972. " Tex_ChangeCommand: calls ChangeCommand() to change the environment {{{
  973. " Description:
  974. " Finds out which environment the cursor is positioned in and changes
  975. " that to the chosen new environment. This function knows the changes
  976. " which need to be made to change one env to another and calls
  977. " ChangeCommand() with the info.
  978. "
  979. function! Tex_ChangeCommand(isvisual)
  980. let pos_com = Tex_GetPos()
  981. let com_line = searchpair('\\\k\{-}{', '', '}', 'b')
  982. if com_line != 0
  983. normal l
  984. let com_name = expand('<cword>')
  985. endif
  986. if !exists('com_name')
  987. echomsg "You are not inside command"
  988. call Tex_SetPos(pos_com)
  989. return 0
  990. endif
  991. exe 'echomsg "You are within a '.com_name.' command."'
  992. let change_com = PromptForCommand('Do you want to change it to (number or name)? ')
  993. if change_com == ''
  994. call Tex_SetPos(pos_com)
  995. return 0
  996. else
  997. call <SID>ChangeCommand(change_com)
  998. call Tex_SetPos(pos_com)
  999. return 0
  1000. endif
  1001. endfunction
  1002. " }}}
  1003. " ChangeCommand: Changes current command according to prompt menu {{{
  1004. " Description:
  1005. "
  1006. function! s:ChangeCommand(newcom)
  1007. exe 'normal! ct{'.a:newcom."\<Esc>"
  1008. endfunction
  1009. " }}}
  1010. endif
  1011. " }}}
  1012. " Tex_SetFastCommandMaps: function for setting up the <F7> keys {{{
  1013. " Description: This function is made public so it can be called by the
  1014. " SetTeXOptions() function in main.vim
  1015. function! Tex_SetFastCommandMaps()
  1016. if g:Tex_PromptedCommands != ''
  1017. if !hasmapto('<Plug>Tex_FastCommandInsert', 'i')
  1018. imap <silent> <buffer> <F7> <Plug>Tex_FastCommandInsert
  1019. endif
  1020. if !hasmapto('<Plug>Tex_FastCommandInsert', 'n')
  1021. nmap <silent> <buffer> <F7> <Plug>Tex_FastCommandInsert
  1022. endif
  1023. if !hasmapto('<Plug>Tex_FastCommandChange', 'i')
  1024. imap <silent> <buffer> <S-F7> <Plug>Tex_FastCommandChange
  1025. endif
  1026. if !hasmapto('<Plug>Tex_FastCommandChange', 'n')
  1027. nmap <silent> <buffer> <S-F7> <Plug>Tex_FastCommandChange
  1028. endif
  1029. if !hasmapto('<Plug>Tex_FastCommandInsert', 'v')
  1030. vmap <silent> <buffer> <F7> <Plug>Tex_FastCommandInsert
  1031. endif
  1032. endif
  1033. endfunction " }}}
  1034. " SetEnvMacrosOptions: sets mappings for buffers {{{
  1035. " " Description:
  1036. function! <SID>SetEnvMacrosOptions()
  1037. if exists('b:doneTexEnvMaps')
  1038. return
  1039. endif
  1040. let b:doneTexEnvMaps = 1
  1041. if g:Tex_PromptedEnvironments != '' || g:Tex_HotKeyMappings != ''
  1042. call Tex_SetFastEnvironmentMaps()
  1043. endif
  1044. if g:Tex_PromptedCommands != ''
  1045. call Tex_SetFastCommandMaps()
  1046. endif
  1047. call Tex_SetItemMaps()
  1048. endfunction " }}}
  1049. " Catch the Filetype event so we set maps for each buffer {{{
  1050. augroup LatexSuite
  1051. au LatexSuite User LatexSuiteFileType
  1052. \ call Tex_Debug('envmacros.vim: Catching LatexSuiteFileType event', 'env') |
  1053. \ call s:SetEnvMacrosOptions()
  1054. augroup END
  1055. " }}}
  1056. " this statement has to be at the end.
  1057. let s:doneOnce = 1
  1058. " vim:fdm=marker:nowrap:noet:ff=unix