Skip to content

Commit 636c8a9

Browse files
Adding indenttabchar, indentspacechar and spacechar options
1 parent 98ff79d commit 636c8a9

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

internal/config/settings.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ var defaultCommonSettings = map[string]interface{}{
7070
"hltrailingws": false,
7171
"ignorecase": true,
7272
"incsearch": true,
73-
"indentchar": " ",
73+
"indenttabchar": " ",
74+
"indentspacechar": " ",
75+
"spacechar": " ",
7476
"keepautoindent": false,
7577
"matchbrace": true,
7678
"matchbraceleft": true,
@@ -210,6 +212,13 @@ func validateParsedSettings() error {
210212
}
211213
continue
212214
}
215+
216+
if k == "indentchar" {
217+
// migrate to "indenttabchar" from "indentchar"
218+
parsedSettings["indenttabchar"] = v
219+
err = errors.New("indentchar has been deprecated, use indenttabchar instead")
220+
}
221+
213222
if _, ok := defaults[k]; ok {
214223
if e := verifySetting(k, v, defaults[k]); e != nil {
215224
err = e

internal/display/bufwindow.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,25 @@ func (w *BufWindow) displayBuffer() {
571571
}
572572
}
573573

574-
if r == '\t' {
575-
indentrunes := []rune(b.Settings["indentchar"].(string))
574+
if r == '\t' || (r == ' ' && bloc.X < blineLen) {
575+
var indentrunes []rune
576+
switch r {
577+
case '\t':
578+
indentrunes = []rune(b.Settings["indentchar"].(string))
579+
case ' ':
580+
if bloc.X%tabsize == 0 && bloc.X < leadingwsEnd {
581+
indentrunes = []rune(b.Settings["indentspacechar"].(string))
582+
} else {
583+
indentrunes = []rune(b.Settings["spacechar"].(string))
584+
}
585+
}
586+
587+
if len(indentrunes) == 0 {
588+
r = ' '
589+
} else {
590+
r = indentrunes[0]
591+
}
592+
576593
// if empty indentchar settings, use space
577594
if len(indentrunes) == 0 {
578595
indentrunes = []rune{' '}

runtime/help/options.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,22 @@ Here are the available options:
203203

204204
default value: `true`
205205

206-
* `indentchar`: sets the indentation character. This will not be inserted into
207-
files; it is only a visual indicator that whitespace is present. If set to a
208-
printing character, it functions as a subset of the "show invisibles"
209-
setting available in many other text editors. The color of this character is
210-
determined by the `indent-char` field in the current theme rather than the
211-
default text color.
206+
* `indenttabchar`: sets the indentation character for tabs. This will not be
207+
inserted into files; it is only a visual indicator that whitespace is present.
208+
If set to a printing character, it functions as a subset of the
209+
"show invisibles" setting available in many other text editors. The color of
210+
this character is determined by the `indent-char` field in the current theme
211+
rather than the default text color.
212+
213+
default value: ` ` (space)
214+
215+
* `indentspacechar`: same as `indenttabchar` except for spaces that are at
216+
locations that are divisible by `tabsize`.
217+
218+
default value: ` ` (space)
219+
220+
* `spacechar`: same as `indenttabchar` but for all spaces. `indentspacechar`
221+
takes precedence over this option.
212222

213223
default value: ` ` (space)
214224

0 commit comments

Comments
 (0)