vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 101c0e1ef804eae9729be41192f7c2e01c17e1b4 parent ab448e6b349f2c26b0c382f87d4d530d093c2955 Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 31 Dec 2015 12:28:55 +0100 text: introduce text_newline_insert Diffstat:
| M | text.c | | | 11 | +++++++++++ |
| M | text.h | | | 2 | ++ |
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/text.c b/text.c @@ -664,6 +664,17 @@ bool text_vprintf(Text *txt, size_t pos, const char *format, va_list ap) { return ret; } +bool text_insert_newline(Text *txt, size_t pos) { + switch (text_newline_type(txt)) { + case TEXT_NEWLINE_NL: + return text_insert(txt, pos, "\n", 1); + case TEXT_NEWLINE_CRNL: + return text_insert(txt, pos, "\r\n", 2); + default: + return false; + } +} + static size_t action_undo(Text *txt, Action *a) { size_t pos = EPOS; for (Change *c = a->change; c; c = c->next) { diff --git a/text.h b/text.h @@ -40,6 +40,8 @@ struct stat text_stat(Text*); bool text_appendf(Text*, const char *format, ...); bool text_printf(Text*, size_t pos, const char *format, ...); bool text_vprintf(Text*, size_t pos, const char *format, va_list ap); +/* inserts a line ending character (depending on file type) */ +bool text_insert_newline(Text*, size_t pos); /* insert `len' bytes starting from `data' at `pos' which has to be * in the interval [0, text_size(txt)] */ bool text_insert(Text*, size_t pos, const char *data, size_t len);