]> git.gir.st - VimFx.git/blob - extension/lib/api-frame.coffee
Treat everything in the devtools as adjustable
[VimFx.git] / extension / lib / api-frame.coffee
1 ###
2 # Copyright Simon Lydell 2016.
3 #
4 # This file is part of VimFx.
5 #
6 # VimFx is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # VimFx is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
18 ###
19
20 # This file defines VimFx’s config file API, for the frame script.
21
22 messageManager = require('./message-manager')
23
24 createConfigAPI = (vim, onShutdown = module.onShutdown) -> {
25 listen: (message, listener) ->
26 unless typeof message == 'string'
27 throw new Error("VimFx: The first argument must be a message string.
28 Got: #{message}")
29 unless typeof listener == 'function'
30 throw new Error("VimFx: The second argument must be a listener function.
31 Got: #{listener}")
32 messageManager.listen(message, listener, {
33 prefix: 'config:'
34 onShutdown
35 })
36
37 setHintMatcher: (hintMatcher) ->
38 unless typeof hintMatcher == 'function'
39 throw new Error("VimFx: A hint matcher must be a function.
40 Got: #{hintMatcher}")
41 vim.hintMatcher = hintMatcher
42 onShutdown(-> vim.hintMatcher = null)
43 }
44
45 module.exports = createConfigAPI
Imprint / Impressum