size_t col;
} Sel;
-void buf_load(Buf* buf, char* path);
+unsigned buf_load(Buf* buf, char* path);
void buf_save(Buf* buf);
void buf_init(Buf* buf);
unsigned buf_ins(Buf* buf, bool indent, unsigned off, Rune rune);
#include <edit.h>
#include <ctype.h>
-void buf_load(Buf* buf, char* path) {
- if (!strcmp(path,"-")) {
+unsigned buf_load(Buf* buf, char* path) {
+ unsigned off = 0;
+ buf->path = stringdup(path);
+ char* addr = strrchr(buf->path, ':');
+ if (addr) *addr = '\0', addr++;
+ if (!strcmp(buf->path,"-")) {
buf->charset = UTF_8;
Rune r;
while (RUNE_EOF != (r = fgetrune(stdin)))
buf_ins(buf, false, buf_end(buf), r);
} else {
- FMap file = fmap(path);
- buf->path = stringdup(path);
+ FMap file = fmap(buf->path);
buf->charset = (file.buf ? charset(file.buf, file.len, &buf->crlf) : UTF_8);
/* load the file contents if it has any */
if (buf->charset > UTF_8) {
utf8load(buf, file);
}
funmap(file);
+ if (addr)
+ off = buf_setln(buf, strtoul(addr, NULL, 0));
}
buf->modified = false;
free(buf->undo);
buf->undo = NULL;
+ return off;
}
void buf_save(Buf* buf) {
unsigned buf_setln(Buf* buf, unsigned line) {
unsigned off = 0;
- while (line > 0 && off < buf_end(buf))
+ while (line > 1 && off < buf_end(buf))
line--, off = buf_byline(buf, off, DOWN);
return off;
}
void view_init(View* view, char* file) {
memset(view, 0, sizeof(View));
buf_init(&(view->buffer));
- if (file)
- buf_load(&(view->buffer), file);
+ if (file) {
+ view->selection.end = buf_load(&(view->buffer), file);
+ view->selection.beg = view->selection.end;
+ }
}
size_t view_limitrows(View* view, size_t maxrows, size_t ncols) {