tvi: basic section and paragraph boundaries - 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 d1f4855224db5c5e09d987e742cd43bace5139ba
 (DIR) parent 58191346a45866137a12738b1b82b31f40a673aa
 (HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
       Date:   Fri, 15 May 2015 18:32:57 +0430
       
       vi: basic section and paragraph boundaries
       
       Diffstat:
         M vi.c                                |      45 +++++++++++++++++++++++++++++++
       
       1 file changed, 45 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/vi.c b/vi.c
       t@@ -286,6 +286,27 @@ static int lbuf_wordend(struct lbuf *lb, int *row, int *col, int big, int dir)
                return 0;
        }
        
       +static int lbuf_paragraphbeg(struct lbuf *lb, int *row, int *col, int dir)
       +{
       +        while (*row >= 0 && *row < lbuf_len(lb) && !strcmp("\n", lbuf_get(lb, *row)))
       +                *row += dir;
       +        while (*row >= 0 && *row < lbuf_len(lb) && strcmp("\n", lbuf_get(lb, *row)))
       +                *row += dir;
       +        *row = MAX(0, MIN(*row, lbuf_len(lb) - 1));
       +        lbuf_eol(lb, row, col, -1);
       +        return 0;
       +}
       +
       +static int lbuf_sectionbeg(struct lbuf *lb, int *row, int *col, int dir)
       +{
       +        *row += dir;
       +        while (*row >= 0 && *row < lbuf_len(lb) && lbuf_get(lb, *row)[0] != '{')
       +                *row += dir;
       +        *row = MAX(0, MIN(*row, lbuf_len(lb) - 1));
       +        lbuf_eol(lb, row, col, -1);
       +        return 0;
       +}
       +
        /* read a line motion */
        static int vi_motionln(int *row, int cmd)
        {
       t@@ -436,6 +457,30 @@ static int vi_motion(int *row, int *col)
                                if (lbuf_wordbeg(xb, row, col, 0, +1))
                                        break;
                        break;
       +        case '{':
       +                for (i = 0; i < cnt; i++)
       +                        if (lbuf_paragraphbeg(xb, row, col,  -1))
       +                                break;
       +                break;
       +        case '}':
       +                for (i = 0; i < cnt; i++)
       +                        if (lbuf_paragraphbeg(xb, row, col, +1))
       +                                break;
       +                break;
       +        case '[':
       +                if (vi_read() != '[')
       +                        return -1;
       +                for (i = 0; i < cnt; i++)
       +                        if (lbuf_sectionbeg(xb, row, col, -1))
       +                                break;
       +                break;
       +        case ']':
       +                if (vi_read() != ']')
       +                        return -1;
       +                for (i = 0; i < cnt; i++)
       +                        if (lbuf_sectionbeg(xb, row, col, +1))
       +                                break;
       +                break;
                case '0':
                        lbuf_eol(xb, row, col, -1);
                        break;