Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
context.vim118 linesDownload Raw Back to ftplugin
1vim9script2 3# Vim filetype plugin file4# Language:           ConTeXt typesetting engine5# Maintainer:         Nicola Vitacolonna <nvitacolonna@gmail.com>6# Former Maintainers: Nikolai Weibull <now@bitwi.se>7# Latest Revision:    2026 Jan 108 9if exists("b:did_ftplugin")10  finish11endif12 13import autoload '../autoload/context.vim'14 15b:did_ftplugin = 116 17b:undo_ftplugin = "setl com< cms< def< inc< sua< fo< ofu<"18 19setlocal comments=b:%D,b:%C,b:%M,:%20setlocal commentstring=%\ %s21setlocal formatoptions+=tjcroql222setlocal omnifunc=context.Complete23setlocal suffixesadd=.tex,.mkxl,.mkvi,.mkiv,.mkii24 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 32if exists("g:loaded_matchit") && !exists("b:match_words")33  b:match_ignorecase = 034  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"37endif38 39if !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    }46 47  def UndoMap(mapping: string, modes: string)48    for mode in modes49      b:undo_ftplugin ..= printf(" | silent! execute '%sunmap <buffer> %s'", mode, mapping)50    endfor51  enddef52 53  def MoveAround(count: number, what: string, flags: string)54    search(context_regex[what], flags .. 's')  # 's' sets previous context mark55    var i = 256    while i <= count57      search(context_regex[what], flags)58      i += 159    endwhile60  enddef61 62  # Macros to move around63  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>75 76  for mapping in ['[[', ']]', '[]', '][', '[{', ']}']77    UndoMap(mapping, 'nv')78  endfor79 80  # Other useful mappings81  const tp_regex = '?^$\|^\s*\\\(item\|start\|stop\|blank\|\%(sub\)*section\|chapter\|\%(sub\)*subject\|title\|part\)'82 83  def TeXPar()84    cursor(search(tp_regex, 'bcW') + 1, 1)85    normal! V86    cursor(search(tp_regex, 'W') - 1, 1)87  enddef88 89  # Reflow paragraphs with mappings like gqtp ("gq TeX paragraph")90  onoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr>91  # Select TeX paragraph92  vnoremap <silent><buffer> tp <scriptcmd>TeXPar()<cr>93 94  # $...$ text object95  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$99 100  for mapping in ['tp', 'i$', 'a$']101    UndoMap(mapping, 'ov')102  endfor103endif104 105if !exists('current_compiler')106  b:undo_ftplugin ..= "| compiler make"107  compiler context108endif109 110b:undo_ftplugin ..= "| sil! delc -buffer ConTeXt | sil! delc -buffer ConTeXtLog | sil! delc -buffer ConTeXtJobStatus | sil! delc -buffer ConTeXtStopJobs"111# Commands for asynchronous typesetting112command! -buffer -nargs=? -complete=buffer ConTeXt          context.Typeset(<q-args>)113command! -buffer -nargs=0                  ConTeXtLog       context.Log(bufname('%'))114command!         -nargs=0                  ConTeXtJobStatus context.JobStatus()115command!         -nargs=0                  ConTeXtStopJobs  context.StopJobs()116 117# vim: sw=2 fdm=marker118 
codekingpro/portable-devtools · Team Ai