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