Skip to content

Commit f2c18b2

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

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func (w *BufWindow) displayBuffer() {
494494
}
495495
bloc.X = bslice
496496

497-
draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool) {
497+
draw := func(r rune, combc []rune, validrune bool, style tcell.Style, highlight bool, showcursor bool) {
498498
if nColsBeforeStart <= 0 && vloc.Y >= 0 {
499499
if highlight {
500500
if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) {
@@ -571,9 +571,20 @@ func (w *BufWindow) displayBuffer() {
571571
}
572572
}
573573

574-
if r == '\t' {
575-
indentrunes := []rune(b.Settings["indentchar"].(string))
576-
// if empty indentchar settings, use space
574+
if r == '\t' || (r == ' ' && bloc.X < blineLen && validrune) {
575+
var indentrunes []rune
576+
switch r {
577+
case '\t':
578+
indentrunes = []rune(b.Settings["indenttabchar"].(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 no override for current character, use space
577588
if len(indentrunes) == 0 {
578589
indentrunes = []rune{' '}
579590
}
@@ -692,7 +703,7 @@ func (w *BufWindow) displayBuffer() {
692703
// If a word (or just a wide rune) does not fit in the window
693704
if vloc.X+wordwidth > maxWidth && vloc.X > w.gutterOffset {
694705
for vloc.X < maxWidth {
695-
draw(' ', nil, config.DefStyle, false, false)
706+
draw(' ', nil, false, config.DefStyle, false, false)
696707
}
697708

698709
// We either stop or we wrap to draw the word in the next line
@@ -708,7 +719,7 @@ func (w *BufWindow) displayBuffer() {
708719
}
709720

710721
for _, r := range word {
711-
draw(r.r, r.combc, r.style, true, true)
722+
draw(r.r, r.combc, true, r.style, true, true)
712723

713724
// Draw any extra characters either spaces for tabs or @ for incomplete wide runes
714725
if r.width > 1 {
@@ -718,7 +729,7 @@ func (w *BufWindow) displayBuffer() {
718729
}
719730

720731
for i := 1; i < r.width; i++ {
721-
draw(char, nil, r.style, true, false)
732+
draw(char, nil, false, r.style, true, false)
722733
}
723734
}
724735
bloc.X++
@@ -764,7 +775,7 @@ func (w *BufWindow) displayBuffer() {
764775

765776
if vloc.X != maxWidth {
766777
// Display newline within a selection
767-
draw(' ', nil, config.DefStyle, true, true)
778+
draw(' ', nil, false, config.DefStyle, true, true)
768779
}
769780

770781
bloc.X = w.StartCol

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)