1
" File: wizardfuncs.vim
2
" Author: Mikolaj Machowski <mikmach@wp.pl>
6
" History: pluginized by Srinath Avadhanula
7
"=============================================================================
9
if exists('s:doneOnce')
14
let s:mapleader = exists('mapleader') ? mapleader : "\\"
15
" ==============================================================================
16
" Specialized functions for handling sections from command line
17
" ==============================================================================
19
com! -nargs=? TSection call Tex_section(<f-args>)
20
com! -nargs=? TSectionAdvanced call Tex_section_adv(<f-args>)
22
" Tex_VisSecAdv: handles visual selection for sections {{{
23
function! Tex_VisSecAdv(section)
24
let shorttitle = input("Short title? ")
25
let toc = input("Include in table of contents [y]/n ? ")
26
let sstructure = "\\".a:section
27
if ( toc == "" || toc == "y" )
33
let shorttitle = '['.shorttitle.']'
35
exe "normal `>a}\<cr>\<esc>`<i".sstructure.toc.shorttitle."{"
39
" Tex_InsSecAdv: section wizard in insert mode {{{
40
function! Tex_InsSecAdv(structure)
41
let ttitle = input("Title? ")
42
let shorttitle = input("Short title? ")
43
let toc = input("Include in table of contents [y]/n ? ")
45
let sstructure = "\\".a:structure
47
if ( toc == "" || toc == "y" )
54
let shorttitle = '['.shorttitle.']'
57
let ttitle = '{'.ttitle.'}'
59
return sstructure.toc.shorttitle.ttitle
64
function! Tex_section(...) "{{{
65
silent let pos = line('.').' | normal! '.virtcol('.').'|'
66
silent let last_section_value = s:Tex_section_detection()
68
silent let last_section_name = s:Tex_section_name(last_section_value)
69
silent call s:Tex_section_call(last_section_name)
70
elseif a:1 =~ "[+=\-]"
71
silent let sec_arg = a:1
72
silent let curr_section_value = s:Tex_section_curr_rel_value(sec_arg, last_section_value)
73
silent let curr_section_name = s:Tex_section_name(curr_section_value)
74
silent call s:Tex_section_call(curr_section_name)
76
echo s:last_section_line
78
silent let curr_section_value = s:Tex_section_curr_value(a:1)
79
silent let curr_section_name = s:Tex_section_name(curr_section_value)
80
silent call s:Tex_section_call(curr_section_name)
84
function! Tex_section_adv(...) "{{{
85
let pos = line('.').' | normal! '.virtcol('.').'|'
86
silent let last_section_value = s:Tex_section_detection()
88
silent let last_section_name = s:Tex_section_name(last_section_value)
89
let section = Tex_InsSecAdv(last_section_name)
90
elseif a:1 =~ "[+=\-]"
91
silent let sec_arg = a:1
92
silent let curr_section_value = s:Tex_section_curr_rel_value(sec_arg, last_section_value)
93
silent let curr_section_name = s:Tex_section_name(curr_section_value)
94
let section = Tex_InsSecAdv(curr_section_name)
96
silent let curr_section_value = s:Tex_section_curr_value(a:1)
97
silent let curr_section_name = s:Tex_section_name(curr_section_value)
98
silent call s:Tex_section_call(curr_section_name)
99
let section = Tex_InsSecAdv(curr_section_name)
101
exe "normal i".section
104
function! s:Tex_section_detection() "{{{
105
let pos = line('.').' | normal! '.virtcol('.').'|'
106
let last_section1 = search("\\\\\subparagraph\\|\\\\paragraph\\|\\\\subsubsection\\|\\\\subsection\\|\\\\section\\|\\\\chapter\\|\\\part\)", "b")
108
let last_section2 = search("\\\\\part\\|\\\\chapter\\|\\\\section\\|\\\\subsection\\|\\\\subsubsection\\|\\\\paragraph\\|\\\subparagraph\)", "b")
109
if last_section1 > last_section2
110
let last_section = last_section1
112
let last_section = last_section2
116
if getline(".") =~ "\\\\part"
117
let last_section_value = 0
118
elseif getline(".") =~ "\\\\chapter"
119
let last_section_value = 1
120
elseif getline(".") =~ "\\\\section"
121
let last_section_value = 2
122
elseif getline(".") =~ "\\\\subsection"
123
let last_section_value = 3
124
elseif getline(".") =~ "\\\\subsubsection"
125
let last_section_value = 4
126
elseif getline(".") =~ "\\\\paragraph"
127
let last_section_value = 5
128
elseif getline(".") =~ "\\\\subparagraph"
129
let last_section_value = 6
131
let s:last_section_line = getline(".")
133
let last_section_value = 0
136
return last_section_value
138
function! s:Tex_section_curr_value(sec_arg) "{{{
139
if a:sec_arg == "pa" || a:sec_arg == "0" || a:sec_arg == "part"
140
let curr_section_value = 0
141
elseif a:sec_arg == "ch" || a:sec_arg == "1" || a:sec_arg == "chapter"
142
let curr_section_value = 1
143
elseif a:sec_arg == "se" || a:sec_arg == "2" || a:sec_arg == "section"
144
let curr_section_value = 2
145
elseif a:sec_arg == "ss" || a:sec_arg == "3" || a:sec_arg == "subsection"
146
let curr_section_value = 3
147
elseif a:sec_arg == "s2" || a:sec_arg == "4" || a:sec_arg == "subsubsection"
148
let curr_section_value = 4
149
elseif a:sec_arg == "pr" || a:sec_arg == "5" || a:sec_arg == "paragraph"
150
let curr_section_value = 5
151
elseif a:sec_arg == "sp" || a:sec_arg == "6" || a:sec_arg == "subparagraph"
152
let curr_section_value = 6
154
return curr_section_value
156
function! s:Tex_section_curr_rel_value(sec_arg, last_section_value) "{{{
157
let last_section_value = a:last_section_value
158
if a:sec_arg == "+" || a:sec_arg == "+1"
159
let curr_section_value = last_section_value + 1
160
elseif a:sec_arg == "++" || a:sec_arg == "+2"
161
let curr_section_value = last_section_value + 2
162
elseif a:sec_arg == "-" || a:sec_arg == "-1"
163
let curr_section_value = last_section_value - 1
164
elseif a:sec_arg == "--" || a:sec_arg == "-2"
165
let curr_section_value = last_section_value - 2
166
elseif a:sec_arg == "="
167
let curr_section_value = last_section_value
169
exe "let curr_section_value = last_section_value".a:sec_arg
171
if curr_section_value < 0
172
let curr_section_value = 0
173
elseif curr_section_value > 6
174
let curr_section_value = 6
176
return curr_section_value
178
function! s:Tex_section_name(section_value) "{{{
179
if a:section_value == 0
180
let section_name = "part"
181
elseif a:section_value == 1
182
let section_name = "chapter"
183
elseif a:section_value == 2
184
let section_name = "section"
185
elseif a:section_value == 3
186
let section_name = "subsection"
187
elseif a:section_value == 4
188
let section_name = "subsubsection"
189
elseif a:section_value == 5
190
let section_name = "paragraph"
191
elseif a:section_value == 6
192
let section_name = "subparagraph"
196
function! s:Tex_section_call(section_name) "{{{
197
exe "normal! i\\".a:section_name."{<++>}<++>\<Esc>0\<C-j>"
198
" let ret_section = "\\".a:section_name."{<++>}<++>"
199
" exe "normal! i\<C-r>=IMAP_PutTextWithMovement(ret_section)\<CR>"
203
" ==============================================================================
204
" Add looking help into latexhelp.txt
205
" ==============================================================================
207
inoremap <silent> <Plug>Tex_Help <C-o>:call <SID>TexHelp()<CR>
208
nnoremap <silent> <Plug>Tex_Help :call <SID>TexHelp()<CR>
209
command! -nargs=0 THelp call <SID>TexHelp()
210
call Tex_MakeMap('<F1>', '<Plug>Tex_Help', 'i', '')
211
call Tex_MakeMap('<F1>', '<Plug>Tex_Help', 'n', '')
213
" TexHelp: Cursor being on LaTeX item check if exists help tag about it " {{{
214
function! s:TexHelp()
215
let syntax_item = synIDattr(synID(line('.'),col('.')-1,0),"name")
216
if syntax_item =~ '^tex'
218
let curword = expand('<cword>')
221
if curword =~ "^\\" || syntax_item == 'texSectionName'
222
exe 'silent! help '.curword
223
if v:errmsg =~ '^E149:'
225
exe "echomsg 'Sorry, no help for LaTeX: ".curword."'"
237
" ==============================================================================
238
" Tables of shortcuts
239
" ==============================================================================
241
command! -nargs=? Tshortcuts call Tex_shortcuts(<f-args>)<CR>
243
" Tex_shortcuts: Show shortcuts in terminal after : command {{{
244
function! Tex_shortcuts(...)
246
let shorts = input(" Allowed arguments are:"
248
\."\n e Environments"
253
\."\n Enter your choice (<Enter> quits) : ")
254
call Tex_shortcuts(shorts)
256
echo g:generalshortcuts
258
echo g:environmentshortcuts
262
echo g:sectionshortcuts
266
echo g:generalshortcuts
267
echo g:environmentshortcuts
269
echo g:sectionshortcuts
276
" General shortcuts {{{
277
let g:generalshortcuts = ''
278
\."\n General shortcuts"
279
\."\n <mapleader> is a value of <Leader>"
280
\."\n ".s:mapleader.'ll compile whole document'
281
\."\n ".s:mapleader.'lv view compiled document'
282
\."\n ".s:mapleader.'ls forward searching (if possible)'
283
\."\n ".s:mapleader.'rf refresh folds'
285
" Environment shortcuts {{{
286
let g:environmentshortcuts = ''
287
\."\n Environment shortcuts"
288
\."\n <mapleader> is a value of g:Tex_Leader2"
290
\."\n ELI ".g:Tex_Leader2."li list EQN ".g:Tex_Leader2."qn quotation"
291
\."\n EDE ".g:Tex_Leader2."de description ESB ".g:Tex_Leader2."sb sloppybar"
292
\."\n EEN ".g:Tex_Leader2."en enumerate ETI ".g:Tex_Leader2."ti theindex"
293
\."\n EIT ".g:Tex_Leader2."it itemize ETP ".g:Tex_Leader2."tp titlepage"
294
\."\n ETI ".g:Tex_Leader2."ti theindex EVM ".g:Tex_Leader2."vm verbatim"
295
\."\n ETL ".g:Tex_Leader2."tl trivlist EVE ".g:Tex_Leader2."ve verse"
296
\."\n ETE ".g:Tex_Leader2."te table ETB ".g:Tex_Leader2."tb thebibliography"
297
\."\n ETG ".g:Tex_Leader2."tg tabbing ENO ".g:Tex_Leader2."no note"
298
\."\n ETR ".g:Tex_Leader2."tr tabular EOV ".g:Tex_Leader2."ov overlay"
299
\."\n EAR ".g:Tex_Leader2."ar array ESL ".g:Tex_Leader2."sl slide"
300
\."\n EDM ".g:Tex_Leader2."dm displaymath EAB ".g:Tex_Leader2."ab abstract"
301
\."\n EEA ".g:Tex_Leader2."ea eqnarray EAP ".g:Tex_Leader2."ap appendix"
302
\."\n EEQ ".g:Tex_Leader2."eq equation ECE ".g:Tex_Leader2."ce center"
303
\."\n EDO ".g:Tex_Leader2."do document EFI ".g:Tex_Leader2."fi figure"
304
\."\n EFC ".g:Tex_Leader2."fc filecontents ELR ".g:Tex_Leader2."lr lrbox"
305
\."\n EFL ".g:Tex_Leader2."fl flushleft EMP ".g:Tex_Leader2."mp minipage"
306
\."\n EFR ".g:Tex_Leader2."fr flushright EPI ".g:Tex_Leader2."pi picture"
307
\."\n EMA ".g:Tex_Leader2."ma math EQE ".g:Tex_Leader2."qe quote"
310
let g:fontshortcuts = ''
311
\."\n Font shortcuts"
312
\."\n <mapleader> is a value of g:Tex_Leader"
313
\."\n Shortcuts Effects"
315
\."\n FBF ".g:Tex_Leader."bf \\textbf{} {\\bfseries }"
316
\."\n FMD ".g:Tex_Leader."md \\textmd{} {\\mdseries }"
318
\."\n FTT ".g:Tex_Leader."tt \\texttt{} {\\ttfamily }"
319
\."\n FSF ".g:Tex_Leader."sf \\textsf{} {\\sffamily }"
320
\."\n FRM ".g:Tex_Leader."rm \\textrm{} {\\rmfamily }"
322
\."\n FUP ".g:Tex_Leader."up \\textup{} {\\upshape }"
323
\."\n FSL ".g:Tex_Leader."sl \\textsl{} {\\slshape }"
324
\."\n FSC ".g:Tex_Leader."sc \\textsc{} {\\scshape }"
325
\."\n FIT ".g:Tex_Leader."it \\textit{} {\\itshape }"
327
" Section shortcuts {{{
328
let g:sectionshortcuts = ''
329
\."\n Section shortcuts"
330
\."\n <mapleader> is a value of g:Tex_Leader2"
332
\."\n SPA ".g:Tex_Leader2."pa part"
333
\."\n SCH ".g:Tex_Leader2."ch chapter"
334
\."\n SSE ".g:Tex_Leader2."se section"
335
\."\n SSS ".g:Tex_Leader2."ss subsection"
336
\."\n SS2 ".g:Tex_Leader2."s2 subsubsection"
337
\."\n SPG ".g:Tex_Leader2."pg paragraph"
338
\."\n SSP ".g:Tex_Leader2."sp subparagraph"
341
let g:mathshortcuts = ''
342
\."\n Math shortcuts - Insert mode"
343
\."\n `a \\alpha `b \\beta"
344
\."\n `g \\gamma `d \\delta"
345
\."\n `e \\varepsilon `z \\zeta"
346
\."\n `h \\eta `q \\theta"
347
\."\n `i \\iota `k \\kappa"
348
\."\n `l \\lambda `m \\mu"
349
\."\n `n \\nu `x \\xi"
350
\."\n `p \\pi `r \\rho"
351
\."\n `s \\sigma `v \\varsigma"
352
\."\n `t \\tau `u \\upsilon"
353
\."\n `f \\varphi `c \\chi"
354
\."\n `y \\psi `w \\omega"
355
\."\n `A \\Alpha `B \\Beta"
356
\."\n `G \\Gamma `D \\Delta"
357
\."\n `E \\Epsilon `Z \\mathrm{Z}"
358
\."\n `H \\Eta `K \\Kappa"
359
\."\n `L \\Lambda `M \\Mu"
360
\."\n `N \\Nu `X \\Xi"
361
\."\n `P \\Pi `R \\Rho"
362
\."\n `S \\Sigma `T \\Tau"
363
\."\n `U \\Upsilon `C \\Chi"
364
\."\n `Y \\Psi `W \\Omega"
365
\."\n `( \\subset `) \\Subset"
366
\."\n `= \\equiv =~ \\approx"
367
\."\n `- \\bigcap `+ \\bigcup"
368
\."\n `. \\cdot `* \\times"
369
\."\n `\\ \\setminus `@ \\circ"
370
\."\n `& \\wedge `, \\nonumber"
371
\."\n `8 \\infty `_ \\bar{}"
372
\."\n `: \\ddot{} `; \\dot{}"
373
\."\n `^ \\hat{} `~ \\tilde{}"
377
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4