~spacexplorer/+junk/myenv

« back to all changes in this revision

Viewing changes to vim/vim/ftplugin/latex-suite/wizardfuncs.vim

  • Committer: Kim Allamandola
  • Date: 2011-05-02 05:39:17 UTC
  • Revision ID: spacexplorer@gmail.com-20110502053917-x0yl2lr9ri4yskr2
InitĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"        File: wizardfuncs.vim
 
2
"      Author: Mikolaj Machowski <mikmach@wp.pl>
 
3
" Description: 
 
4
 
5
" Installation:
 
6
"      History: pluginized by Srinath Avadhanula
 
7
"=============================================================================
 
8
 
 
9
if exists('s:doneOnce')
 
10
        finish
 
11
endif
 
12
let s:doneOnce = 1
 
13
 
 
14
let s:mapleader = exists('mapleader') ? mapleader : "\\"
 
15
" ==============================================================================
 
16
" Specialized functions for handling sections from command line
 
17
" ============================================================================== 
 
18
 
 
19
com! -nargs=? TSection call Tex_section(<f-args>)
 
20
com! -nargs=? TSectionAdvanced call Tex_section_adv(<f-args>)
 
21
 
 
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" )
 
28
                let toc = ""
 
29
        else
 
30
                let toc = "*"
 
31
        endif
 
32
        if shorttitle != ""
 
33
                let shorttitle = '['.shorttitle.']'
 
34
        endif
 
35
        exe "normal `>a}\<cr>\<esc>`<i".sstructure.toc.shorttitle."{"
 
36
endfunction 
 
37
 
 
38
" }}}
 
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 ? ")
 
44
        "Structure
 
45
        let sstructure = "\\".a:structure
 
46
        "TOC
 
47
        if ( toc == "" || toc == "y" )
 
48
                let toc = ""
 
49
        else
 
50
                let toc = "*"
 
51
        endif
 
52
        "Shorttitle
 
53
        if shorttitle != ""
 
54
                let shorttitle = '['.shorttitle.']'
 
55
        endif
 
56
        "Title
 
57
        let ttitle = '{'.ttitle.'}'
 
58
        "Happy end?
 
59
        return sstructure.toc.shorttitle.ttitle 
 
60
endfunction 
 
61
 
 
62
 
 
63
" }}}
 
64
function! Tex_section(...) "{{{
 
65
        silent let pos = line('.').' | normal! '.virtcol('.').'|'
 
66
        silent let last_section_value = s:Tex_section_detection()
 
67
        if a:0 == 0
 
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)
 
75
        elseif a:1 == "?"
 
76
                echo s:last_section_line
 
77
        else
 
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)
 
81
        endif
 
82
        silent exe pos
 
83
endfunction "}}}
 
84
function! Tex_section_adv(...) "{{{
 
85
        let pos = line('.').' | normal! '.virtcol('.').'|'
 
86
        silent let last_section_value = s:Tex_section_detection()
 
87
        if a:0 == 0
 
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)
 
95
        else
 
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)
 
100
        endif
 
101
        exe "normal i".section
 
102
        exe pos
 
103
endfunction "}}}
 
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")
 
107
        exe pos
 
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
 
111
        else
 
112
                let last_section = last_section2
 
113
        endif
 
114
        if last_section != 0
 
115
                exe last_section
 
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
 
130
                endif
 
131
                let s:last_section_line = getline(".")
 
132
        else
 
133
                let last_section_value = 0
 
134
        endif
 
135
        exe pos
 
136
        return last_section_value
 
137
endfunction "}}}
 
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
 
153
        endif
 
154
        return curr_section_value
 
155
endfunction "}}}
 
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
 
168
        else
 
169
                exe "let curr_section_value = last_section_value".a:sec_arg
 
170
        endif
 
171
        if curr_section_value < 0
 
172
                let curr_section_value = 0
 
173
        elseif curr_section_value > 6
 
174
                let curr_section_value = 6
 
175
        endif
 
176
        return curr_section_value
 
177
endfunction "}}}
 
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"
 
193
        endif
 
194
        return section_name
 
195
endfunction "}}}
 
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>"
 
200
"       normal f}i
 
201
endfunction "}}}
 
202
 
 
203
" ==============================================================================
 
204
" Add looking help into latexhelp.txt
 
205
" ============================================================================== 
 
206
 
 
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', '')
 
212
 
 
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'
 
217
                setlocal isk+=\
 
218
                let curword = expand('<cword>')
 
219
                setlocal isk-=\
 
220
                let v:errmsg = ''
 
221
                if curword =~ "^\\" || syntax_item == 'texSectionName'
 
222
                        exe 'silent! help '.curword
 
223
                        if v:errmsg =~ '^E149:'
 
224
                                echohl ErrorMsg
 
225
                                exe "echomsg 'Sorry, no help for LaTeX: ".curword."'"
 
226
                                echohl None
 
227
                                let v:errmsg = ''
 
228
                        endif
 
229
                else
 
230
                        help
 
231
                endif
 
232
        else
 
233
                help
 
234
        endif
 
235
endfunction " }}}
 
236
 
 
237
" ==============================================================================
 
238
" Tables of shortcuts
 
239
" ============================================================================== 
 
240
"
 
241
command! -nargs=? Tshortcuts call Tex_shortcuts(<f-args>)<CR>
 
242
 
 
243
" Tex_shortcuts: Show shortcuts in terminal after : command {{{
 
244
function! Tex_shortcuts(...)
 
245
        if a:0 == 0
 
246
                let shorts = input(" Allowed arguments are:"
 
247
                \."\n g     General"
 
248
                \."\n e     Environments"
 
249
                \."\n f     Fonts"
 
250
                \."\n s     Sections"
 
251
                \."\n m     Math"
 
252
                \."\n a     All"
 
253
                \."\n Enter your choice (<Enter> quits) : ")
 
254
                call Tex_shortcuts(shorts)
 
255
        elseif a:1 == 'g'
 
256
                echo g:generalshortcuts
 
257
        elseif a:1 == 'e'
 
258
                echo g:environmentshortcuts
 
259
        elseif a:1 == 'f'
 
260
                echo g:fontshortcuts
 
261
        elseif a:1 == 's'
 
262
                echo g:sectionshortcuts
 
263
        elseif a:1 == 'm'
 
264
                echo g:mathshortcuts
 
265
        elseif a:1 == 'a'
 
266
                echo g:generalshortcuts
 
267
                echo g:environmentshortcuts
 
268
                echo g:fontshortcuts
 
269
                echo g:sectionshortcuts
 
270
                echo g:mathshortcuts
 
271
        endif
 
272
 
 
273
endfunction
 
274
" }}}
 
275
 
 
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'
 
284
" }}}
 
285
" Environment shortcuts {{{
 
286
let g:environmentshortcuts = ''
 
287
\."\n Environment shortcuts"
 
288
\."\n <mapleader> is a value of g:Tex_Leader2"
 
289
\."\n I     v&V                       I     v&V"
 
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"
 
308
" }}}
 
309
" Font shortcuts {{{
 
310
let g:fontshortcuts = ''
 
311
\."\n Font shortcuts"
 
312
\."\n <mapleader> is a value of g:Tex_Leader"
 
313
\."\n Shortcuts         Effects"
 
314
\."\n I        v&V      I&v               V"
 
315
\."\n FBF      ".g:Tex_Leader."bf      \\textbf{}         {\\bfseries }"
 
316
\."\n FMD      ".g:Tex_Leader."md      \\textmd{}         {\\mdseries }"
 
317
\."\n"
 
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 }"
 
321
\."\n"
 
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 }"
 
326
" }}}
 
327
" Section shortcuts {{{
 
328
let g:sectionshortcuts = ''
 
329
\."\n Section shortcuts"
 
330
\."\n <mapleader> is a value of g:Tex_Leader2"
 
331
\."\n I     v&V"
 
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"
 
339
" }}}
 
340
" Math shortcuts {{{
 
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{}"
 
374
\."\n `6     \\partial"
 
375
" }}}
 
376
 
 
377
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4