Commits

Steve Borho committed 988cc5f

changeset: support user-defined tab widths

Uses python str.expandtabs() function to expand tabs within the patch
lines before displaying them. This provides correct tab functionality,
but has the downside of making cut-paste of the GUI buffer different
from the actual patch. Since we offer patch export to file
functionality, this is probably a good tradeoff.

Comments (0)

Files changed (2)

hggtk/changeset.py

 
     def prepare_diff(self, difflines, offset, fname):
         '''Borrowed from hgview; parses changeset diffs'''
+        import hglib
+        tw = hglib.gettabwidth(self.ui)
         DIFFHDR = "=== %s ===\n"
         idx = 0
         outlines = []
                 continue
             elif l.startswith("---"):
                 continue
+            elif l.startswith("@@"):
+                tag = "blue"
             elif l.startswith("+"):
                 tag = "green"
                 stats[0] += 1
+                if tw:
+                    l = l[0] + l[1:].expandtabs(tw)
             elif l.startswith("-"):
                 stats[1] += 1
                 tag = "red"
-            elif l.startswith("@@"):
-                tag = "blue"
+                if tw:
+                    l = l[0] + l[1:].expandtabs(tw)
             else:
                 tag = "black"
+                if tw:
+                    l = l[0] + l[1:].expandtabs(tw)
             l = l+"\n"
             length = len(l.decode('utf-8'))
             addtag( tag, offset, length )
             return ''
     return p
 
+def gettabwidth(ui):
+    tabwidth = ui.config('tortoisehg', 'tabwidth')
+    try:
+        tabwidth = int(tabwidth)
+        if tabwidth < 1 or tabwidth > 16:
+            tabwidth = None
+    except (ValueError, TypeError), e:
+        tabwidth = None
+    return tabwidth
+
 
 class GtkUi(ui.ui):
     '''