From 30677ab5ea48fcddb983e113b4b6ae1a62baea67 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 20 Dec 2016 16:06:09 -0500 Subject: [PATCH] copyindent now literally copies the indent characters from the previous line. This allows for better handling of non-standard indents as well as mixing of tab and space characters --- TODO.md | 2 ++ libedit/buf.c | 13 ++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/TODO.md b/TODO.md index 4edf750..59c26a7 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,6 @@ # Implementation Tweaks and Bug Fixes +* Indent on first line of buffer causes infinite loop * block selection should handle brace-balancing * Add tag for ctags lookup and line number jump * add a shortcut to autocomplete ctag @@ -11,6 +12,7 @@ Nice to haves: +* focus should follow mouse between regions * Expand tabs setting should be disabled if opened file contains tabs * Add a tools dir to namespace utility scripts only useful inside the editor * shift+click to extend selection diff --git a/libedit/buf.c b/libedit/buf.c index 5737699..59e06f1 100644 --- a/libedit/buf.c +++ b/libedit/buf.c @@ -109,12 +109,6 @@ static void clear_redo(Buf* buf) { buf->redo = NULL; } -static unsigned getindent(Buf* buf, unsigned off) { - off = buf_bol(buf, off); - for (; off < buf_end(buf) && (' ' == buf_get(buf, off) || '\t' == buf_get(buf, off)); off++); - return buf_getcol(buf, off) / TabWidth; -} - static void delete(Buf* buf, unsigned off) { syncgap(buf, off); buf->gapend++; @@ -287,9 +281,10 @@ unsigned buf_insert(Buf* buf, bool fmt, unsigned off, Rune rune) { } } if (fmt && buf->copy_indent && (rune == '\n' || rune == RUNE_CRLF)) { - unsigned indent = getindent(buf, off-1); - for (; indent > 0; indent--) - off = buf_insert(buf, indent, off, '\t'); + unsigned beg = buf_bol(buf, off-1), end = beg; + for (; end < buf_end(buf) && (' ' == buf_get(buf, end) || '\t' == buf_get(buf, end)); end++); + for (; beg < end; beg++) + off = buf_insert(buf, true, off, buf_get(buf, beg)); } clear_redo(buf); return off; -- 2.49.0