aboutsummaryrefslogtreecommitdiff
path: root/files/.vim/plugin/XMLFolding.vim
blob: ec5487b1d59ba9c77b1903393622eae77fd442a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
" About XMLFolding Script                                                  {{{

" XMLFolding version 1.1 - May 13th, 2006
" Author: Thadeu Aparecido Coelho de Paula
" E-mail: thadeudepaula@gmail.com
" WebPage: http://mundolivre.hostrixonline.com
" 
" This is my first vim script... at this point I already worked three
" continual weeks to make it. Never give up your objectives!
" I hope that you enjoy it, and use it to accomplish your projects!
"
" This script is under GNU Public License... use it, change it, sell it but 
" never forget to mention the original author"
"
" Made using Vim 6.04 on Debian GNU/Linux
"
" This Script supports:
"
" Folding of comments "<!-- -->"
" Folding of open/close tags in different lines "<> </>"
" Folding between CDATA markers "<![CDATA[" and "]]>"

" }}}

" Howto                                                                    {{{

   " Installing                                                            {{{
" Copy this file for any location yow want to... I suggest that you put it on
" your ~/.vim/plugin directory.
"
" To load this script in your vim session, type on normal mode:
" :so ~/.vim/script/XMLFolding.vim
" (If you saved on local where I suggested!)

"}}}

   " How to load this script automaticaly?                                 {{{
"You can use this script more easily configuring your vim to run it on start...
"You'll need to put this line in your /etc/vim/vimrc or ~/.vimrc:

" au BufNewFile,BufRead *.xml,*.htm,*.html so ~/.vim/plugin/XMLFolding.vim

" The "*.xml,*.html" can be changed for the file extensions that you want to
" use with this script.
   "}}}

   " Limitatios... i.e, when the fold won't occurs                         {{{

" The syntax need to be perfectly to match correctly... the tags needs to be
" nested correctly...
" All the tags nested in the same line will not be folded... like this:
" 
" <start>blablabla<middle>blablabla</middle>asdsad
" </start>
"
" In this example only "start" will be folded...
"
" An other problem will occur when you end the line closing a tag different
" than the open tag that starts the line, because the matches ignore the lines
" that starts opening a tag and ends closing a tag...
"
" <start><middle>asdasdsd</middle>
" </start>
"
" This will cause an error, because MATCHES ARE NOT MADE BY THE CONTENT OF A
" TAG, but by the presence of start and end aspect: <----> </----> independent
" of the tag content... if it encounter an incorrect nesting, the folding for
" the document will be broken. 
"
" This way, the script serves as an validator, limited but functional!
 
   "}}}


"}}}

" Folding def commands                                                     {{{

   " Basic vim commands for folding definition                             {{{
syn sync fromstart
set foldmethod=syntax
   "}}}

   " Matches and regions                                                   {{{

syn region XMLFold start=+^<\([^/?!><]*[^/]>\)\&.*\(<\1\|[[:alnum:]]\)$+ end=+^</.*[^-?]>$+ fold transparent keepend extend

syn match XMLCData "<!\[CDATA\[\_.\{-}\]\]>" fold transparent extend

syn match XMLCommentFold "<!--\_.\{-}-->" fold transparent extend


   "}}}

   " Label shown for folded lines                                          {{{
set foldtext=XMLFoldLabel()
 fun! XMLFoldLabel()
  let getcontent = substitute(getline(v:foldstart), "^[[:space:]]*", "", 'g')
	let linestart = substitute(v:folddashes, ".", '�', 'g')
	return linestart . " " . getcontent
endfunction

   "}}}

"}}}