Commits

Nicholas Dudfield committed 05839e1

Before dumping overwrought colemak-qwerty remap

  • Participants
  • Parent commits 0e7ce77

Comments (0)

Files changed (2)

Default (Windows).sublime-keymap

       "alt+r"
     ]
   },
-  {
-    "args": {}, 
-    "command": "half_sels", 
-    "context": [], 
-    "keys": [
-      "alt+w"
-    ]
-  },
  {
     "__doc__" : "Copy this to the end of your User/ keymap",
     "command": "volcanise",
     def __getitem__(self, (x, y)):
         return list.__getitem__(self, y)[x]
 
+class Bindings(object):
+    def __init__(self, layout):
+        self.layout = layout
+
+    def __getattr__(self, attr):
+        try:
+            return self.layout[getattr(self.mapping, attr)]
+        except AttributeError:
+            return object.__getattribute__(self, attr)
+    __getitem__ = __getattr__
+
 @apply
 def generate_bindings():
     layouts = {
 2    z   x   c   v      b   k      m   ,   .   /          """)
 }
 
-    class bindings(object):
-        def __init__(self, layout):
-            self.layout = layout
-        def __getattr__(self, attr):
-            return layouts[self.layout][getattr(self, attr.upper())]
-        __getitem__ = __getattr__
+    class VolcaniseBindings(Bindings):
+        class mapping:
+            up         = (7, 0)
+            down       = (7, 1)
+            left       = (6, 1)
+            right      = (8, 1)
 
-        UP         = (7, 0)
-        DOWN       = (7, 1)
-        LEFT       = (6, 1)
-        RIGHT      = (8, 1)
+            bol        = (5, 1)
+            eol        = (9, 1)
 
-        EOL        = (5, 1)
-        BOL        = (9, 1)
+            word_token = (9, 0)
+            char_token = (8, 0)
 
-        WORD_TOKEN = (9, 0)
-        CHAR_TOKEN = (8, 0)
+        alt   = 'alt'
+        shift = 'shift'
 
-    colemak = bindings('colemak')
+        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
+
 ################################### CONSTANTS ##################################
 
 RE_SPECIAL_CHARS = re.compile (
 OUTLINE            = sublime.DRAW_OUTLINED
 HIDDEN             = sublime.HIDDEN
 
+# This is used to determine if upon landing after pressing a single character
+# jump in `word` mode whether to select the beginning of the view.word(region)
+ALPHABET           = (string.lowercase + string.uppercase) + '_' # digits?
 CHARACTERS         = list(string.printable)[:-6]
 CHARACTERS_PATTERN = '(%s)' % '|'.join(escape_regex(c) for c in CHARACTERS)
 
-# commands
+# Commands
 EXIT               = 'exit'
 REVERSE            = 'reverse'
 
         return (reversed if direction == BACK else iter)(ret)
     return wrapper
 
+#TODO: code folding
 @directioned_visible
 def page_range(visible, leader):
     return ( xrange(*sorted((leader.end() + 1, visible.end()))),
     # ???                           # LandBack states
 
     class defaults:
-        # self.view            = 'indexed here, but set in __new__'
+        # view          = 'indexed here, but set in __new__'
         mode_state      =  "insert"
 
         token_type      =  ''
     def __ne__(self, other):
         return self.mode_state != other
 
-class StateTracker(sublime_plugin.EventListener):
+class StateManager(sublime_plugin.EventListener):
     def on_close(self, view):
         State.forget(view)
 
         if digraph in state.menu_regions:
             region = state.menu_regions[digraph]
             if hasattr(region, 'word'): region = region.word
-            self.land_backs(view, state, region, digraph = 1)
+            self.land_backs(view, state, region)
 
         state.mode_state = state.WAITING
 
-    def land_backs(self, view, state, region, digraph=False):
+    def land_backs(self, view, state, region):
         sel_set   = view.sel()
         leader    = sel_set[0]
 
-        if ( digraph and region.empty() and view.substr(region)
-             in (string.lowercase + string.uppercase) ):
+        if ( region.empty() and state.token_type == 'word' and all (
+            c in ALPHABET for c in ( view.substr(region) +
+                                     view.substr(view.word(region)) ) )):
              region = view.word(region)
 
         direction = sel_direction(leader, state.direction)
         digraph_underlines = []
 
         print_set          = set(CHARACTERS)
+
+        if token_type == 'word':
+            print_set -= set(''.join(map(str, range(10))))
+
         leader             = view.sel()[0]
         visible            = view.visible_region()
 
                     line_numbers.append(reg)
                     digraph_outlines[key] = reg
 
+        # Should paint_regions() regions be
         painted['direction_indicator']  = indicator
         painted['characters']           = characters.values()
         painted['digraph.line_numbers'] = line_numbers
     run(argv=['sys.executable', __file__, '--with-doctest', '-s'])
     print '\nReloads: %s' % times_module_has_been_reloaded
 
-################################################################################
+################################################################################