Skip to content

Commit a43c5f5

Browse files
michiccpatthoyts
authored andcommitted
git-gui: add configurable tab size to the diff view
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 <[email protected]> Signed-off-by: Pat Thoyts <[email protected]>
1 parent a3b3ae3 commit a43c5f5

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

git-gui.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ set default_config(gui.fontdiff) [font configure font_diff]
912912
set default_config(gui.maxfilesdisplayed) 5000
913913
set default_config(gui.usettk) 1
914914
set default_config(gui.warndetachedcommit) 1
915+
set default_config(gui.tabsize) 8
915916
set font_descs {
916917
{fontui font_ui {mc "Main Font"}}
917918
{fontdiff font_diff {mc "Diff/Console Font"}}

lib/diff.tcl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# git-gui diff viewer
22
# Copyright (C) 2006, 2007 Shawn Pearce
33

4+
proc apply_tab_size {{firsttab {}}} {
5+
global have_tk85 repo_config ui_diff
6+
7+
set w [font measure font_diff "0"]
8+
if {$have_tk85 && $firsttab != 0} {
9+
$ui_diff configure -tabs [list [expr {$firsttab * $w}] [expr {($firsttab + $repo_config(gui.tabsize)) * $w}]]
10+
} elseif {$have_tk85 || $repo_config(gui.tabsize) != 8} {
11+
$ui_diff configure -tabs [expr {$repo_config(gui.tabsize) * $w}]
12+
} else {
13+
$ui_diff configure -tabs {}
14+
}
15+
}
16+
417
proc clear_diff {} {
518
global ui_diff current_diff_path current_diff_header
619
global ui_index ui_workdir
@@ -105,6 +118,8 @@ proc show_diff {path w {lno {}} {scroll_pos {}} {callback {}}} {
105118

106119
set cont_info [list $scroll_pos $callback]
107120

121+
apply_tab_size 0
122+
108123
if {[string first {U} $m] >= 0} {
109124
merge_load_stages $path [list show_unmerged_diff $cont_info]
110125
} elseif {$m eq {_O}} {
@@ -401,7 +416,10 @@ proc read_diff {fd conflict_size cont_info} {
401416

402417
# -- Automatically detect if this is a 3 way diff.
403418
#
404-
if {[string match {@@@ *} $line]} {set is_3way_diff 1}
419+
if {[string match {@@@ *} $line]} {
420+
set is_3way_diff 1
421+
apply_tab_size 1
422+
}
405423

406424
if {$::current_diff_inheader} {
407425

lib/option.tcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ proc do_options {} {
161161
{b gui.warndetachedcommit {mc "Warn before committing to a detached head"}}
162162
{s gui.stageuntracked {mc "Staging of untracked files"} {list "yes" "no" "ask"}}
163163
{b gui.displayuntracked {mc "Show untracked files"}}
164+
{i-1..99 gui.tabsize {mc "Tab spacing"}}
164165
} {
165166
set type [lindex $option 0]
166167
set name [lindex $option 1]

0 commit comments

Comments
 (0)