annotate runtime/autoload/typeset.vim @ 29781:bcb7e4222d17

Added tag v9.0.0229 for changeset 9f8dd1b775634662463d1bef16a2cbf4184086aa
author Bram Moolenaar <Bram@vim.org>
date Sat, 20 Aug 2022 13:15:04 +0200
parents 2acb87ee55fc
children d6dde6229b36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 vim9script
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 # Language: Generic TeX typesetting engine
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 # Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 # Latest Revision: 2022 Aug 12
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 # Constants and helpers {{{
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 const SLASH = !exists("+shellslash") || &shellslash ? '/' : '\'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 def Echo(msg: string, mode: string, label: string)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 redraw
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 echo "\r"
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 execute 'echohl' mode
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 echomsg printf('[%s] %s', label, msg)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 echohl None
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 def EchoMsg(msg: string, label = 'Notice')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 Echo(msg, 'ModeMsg', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 def EchoWarn(msg: string, label = 'Warning')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 Echo(msg, 'WarningMsg', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 def EchoErr(msg: string, label = 'Error')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 Echo(msg, 'ErrorMsg', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 # }}}
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 # Track jobs {{{
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 var running_jobs = {} # Dictionary of job IDs of jobs currently executing
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 def AddJob(label: string, j: job)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 if !has_key(running_jobs, label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 running_jobs[label] = []
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 add(running_jobs[label], j)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 def RemoveJob(label: string, j: job)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 if has_key(running_jobs, label) && index(running_jobs[label], j) != -1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 remove(running_jobs[label], index(running_jobs[label], j))
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 def GetRunningJobs(label: string): list<job>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 return has_key(running_jobs, label) ? running_jobs[label] : []
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 # }}}
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 # Callbacks {{{
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 def ProcessOutput(qfid: number, wd: string, efm: string, ch: channel, msg: string)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 # Make sure the quickfix list still exists
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 if getqflist({'id': qfid}).id != qfid
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 EchoErr("Quickfix list not found, stopping the job")
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 call job_stop(ch_getjob(ch))
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 return
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 # Make sure the working directory is correct
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 silent execute "lcd" wd
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 setqflist([], 'a', {'id': qfid, 'lines': [msg], 'efm': efm})
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 silent lcd -
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 def CloseCb(ch: channel)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 job_status(ch_getjob(ch)) # Trigger exit_cb's callback
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 def ExitCb(label: string, jobid: job, exitStatus: number)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 RemoveJob(label, jobid)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 if exitStatus == 0
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 botright cwindow
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 EchoMsg('Success!', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 elseif exitStatus < 0
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 EchoWarn('Job terminated', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 else
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 botright copen
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 wincmd p
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 EchoWarn('There are errors.', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 # }}}
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 # Create a new empty quickfix list at the end of the stack and return its id {{{
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 def NewQuickfixList(path: string): number
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 if setqflist([], ' ', {'nr': '$', 'title': path}) == -1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 return -1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 return getqflist({'nr': '$', 'id': 0}).id
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 # }}}
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 # Public interface {{{
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 # When a TeX document is split into several source files, each source file
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 # may contain a "magic line" specifiying the "root" file, e.g.:
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 #
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 # % !TEX root = main.tex
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 #
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 # Using this line, Vim can know which file to typeset even if the current
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 # buffer is different from main.tex.
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 #
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 # This function searches for the magic line in the first ten lines of the
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 # given buffer, and returns the full path of the root document.
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 #
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 # NOTE: the value of "% !TEX root" *must* be a relative path.
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 export def FindRootDocument(bufname: string = bufname("%")): string
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 const bufnr = bufnr(bufname)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 if !bufexists(bufnr)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 return bufname
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 var rootpath = fnamemodify(bufname(bufnr), ':p')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 # Search for magic line `% !TEX root = ...` in the first ten lines
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 const header = getbufline(bufnr, 1, 10)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 const idx = match(header, '^\s*%\s\+!TEX\s\+root\s*=\s*\S')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 if idx > -1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 const main = matchstr(header[idx], '!TEX\s\+root\s*=\s*\zs.*$')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 rootpath = simplify(fnamemodify(rootpath, ":h") .. SLASH .. main)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 return rootpath
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 export def LogPath(bufname: string): string
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 const logfile = FindRootDocument(bufname)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 return fnamemodify(logfile, ":r") .. ".log"
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 # Typeset the specified path
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 #
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 # Parameters:
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 # label: a descriptive string used in messages to identify the kind of job
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 # Cmd: a function that takes the path of a document and returns the typesetting command
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 # path: the path of the document to be typeset. To avoid ambiguities, pass a *full* path.
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 # efm: the error format string to parse the output of the command.
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 # env: environment variables for the process (passed to job_start())
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 #
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 # Returns:
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 # true if the job is started successfully;
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 # false otherwise.
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 export def Typeset(
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 label: string,
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 Cmd: func(string): list<string>,
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 path: string,
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 efm: string,
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 env: dict<string> = {}
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 ): bool
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 var fp = fnamemodify(path, ":p")
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 var wd = fnamemodify(fp, ":h")
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 var qfid = NewQuickfixList(fp)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 if qfid == -1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 EchoErr('Could not create quickfix list', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 return false
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 if !filereadable(fp)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 EchoErr(printf('File not readable: %s', fp), label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 return false
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 var jobid = job_start(Cmd(path), {
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 env: env,
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 cwd: wd,
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 in_io: "null",
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 callback: (c, m) => ProcessOutput(qfid, wd, efm, c, m),
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 close_cb: CloseCb,
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 exit_cb: (j, e) => ExitCb(label, j, e),
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 })
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 if job_status(jobid) ==# "fail"
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 EchoErr("Failed to start job", label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 return false
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 AddJob(label, jobid)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 EchoMsg('Typesetting...', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 return true
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 export def JobStatus(label: string)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 EchoMsg('Jobs still running: ' .. string(len(GetRunningJobs(label))), label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 export def StopJobs(label: string)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 for job in GetRunningJobs(label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 job_stop(job)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 endfor
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 EchoMsg('Done.', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 # Typeset the specified buffer
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 #
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 # Parameters:
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 # name: a buffer's name. this may be empty to indicate the current buffer.
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 # cmd: a function that takes the path of a document and returns the typesetting command
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 # label: a descriptive string used in messages to identify the kind of job
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 # env: environment variables for the process (passed to job_start())
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 #
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 # Returns:
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 # true if the job is started successfully;
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 # false otherwise.
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 export def TypesetBuffer(
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 name: string,
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 Cmd: func(string): list<string>,
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 env = {},
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 label = 'Typeset'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 ): bool
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 const bufname = bufname(name)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 if empty(bufname)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 EchoErr('Please save the buffer first.', label)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 return false
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 const efm = getbufvar(bufnr(bufname), "&efm")
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 const rootpath = FindRootDocument(bufname)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 return Typeset('ConTeXt', Cmd, rootpath, efm, env)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 # }}}
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 # vim: sw=2 fdm=marker