# load generate dependencies
-include *.d lib/*.d tests/*.d tests/lib/*.d
+
Log* redo; /* redo list */
bool modified; /* tracks whether the buffer has been modified */
uint transid; /* tracks the last used transaction id for log entries */
- void (*errfn)(char*); /* callback for error messages */
} Buf;
/* cursor/selection representation */
size_t col;
} Sel;
-void buf_init(Buf* buf, void (*errfn)(char*));
+void buf_init(Buf* buf);
size_t buf_load(Buf* buf, char* path);
void buf_reload(Buf* buf);
void buf_save(Buf* buf);
DOWN = +1
};
-void view_init(View* view, char* file, void (*errfn)(char*));
+void view_init(View* view, char* file);
void view_reload(View* view);
size_t view_limitrows(View* view, size_t maxrows, size_t ncols);
void view_resize(View* view, size_t nrows, size_t ncols);
View view;
} Region;
-void win_init(KeyBinding* bindings, void (*errfn)(char*));
+void win_init(KeyBinding* bindings);
void win_save(char* path);
void win_loop(void);
void win_quit(void);
static size_t next_size(size_t curr);
static Rune nextrune(Buf* buf, size_t off, int move, bool (*testfn)(Rune));
-void buf_init(Buf* buf, void (*errfn)(char*)) {
+void buf_init(Buf* buf) {
/* cleanup old data if there is any */
if (buf->bufstart) {
free(buf->bufstart);
buf->gapend = buf->bufend;
buf->undo = NULL;
buf->redo = NULL;
- buf->errfn = errfn;
assert(buf->bufstart);
}
/* Read the file into the buffer */
while (sb.st_size && (nread = read(fd, buf->gapstart, sb.st_size)) > 0)
buf->gapstart += nread, sb.st_size -= nread;
- if (nread < 0) buf->errfn("Failed to read file");
}
if (fd > 0) close(fd);
}
void buf_reload(Buf* buf) {
- void (*errfn)(char*) = buf->errfn;
char* path = buf->path;
- buf_init(buf, errfn);
+ buf_init(buf);
buf_load(buf, path);
}
/* report success or failure */
if (nwrite >= 0)
buf->modified = false;
- else
- buf->errfn("Failed to write file");
+ //else
+ // buf->errfn("Failed to write file");
} else {
- buf->errfn("Need a filename: SaveAs ");
+ //buf->errfn("Need a filename: SaveAs ");
}
}
static void sync_center(View* view, size_t csr);
static size_t getoffset(View* view, size_t row, size_t col);
-void view_init(View* view, char* file, void (*errfn)(char*)) {
+void view_init(View* view, char* file) {
if (view->nrows) {
for (size_t i = 0; i < view->nrows; i++)
free(view->rows[i]);
view->sync_center = true;
view->prev_csr = 0;
/* load the file and jump to the address returned from the load function */
- buf_init(&(view->buffer), errfn);
+ buf_init(&(view->buffer));
if (file) {
size_t pos = buf_load(&(view->buffer), file);
if (pos > 0) {
/******************************************************************************/
-void win_init(KeyBinding* bindings, void (*errfn)(char*)) {
+void win_init(KeyBinding* bindings) {
for (int i = 0; i < SCROLL; i++)
- view_init(&(Regions[i].view), NULL, errfn);
+ view_init(&(Regions[i].view), NULL);
x11_init();
CurrFont = x11_font_load(FontString);
Regions[SCROLL].clrnor = Colors[ClrScrollNor];
if (!win_buf(EDIT)->modified || (now-before) <= (uint64_t)ClickTime)
exit(0);
else
- win_buf(EDIT)->errfn("File is modified.");
+ view_append(win_view(TAGS), "File is modified.");
before = now;
}
(e->type == FocusIn ? XSetICFocus : XUnsetICFocus)(X.xic);
Buf* buf = win_buf(EDIT);
if (buf->path && buf->modtime != modtime(buf->path))
- buf->errfn("File modified externally: Get {Put }");
+ view_append(win_view(TAGS), "File modified externally: Get {Put }");
}
static void xkeypress(XEvent* e) {
/* Action Callbacks
******************************************************************************/
-static void ondiagmsg(char* msg) {
- view_append(win_view(TAGS), msg);
- win_setregion(TAGS);
-}
-
static void trim_whitespace(char* arg) {
Buf* buf = win_buf(EDIT);
if (TrimOnSave && buf_end(buf) > 0) {
static void get(char* arg) {
if (arg)
- view_init(win_view(EDIT), arg, ondiagmsg);
+ view_init(win_view(EDIT), arg);
else
view_reload(win_view(EDIT));
}
if (!ShellCmd[0]) ShellCmd[0] = "/bin/sh";
/* create the window */
- win_init(Bindings, ondiagmsg);
+ win_init(Bindings);
x11_window("tide");
/* if we still have args left we're going to open it in this instance */
- if (*argv) view_init(win_view(EDIT), *argv, ondiagmsg);
+ if (*argv) view_init(win_view(EDIT), *argv);
/* now create the window and start the event loop */
win_loop();