Skip to content

Commit

Permalink
Do not change all suitable space indents into tabs for Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Jul 29, 2024
1 parent f7a5476 commit f3c4580
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

## General

- [ ] In makefiles with 2 space indent, followed by 4 space indent, before all the make targets, do not change the 4 spaces into a tab.
- [ ] When opening a file and pressing `ctrl-f` and then `return`: search for the previously searched for string.
- [ ] Let the status bar be toggled by the `ctrl-o` menu. Let `ctrl-g` when not on a definition do something useful, like cycle indenting a block 0 to 7 indentations.
- [ ] Change the cursor color when it is past 80 lines (or the set wrap width).
Expand Down
24 changes: 19 additions & 5 deletions v2/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,26 @@ func (e *Editor) Save(c *vt100.Canvas, tty *vt100.TTY) error {
s = strings.ReplaceAll(s, fromString, toString)
}
} else if e.mode == mode.Make || e.mode == mode.Just {
// NOTE: This is a hack, that can only replace 10 levels deep.
for level := 10; level > 0; level-- {
fromString := "\n" + strings.Repeat(" ", level*e.indentation.PerTab)
toString := "\n" + strings.Repeat("\t", level)
s = strings.ReplaceAll(s, fromString, toString)
var (
level int
fromString, toString, prevLine string
lines = strings.Split(s, "\n")
)
NEXTLINE:
for i, line := range lines {
// NOTE: This is a hack, that can only replace 10 levels deep.
for level = 10; level > 0; level-- {
if strings.HasPrefix(prevLine, " ") && len(prevLine) > 2 && prevLine[2] != ' ' {
// make no replacements for this case, where the previous line has a 2-space indentation
continue NEXTLINE
}
fromString = "\n" + strings.Repeat(" ", level*e.indentation.PerTab)
toString = "\n" + strings.Repeat("\t", level)
lines[i] = strings.ReplaceAll(lines[i], fromString, toString)
}
prevLine = line
}
s = strings.Join(lines, "\n")
}

// Should the file be saved with the executable bit enabled?
Expand Down

0 comments on commit f3c4580

Please sign in to comment.