Commits

Nicholas Dudfield committed 61598c0

Reversed digraphs working for 2 char regions

  • Participants
  • Parent commits 05e2b61

Comments (0)

Files changed (2)

File volcanise.py

 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
 
+class bunch(dict):
+    def __init__(self, *args):
+        dict.__init__(self, *args)
+        self.__dict__ = self
+
 def directioned_visible(f):
     @wraps(f)
     def wrapper(view, trend):
     substr = view.substr(region)
 
     if isinstance(pattern, basestring):
-        pattern = re.compile(pattern)
+        pattern = re.compile(pattern, flags)
 
     finds = []
     for m in pattern.finditer(substr):
     # region keys and the scope flags used by view.add_regions
     REGIONS       = {
         'digraph.underlines'            : [ '$scope',           UNDERLINE],
-        'digraph.reversed_underlines'   : [ '$scope',           UNDERLINE],
+        'digraph.reversed_underlines'   : [ '$scope',           UNDERLINE | OUTLINE],
         'digraph.outlines'              : [ '$scope',           OUTLINE],
         'digraph.line_numbers'          : [('$scope', '$icon'), HIDDEN],
         'direction_indicator'           : [ '$scope',           UNDERLINE],
         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)
+             
+             if view.word(region).end() != region.begin():
+                region = view.word(region)
 
         direction = sel_direction(leader, state.direction)
         extend    = len(leader) and not view.get_regions('auto_select')
         trend              = state.direction
         token_type         = state.token_type
 
-        painted            = {}
-
-        characters         = {}
-        line_numbers       = []
-        digraph_outlines   = {}
-        digraph_underlines = []
+        characters                  = {}
+        line_numbers                = []
+        digraph_outlines            = {}
+        digraph_underlines          = []
         digraph_reversed_underlines = []
 
         print_set          = set(CHARACTERS)
                     if word.isdigit(): continue
                     found = False
 
-                    for is_reversed, word in enumerate((word, word[::1])):
+                    for is_reversed in range(2):
                         if found: break
                         if is_reversed: word = word[::-1]
 
                             found = None
 
                             if is_reversed:
-                                pts  = ( region.end() - end - 1,
-                                         region.end() - start)
+                                pts  = ( region.end() - start,
+                                         region.end() - end - 1)
                             else:
                                 pts = ( region.begin() + start,
                                         region.begin() + end + 1 )
                                 if token_type == 'word' and ch in characters:
                                     characters.pop(ch)
 
-                                r = digraph_outlines[digraph] = sublime.Region(
-                                                                         *pts )
+                                r = digraph_outlines[digraph] = sublime.Region(*pts)
                                 r.word = region
 
-                                if abs(start - end) > 1:
-                                    for pt in (r.begin(), r.end() -1):
-                                        digraph_underlines.append (
-                                            sublime.Region(pt) )
-                                    if is_reversed:
-                                        digraph_reversed_underlines.append(
-                                            digraph_underlines.pop(-1)
-                                        )
+                                for pt in (r.begin(), r.end() -1):
+                                    digraph_underlines.append(
+                                        sublime.Region(pt) )
+                                if is_reversed:
+                                    digraph_reversed_underlines.append(
+                                        digraph_underlines.pop())
                                 break
 
         indicator = [sublime.Region(leader.b + min(0, state.direction))]
 
+        # Line number gutter jumps
         if token_type == 'word':
             start, end   = [view.rowcol(pt)[0] for pt in ( visible.begin(),
                                                            visible.end() )]
 
             for ln in xrange(start, end+1):
-                key = str(ln+1)[-2:]
-                if len(key) == 1: key = '0' + key
+                key = ('%02d' % (ln+1))[-2:]
 
                 if ( key[0] not in characters
                      and key not in digraph_outlines ):
                     digraph_outlines[key] = reg
 
         # Should paint_regions() regions be a State method?
-        painted['direction_indicator']  = indicator
-        painted['characters']           = characters.values()
-        painted['digraph.line_numbers'] = line_numbers
-        painted['digraph.outlines']     = digraph_outlines.values()
-        painted['digraph.underlines']   = digraph_underlines
-        painted['digraph.reversed_underlines']   = digraph_reversed_underlines
+        painted=(
+            ('direction_indicator',          indicator),
+            ('characters',                   characters.values()),
+            ('digraph.outlines',             digraph_outlines.values()),
+            ('digraph.line_numbers',         line_numbers),
+            ('digraph.reversed_underlines',  digraph_reversed_underlines),
+            ('digraph.underlines',           digraph_underlines),
+        )
 
-        for k, v in painted.items(): state.paint_regions(k, v)
-
+        for k, v in painted: state.paint_regions(k, v)
         if token_type == 'word': characters.update(digraph_outlines)
         state.menu_regions = characters
 

File volcanise.sublime-settings

 
     "region_scopes" : {
         "digraph.underlines"            : "support",
-        "digraph.reversed_underlines"   : "entity",
+        "digraph.reversed_underlines"   : "string",
         "digraph.outlines"              : "entity",
         "digraph.line_numbers"          : ["entity", "bookmark"],
         "characters"                    : "string",