diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-03-28 12:10:03 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-03-28 12:25:06 +0200 |
| commit | 64e204b205f09fdbac728c8910bf1867c286ebaa (patch) | |
| tree | 36c4c91247f59ab9e13336d090dc5cdde9a754d7 /main.c | |
| parent | 647dc4c030c0ee876d85de0447f4d706d600d3f6 (diff) | |
| download | vis-64e204b205f09fdbac728c8910bf1867c286ebaa.tar.gz vis-64e204b205f09fdbac728c8910bf1867c286ebaa.tar.xz | |
vis: support column based alignment
That is when multiple cursors are on the same line, the first
cursor on every line is aligned, then the second one and so on.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 49 |
1 files changed, 27 insertions, 22 deletions
@@ -1224,34 +1224,39 @@ static const char *cursors_align(Vis *vis, const char *keys, const Arg *arg) { static const char *cursors_align_indent(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); Text *txt = vis_text(vis); - int mincol = INT_MAX, maxcol = 0; - - for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) { - int col = text_line_width_get(txt, view_cursors_pos(c)); - if (col < mincol) - mincol = col; - if (col > maxcol) - maxcol = col; - } + bool left_align = arg->i < 0; + int columns = view_cursors_column_count(view); + + for (int i = 0; i < columns; i++) { + int mincol = INT_MAX, maxcol = 0; + for (Cursor *c = view_cursors_column(view, i); c; c = view_cursors_column_next(c, i)) { + int col = text_line_width_get(txt, view_cursors_pos(c)); + if (col < mincol) + mincol = col; + if (col > maxcol) + maxcol = col; + } - size_t len = maxcol - mincol; - char *buf = malloc(len+1); - if (!buf) - return keys; - memset(buf, ' ', len); + size_t len = maxcol - mincol; + char *buf = malloc(len+1); + if (!buf) + return keys; + memset(buf, ' ', len); - for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) { - size_t pos = view_cursors_pos(c); - int col = text_line_width_get(txt, pos); - if (col < maxcol) { - size_t off = maxcol - col; - if (off <= len) - text_insert(txt, pos, buf, off); + for (Cursor *c = view_cursors_column(view, i); c; c = view_cursors_column_next(c, i)) { + size_t pos = view_cursors_pos(c); + int col = text_line_width_get(txt, pos); + if (col < maxcol) { + size_t off = maxcol - col; + if (off <= len) + text_insert(txt, pos, buf, off); + } } + + free(buf); } view_draw(view); - free(buf); return keys; } |
