Commits

Nicholas Dudfield committed 3fdc461

Added in qwerty bindings generator dumped to Default.qwerty-keymap

Comments (0)

Files changed (2)

Default (Windows).sublime-keymap

 [
   {
-    //"argr_comment": "TODO", 
-    "args": {
-      "token_type": "word"
-    }, 
-    "command": "volcanise", 
-    "context": [
-      {
-        "key": "setting.volcanise", 
-        "operand": false, 
-        "operator": "equal"
-      }
-    ], 
-    "keys": [
-      "alt+pause"
-    ]
-  }, 
-  {
-    //"argr_comment": "TODO", 
     "args": {
       "token_type": "char",
       "cmd" : "toggle"
     ]
   }, 
   {
-    //"argr_comment": "TODO", 
     "args": {
       "token_type": "word",
       "cmd": "toggle"
     "command": "volcanise", 
     "context": [], 
     "keys": [
-      "alt+semicolon"
+      "alt+;"
     ]
   }, 
   {
-    //"argr_comment": "TODO", 
     "args": {
       "cmd": "exit"
     }, 
   },
   {
     "args": {
-      "panel": "incremental_find", 
-      "reverse": false
-    }, 
-    "command": "show_panel", 
-    "context": [
-      {
-        "key": "setting.volcanise", 
-        "operand": true, 
-        "operator": "equal"
-      }
-    ], 
-    "keys": [
-      "alt+f"
-    ]
-  }, 
-  {
-    "args": {
       "by": "words", 
       "extend": false, 
       "forward": false
           "command": "move"
         }, 
         {
-          //"argr_comment": "TODO", 
           "args": {
             "token_type": "word"
           }, 
           "command": "move"
         }, 
         {
-          //"argr_comment": "TODO", 
           "args": {
             "token_type": "word"
           }, 
           "command": "move"
         }, 
         {
-          //"argr_comment": "TODO", 
           "args": {
             "token_type": "word"
           }, 
           "command": "move"
         }, 
         {
-          //"argr_comment": "TODO", 
           "args": {
             "token_type": "word"
           }, 
           "command": "move"
         }, 
         {
-          //"argr_comment": "TODO", 
           "args": {
             "token_type": "word"
           }, 
           "command": "move"
         }, 
         {
-          //"argr_comment": "TODO", 
           "args": {
             "token_type": "word"
           }, 
           "command": "move"
         }, 
         {
-          //"argr_comment": "TODO", 
           "args": {
             "token_type": "word"
           }, 
           "command": "move"
         }, 
         {
-          //"argr_comment": "TODO", 
           "args": {
             "token_type": "word"
           }, 
   }, 
   {
     "args": {
-      "by": "words", 
-      "extend": false, 
-      "forward": false
-    }, 
-    "command": "move", 
-    "context": [
-      {
-        "key": "setting.volcanise", 
-        "operand": true, 
-        "operator": "equal"
-      }
-    ], 
-    "keys": [
-      "ctrl+alt+n"
-    ]
-  }, 
-  {
-    "args": {
-      "by": "words", 
-      "extend": false, 
-      "forward": true
-    }, 
-    "command": "move", 
-    "context": [
-      {
-        "key": "setting.volcanise", 
-        "operand": true, 
-        "operator": "equal"
-      }
-    ], 
-    "keys": [
-      "ctrl+alt+i"
-    ]
-  }, 
-  {
-    "args": {
       "to": "word"
     }, 
     "command": "expand_selection", 
   }, 
   {
     "args": {
-      "by": "pages", 
-      "extend": false, 
-      "forward": false
-    }, 
-    "command": "move", 
-    "context": [
-      {
-        "key": "setting.volcanise", 
-        "operand": true, 
-        "operator": "equal"
-      }
-    ], 
-    "keys": [
-      "ctrl+alt+u"
-    ]
-  }, 
-  {
-    "args": {
-      "by": "pages", 
-      "extend": false, 
-      "forward": true
-    }, 
-    "command": "move", 
-    "context": [
-      {
-        "key": "setting.volcanise", 
-        "operand": true, 
-        "operator": "equal"
-      },
-      {
-        "key": "setting.auto_select", 
-        "operand": false, 
-        "operator": "equal"
-      }
-    ], 
-    "keys": [
-      "ctrl+alt+e"
-    ]
-  }, 
-  {
-    "args": {
       "by": "characters", 
       "extend": true, 
       "forward": false
     ]
   }, 
   {
-    //"argr_comment": "TODO", 
     "args": {
       "cmd": "reverse"
     }, 
 import re
 
 from functools import wraps
+from os.path import join
 
 # Sublime Libs
 import sublime
 
 ################################### BINDINGS ###################################
 
-class layout(list):
-    def __init__(self, text_repr):
-        for ln in (l for l in text_repr.strip().splitlines()[1:] if l.strip()):
-            self.append(ln.split()[1:])
-    def __getitem__(self, (x, y)):
-        return list.__getitem__(self, y)[x]
+def test_generate_bindings():
+    # Hijack `only loaded more than once` nose testing machinery
+    colemak_qwerty = { ':': 'P', ';': 'p', 'd': 'g', 'e': 'k', 'f': 'e',
+                       'g': 't', 'i': 'l', 'j': 'y', 'k': 'n', 'l': 'u',
+                       'n': 'j', 'o': ';', 'p': 'r', 'r': 's', 's': 'd',
+                       't': 'f', 'u': 'i', 'y': 'o' }
 
-class Bindings(object):
-    def __init__(self, layout):
-        self.layout = layout
+    pth = lambda p: join( sublime.packages_path(), 'Volcanise', p)
 
-    def __getattr__(self, attr):
-        try:
-            return self.layout[getattr(self.mapping, attr)]
-        except AttributeError:
-            return object.__getattribute__(self, attr)
-    __getitem__ = __getattr__
+    with open(pth('Default (Windows).sublime-keymap'), 'r') as fh:
+        bindings = json.load(fh)
+        for binding in bindings:
+            binding['keys'] = [ '+'.join ( colemak_qwerty.get(el, el)
+                              for el in key.split('+') ) for key in
+                              binding.get('keys', []) ]
 
-@apply
-def generate_bindings():
-    layouts = {
-    "qwerty" :  layout("""
-x   0   1   2   3      4   5      6   7   8   9     10 11
-0  q   w   e   r      t   y      u   i   o   p     [  ]
-1   a   s   d   f      g   h      j   k   l   ;     '  \\
-2    z   x   c   v      b   n      m   ,   .   /          """),
-
-    "colemak" :  layout("""
-x   0   1   2   3      4   5      6   7   8   9      10 11
-0  q   w   f   p      g   j      l   u   y   ;      [  ]
-1   a   r   s   t      d   h      n   e   i   o      '  \\
-2    z   x   c   v      b   k      m   ,   .   /          """)
-}
-
-    class VolcaniseBindings(Bindings):
-        class mapping:
-            up         = (7, 0)
-            down       = (7, 1)
-            left       = (6, 1)
-            right      = (8, 1)
-
-            bol        = (5, 1)
-            eol        = (9, 1)
-
-            word_token = (9, 0)
-            char_token = (8, 0)
-
-        alt   = 'alt'
-        shift = 'shift'
-
-        class move_commands:
-            move_to = [ ('alt+bols',  'bol', 'extends'),
-                        ('alt+eol',  'eol',  'extends')]
-
-            move    = [ ('alt+left',  'words'),
-                        ('alt+right', 'word_ends') ]
-
-    colemak = VolcaniseBindings(layouts['colemak'])
-
-    assert colemak.up == 'u'
-    assert colemak.left == 'n'
-    assert json.dumps({"up" : "%(up)s" % colemak}) == '{"up": "u"}'
-
-    qwerty = VolcaniseBindings(layouts['qwerty'])
-    assert qwerty.word_token == 'p'
-    assert qwerty['alt'] == 'alt'
-    print qwerty.move_commands.move_to[0][0] % qwerty
+        with open(pth('Default.qwerty-keymap'), 'w') as fh:
+            json.dump(bindings, fh, indent=4)
 
 ################################### CONSTANTS ##################################
 
 
 #################################### HELPERS ###################################
 
-
 def empty(r):                      return sublime.Region(r.begin())
 def rev_sel(r):                    return sublime.Region(r.b, r.a)
 def sel_direction(sel, zero=FWD):  return cmp(sel.b, sel.a) or zero
         sel_set   = view.sel()
         leader    = sel_set[0]
 
+        # TODO:
         if ( region.empty() and state.token_type == 'word' and all (
             c in ALPHABET for c in ( view.substr(region) +
                                      view.substr(view.word(region)) ) )):