jim

Simple, lightweight, modal, vim-inspired text editor
git clone git://git.janpasierb.com/jim.git
Log | Files | Refs | README | LICENSE

commit 5792153dbb8c6f871ca8284ab13aaa2b3cb7ba52
parent 1d9b67184ca1e9c1ffadbeab5b82fb9a25a50f81
Author: Jan P. Pasierb <me@janpasierb.com>
Date:   Fri, 22 Dec 2023 23:17:02 +0000

nonexistent file provided as an arg is now auto-created

Diffstat:
Mfile.c | 26+++++++++++++++-----------
Dtest | 1-
2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/file.c b/file.c @@ -40,19 +40,23 @@ void editorOpen(char* filename) { editorSelectSyntaxHighlight(); FILE* fp = fopen(filename, "r"); - if (!fp) die("fopen"); + if (fp) { + char* line = NULL; + size_t linecap = 0; + ssize_t linelen; + while((linelen = getline(&line, &linecap, fp)) != -1) { + while(linelen > 0 && (line[linelen - 1] == '\n' || line[linelen - 1] == RETURN)) + linelen--; + editorInsertRow(E.numrows, line, linelen); + } - char* line = NULL; - size_t linecap = 0; - ssize_t linelen; - while((linelen = getline(&line, &linecap, fp)) != -1) { - while(linelen > 0 && (line[linelen - 1] == '\n' || line[linelen - 1] == RETURN)) - linelen--; - editorInsertRow(E.numrows, line, linelen); - } + free(line); + fclose(fp); + } else { + if(-1 == open(E.filename, O_RDONLY | O_CREAT, 0644)) + die("fopen"); + } - free(line); - fclose(fp); E.dirty = 0; } diff --git a/test b/test @@ -1 +0,0 @@ -