From c228ab6fdd87b06640a4b0d38c1d8c7a6662e502 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 2 Dec 2016 13:56:23 -0500 Subject: [PATCH] Added function to jump to a specified line --- inc/edit.h | 1 + libedit/buf.c | 7 +++++++ 2 files changed, 8 insertions(+) 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); -- 2.52.0