]> git.gir.st - VimFx.git/blob - extension/lib/api-frame.coffee
Fix the `yy` command in Reader View
[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(
28 "VimFx: The first argument must be a message string. Got: #{message}"
29 )
30 unless typeof listener == 'function'
31 throw new Error(
32 "VimFx: The second argument must be a listener function.
33 Got: #{listener}"
34 )
35 messageManager.listen(message, listener, {
36 prefix: 'config:'
37 onShutdown
38 })
39
40 setHintMatcher: (hintMatcher) ->
41 unless typeof hintMatcher == 'function'
42 throw new Error(
43 "VimFx: A hint matcher must be a function. Got: #{hintMatcher}"
44 )
45 vim.hintMatcher = hintMatcher
46 onShutdown(-> vim.hintMatcher = null)
47
48 getMarkerElement: (id) ->
49 data = vim.state.markerElements[id]
50 return if data then data.element else null
51 }
52
53 module.exports = createConfigAPI
Imprint / Impressum