Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tab-size from EditorConfig #1239

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

krobelus
Copy link
Contributor

@krobelus krobelus commented Oct 15, 2022

For projects that use tab width != 8, we need to set the "tab-size"
config option. Many projects these days state their preference in a
".editorconfig" file.

Add an optional dependency to the EditorConfig library to read such
files. Prefer the tab-size from EditorConfig, over the "tab-size"
config option. Not being able to override the EditorConfig tab-size
seems counterintuitive but I don't see why someone would want that, so
I'd wait until someone complains. If we want that we could implement a
"tab-size-from-editorconfig" option that defaults to true.

Closes #840

@krobelus krobelus force-pushed the tab-size-from-editorconfig branch 4 times, most recently from 491dbe1 to e1fd636 Compare October 20, 2022 20:20
@krobelus krobelus force-pushed the tab-size-from-editorconfig branch from e1fd636 to f5f213d Compare January 6, 2023 07:16
ncurses defines a global variable called TABSIZE which is the number
of columns occupied by a tab character. We set this option to the
value of the tab-size option.  I believe we never rely on TABSIZE
because we always expand tabs to the appropriate number of spaces
before passing them to ncurses.

The following patches will potentially give each screen its own
tab-size, which is not possible with the global TABSIZE, so we should
not be using it anyway.
The next patch wants to pass in a tab-size other than the global
opt_tab_size, so let's add the parameters to enable that.

The next commit really only cares about places where we render diff
hunks. Hence, keep passing "opt_tab_size" (or for brevity, 0) to
calls that never draw diff hunks anyway.
For projects that use tab width != 8, users want to set the "tab-size"
config option.  Many projects these days already state their preference
in a ".editorconfig" file. GitHub honors that file when rendering
diffs and blobs.

Add an optional dependency to the EditorConfig library to read such
files. Prefer the tab-size from EditorConfig, over the "tab-size"
config option. Not being able to override the EditorConfig tab-size
seems counterintuitive but I don't see why someone would want that,
so I'd mayb ewait until someone complains. If we want that we could
implement a "tab-size-from-editorconfig" option that defaults to true.

Implementation hiccups:

Unfortunately, we currently don't always fill "repo.worktree" - only
in the special cases where either of $GIT_WORK_TREE or core.worktree is
defined. Hence we need to run an extra "git rev-parse --show-toplevel".
We do run "git rev-parse --is-inside-worktree [...]" elsewhere but
we can't add "--show-toplevel" to that call or else we'd fail when
run in bare repos.

The use of diff_get_pathname() is a bit wasteful, we should probably
refactor this to just remember the last line of type LINE_DIFF_ADD_FILE
or LINE_DIFF_HEADER.

Closes jonas#840
@krobelus krobelus force-pushed the tab-size-from-editorconfig branch from f5f213d to 6b69ad0 Compare March 5, 2023 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tab width from EditorConfig
1 participant