annotate runtime/autoload/RstFold.vim @ 16855:19162ff4eacd v8.1.1429

patch 8.1.1429: "pos" option of popup window not supported yet commit https://github.com/vim/vim/commit/ac1f1bc222b7de3cb2d3f1f2aa076f11c75e69de Author: Bram Moolenaar <Bram@vim.org> Date: Thu May 30 21:24:26 2019 +0200 patch 8.1.1429: "pos" option of popup window not supported yet Problem: "pos" option of popup window not supported yet. Solution: Implement the option. Rename popup_getposition() to popup_getpos().
author Bram Moolenaar <Bram@vim.org>
date Thu, 30 May 2019 21:30:04 +0200
parents 9d3d7b0f4861
children
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
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
3 " Last Modified: 2018-12-29
14421
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()
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
6 if !g:rst_fold_enabled
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
7 return
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
8 endif
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
9
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 let closure = {'header_types': {}, 'max_level': 0, 'levels': {}}
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 function closure.Process(match) dict
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 let curline = getcurpos()[1]
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 if has_key(self.levels, curline - 1)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 " For over+under-lined headers, the regex will match both at the
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 " 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
16 return
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 let lines = split(a:match, '\n')
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let key = repeat(lines[-1][0], len(lines))
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 if !has_key(self.header_types, key)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 let self.max_level += 1
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 let self.header_types[key] = self.max_level
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 let self.levels[curline] = self.header_types[key]
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 endfunction
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 let save_cursor = getcurpos()
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
27 let save_mark = getpos("'[")
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 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
29 call setpos('.', save_cursor)
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
30 call setpos("'[", save_mark)
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 let b:RstFoldCache = closure.levels
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endfunction
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 function RstFold#GetRstFold()
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
35 if !g:rst_fold_enabled
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
36 return
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
37 endif
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
38
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 if !has_key(b:, 'RstFoldCache')
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 call s:CacheRstFold()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 if has_key(b:RstFoldCache, v:lnum)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 return '>' . b:RstFoldCache[v:lnum]
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 else
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 return '='
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 endfunction
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 function RstFold#GetRstFoldText()
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
50 if !g:rst_fold_enabled
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
51 return
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
52 endif
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
53
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 if !has_key(b:, 'RstFoldCache')
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 call s:CacheRstFold()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 let indent = repeat(' ', b:RstFoldCache[v:foldstart] - 1)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 let thisline = getline(v:foldstart)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 " For over+under-lined headers, skip the overline.
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 let text = thisline =~ '^\([=`:.''"~^_*+#-]\)\1\+$' ? getline(v:foldstart + 1) : thisline
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 return indent . text
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 endfunction