utils 0.0.67 → 0.0.68

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/VERSION +1 -1
  2. data/bin/edit +3 -1
  3. data/lib/utils/editor.rb +14 -0
  4. data/lib/utils/version.rb +1 -1
  5. data/utils.gemspec +3 -3
  6. metadata +3 -74
  7. data/lib/utils/config/vim/after/syntax/haml.vim +0 -9
  8. data/lib/utils/config/vim/after/syntax/html.vim +0 -11
  9. data/lib/utils/config/vim/autoload/Align.vim +0 -1029
  10. data/lib/utils/config/vim/autoload/AlignMaps.vim +0 -330
  11. data/lib/utils/config/vim/autoload/ctrlp/bookmarkdir.vim +0 -139
  12. data/lib/utils/config/vim/autoload/ctrlp/buffertag.vim +0 -238
  13. data/lib/utils/config/vim/autoload/ctrlp/changes.vim +0 -96
  14. data/lib/utils/config/vim/autoload/ctrlp/dir.vim +0 -90
  15. data/lib/utils/config/vim/autoload/ctrlp/line.vim +0 -63
  16. data/lib/utils/config/vim/autoload/ctrlp/mixed.vim +0 -83
  17. data/lib/utils/config/vim/autoload/ctrlp/mrufiles.vim +0 -119
  18. data/lib/utils/config/vim/autoload/ctrlp/quickfix.vim +0 -62
  19. data/lib/utils/config/vim/autoload/ctrlp/rtscript.vim +0 -49
  20. data/lib/utils/config/vim/autoload/ctrlp/tag.vim +0 -112
  21. data/lib/utils/config/vim/autoload/ctrlp/undo.vim +0 -154
  22. data/lib/utils/config/vim/autoload/ctrlp/utils.vim +0 -72
  23. data/lib/utils/config/vim/autoload/ctrlp.vim +0 -1772
  24. data/lib/utils/config/vim/autoload/rails.vim +0 -4570
  25. data/lib/utils/config/vim/autoload/rubycomplete.vim +0 -801
  26. data/lib/utils/config/vim/autoload/sqlcomplete.vim +0 -741
  27. data/lib/utils/config/vim/autoload/vimball.vim +0 -750
  28. data/lib/utils/config/vim/colors/flori.vim +0 -116
  29. data/lib/utils/config/vim/compiler/coffee.vim +0 -68
  30. data/lib/utils/config/vim/compiler/eruby.vim +0 -40
  31. data/lib/utils/config/vim/compiler/ruby.vim +0 -67
  32. data/lib/utils/config/vim/compiler/rubyunit.vim +0 -34
  33. data/lib/utils/config/vim/doc/Decho.txt +0 -372
  34. data/lib/utils/config/vim/doc/coffee-script.txt +0 -116
  35. data/lib/utils/config/vim/doc/ctrlp.txt +0 -1113
  36. data/lib/utils/config/vim/doc/fugitive.txt +0 -257
  37. data/lib/utils/config/vim/doc/rails.txt +0 -1022
  38. data/lib/utils/config/vim/doc/xml-plugin.txt +0 -226
  39. data/lib/utils/config/vim/ftdetect/coffee.vim +0 -8
  40. data/lib/utils/config/vim/ftdetect/eco.vim +0 -1
  41. data/lib/utils/config/vim/ftdetect/ragel.vim +0 -2
  42. data/lib/utils/config/vim/ftdetect/ruby.vim +0 -17
  43. data/lib/utils/config/vim/ftdetect/slim.vim +0 -2
  44. data/lib/utils/config/vim/ftplugin/coffee.vim +0 -221
  45. data/lib/utils/config/vim/ftplugin/eruby.vim +0 -100
  46. data/lib/utils/config/vim/ftplugin/ruby.vim +0 -260
  47. data/lib/utils/config/vim/ftplugin/xml.vim +0 -941
  48. data/lib/utils/config/vim/indent/IndentAnything_html.vim +0 -35
  49. data/lib/utils/config/vim/indent/coffee.vim +0 -338
  50. data/lib/utils/config/vim/indent/eruby.vim +0 -77
  51. data/lib/utils/config/vim/indent/javascript.vim +0 -116
  52. data/lib/utils/config/vim/indent/ruby.vim +0 -377
  53. data/lib/utils/config/vim/indent/slim.vim +0 -75
  54. data/lib/utils/config/vim/plugin/AlignMapsPlugin.vim +0 -242
  55. data/lib/utils/config/vim/plugin/AlignPlugin.vim +0 -41
  56. data/lib/utils/config/vim/plugin/Decho.vim +0 -592
  57. data/lib/utils/config/vim/plugin/IndentAnything.vim +0 -675
  58. data/lib/utils/config/vim/plugin/bufexplorer.vim +0 -1144
  59. data/lib/utils/config/vim/plugin/cecutil.vim +0 -508
  60. data/lib/utils/config/vim/plugin/ctrlp.vim +0 -61
  61. data/lib/utils/config/vim/plugin/fugitive.vim +0 -2041
  62. data/lib/utils/config/vim/plugin/lusty-explorer.vim +0 -1509
  63. data/lib/utils/config/vim/plugin/rails.vim +0 -339
  64. data/lib/utils/config/vim/plugin/rubyextra.vim +0 -193
  65. data/lib/utils/config/vim/plugin/surround.vim +0 -628
  66. data/lib/utils/config/vim/plugin/taglist.vim +0 -4546
  67. data/lib/utils/config/vim/plugin/test/IndentAnything/test.js +0 -131
  68. data/lib/utils/config/vim/plugin/vimballPlugin.vim +0 -40
  69. data/lib/utils/config/vim/syntax/Decho.vim +0 -101
  70. data/lib/utils/config/vim/syntax/coffee.vim +0 -217
  71. data/lib/utils/config/vim/syntax/eco.vim +0 -62
  72. data/lib/utils/config/vim/syntax/eruby.vim +0 -73
  73. data/lib/utils/config/vim/syntax/javascript.vim +0 -246
  74. data/lib/utils/config/vim/syntax/ragel.vim +0 -165
  75. data/lib/utils/config/vim/syntax/ruby.vim +0 -367
  76. data/lib/utils/config/vim/syntax/slim.vim +0 -117
  77. data/lib/utils/config/vimrc +0 -540
@@ -1,941 +0,0 @@
1
- " Vim script file vim600:fdm=marker:
2
- " FileType: XML
3
- " Author: Devin Weaver <vim (at) tritarget.com>
4
- " Maintainer: Devin Weaver <vim (at) tritarget.com>
5
- " Last Change: $Date: 2008-10-16 10:01:12 -0400 (Thu, 16 Oct 2008) $
6
- " Version: $Revision: 78 $
7
- " Location: http://www.vim.org/scripts/script.php?script_id=301
8
- " Licence: This program is free software; you can redistribute it
9
- " and/or modify it under the terms of the GNU General Public
10
- " License. See http://www.gnu.org/copyleft/gpl.txt
11
- " Credits: Brad Phelan <bphelan (at) mathworks.co.uk> for completing
12
- " tag matching and visual tag completion.
13
- " Ma, Xiangjiang <Xiangjiang.Ma (at) broadvision.com> for
14
- " pointing out VIM 6.0 map <buffer> feature.
15
- " Luc Hermitte <hermitte (at) free.fr> for testing the self
16
- " install documentation code and providing good bug fixes.
17
- " Guo-Peng Wen for the self install documentation code.
18
- " Shawn Boles <ickybots (at) gmail.com> for fixing the
19
- " <Leader>x cancelation bug.
20
- " Martijn van der Kwast <mvdkwast@gmx.net> for patching
21
- " problems with multi-languages (XML and PHP).
22
-
23
- " This script provides some convenience when editing XML (and some SGML)
24
- " formated documents.
25
-
26
- " Section: Documentation
27
- " ----------------------
28
- "
29
- " Documentation should be available by ":help xml-plugin" command, once the
30
- " script has been copied in you .vim/plugin directory.
31
- "
32
- " You still can read the documentation at the end of this file. Locate it by
33
- " searching the "xml-plugin" string (and set ft=help to have
34
- " appropriate syntaxic coloration).
35
-
36
- " Note: If you used the 5.x version of this file (xmledit.vim) you'll need to
37
- " comment out the section where you called it since it is no longer used in
38
- " version 6.x.
39
-
40
- " TODO: Revamp ParseTag to pull appart a tag a rebuild it properly.
41
- " a tag like: < test nowrap testatt=foo >
42
- " should be fixed to: <test nowrap="nowrap" testatt="foo"></test>
43
-
44
- "==============================================================================
45
-
46
- " Only do this when not done yet for this buffer
47
- if exists("b:did_ftplugin")
48
- finish
49
- endif
50
- " sboles, init these variables so vim doesn't complain on wrap cancel
51
- let b:last_wrap_tag_used = ""
52
- let b:last_wrap_atts_used = ""
53
-
54
- " WrapTag -> Places an XML tag around a visual selection. {{{1
55
- " Brad Phelan: Wrap the argument in an XML tag
56
- " Added nice GUI support to the dialogs.
57
- " Rewrote function to implement new algorythem that addresses several bugs.
58
- if !exists("*s:WrapTag")
59
- function s:WrapTag(text)
60
- if (line(".") < line("'<"))
61
- let insert_cmd = "o"
62
- elseif (col(".") < col("'<"))
63
- let insert_cmd = "a"
64
- else
65
- let insert_cmd = "i"
66
- endif
67
- if strlen(a:text) > 10
68
- let input_text = strpart(a:text, 0, 10) . '...'
69
- else
70
- let input_text = a:text
71
- endif
72
- let wraptag = inputdialog('Tag to wrap "' . input_text . '" : ')
73
- if strlen(wraptag)==0
74
- if strlen(b:last_wrap_tag_used)==0
75
- undo
76
- return
77
- endif
78
- let wraptag = b:last_wrap_tag_used
79
- let atts = b:last_wrap_atts_used
80
- else
81
- let atts = inputdialog('Attributes in <' . wraptag . '> : ')
82
- endif
83
- if (visualmode() ==# 'V')
84
- let text = strpart(a:text,0,strlen(a:text)-1)
85
- if (insert_cmd ==# "o")
86
- let eol_cmd = ""
87
- else
88
- let eol_cmd = "\<Cr>"
89
- endif
90
- else
91
- let text = a:text
92
- let eol_cmd = ""
93
- endif
94
- if strlen(atts)==0
95
- let text = "<".wraptag.">".text."</".wraptag.">"
96
- let b:last_wrap_tag_used = wraptag
97
- let b:last_wrap_atts_used = ""
98
- else
99
- let text = "<".wraptag." ".atts.">".text."</".wraptag.">"
100
- let b:last_wrap_tag_used = wraptag
101
- let b:last_wrap_atts_used = atts
102
- endif
103
- execute "normal! ".insert_cmd.text.eol_cmd
104
- endfunction
105
- endif
106
-
107
- " NewFileXML -> Inserts <?xml?> at top of new file. {{{1
108
- if !exists("*s:NewFileXML")
109
- function s:NewFileXML( )
110
- " Where is g:did_xhtmlcf_inits defined?
111
- if &filetype == 'xml' || (!exists ("g:did_xhtmlcf_inits") && exists ("g:xml_use_xhtml") && (&filetype == 'html' || &filetype == 'xhtml'))
112
- if append (0, '<?xml version="1.0"?>')
113
- normal! G
114
- endif
115
- endif
116
- endfunction
117
- endif
118
-
119
-
120
- " Callback -> Checks for tag callbacks and executes them. {{{1
121
- if !exists("*s:Callback")
122
- function s:Callback( xml_tag, isHtml )
123
- let text = 0
124
- if a:isHtml == 1 && exists ("*HtmlAttribCallback")
125
- let text = HtmlAttribCallback (a:xml_tag)
126
- elseif exists ("*XmlAttribCallback")
127
- let text = XmlAttribCallback (a:xml_tag)
128
- endif
129
- if text != '0'
130
- execute "normal! i " . text ."\<Esc>l"
131
- endif
132
- endfunction
133
- endif
134
-
135
-
136
- " IsParsableTag -> Check to see if the tag is a real tag. {{{1
137
- if !exists("*s:IsParsableTag")
138
- function s:IsParsableTag( tag )
139
- " The "Should I parse?" flag.
140
- let parse = 1
141
-
142
- " make sure a:tag has a proper tag in it and is not a instruction or end tag.
143
- if a:tag !~ '^<[[:alnum:]_:\-].*>$'
144
- let parse = 0
145
- endif
146
-
147
- " make sure this tag isn't already closed.
148
- if strpart (a:tag, strlen (a:tag) - 2, 1) == '/'
149
- let parse = 0
150
- endif
151
-
152
- return parse
153
- endfunction
154
- endif
155
-
156
-
157
- " ParseTag -> The major work hourse for tag completion. {{{1
158
- if !exists("*s:ParseTag")
159
- function s:ParseTag( )
160
- " Save registers
161
- let old_reg_save = @"
162
- let old_save_x = @x
163
-
164
- if (!exists("g:xml_no_auto_nesting") && strpart (getline ("."), col (".") - 2, 2) == '>>')
165
- let multi_line = 1
166
- execute "normal! \"xX"
167
- else
168
- let multi_line = 0
169
- endif
170
-
171
- let @" = ""
172
- execute "normal! \"xy%%"
173
- let ltag = @"
174
- if (&filetype == 'html' || &filetype == 'xhtml') && (!exists ("g:xml_no_html"))
175
- let html_mode = 1
176
- let ltag = substitute (ltag, '[^[:graph:]]\+', ' ', 'g')
177
- let ltag = substitute (ltag, '<\s*\([^[:alnum:]_:\-[:blank:]]\=\)\s*\([[:alnum:]_:\-]\+\)\>', '<\1\2', '')
178
- else
179
- let html_mode = 0
180
- endif
181
-
182
- if <SID>IsParsableTag (ltag)
183
- " find the break between tag name and atributes (or closing of tag)
184
- let index = matchend (ltag, '[[:alnum:]_:\-]\+')
185
-
186
- let tag_name = strpart (ltag, 1, index - 1)
187
- if strpart (ltag, index) =~ '[^/>[:blank:]]'
188
- let has_attrib = 1
189
- else
190
- let has_attrib = 0
191
- endif
192
-
193
- " That's (index - 1) + 2, 2 for the '</' and 1 for the extra character the
194
- " while includes (the '>' is ignored because <Esc> puts the curser on top
195
- " of the '>'
196
- let index = index + 2
197
-
198
- " print out the end tag and place the cursor back were it left off
199
- if html_mode && tag_name =~? '^\(img\|input\|param\|frame\|br\|hr\|meta\|link\|base\|area\)$'
200
- if has_attrib == 0
201
- call <SID>Callback (tag_name, html_mode)
202
- endif
203
- if exists ("g:xml_use_xhtml")
204
- execute "normal! i /\<Esc>l"
205
- endif
206
- else
207
- if multi_line
208
- " Can't use \<Tab> because that indents 'tabstop' not 'shiftwidth'
209
- " Also >> doesn't shift on an empty line hence the temporary char 'x'
210
- let com_save = &comments
211
- set comments-=n:>
212
- execute "normal! a\<Cr>\<Cr>\<Esc>kAx\<Esc>>>$\"xx"
213
- execute "set comments=" . substitute(com_save, " ", "\\\\ ", "g")
214
- else
215
- if has_attrib == 0
216
- call <SID>Callback (tag_name, html_mode)
217
- endif
218
- if exists("g:xml_jump_string")
219
- let index = index + strlen(g:xml_jump_string)
220
- let jump_char = g:xml_jump_string
221
- call <SID>InitEditFromJump()
222
- else
223
- let jump_char = ""
224
- endif
225
- execute "normal! a</" . tag_name . ">" . jump_char . "\<Esc>" . index . "h"
226
- endif
227
- endif
228
- endif
229
-
230
- " restore registers
231
- let @" = old_reg_save
232
- let @x = old_save_x
233
-
234
- if multi_line
235
- startinsert!
236
- else
237
- execute "normal! l"
238
- startinsert
239
- endif
240
- endfunction
241
- endif
242
-
243
-
244
- " ParseTag2 -> Experimental function to replace ParseTag {{{1
245
- "if !exists("*s:ParseTag2")
246
- "function s:ParseTag2( )
247
- " My thought is to pull the tag out and reformat it to a normalized tag
248
- " and put it back.
249
- "endfunction
250
- "endif
251
-
252
-
253
- " BuildTagName -> Grabs the tag's name for tag matching. {{{1
254
- if !exists("*s:BuildTagName")
255
- function s:BuildTagName( )
256
- "First check to see if we Are allready on the end of the tag. The / search
257
- "forwards command will jump to the next tag otherwise
258
-
259
- " Store contents of register x in a variable
260
- let b:xreg = @x
261
-
262
- exec "normal! v\"xy"
263
- if @x=='>'
264
- " Don't do anything
265
- else
266
- exec "normal! />/\<Cr>"
267
- endif
268
-
269
- " Now we head back to the < to reach the beginning.
270
- exec "normal! ?<?\<Cr>"
271
-
272
- " Capture the tag (a > will be catured by the /$/ match)
273
- exec "normal! v/\\s\\|$/\<Cr>\"xy"
274
-
275
- " We need to strip off any junk at the end.
276
- let @x=strpart(@x, 0, match(@x, "[[:blank:]>\<C-J>]"))
277
-
278
- "remove <, >
279
- let @x=substitute(@x,'^<\|>$','','')
280
-
281
- " remove spaces.
282
- let @x=substitute(@x,'/\s*','/', '')
283
- let @x=substitute(@x,'^\s*','', '')
284
-
285
- " Swap @x and b:xreg
286
- let temp = @x
287
- let @x = b:xreg
288
- let b:xreg = temp
289
- endfunction
290
- endif
291
-
292
- " TagMatch1 -> First step in tag matching. {{{1
293
- " Brad Phelan: First step in tag matching.
294
- if !exists("*s:TagMatch1")
295
- function s:TagMatch1()
296
- " Save registers
297
- let old_reg_save = @"
298
-
299
- "Drop a marker here just in case we have a mismatched tag and
300
- "wish to return (:mark looses column position)
301
- normal! mz
302
-
303
- call <SID>BuildTagName()
304
-
305
- "Check to see if it is an end tag. If it is place a 1 in endtag
306
- if match(b:xreg, '^/')==-1
307
- let endtag = 0
308
- else
309
- let endtag = 1
310
- endif
311
-
312
- " Extract the tag from the whole tag block
313
- " eg if the block =
314
- " tag attrib1=blah attrib2=blah
315
- " we will end up with
316
- " tag
317
- " with no trailing or leading spaces
318
- let b:xreg=substitute(b:xreg,'^/','','g')
319
-
320
- " Make sure the tag is valid.
321
- " Malformed tags could be <?xml ?>, <![CDATA[]]>, etc.
322
- if match(b:xreg,'^[[:alnum:]_:\-]') != -1
323
- " Pass the tag to the matching
324
- " routine
325
- call <SID>TagMatch2(b:xreg, endtag)
326
- endif
327
- " Restore registers
328
- let @" = old_reg_save
329
- endfunction
330
- endif
331
-
332
-
333
- " TagMatch2 -> Second step in tag matching. {{{1
334
- " Brad Phelan: Second step in tag matching.
335
- if !exists("*s:TagMatch2")
336
- function s:TagMatch2(tag,endtag)
337
- let match_type=''
338
-
339
- " Build the pattern for searching for XML tags based
340
- " on the 'tag' type passed into the function.
341
- " Note we search forwards for end tags and
342
- " backwards for start tags
343
- if a:endtag==0
344
- "let nextMatch='normal /\(<\s*' . a:tag . '\(\s\+.\{-}\)*>\)\|\(<\/' . a:tag . '\s*>\)'
345
- let match_type = '/'
346
- else
347
- "let nextMatch='normal ?\(<\s*' . a:tag . '\(\s\+.\{-}\)*>\)\|\(<\/' . a:tag . '\s*>\)'
348
- let match_type = '?'
349
- endif
350
-
351
- if a:endtag==0
352
- let stk = 1
353
- else
354
- let stk = 1
355
- end
356
-
357
- " wrapscan must be turned on. We'll recored the value and reset it afterward.
358
- " We have it on because if we don't we'll get a nasty error if the search hits
359
- " BOF or EOF.
360
- let wrapval = &wrapscan
361
- let &wrapscan = 1
362
-
363
- "Get the current location of the cursor so we can
364
- "detect if we wrap on ourselves
365
- let lpos = line(".")
366
- let cpos = col(".")
367
-
368
- if a:endtag==0
369
- " If we are trying to find a start tag
370
- " then decrement when we find a start tag
371
- let iter = 1
372
- else
373
- " If we are trying to find an end tag
374
- " then increment when we find a start tag
375
- let iter = -1
376
- endif
377
-
378
- "Loop until stk == 0.
379
- while 1
380
- " exec search.
381
- " Make sure to avoid />$/ as well as /\s$/ and /$/.
382
- exec "normal! " . match_type . '<\s*\/*\s*' . a:tag . '\([[:blank:]>]\|$\)' . "\<Cr>"
383
-
384
- " Check to see if our match makes sence.
385
- if a:endtag == 0
386
- if line(".") < lpos
387
- call <SID>MisMatchedTag (0, a:tag)
388
- break
389
- elseif line(".") == lpos && col(".") <= cpos
390
- call <SID>MisMatchedTag (1, a:tag)
391
- break
392
- endif
393
- else
394
- if line(".") > lpos
395
- call <SID>MisMatchedTag (2, '/'.a:tag)
396
- break
397
- elseif line(".") == lpos && col(".") >= cpos
398
- call <SID>MisMatchedTag (3, '/'.a:tag)
399
- break
400
- endif
401
- endif
402
-
403
- call <SID>BuildTagName()
404
-
405
- if match(b:xreg,'^/')==-1
406
- " Found start tag
407
- let stk = stk + iter
408
- else
409
- " Found end tag
410
- let stk = stk - iter
411
- endif
412
-
413
- if stk == 0
414
- break
415
- endif
416
- endwhile
417
-
418
- let &wrapscan = wrapval
419
- endfunction
420
- endif
421
-
422
- " MisMatchedTag -> What to do if a tag is mismatched. {{{1
423
- if !exists("*s:MisMatchedTag")
424
- function s:MisMatchedTag( id, tag )
425
- "Jump back to our formor spot
426
- normal! `z
427
- normal zz
428
- echohl WarningMsg
429
- " For debugging
430
- "echo "Mismatched tag " . a:id . ": <" . a:tag . ">"
431
- " For release
432
- echo "Mismatched tag <" . a:tag . ">"
433
- echohl None
434
- endfunction
435
- endif
436
-
437
- " DeleteTag -> Deletes surrounding tags from cursor. {{{1
438
- " Modifies mark z
439
- if !exists("*s:DeleteTag")
440
- function s:DeleteTag( )
441
- if strpart (getline ("."), col (".") - 1, 1) == "<"
442
- normal! l
443
- endif
444
- if search ("<[^\/]", "bW") == 0
445
- return
446
- endif
447
- normal! mz
448
- normal \5
449
- normal! d%`zd%
450
- endfunction
451
- endif
452
-
453
- " VisualTag -> Selects Tag body in a visual selection. {{{1
454
- " Modifies mark z
455
- if !exists("*s:VisualTag")
456
- function s:VisualTag( )
457
- if strpart (getline ("."), col (".") - 1, 1) == "<"
458
- normal! l
459
- endif
460
- if search ("<[^\/]", "bW") == 0
461
- return
462
- endif
463
- normal! mz
464
- normal \5
465
- normal! %
466
- exe "normal! " . visualmode()
467
- normal! `z
468
- endfunction
469
- endif
470
-
471
- " InsertGt -> close tags only if the cursor is in a HTML or XML context {{{1
472
- " Else continue editing
473
- if !exists("*s:InsertGt")
474
- function s:InsertGt( )
475
- let save_matchpairs = &matchpairs
476
- set matchpairs-=<:>
477
- execute "normal! a>"
478
- execute "set matchpairs=" . save_matchpairs
479
- " When the current char is text within a tag it will not proccess as a
480
- " syntax'ed element and return nothing below. Since the multi line wrap
481
- " feture relies on using the '>' char as text within a tag we must use the
482
- " char prior to establish if it is valid html/xml
483
- if (getline('.')[col('.') - 1] == '>')
484
- let char_syn=synIDattr(synID(line("."), col(".") - 1, 1), "name")
485
- endif
486
- if -1 == match(char_syn, "xmlProcessing") && (0 == match(char_syn, 'html') || 0 == match(char_syn, 'xml'))
487
- call <SID>ParseTag()
488
- else
489
- if col(".") == col("$") - 1
490
- startinsert!
491
- else
492
- execute "normal! l"
493
- startinsert
494
- endif
495
- endif
496
- endfunction
497
- endif
498
-
499
- " InitEditFromJump -> Set some needed autocommands and syntax highlights for EditFromJump. {{{1
500
- if !exists("*s:InitEditFromJump")
501
- function s:InitEditFromJump( )
502
- " Add a syntax highlight for the xml_jump_string.
503
- execute "syntax match Error /\\V" . g:xml_jump_string . "/"
504
- " Remove left over garbage from xml_jump_string on file save.
505
- augroup xml
506
- execute "au BufWritePre <buffer> %s/" . g:xml_jump_string . "//ge"
507
- augroup END
508
- endfunction
509
- endif
510
-
511
- " EditFromJump -> Jump to the end of the tag and continue editing. {{{1
512
- " g:xml_jump_string must be set.
513
- if !exists("*s:EditFromJump")
514
- function s:EditFromJump( )
515
- if exists("g:xml_jump_string")
516
- let foo = search(g:xml_jump_string, 'csW') " Moves cursor by default
517
- execute "normal! " . strlen(g:xml_jump_string) . "x"
518
- if col(".") == col("$") - 1
519
- startinsert!
520
- else
521
- startinsert
522
- endif
523
- else
524
- echohl WarningMsg
525
- echo "Function disabled. xml_jump_string not defined."
526
- echohl None
527
- endif
528
- endfunction
529
- endif
530
-
531
- " Section: Doc installation {{{1
532
- " Function: s:XmlInstallDocumentation(full_name, revision) {{{2
533
- " Install help documentation.
534
- " Arguments:
535
- " full_name: Full name of this vim plugin script, including path name.
536
- " revision: Revision of the vim script. #version# mark in the document file
537
- " will be replaced with this string with 'v' prefix.
538
- " Return:
539
- " 1 if new document installed, 0 otherwise.
540
- " Note: Cleaned and generalized by guo-peng Wen
541
- "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
542
-
543
- function! s:XmlInstallDocumentation(full_name, revision)
544
- " Name of the document path based on the system we use:
545
- if (has("unix"))
546
- " On UNIX like system, using forward slash:
547
- let l:slash_char = '/'
548
- let l:mkdir_cmd = ':silent !mkdir -p '
549
- else
550
- " On M$ system, use backslash. Also mkdir syntax is different.
551
- " This should only work on W2K and up.
552
- let l:slash_char = '\'
553
- let l:mkdir_cmd = ':silent !mkdir '
554
- endif
555
-
556
- let l:doc_path = l:slash_char . 'doc'
557
- "let l:doc_home = l:slash_char . '.vim' . l:slash_char . 'doc'
558
-
559
- " Figure out document path based on full name of this script:
560
- let l:vim_plugin_path = fnamemodify(a:full_name, ':h')
561
- "let l:vim_doc_path = fnamemodify(a:full_name, ':h:h') . l:doc_path
562
- let l:vim_doc_path = matchstr(l:vim_plugin_path,
563
- \ '.\{-}\ze\%(\%(ft\)\=plugin\|macros\)') . l:doc_path
564
- if (!(filewritable(l:vim_doc_path) == 2))
565
- echomsg "Doc path: " . l:vim_doc_path
566
- execute l:mkdir_cmd . l:vim_doc_path
567
- if (!(filewritable(l:vim_doc_path) == 2))
568
- " Try a default configuration in user home:
569
- "let l:vim_doc_path = expand("~") . l:doc_home
570
- let l:vim_doc_path = matchstr(&rtp,
571
- \ escape($HOME, '\') .'[/\\]\%(\.vim\|vimfiles\)')
572
- if (!(filewritable(l:vim_doc_path) == 2))
573
- execute l:mkdir_cmd . l:vim_doc_path
574
- if (!(filewritable(l:vim_doc_path) == 2))
575
- " Put a warning:
576
- echomsg "Unable to open documentation directory"
577
- echomsg " type :help add-local-help for more informations."
578
- return 0
579
- endif
580
- endif
581
- endif
582
- endif
583
-
584
- " Exit if we have problem to access the document directory:
585
- if (!isdirectory(l:vim_plugin_path)
586
- \ || !isdirectory(l:vim_doc_path)
587
- \ || filewritable(l:vim_doc_path) != 2)
588
- return 0
589
- endif
590
-
591
- " Full name of script and documentation file:
592
- let l:script_name = 'xml.vim'
593
- let l:doc_name = 'xml-plugin.txt'
594
- let l:plugin_file = l:vim_plugin_path . l:slash_char . l:script_name
595
- let l:doc_file = l:vim_doc_path . l:slash_char . l:doc_name
596
-
597
- " Bail out if document file is still up to date:
598
- if (filereadable(l:doc_file) &&
599
- \ getftime(l:plugin_file) < getftime(l:doc_file))
600
- return 0
601
- endif
602
-
603
- " Prepare window position restoring command:
604
- if (strlen(@%))
605
- let l:go_back = 'b ' . bufnr("%")
606
- else
607
- let l:go_back = 'enew!'
608
- endif
609
-
610
- " Create a new buffer & read in the plugin file (me):
611
- setl nomodeline
612
- exe 'enew!'
613
- exe 'r ' . l:plugin_file
614
-
615
- setl modeline
616
- let l:buf = bufnr("%")
617
- setl noswapfile modifiable
618
-
619
- norm zR
620
- norm gg
621
-
622
- " Delete from first line to a line starts with
623
- " === START_DOC
624
- 1,/^=\{3,}\s\+START_DOC\C/ d
625
-
626
- " Delete from a line starts with
627
- " === END_DOC
628
- " to the end of the documents:
629
- /^=\{3,}\s\+END_DOC\C/,$ d
630
-
631
- " Remove fold marks:
632
- % s/{\{3}[1-9]/ /
633
-
634
- " Add modeline for help doc: the modeline string is mangled intentionally
635
- " to avoid it be recognized by VIM:
636
- call append(line('$'), '')
637
- call append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:')
638
-
639
- " Replace revision:
640
- exe "normal :1,5s/#version#/ v" . a:revision . "/\<CR>"
641
-
642
- " Save the help document:
643
- exe 'w! ' . l:doc_file
644
- exe l:go_back
645
- exe 'bw ' . l:buf
646
-
647
- " Build help tags:
648
- exe 'helptags ' . l:vim_doc_path
649
-
650
- return 1
651
- endfunction
652
- " }}}2
653
-
654
- let s:revision=
655
- \ substitute("$Revision: 78 $",'\$\S*: \([.0-9]\+\) \$','\1','')
656
- silent! let s:install_status =
657
- \ s:XmlInstallDocumentation(expand('<sfile>:p'), s:revision)
658
- if (s:install_status == 1)
659
- echom expand("<sfile>:t:r") . '-plugin v' . s:revision .
660
- \ ': Help-documentation installed.'
661
- endif
662
-
663
-
664
- " Mappings and Settings. {{{1
665
- " This makes the '%' jump between the start and end of a single tag.
666
- setlocal matchpairs+=<:>
667
- setlocal commentstring=<!--%s-->
668
-
669
- " Have this as an escape incase you want a literal '>' not to run the
670
- " ParseTag function.
671
- if !exists("g:xml_tag_completion_map")
672
- inoremap <buffer> <LocalLeader>. >
673
- inoremap <buffer> <LocalLeader>> >
674
- endif
675
-
676
- " Jump between the beggining and end tags.
677
- nnoremap <buffer> <LocalLeader>5 :call <SID>TagMatch1()<Cr>
678
- nnoremap <buffer> <LocalLeader>% :call <SID>TagMatch1()<Cr>
679
- vnoremap <buffer> <LocalLeader>5 <Esc>:call <SID>VisualTag()<Cr>
680
- vnoremap <buffer> <LocalLeader>% <Esc>:call <SID>VisualTag()<Cr>
681
-
682
- " Wrap selection in XML tag
683
- vnoremap <buffer> <LocalLeader>x "xx:call <SID>WrapTag(@x)<Cr>
684
- nnoremap <buffer> <LocalLeader>d :call <SID>DeleteTag()<Cr>
685
-
686
- " Parse the tag after pressing the close '>'.
687
- if !exists("g:xml_tag_completion_map")
688
- " inoremap <buffer> > ><Esc>:call <SID>ParseTag()<Cr>
689
- inoremap <buffer> > <Esc>:call <SID>InsertGt()<Cr>
690
- else
691
- execute "inoremap <buffer> " . g:xml_tag_completion_map . " <Esc>:call <SID>InsertGt()<Cr>"
692
- endif
693
-
694
- if exists("g:xml_jump_string")
695
- nnoremap <buffer> <LocalLeader><Space> :call <SID>EditFromJump()<Cr>
696
- inoremap <buffer> <LocalLeader><Space> <Esc>:call <SID>EditFromJump()<Cr>
697
- " Clear out all left over xml_jump_string garbage
698
- execute "nnoremap <buffer> <LocalLeader><LocalLeader> :%s/" . g:xml_jump_string . "//ge<Cr>"
699
- " The syntax files clear out any predefined syntax definitions. Recreate
700
- " this when ever a xml_jump_string is created. (in ParseTag)
701
- endif
702
-
703
- augroup xml
704
- au!
705
- au BufNewFile * call <SID>NewFileXML()
706
- augroup END
707
- "}}}1
708
- finish
709
-
710
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
711
- " Section: Documentation content {{{1
712
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
713
- === START_DOC
714
- *xml-plugin.txt* Help edit XML and SGML documents. #version#
715
-
716
- XML Edit {{{2 ~
717
-
718
- A filetype plugin to help edit XML and SGML documents.
719
-
720
- This script provides some convenience when editing XML (and some SGML
721
- including HTML) formated documents. It allows you to jump to the beginning
722
- or end of the tag block your cursor is in. '%' will jump between '<' and '>'
723
- within the tag your cursor is in. When in insert mode and you finish a tag
724
- (pressing '>') the tag will be completed. If you press '>' twice it will
725
- complete the tag and place the cursor in the middle of the tags on it's own
726
- line (helps with nested tags).
727
-
728
- Usage: Place this file into your ftplugin directory. To add html support
729
- Sym-link or copy this file to html.vim in your ftplugin directory. To activte
730
- the script place 'filetype plugin on' in your |.vimrc| file. See |ftplugins|
731
- for more information on this topic.
732
-
733
- If the file edited is of type "html" and "xml_use_html" is defined then the
734
- following tags will not auto complete:
735
- <img>, <input>, <param>, <frame>, <br>, <hr>, <meta>, <link>, <base>, <area>
736
-
737
- If the file edited is of type 'html' and 'xml_use_xhtml' is defined the above
738
- tags will autocomplete the xml closing staying xhtml compatable.
739
- ex. <hr> becomes <hr /> (see |xml-plugin-settings|)
740
-
741
- NOTE: If you used the VIM 5.x version of this file (xmledit.vim) you'll need
742
- to comment out the section where you called it. It is no longer used in the
743
- VIM 6.x version.
744
-
745
- Known Bugs {{{2 ~
746
-
747
- - This script will modify registers ". and "x; register "" will be restored.
748
- - < & > marks inside of a CDATA section are interpreted as actual XML tags
749
- even if unmatched.
750
- - Although the script can handle leading spaces such as < tag></ tag> it is
751
- illegal XML syntax and considered very bad form.
752
- - Placing a literal `>' in an attribute value will auto complete dispite that
753
- the start tag isn't finished. This is poor XML anyway you should use
754
- &gt; instead.
755
- - The matching algorithm can handle illegal tag characters where as the tag
756
- completion algorithm can not.
757
-
758
- ------------------------------------------------------------------------------
759
- *xml-plugin-mappings*
760
- Mappings {{{2 ~
761
-
762
- <LocalLeader> is a setting in VIM that depicts a prefix for scripts and
763
- plugins to use. By default this is the backslash key `\'. See |mapleader|
764
- for details.
765
-
766
- <LocalLeader>Space
767
- Normal or Insert - Continue editing after the ending tag. This
768
- option requires xml_jump_string to be set to function. When a tag
769
- is completed it will append the xml_jump_string. Once this mapping
770
- is ran it will delete the next xml_jump_string pattern to the right
771
- of the curser and delete it leaving you in insert mode to continue
772
- editing.
773
-
774
- <LocalLeader><LocalLeader>
775
- Normal - Will clear the entire file of left over xml_jump_string garbage.
776
- * This will also happen automatically when you save the file. *
777
-
778
- <LocalLeader>x
779
- Visual - Place a custom XML tag to suround the selected text. You
780
- need to have selected text in visual mode before you can use this
781
- mapping. See |visual-mode| for details.
782
-
783
- <LocalLeader>. or <LocalLeader>>
784
- Insert - Place a literal '>' without parsing tag.
785
-
786
- <LocalLeader>5 or <LocalLeader>%
787
- Normal or Visual - Jump to the begining or end tag.
788
-
789
- <LocalLeader>d
790
- Normal - Deletes the surrounding tags from the cursor. >
791
- <tag1>outter <tag2>inner text</tag2> text</tag1>
792
- ^
793
- < Turns to: >
794
- outter <tag2>inner text</tag2> text
795
- ^
796
- <
797
-
798
- ------------------------------------------------------------------------------
799
- *xml-plugin-settings*
800
- Options {{{2 ~
801
-
802
- (All options must be placed in your |.vimrc| prior to the |ftplugin|
803
- command.)
804
-
805
- xml_tag_completion_map
806
- Use this setting to change the default mapping to auto complete a
807
- tag. By default typing a literal `>' will cause the tag your editing
808
- to auto complete; pressing twice will auto nest the tag. By using
809
- this setting the `>' will be a literal `>' and you must use the new
810
- mapping to perform auto completion and auto nesting. For example if
811
- you wanted Control-L to perform auto completion inmstead of typing a
812
- `>' place the following into your .vimrc: >
813
- let xml_tag_completion_map = "<C-l>"
814
- <
815
- xml_no_auto_nesting
816
- This turns off the auto nesting feature. After a completion is made
817
- and another `>' is typed xml-edit automatically will break the tag
818
- accross multiple lines and indent the curser to make creating nested
819
- tqags easier. This feature turns it off. Enter the following in your
820
- .vimrc: >
821
- let xml_no_auto_nesting = 1
822
- <
823
- xml_use_xhtml
824
- When editing HTML this will auto close the short tags to make valid
825
- XML like <hr /> and <br />. Enter the following in your vimrc to
826
- turn this option on: >
827
- let xml_use_xhtml = 1
828
- <
829
- xml_no_html
830
- This turns of the support for HTML specific tags. Place this in your
831
- .vimrc: >
832
- let xml_no_html = 1
833
- <
834
- xml_jump_string
835
- This turns of the support for continuing edits after an ending tag.
836
- xml_jump_string can be any string how ever a simple character will
837
- serfice. Pick a character or small string that is unique and will
838
- not interfer with your normal editing. See the <LocalLeader>Space
839
- mapping for more.
840
- .vimrc: >
841
- let xml_jump_string = "`"
842
- <
843
- ------------------------------------------------------------------------------
844
- *xml-plugin-callbacks*
845
- Callback Functions {{{2 ~
846
-
847
- A callback function is a function used to customize features on a per tag
848
- basis. For example say you wish to have a default set of attributs when you
849
- type an empty tag like this:
850
- You type: <tag>
851
- You get: <tag default="attributes"></tag>
852
-
853
- This is for any script programmers who wish to add xml-plugin support to
854
- there own filetype plugins.
855
-
856
- Callback functions recive one attribute variable which is the tag name. The
857
- all must return either a string or the number zero. If it returns a string
858
- the plugin will place the string in the proper location. If it is a zero the
859
- plugin will ignore and continue as if no callback existed.
860
-
861
- The following are implemented callback functions:
862
-
863
- HtmlAttribCallback
864
- This is used to add default attributes to html tag. It is intended
865
- for HTML files only.
866
-
867
- XmlAttribCallback
868
- This is a generic callback for xml tags intended to add attributes.
869
-
870
- *xml-plugin-html*
871
- Callback Example {{{2 ~
872
-
873
- The following is an example of using XmlAttribCallback in your .vimrc
874
- >
875
- function XmlAttribCallback (xml_tag)
876
- if a:xml_tag ==? "my-xml-tag"
877
- return "attributes=\"my xml attributes\""
878
- else
879
- return 0
880
- endif
881
- endfunction
882
- <
883
- The following is a sample html.vim file type plugin you could use:
884
- >
885
- " Vim script file vim600:fdm=marker:
886
- " FileType: HTML
887
- " Maintainer: Devin Weaver <vim (at) tritarget.com>
888
- " Location: http://www.vim.org/scripts/script.php?script_id=301
889
-
890
- " This is a wrapper script to add extra html support to xml documents.
891
- " Original script can be seen in xml-plugin documentation.
892
-
893
- " Only do this when not done yet for this buffer
894
- if exists("b:did_ftplugin")
895
- finish
896
- endif
897
- " Don't set 'b:did_ftplugin = 1' because that is xml.vim's responsability.
898
-
899
- let b:html_mode = 1
900
-
901
- if !exists("*HtmlAttribCallback")
902
- function HtmlAttribCallback( xml_tag )
903
- if a:xml_tag ==? "table"
904
- return "cellpadding=\"0\" cellspacing=\"0\" border=\"0\""
905
- elseif a:xml_tag ==? "link"
906
- return "href=\"/site.css\" rel=\"StyleSheet\" type=\"text/css\""
907
- elseif a:xml_tag ==? "body"
908
- return "bgcolor=\"white\""
909
- elseif a:xml_tag ==? "frame"
910
- return "name=\"NAME\" src=\"/\" scrolling=\"auto\" noresize"
911
- elseif a:xml_tag ==? "frameset"
912
- return "rows=\"0,*\" cols=\"*,0\" border=\"0\""
913
- elseif a:xml_tag ==? "img"
914
- return "src=\"\" width=\"0\" height=\"0\" border=\"0\" alt=\"\""
915
- elseif a:xml_tag ==? "a"
916
- if has("browse")
917
- " Look up a file to fill the href. Used in local relative file
918
- " links. typeing your own href before closing the tag with `>'
919
- " will override this.
920
- let cwd = getcwd()
921
- let cwd = substitute (cwd, "\\", "/", "g")
922
- let href = browse (0, "Link to href...", getcwd(), "")
923
- let href = substitute (href, cwd . "/", "", "")
924
- let href = substitute (href, " ", "%20", "g")
925
- else
926
- let href = ""
927
- endif
928
- return "href=\"" . href . "\""
929
- else
930
- return 0
931
- endif
932
- endfunction
933
- endif
934
-
935
- " On to loading xml.vim
936
- runtime ftplugin/xml.vim
937
- <
938
- === END_DOC
939
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
940
- " vim: set tabstop=8 shiftwidth=4 softtabstop=4 smartindent
941
- " vim600: set foldmethod=marker smarttab fileencoding=iso-8859-15