blob: e42b99e2e9fb583820791306e7caa2dc3e73d707 [file] [log] [blame]
Bram Moolenaare1f3fd12022-08-15 18:51:32 +01001vim9script
Bram Moolenaar46fceaa2016-10-23 21:21:08 +02002
Bram Moolenaare1f3fd12022-08-15 18:51:32 +01003# Language: ConTeXt typesetting engine
4# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
5# Former Maintainers: Nikolai Weibull <now@bitwi.se>
6# Latest Revision: 2022 Aug 12
Bram Moolenaar46fceaa2016-10-23 21:21:08 +02007
Bram Moolenaare1f3fd12022-08-15 18:51:32 +01008# Typesetting {{{
9import autoload './typeset.vim'
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020010
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010011export def ConTeXtCmd(path: string): list<string>
12 return ['mtxrun', '--script', 'context', '--nonstopmode', '--autogenerate', path]
13enddef
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020014
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010015export def Typeset(bufname: string, env = {}, Cmd = ConTeXtCmd): bool
16 return typeset.TypesetBuffer(bufname, Cmd, env, 'ConTeXt')
17enddef
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020018
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010019export def JobStatus()
20 typeset.JobStatus('ConTeXt')
21enddef
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020022
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010023export def StopJobs()
24 typeset.StopJobs('ConTeXt')
25enddef
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020026
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010027export def Log(bufname: string)
28 execute 'edit' typeset.LogPath(bufname)
29enddef
30# }}}
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020031
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010032# Completion {{{
33def BinarySearch(base: string, keywords: list<string>): list<string>
34 const pat = '^' .. base
35 const len = len(keywords)
36 var res = []
37 var lft = 0
38 var rgt = len
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020039
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010040 # Find the leftmost index matching base
41 while lft < rgt
42 var i = (lft + rgt) / 2
43 if keywords[i] < base
44 lft = i + 1
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020045 else
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010046 rgt = i
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020047 endif
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010048 endwhile
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020049
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010050 while lft < len && keywords[lft] =~ pat
51 add(res, keywords[lft])
52 lft += 1
53 endwhile
54
55 return res
56enddef
57
58var isMetaPostBlock = false
59
60var MP_KEYWORDS: list<string> = []
61var CTX_KEYWORDS: list<string> = []
62
63# Complete only MetaPost keywords in MetaPost blocks, and complete only
64# ConTeXt keywords otherwise.
65export def Complete(findstart: number, base: string): any
66 if findstart == 1
67 if len(synstack(line("."), 1)) > 0 && synIDattr(synstack(line("."), 1)[0], "name") ==# 'contextMPGraphic'
68 isMetaPostBlock = true
69 return match(getline('.'), '\S\+\%' .. col('.') .. 'c')
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020070 endif
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020071
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010072 # Complete only \commands starting with a backslash
73 isMetaPostBlock = false
74 var pos = match(getline('.'), '\\\zs\S\+\%' .. col('.') .. 'c')
75 return (pos == -1) ? -3 : pos
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020076 endif
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010077
78 if isMetaPostBlock
79 if empty(MP_KEYWORDS)
80 MP_KEYWORDS = sort(syntaxcomplete#OmniSyntaxList(['mf\w\+', 'mp\w\+']))
81 endif
82 return BinarySearch(base, MP_KEYWORDS)
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020083 endif
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020084
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010085 if empty(CTX_KEYWORDS)
86 CTX_KEYWORDS = sort(syntaxcomplete#OmniSyntaxList([
87 'context\w\+', 'texAleph', 'texEtex', 'texLuatex', 'texOmega',
88 'texPdftex', 'texTex', 'texXeTeX'
89 ]))
90 endif
91 return BinarySearch(base, CTX_KEYWORDS)
92enddef
93# }}}
Bram Moolenaar46fceaa2016-10-23 21:21:08 +020094
Bram Moolenaare1f3fd12022-08-15 18:51:32 +010095# vim: sw=2 fdm=marker