Beispiel #1
0
static void do_tex_insert_quote(EditState *s)
{
    int offset_bol, len, offset1;
    unsigned int buf[MAX_BUF_SIZE];
    int p;

    offset_bol = eb_goto_bol(s->b, s->offset);
    offset1 = offset_bol;
    len = eb_get_line(s->b, buf, MAX_BUF_SIZE - 1, &offset1);
    p = s->offset - offset_bol;

    if(p >= 1 && buf[p-1] == '\"') {
        eb_insert(s->b, s->offset, (unsigned char *)"\"", 1);
        s->offset++;
    } else if(p >= 2 && (buf[p-1] == '`' || buf[p-1] == '\'') &&
              buf[p-1] == buf[p-2])
    {
        eb_delete(s->b, s->offset - 2, 2);
        eb_insert(s->b, s->offset, (unsigned char *)"\"", 1);
        s->offset++;
    } else {
        if(p == 0 || buf[p-1] == ' ') {
            eb_insert(s->b, s->offset, (unsigned char *)"``", 2);
            s->offset += 2;
        } else {
            eb_insert(s->b, s->offset, (unsigned char *)"''", 2);
            s->offset += 2;
        }
    }
}
Beispiel #2
0
static int org_find_heading(EditState *s, int offset, int *level, int silent)
{
    int offset1, nb, c;

    offset = eb_goto_bol(s->b, offset);
    for (;;) {
        /* Find line starting with '*' */
        /* XXX: should ignore blocks using colorstate */
        if (eb_nextc(s->b, offset, &offset1) == '*') {
            for (nb = 1; (c = eb_nextc(s->b, offset1, &offset1)) == '*'; nb++)
                continue;
            if (c == ' ') {
                *level = nb;
                return offset;
            }
        }
        if (offset == 0)
            break;
        offset = eb_prev_line(s->b, offset);
    }
    if (!silent)
        put_status(s, "Before first heading");

    return -1;
}
Beispiel #3
0
static void do_org_insert_heading(EditState *s, int flags)
{
    int offset, offset0, offset1, level = 1;

    if (check_read_only(s))
        return;

    offset = org_find_heading(s, s->offset, &level, 1);
    offset0 = eb_goto_bol(s->b, s->offset);
    offset1 = eb_goto_eol(s->b, s->offset);

    /* if at beginning of heading line, insert sibling heading before,
     * if in the middle of a heading line, split the heading,
     * otherwise, make the current line a heading line at current level.
     */
    if (flags & 2) {
        /* respect-content: insert heading at end of subtree */
        offset = org_next_heading(s, offset, level, NULL);
        eb_insert_uchar(s->b, offset, '\n');
        eb_insert_uchar(s->b, offset, '\n');
    } else
    if (s->offset <= offset + level + 1) {
        eb_insert_uchar(s->b, offset, '\n');
    } else
    if (offset == offset0 || offset == offset1) {
        offset = s->offset;
        offset += eb_insert_uchar(s->b, offset, '\n');
    } else {
        offset = offset0;
    }        
    offset1 = offset;
    while (eb_match_uchar(s->b, offset1, ' ', &offset1))
        continue;
    eb_delete(s->b, offset, offset1 - offset);

    while (level-- > 0) {
        offset += eb_insert_uchar(s->b, offset, '*');
    }
    offset += eb_insert_uchar(s->b, offset, ' ');
    s->offset = eb_goto_eol(s->b, offset);
    if (flags & 1) {
        /* insert-todo-heading */
        do_org_todo(s);
    }
}
Beispiel #4
0
static int org_is_header_line(EditState *s, int offset)
{
    /* Check if line starts with '*' */
    /* XXX: should ignore blocks using colorstate */
    return eb_nextc(s->b, eb_goto_bol(s->b, offset), &offset) == '*';
}