vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit a670b75622941fdc87ace904db804089328f1a74 parent 464221817ac1a52b5fceb5ddc48d9ceb3eaaf47f Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 15 Apr 2016 21:03:06 +0200 vis-lua: add file.newlines to detect type of new lines Diffstat:
| M | README.md | | | 1 | + |
| M | vis-lua.c | | | 16 | ++++++++++++++++ |
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md @@ -593,6 +593,7 @@ At this time there exists no API stability guarantees. - `lines_iterator()` - `name` - `lines[0..#lines+1]` array giving read/write access to lines + - `newlines` type of newlines either `"nl"` or `"crnl"` - `window` - `file` - `syntax` lexer name used for syntax highlighting or `nil` diff --git a/vis-lua.c b/vis-lua.c @@ -637,10 +637,26 @@ static int file_index(lua_State *L) { lua_pushstring(L, file->name); return 1; } + if (strcmp(key, "lines") == 0) { obj_ref_new(L, file->text, "vis.file.text"); return 1; } + + if (strcmp(key, "newlines") == 0) { + switch (text_newline_type(file->text)) { + case TEXT_NEWLINE_NL: + lua_pushstring(L, "nl"); + break; + case TEXT_NEWLINE_CRNL: + lua_pushstring(L, "crnl"); + break; + default: + lua_pushnil(L); + break; + } + return 1; + } } return index_common(L);