Change tabsize in git-gui

I did some research.

The configuration core.whitespace has nothing to do with how tabs are displayed. It is only used for git to recognize tab related whitespace errors. For example: when indent-with-non-tab is enabled, and core.whitespace is set to tabwidth=4, and a line is indented using 4 spaces or more, then git will report an error.

For git, apart from the tab related whitespace error detection features, a tab character is a character like any other character. It gets compared and it gets dumped to whatever tool is used to display the characters. That means, to configure the displayed tab width you have to configure the "front ends" of git. In case of git diff that would be "less" (the unix tool "less"). In case of git gui that would be git-gui itself.

Configuring less is easy. You can set the git configuration core.pager to setup less to display a tab using 4 spaces (less has a parameter -xn to set tabwidth to n).

Configuring git-gui turned out to be considerably harder. Git-gui is written in Tcl/Tk. I found a Tcl/Tk option to configure the tab width in text widgets. I also found a line in git-gui.sh where it looks like the text widget is being initialized.

This is line 3346 of the file git-gui.sh in git version 1.7.5:

catch {$ui_diff configure -tabstyle wordprocessor}

I changed that, according the Tcl/Tk manual, to:

catch {$ui_diff configure -tabs "[expr {4 * [font measure $font 0]}]" -tabstyle wordprocessor}

That did not seem to have any effect. I tried different values for -tabs and they did have some effect on displayed tab width, so it seems to be the correct line to modify.

Unfortunately, Tcl/Tk does not seem to have a notion of tab width in terms of characters, instead, the tab width has to be set in pixels or centimeters.

Note that I have no experience in Tcl/TK whatsoever, so maybe I am just overlooking something simple here.

Anyway, now you know where to start digging. Remember to report back here if you have a working solution. Good luck.


As of git-gui-0.20 and git 2.4.0 (commit) a configuration parameter exists which has been added to configure the displayed tabsize in git gui.

Add this to your ~/.gitconfig

[gui]
    tabsize = 4

or change it via the configuration menu of git-gui (Edit -> Options...)


I elaborated research made by lesmana.

The line

catch {$ui_diff configure -tabstyle wordprocessor}`

mentioned by lesmana should be replaced with following:

catch {$ui_diff configure -tabs "[expr {[get_config gui.tabsize] * [font measure font_diff 0]}] left" -tabstyle wordprocessor}

After doing this one can tune tab size using option "tabsize" in [gui] section of git configuration file (aka gui.tabsize). Bad news:

  1. Some tabs after last non-whitespace character turn into simple spaces. This looks like a bug in tcl.
  2. One has to restart git-gui after changing font size to get correct tabs. Who knows how to resolve it?

Tested with:

  • git-gui version 0.13.0.8.g8f85
  • git version 1.7.4.1
  • tcl version 8.4.16-2 (Ubuntu 11.04 i386 package)

Tags:

Git

Git Gui