git-gui: add configurable tab size to the diff view
authorMichael Lutz <michi@icosahedron.de>
Sun, 12 Feb 2012 15:55:17 +0000 (16:55 +0100)
committerPat Thoyts <patthoyts@users.sourceforge.net>
Mon, 6 Oct 2014 09:34:52 +0000 (10:34 +0100)
For Tk 8.5 the "wordprocessor" mode allows us to get a bit fancy for merge
diffs and intend the tabs by one to compensate for the additional diff
marker at the line start.

The code is heavily based on how gitk handles tabs.

Signed-off-by: Michael Lutz <michi@icosahedron.de>
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
git-gui.sh
lib/diff.tcl
lib/option.tcl
index 6cbb36eab6a75aa0b2bdf751eade5a6ae6ea76f2..bf686996164c076150c7a6b9cb2e8c129721810d 100755 (executable)
@@ -912,6 +912,7 @@ set default_config(gui.fontdiff) [font configure font_diff]
 set default_config(gui.maxfilesdisplayed) 5000
 set default_config(gui.usettk) 1
 set default_config(gui.warndetachedcommit) 1
+set default_config(gui.tabsize) 8
 set font_descs {
        {fontui   font_ui   {mc "Main Font"}}
        {fontdiff font_diff {mc "Diff/Console Font"}}
index b0a5180af71ac04c58d2dd44664df98b67d3a770..0d569862156d9e984f3c04f5662880148f92bc21 100644 (file)
@@ -1,6 +1,19 @@
 # git-gui diff viewer
 # Copyright (C) 2006, 2007 Shawn Pearce
 
+proc apply_tab_size {{firsttab {}}} {
+       global have_tk85 repo_config ui_diff
+
+       set w [font measure font_diff "0"]
+       if {$have_tk85 && $firsttab != 0} {
+               $ui_diff configure -tabs [list [expr {$firsttab * $w}] [expr {($firsttab + $repo_config(gui.tabsize)) * $w}]]
+       } elseif {$have_tk85 || $repo_config(gui.tabsize) != 8} {
+               $ui_diff configure -tabs [expr {$repo_config(gui.tabsize) * $w}]
+       } else {
+               $ui_diff configure -tabs {}
+       }
+}
+
 proc clear_diff {} {
        global ui_diff current_diff_path current_diff_header
        global ui_index ui_workdir
@@ -105,6 +118,8 @@ proc show_diff {path w {lno {}} {scroll_pos {}} {callback {}}} {
 
        set cont_info [list $scroll_pos $callback]
 
+       apply_tab_size 0
+
        if {[string first {U} $m] >= 0} {
                merge_load_stages $path [list show_unmerged_diff $cont_info]
        } elseif {$m eq {_O}} {
@@ -401,7 +416,10 @@ proc read_diff {fd conflict_size cont_info} {
 
                # -- Automatically detect if this is a 3 way diff.
                #
-               if {[string match {@@@ *} $line]} {set is_3way_diff 1}
+               if {[string match {@@@ *} $line]} {
+                       set is_3way_diff 1
+                       apply_tab_size 1
+               }
 
                if {$::current_diff_inheader} {
 
index 23c9ae72a43c3f2b6ac0409ded488869f3b2de0d..b5b6b2fea6c29ce7f1deb9e2c23060b92fbd83e4 100644 (file)
@@ -161,6 +161,7 @@ proc do_options {} {
                {b gui.warndetachedcommit {mc "Warn before committing to a detached head"}}
                {s gui.stageuntracked {mc "Staging of untracked files"} {list "yes" "no" "ask"}}
                {b gui.displayuntracked {mc "Show untracked files"}}
+               {i-1..99 gui.tabsize {mc "Tab spacing"}}
                } {
                set type [lindex $option 0]
                set name [lindex $option 1]