tmot: word motions stop at empty lines - neatvi - [fork] simple vi-type editor with UTF-8 support (HTM) git clone git://src.adamsgaard.dk/neatvi (DIR) Log (DIR) Files (DIR) Refs (DIR) README --- (DIR) commit 5eaaf403f7dc6a08f434aea8825e692102bf258a (DIR) parent 979fba724b1590629fd7a6d45abdf68cc4f61490 (HTM) Author: Ali Gholami Rudi <ali@rudi.ir> Date: Mon, 23 May 2016 14:34:27 +0430 mot: word motions stop at empty lines Diffstat: M mot.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) --- (DIR) diff --git a/mot.c b/mot.c t@@ -151,12 +151,13 @@ static int lbuf_wordlast(struct lbuf *lb, int kind, int dir, int *row, int *off) int lbuf_wordbeg(struct lbuf *lb, int big, int dir, int *row, int *off) { - int nl = 0; + int nl; lbuf_wordlast(lb, big ? 3 : uc_kind(lbuf_chr(lb, *row, *off)), dir, row, off); + nl = uc_code(lbuf_chr(lb, *row, *off)) == '\n'; if (lbuf_next(lb, dir, row, off)) return 1; while (uc_isspace(lbuf_chr(lb, *row, *off))) { - nl = uc_code(lbuf_chr(lb, *row, *off)) == '\n' ? nl + 1 : 0; + nl += uc_code(lbuf_chr(lb, *row, *off)) == '\n'; if (nl == 2) return 0; if (lbuf_next(lb, dir, row, off)) t@@ -167,19 +168,22 @@ int lbuf_wordbeg(struct lbuf *lb, int big, int dir, int *row, int *off) int lbuf_wordend(struct lbuf *lb, int big, int dir, int *row, int *off) { - int nl = uc_code(lbuf_chr(lb, *row, *off)) == '\n' ? -1 : 0; - if (!uc_isspace(lbuf_chr(lb, *row, *off))) + int nl = 0; + if (!uc_isspace(lbuf_chr(lb, *row, *off))) { if (lbuf_next(lb, dir, row, off)) return 1; + nl = dir < 0 && uc_code(lbuf_chr(lb, *row, *off)) == '\n'; + } + nl += dir > 0 && uc_code(lbuf_chr(lb, *row, *off)) == '\n'; while (uc_isspace(lbuf_chr(lb, *row, *off))) { - nl = uc_code(lbuf_chr(lb, *row, *off)) == '\n' ? nl + 1 : 0; + if (lbuf_next(lb, dir, row, off)) + return 1; + nl += uc_code(lbuf_chr(lb, *row, *off)) == '\n'; if (nl == 2) { if (dir < 0) lbuf_next(lb, -dir, row, off); return 0; } - if (lbuf_next(lb, dir, row, off)) - return 1; } if (lbuf_wordlast(lb, big ? 3 : uc_kind(lbuf_chr(lb, *row, *off)), dir, row, off)) return 1;