Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 1 | vim9script |
| 2 | |
| 3 | # Vim filetype plugin file |
| 4 | # Language: ConTeXt typesetting engine |
| 5 | # Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> |
| 6 | # Former Maintainers: Nikolai Weibull <now@bitwi.se> |
Lifepillar | 0bca4a0 | 2023-12-27 18:49:50 +0100 | [diff] [blame] | 7 | # Latest Revision: 2023 Dec 26 |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 8 | |
| 9 | if exists("b:did_ftplugin") |
| 10 | finish |
| 11 | endif |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 12 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 13 | import autoload '../autoload/context.vim' |
| 14 | |
| 15 | b:did_ftplugin = 1 |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 16 | |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 17 | if !exists('current_compiler') |
| 18 | compiler context |
| 19 | endif |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 20 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 21 | b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<" |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 22 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 23 | setlocal comments=b:%D,b:%C,b:%M,:% |
| 24 | setlocal commentstring=%\ %s |
| 25 | setlocal formatoptions+=tjcroql2 |
| 26 | setlocal omnifunc=context.Complete |
| 27 | setlocal suffixesadd=.tex,.mkxl,.mkvi,.mkiv,.mkii |
| 28 | |
| 29 | &l:define = '\\\%([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\=' |
| 30 | .. 'def\|\\font\|\\\%(future\)\=let' |
| 31 | .. '\|\\new\%(count\|dimen\|skip\|muskip\|box\|toks\|read\|write' |
| 32 | .. '\|fam\|insert\|if\)' |
| 33 | |
| 34 | &l:include = '^\s*\\\%(input\|component\|product\|project\|environment\)' |
| 35 | |
| 36 | if exists("g:loaded_matchit") && !exists("b:match_words") |
| 37 | b:match_ignorecase = 0 |
| 38 | b:match_skip = 'r:\\\@<!\%(\\\\\)*%' |
| 39 | b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],\\start\(\a\+\):\\stop\1' |
| 40 | b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip" |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 41 | endif |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 42 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 43 | if !get(g:, 'no_context_maps', 0) && !get(g:, 'no_plugin_maps', 0) |
| 44 | const context_regex = { |
| 45 | 'beginsection': '\\\%(start\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>', |
| 46 | 'endsection': '\\\%(stop\)\=\%(\%(sub\)*section\|\%(sub\)*subject\|chapter\|part\|component\|product\|title\)\>', |
| 47 | 'beginblock': '\\\%(start\|setup\|define\)', |
| 48 | 'endblock': '\\\%(stop\|setup\|define\)', |
| 49 | } |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 50 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 51 | def UndoMap(mapping: string, modes: string) |
| 52 | for mode in modes |
| 53 | b:undo_ftplugin ..= printf(" | silent! execute '%sunmap <buffer> %s'", mode, mapping) |
| 54 | endfor |
| 55 | enddef |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 56 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 57 | def MoveAround(count: number, what: string, flags: string) |
| 58 | search(context_regex[what], flags .. 's') # 's' sets previous context mark |
| 59 | var i = 2 |
| 60 | while i <= count |
| 61 | search(context_regex[what], flags) |
| 62 | i += 1 |
| 63 | endwhile |
| 64 | enddef |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 65 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 66 | # Macros to move around |
| 67 | nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr> |
| 68 | vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr> |
| 69 | nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr> |
| 70 | vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr> |
| 71 | nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr> |
| 72 | vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr> |
| 73 | nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr> |
| 74 | vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr> |
| 75 | nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr> |
| 76 | vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr> |
| 77 | nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr> |
| 78 | vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr> |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 79 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 80 | for mapping in ['[[', ']]', '[]', '][', '[{', ']}'] |
| 81 | UndoMap(mapping, 'nv') |
| 82 | endfor |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 83 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 84 | # Other useful mappings |
| 85 | const tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)' |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 86 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 87 | def TeXPar() |
| 88 | cursor(search(tp_regex, 'bcW') + 1, 1) |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 89 | normal! V |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 90 | cursor(search(tp_regex, 'W') - 1, 1) |
| 91 | enddef |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 92 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 93 | # Reflow paragraphs with mappings like gqtp ("gq TeX paragraph") |
| 94 | onoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr> |
| 95 | # Select TeX paragraph |
| 96 | vnoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr> |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 97 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 98 | # $...$ text object |
| 99 | onoremap <silent><buffer> i$ <scriptcmd>normal! T$vt$<cr> |
| 100 | onoremap <silent><buffer> a$ <scriptcmd>normal! F$vf$<cr> |
| 101 | vnoremap <buffer> i$ T$ot$ |
| 102 | vnoremap <buffer> a$ F$of$ |
Bram Moolenaar | 2286304 | 2021-10-16 15:23:36 +0100 | [diff] [blame] | 103 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 104 | for mapping in ['tp', 'i$', 'a$'] |
| 105 | UndoMap(mapping, 'ov') |
| 106 | endfor |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 107 | endif |
| 108 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 109 | # Commands for asynchronous typesetting |
| 110 | command! -buffer -nargs=? -complete=buffer ConTeXt context.Typeset(<q-args>) |
| 111 | command! -buffer -nargs=0 ConTeXtLog context.Log('%') |
| 112 | command! -nargs=0 ConTeXtJobStatus context.JobStatus() |
| 113 | command! -nargs=0 ConTeXtStopJobs context.StopJobs() |
Bram Moolenaar | 46fceaa | 2016-10-23 21:21:08 +0200 | [diff] [blame] | 114 | |
Bram Moolenaar | e1f3fd1 | 2022-08-15 18:51:32 +0100 | [diff] [blame] | 115 | # vim: sw=2 fdm=marker |