-
Notifications
You must be signed in to change notification settings - Fork 4
/
edit_org_to_help.vim
68 lines (58 loc) · 2.58 KB
/
edit_org_to_help.vim
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
" ======== Do some easy edits
set ignorecase
normal! ggd4j
%s/\[\[[^]]\+\/license.html\]\[\([^]]*\)\]\]/\1: https:\/\/www.lua.org\/license.html/
normal! 2jdap
/^\* 3 --/,/^\* 5 --/-d
/^\* 6 --/,/^\* 8 --/-d
/^\*\+ 2.10.1 --/,/^\*\+ 2.10.2 --/-d
%s/ / /g
%s/\n\s*#+begin_example/>/
%s/^\s*#+end_example\n/</
%s/^\ze\*\+ \d/\=repeat('=', 78)."\n"/
g/^\s*:PROPERTIES:$/,+2d
silent! %s/^\s\+$//g
" ======== Handle markup first
" Special cases:
%s/=%=\/x\//`%x`/
%s/\*\/\(\S*\)\/:\*/`\1`:/
%s/\*=\(\S*\)=:\*/`\1`:/
%s/\*"\(\S*\)":\*/`\1`:/
%s/\*=\*/`=`/
%s/^\*\*\*\* \(.*\):/\1\~/
%s/=www.lua.org=/www.lua.org/
%s/=\(\([\][]\)=\+\2\)=/`\1`/g
%s/[^=]\zs=\([~=]=\)=\ze[^=\]]/`\1`/g
" big sweeps:
%s/\*\(\w\%([^*]*\w\)\?\)\*/`\1`/g
%s/\%(\s\|^\)\zs\/\(\w\%([^/]*\w\)\?\)\//`\1`/g
%s/\%([[{]\|\s\|^\)\zs\/\(\w\%([^/]*\S\)\?\)\//`\1`/g
" verbatim used a lot in links, do later
" Add target for metamethod/metatable
0/^- `add`/-call append('.', ' *lua_metamethods* *lua_metatable_events*')
" ======== Set up columns/sections
" insert table of contents
execute '0/1 --/-2read toc/' . expand('%:t:r') . '.txt'
" Change section headers to proper format and insert link targets
0/lua_reference_toc/;/===/g/^\d/execute printf('%%s/^\*\+ %s -- \(.*\)/\=toupper(submatch(1))..repeat(" ", 78-strwidth(submatch(1).."%s")).."*%s*"', expand('<cWORD>'), split(getline('.'))[-1], split(getline('.'))[-1][1:-2])
" ======== Set up columns/sections
" Link removed sections to online docs
if expand('%:t:r') == 'en'
%s/\[\[#\([3467][0-9.]*\)\]\[§[0-9.]*\]\]/https:\/\/www.lua.org\/manual\/5.1\/manual.html#\1/g
else
execute '%s/\[\[#\([3467][0-9.]*\)\]\[§[0-9.]*\]\]/https:\/\/www.lua.org\/manual\/5.1\/' . expand('%:t:r') . '\/manual.html#\1/g'
endif
" Set up function links
%s/\[\[[^]]\+\]\[=\([^=]\+\)=\]\]/|\1|/g
" Note: type duplicates helptag.
" Set up section links, some have no links, so `silent!`:
0/lua_reference_toc/;/===/g/^\d/execute printf('silent! %%s/\[\[#\V%s\m\]\[[^]]*\]\]/%s/g', expand('<cWORD>'), split(getline('.'))[-1])
setlocal shiftwidth=4
" reformat and set up builtin function, option/variable targets
g/--------------\n\n\*\{3}/,+2s/--------------\n\n\*\{3} =\([^(]\+\)\( (.*)\)\?=\n/\=submatch(1).submatch(2).repeat(' ', 74-strwidth(submatch(1).submatch(1).submatch(2))).'*'.submatch(1).'()*'/|silent +1,/^---\|^===/->
" Fix the variables (remove parens)
%s/^\(\S*\)[^(]*\1()\*$/\=submatch(1)..repeat(' ', 76-strwidth(submatch(1))*2)..'*'..submatch(1)..'*'
" Finish verbatim
%s/\%([\t ("']\|^\)\zs=\([^= \t]\%([^=]*[^= \t]\)\?\)=/`\1`/g
write! translations/lua_reference.%:t:rx
quit!