2 # Copyright Simon Lydell 2015.
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 notation = require('vim-like-key-notation')
21 prefs = require('./prefs')
22 utils = require('./utils')
24 applyMigrations = (migrations) ->
25 for migration, index in migrations
26 pref = "migration.#{ index }.applied"
27 # This allows to manually choose migrations to apply. Be careful, though,
28 # since some migrations might have to run in order!
29 unless prefs.has(pref) and prefs.get(pref)
34 commaSeparatedList = /.[^,]*,?/g
36 commaSeparatedListItem = ///^
38 (?: (Shift) | ([acm])+ )
45 convertKey = (keyStr) ->
46 return keyStr.match(commaSeparatedList).map((part) ->
47 [match, shift, modifiers, key] = part.match(commaSeparatedListItem)
49 return notation.stringify({
51 shiftKey: Boolean(shift)
52 altKey: 'a' in modifiers
53 ctrlKey: 'c' in modifiers
54 metaKey: 'm' in modifiers
58 convertPattern = (pattern) ->
59 return utils.regexpEscape(pattern)
60 .replace(/\\\*/g, '.*')
62 .replace(/\s+/g, '\\s+')
64 splitListString = (str) ->
65 return str.split(/\s*,[\s,]*/)