2 # Copyright Simon Lydell 2016.
4 # This file is part of VimFx.
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.
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.
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/>.
20 # This file defines VimFx’s config file API, for the frame script.
22 messageManager = require('./message-manager')
24 createConfigAPI = (vim, onShutdown = module.onShutdown) -> {
25 listen: (message, listener) ->
26 unless typeof message == 'string'
28 "VimFx: The first argument must be a message string. Got: #{message}"
30 unless typeof listener == 'function'
32 "VimFx: The second argument must be a listener function.
35 messageManager.listen(message, listener, {
40 setHintMatcher: (hintMatcher) ->
41 unless typeof hintMatcher == 'function'
43 "VimFx: A hint matcher must be a function. Got: #{hintMatcher}"
45 vim.hintMatcher = hintMatcher
46 onShutdown(-> vim.hintMatcher = null)
48 getMarkerElement: (id) ->
49 data = vim.state.markerElements[id]
50 return if data then data.element else null
53 module.exports = createConfigAPI