MCPcopy Index your code
hub / github.com/micro-editor/micro / Retab

Method Retab

internal/buffer/buffer.go:1265–1291  ·  view source on GitHub ↗

Retab changes all tabs to spaces or vice versa

()

Source from the content-addressed store, hash-verified

1263
1264// Retab changes all tabs to spaces or vice versa
1265func (b *Buffer) Retab() {
1266 toSpaces := b.Settings["tabstospaces"].(bool)
1267 tabsize := util.IntOpt(b.Settings["tabsize"])
1268
1269 for i := 0; i < b.LinesNum(); i++ {
1270 l := b.LineBytes(i)
1271
1272 ws := util.GetLeadingWhitespace(l)
1273 if len(ws) != 0 {
1274 if toSpaces {
1275 ws = bytes.ReplaceAll(ws, []byte{'\t'}, bytes.Repeat([]byte{' '}, tabsize))
1276 } else {
1277 ws = bytes.ReplaceAll(ws, bytes.Repeat([]byte{' '}, tabsize), []byte{'\t'})
1278 }
1279 }
1280
1281 l = bytes.TrimLeft(l, " \t")
1282
1283 b.Lock()
1284 b.lines[i].data = append(ws, l...)
1285 b.Unlock()
1286
1287 b.MarkModified(i, i)
1288 }
1289
1290 b.setModified()
1291}
1292
1293// ParseCursorLocation turns a cursor location like 10:5 (LINE:COL)
1294// into a loc

Callers

nothing calls this directly

Calls 8

IntOptFunction · 0.92
GetLeadingWhitespaceFunction · 0.92
MarkModifiedMethod · 0.80
setModifiedMethod · 0.80
LinesNumMethod · 0.65
LineBytesMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected