annotate runtime/autoload/RstFold.vim @ 14972:5d52b21b2e7f v8.1.0497

patch 8.1.0497: :%diffput changes order of lines commit https://github.com/vim/vim/commit/5f57bdcab77bc417ae0357fe8ad6c7259b6d25df Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 25 17:52:23 2018 +0200 patch 8.1.0497: :%diffput changes order of lines Problem: :%diffput changes order of lines. (Markus Braun) Solution: Do adjust marks when using internal diff.
author Bram Moolenaar <Bram@vim.org>
date Thu, 25 Oct 2018 18:00:07 +0200
parents 2f7e67dd088c
children 9d3d7b0f4861
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Author: Antony Lee <anntzer.lee@gmail.com>
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Description: Helper functions for reStructuredText syntax folding
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Last Modified: 2018-01-07
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 function s:CacheRstFold()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 let closure = {'header_types': {}, 'max_level': 0, 'levels': {}}
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 function closure.Process(match) dict
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 let curline = getcurpos()[1]
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 if has_key(self.levels, curline - 1)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 " For over+under-lined headers, the regex will match both at the
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 " overline and at the title itself; in that case, skip the second match.
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 return
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 let lines = split(a:match, '\n')
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 let key = repeat(lines[-1][0], len(lines))
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 if !has_key(self.header_types, key)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 let self.max_level += 1
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 let self.header_types[key] = self.max_level
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 let self.levels[curline] = self.header_types[key]
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 endfunction
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 let save_cursor = getcurpos()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 silent keeppatterns %s/\v^%(%(([=`:.'"~^_*+#-])\1+\n)?.{1,2}\n([=`:.'"~^_*+#-])\2+)|%(%(([=`:.''"~^_*+#-])\3{2,}\n)?.{3,}\n([=`:.''"~^_*+#-])\4{2,})$/\=closure.Process(submatch(0))/gn
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 call setpos('.', save_cursor)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 let b:RstFoldCache = closure.levels
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 endfunction
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 function RstFold#GetRstFold()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 if !has_key(b:, 'RstFoldCache')
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call s:CacheRstFold()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 if has_key(b:RstFoldCache, v:lnum)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 return '>' . b:RstFoldCache[v:lnum]
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 else
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 return '='
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 endfunction
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 function RstFold#GetRstFoldText()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 if !has_key(b:, 'RstFoldCache')
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 call s:CacheRstFold()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 let indent = repeat(' ', b:RstFoldCache[v:foldstart] - 1)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 let thisline = getline(v:foldstart)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 " For over+under-lined headers, skip the overline.
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 let text = thisline =~ '^\([=`:.''"~^_*+#-]\)\1\+$' ? getline(v:foldstart + 1) : thisline
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 return indent . text
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 endfunction