Exemple #1
0
static void build_bufed_list(EditState *s)
{
    QEmacsState *qs = s->qe_state;
    EditBuffer *b, *b1;
    BufedState *hs;
    int last_index = list_get_pos(s);
    int i, flags;

    hs = s->mode_data;

    free_strings(&hs->items);
    for (b = qs->first_buffer; b != NULL; b = b->next) {
        if (!(b->flags & BF_SYSTEM) || (hs->flags & BUFED_ALL_VISIBLE))
            add_string(&hs->items, b->name);
    }

    /* build buffer */
    b = s->b;
    flags = b->flags;
    b->flags &= ~BF_READONLY;
    eb_delete(b, 0, b->total_size);
    for (i = 0; i < hs->items.nb_items; i++) {
        eb_printf(b, " %-20s", hs->items.items[i]->str);
        b1 = eb_find(hs->items.items[i]->str);
        if (b1) {
            /* CG: should also display mode */
            eb_printf(b, " %10d  %s", b1->total_size, b1->filename);
        }
        eb_printf(b, "\n");
    }
    b->flags = flags;
    s->offset = eb_goto_pos(s->b, last_index, 0);
}
Exemple #2
0
/* show a list of buffers */
static void do_list_buffers(EditState *s)
{
    QEmacsState *qs = s->qe_state;
    BufedState *bs;
    EditBuffer *b;
    EditState *e;
    int width, i;

    /* XXX: must close this buffer when destroying window: add a
       special buffer flag to tell this */
    b = eb_new("*bufed*", BF_READONLY | BF_SYSTEM);

    width = qs->width / 4;
    e = insert_window_left(b, width, WF_MODELINE);
    do_set_mode(e, &bufed_mode, NULL);

    bs = e->mode_data;

    /* if active buffer is found, go directly on it */
    for(i=0;i<bs->items.nb_items;i++) {
        if (!strcmp(bs->items.items[i]->str, s->b->name)) {
            e->offset = eb_goto_pos(e->b, i, 0);
            break;
        }
    }

    /* modify active window */
    qs->active_window = e;
}
Exemple #3
0
/* XXX: optimize !!!!! */
static void tty_gotoxy(ShellState *s, int x, int y)
{
    int total_lines, line_num, col_num, offset, offset1, c;
    unsigned char buf1[10];

    /* compute offset */
    eb_get_pos(s->b, &total_lines, &col_num, s->b->total_size);
    line_num = total_lines - TTY_YSIZE;
    if (line_num < 0)
        line_num = 0;
    line_num += y;
    /* add lines if necessary */
    while (line_num >= total_lines) {
        buf1[0] = '\n';
        eb_insert(s->b, s->b->total_size, buf1, 1);
        total_lines++;
    }
    offset = eb_goto_pos(s->b, line_num, 0);
    for(;x > 0; x--) {
        c = eb_nextc(s->b, offset, &offset1);
        if (c == '\n') {
            buf1[0] = ' ';
            for(;x > 0; x--) {
                eb_insert(s->b, offset, buf1, 1);
            }
            break;
        } else {
            offset = offset1;
        }
    }
    s->cur_offset = offset;
}
Exemple #4
0
static void rectangle_insert(EditState *s, const char *str)
{
	int line, col, start_line, i, loff;
	eb_get_pos(s->b, &start_line, &col, s->b->mark);
	eb_get_pos(s->b, &line, &col, s->offset);

	for (i = start_line; i <= line; i++) {
		loff = eb_goto_pos(s->b, i, 0);
		eb_insert(s->b, loff, str, strlen(str));
	}

	s->region_style = 0;
}
Exemple #5
0
static void rectangle_cut(EditState *s)
{
	int line, col, start_line, i, loff;
	eb_get_pos(s->b, &start_line, &col, s->b->mark);
	eb_get_pos(s->b, &line, &col, s->offset);

	for (i = start_line; i <= line; i++) {
		loff = eb_goto_pos(s->b, i, 0);
		if (eb_is_empty_line(s->b, loff))
			continue;
		eb_delete(s->b, loff, col);
	}
	s->region_style = 0;
	put_status(s, "Rectangle cut done on line %d to line %d\n",
		   start_line, line);
}
Exemple #6
0
/* show a list of buffers */
static void do_list_buffers(EditState *s, int argval)
{
    QEmacsState *qs = s->qe_state;
    BufedState *bs;
    EditBuffer *b, *b0;
    EditState *e, *e1;
    int width, i;

    /* remember current buffer for target positioning, because
     * s may be destroyed by insert_window_left
     * CG: remove this kludge once we have delayed EditState free
     */
    b0 = s->b;

    /* XXX: must close this buffer when destroying window: add a
       special buffer flag to tell this */
    b = eb_scratch("*bufed*", BF_READONLY | BF_SYSTEM | BF_UTF8);

    width = qs->width / 5;
    e = insert_window_left(b, width, WF_MODELINE);
    edit_set_mode(e, &bufed_mode, NULL);

    bs = e->mode_data;
    if (argval != NO_ARG) {
        bs->flags |= BUFED_ALL_VISIBLE;
        build_bufed_list(e);
    }

    e1 = find_window(e, KEY_RIGHT);
    if (e1)
        b0 = e1->b;

    /* if active buffer is found, go directly on it */
    for (i = 0; i < bs->items.nb_items; i++) {
        if (strequal(bs->items.items[i]->str, b0->name)) {
            e->offset = eb_goto_pos(e->b, i, 0);
            break;
        }
    }

    /* modify active window */
    qs->active_window = e;
}
Exemple #7
0
/* get current offset of the line in list */
int list_get_offset(EditState *s)
{
    int line, col;
    eb_get_pos(s->b, &line, &col, s->offset);
    return eb_goto_pos(s->b, line, 0);
}