From: Michael D. Lowis Date: Fri, 2 Dec 2016 18:56:23 +0000 (-0500) Subject: Added function to jump to a specified line X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c228ab6fdd87b06640a4b0d38c1d8c7a6662e502;p=projs%2Ftide.git Added function to jump to a specified line --- diff --git a/inc/edit.h b/inc/edit.h index 7177c62..5657d5a 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -62,6 +62,7 @@ unsigned buf_ins(Buf* buf, bool indent, unsigned off, Rune rune); void buf_del(Buf* buf, unsigned pos); unsigned buf_undo(Buf* buf, unsigned pos); unsigned buf_redo(Buf* buf, unsigned pos); +unsigned buf_setln(Buf* buf, unsigned line); Rune buf_get(Buf* buf, unsigned pos); bool buf_iseol(Buf* buf, unsigned pos); unsigned buf_bol(Buf* buf, unsigned pos); diff --git a/libedit/buf.c b/libedit/buf.c index 3a8573c..0d7553d 100644 --- a/libedit/buf.c +++ b/libedit/buf.c @@ -233,6 +233,13 @@ unsigned buf_redo(Buf* buf, unsigned pos) { return swaplog(buf, &(buf->redo), &(buf->undo), pos); } +unsigned buf_setln(Buf* buf, unsigned line) { + unsigned off = 0; + while (line > 0 && off < buf_end(buf)) + line--, off = buf_byline(buf, off, DOWN); + return off; +} + Rune buf_get(Buf* buf, unsigned off) { if (off >= buf_end(buf)) return (Rune)'\n'; size_t bsz = (buf->gapstart - buf->bufstart);