Retab changes all tabs to spaces or vice versa
()
| 1263 | |
| 1264 | // Retab changes all tabs to spaces or vice versa |
| 1265 | func (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 |
nothing calls this directly
no test coverage detected