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 loads the user config file: config.js and frame.js.
22 createConfigAPI = require('./api')
23 messageManager = require('./message-manager')
24 utils = require('./utils')
26 {OS} = Components.utils.import('resource://gre/modules/osfile.jsm', {})
28 load = (vimfx, callback = ->) ->
29 configDir = vimfx.options.config_file_directory
35 scope = {vimfx: createConfigAPI(vimfx)}
37 # Calling `vimfx.createKeyTrees()` after each `vimfx.set()` that modifies a
38 # shortcut is absolutely redundant and may make Firefox start slower. Do it
40 vimfx.skipCreateKeyTrees = true
41 error = loadFile(configDir, 'config.js', scope)
42 vimfx.skipCreateKeyTrees = false
43 vimfx.createKeyTrees()
49 messageManager.send('loadConfig', null, callback)
51 loadFile = (dir, file, scope) ->
52 expandedDir = utils.expandPath(dir)
53 uri = OS.Path.toFileURI(OS.Path.join(expandedDir, file))
55 Services.scriptloader.loadSubScriptWithOptions(uri, {
56 target: Object.assign({
57 __dirname: OS.Path.toFileURI(expandedDir)
64 console.error("VimFx: Error loading #{file}", uri, error)