Exemplo n.º 1
0
int
operyank(int f, int n)
{
    MARK savedot;
    REGION region;
    int s;

    savedot = DOT;
    opcmd = OPDEL;
    wantregion = &region;
    s = vile_op(f, n, yankregion, "Yank");
    wantregion = 0;
    /*
     * If the associated motion was to the left, or up, we want to set DOT to
     * the beginning of the region, to match vi's behavior.  Otherwise leave
     * DOT where it is.
     */
    if (s == TRUE && b_val(curbp, MDYANKMOTION)) {
	if (line_no(curbp, post_op_dot.l) != 0
	    && line_no(curbp, post_op_dot.l) < line_no(curbp, savedot.l)) {
	    savedot = post_op_dot;
	} else if (!samepoint(region.r_orig, region.r_end)) {
	    if (sameline(region.r_orig, savedot)
		&& sameline(region.r_end, savedot)
		&& region.r_orig.o < savedot.o) {
		savedot = region.r_orig;
	    }
	}
    }
    DOT = savedot;
    return s;
}
Exemplo n.º 2
0
static int
dot_vs_mark(void)
{
    int cmp = line_no(curbp, DOT.l) - line_no(curbp, MK.l);
    if (cmp == 0)
	cmp = DOT.o - MK.o;
    return cmp;
}
Exemplo n.º 3
0
static int
show_mark(int count, BUFFER *bp, MARK mark, int name)
{
    static int tab = 8;		/* no b_val(bp,VAL_TAB) -- set_rdonly uses 8 */
    static int stop;

    if (!samepoint(mark, nullmark)) {

	if (!count) {
	    bprintf("\nMark  Line     Column");
	    if (stop == 0) {
		stop = ((DOT.o + tab - 1) / tab) * tab;
	    }
	    bpadc(' ', stop - DOT.o);
	    bprintf("Text");
	    bprintf("\n----  -------- ------");
	    bpadc(' ', stop - DOT.o);
	    bprintf("----");
	}

	bprintf("\n%c     %8d %8d",
		name,
		line_no(bp, mark.l),
		mk_to_vcol(curwp, mark, FALSE, 0, 0) + 1);
	if (llength(mark.l) > 0) {
	    bpadc(' ', stop - DOT.o);
	    bputsn(lvalue(mark.l), llength(mark.l));
	}
	return 1;
    }
    return 0;
}
Exemplo n.º 4
0
void
on_double_click(void)
{
    MARK save;

    save = DOT;
    TRACE(("MOUSE double-click DOT %d.%d\n", line_no(curbp, DOT.l), DOT.o));
    sel_release();
    if (!is_at_end_of_line(DOT)
	&& !isSpace(CharAtDot())) {
	while (DOT.o > 0) {
	    DOT.o -= BytesBefore(DOT.l, DOT.o);
	    if (isSpace(CharAtDot())) {
		DOT.o += BytesAt(DOT.l, DOT.o);
		break;
	    }
	}
	sel_begin();
	MK = DOT;
	while (!is_at_end_of_line(DOT)) {
	    DOT.o += BytesAt(DOT.l, DOT.o);
	    if (is_at_end_of_line(DOT)
		|| isSpace(CharAtDot())) {
		DOT.o -= BytesBefore(DOT.l, DOT.o);
		break;
	    }
	}
	sel_extend(FALSE, TRUE);
    }
    DOT = save;
    update(TRUE);
}
Exemplo n.º 5
0
static void
show_selection_position(int yanked)
{
#ifdef WMDTERSELECT
    if (!w_val(curwp, WMDTERSELECT)) {
	mlwrite("(%d,%d) thru (%d,%d) %s",
		line_no(selbufp, selregion.ar_region.r_orig.l),
		getcol(selregion.ar_region.r_orig, FALSE) + 1,
		line_no(selbufp, selregion.ar_region.r_end.l),
		getcol(selregion.ar_region.r_end, FALSE),
		yanked ? "yanked" : "selected");

    }
#endif /* WMDTERSELECT */
    show_mark_is_set('<');
    show_mark_is_set('>');
}
void
export_stream_reader::
report_state(std::ostream& os) const {

    const export_line_parser* exlp(exline());

    os << "\texport_stream_label: " << name() << "\n";
    if (exlp) {
        os << "\texport_line_no: " << line_no() << "\n"
           << "\texport_line: ";
        exlp->write_export_line(os);
        os << "\n";
    } else {
        os << "\tno export_line currently set\n";
    }
}
Exemplo n.º 7
0
void
on_triple_click(void)
{
    MARK save;

    save = DOT;
    TRACE(("MOUSE triple-click DOT %d.%d\n", line_no(curbp, DOT.l), DOT.o));
    sel_release();
    gotobol(FALSE, 1);
    sel_begin();
    MK = DOT;
    gotoeol(FALSE, 1);
    sel_extend(FALSE, TRUE);
    DOT = save;
    update(TRUE);
}
Exemplo n.º 8
0
// Returns the current location in the source text.
inline Location
Input_buffer::location() const
{
  return {file(), line_no(), column_no()};
}
Exemplo n.º 9
0
int
multimotion(int f, int n)
{
    const CMDFUNC *cfp;
    int status, c, waserr;
    int pasting;
    REGIONSHAPE shape;
    MARK savedot;
    MARK savemark;
    MARK realdot;
    BUFFER *origbp = curbp;
    static int wassweephack = FALSE;

    /* Use the repeat-count as a shortcut to specify the type of selection.
     * I'd use int-casts of the enum value, but declaring enums with
     * specific values isn't 100% portable.
     */
    n = need_at_least(f, n, 1);

    if (n == 3)
	regionshape = rgn_RECTANGLE;
    else if (n == 2)
	regionshape = rgn_FULLLINE;
    else
	regionshape = rgn_EXACT;
    shape = regionshape;

    sweephack = FALSE;
    savedot = DOT;
    switch (doingsweep) {
    case TRUE:			/* the same command terminates as starts the sweep */
	if (doingsweep) {
	    do_sweep(FALSE);
	}
	mlforce("[Sweeping: Completed]");
	regionshape = shape;
	/* since the terminating 'q' is executed as a motion, we have
	   now lost the value of sweephack we were interested in, the
	   one that tells us to include DOT.o in the selection.
	   so we preserved it in wassweephack, and restore it here.
	 */
	if (wassweephack)
	    sweephack = wassweephack;
	return TRUE;
    case SORTOFTRUE:
	if (doingsweep != TRUE) {
	    do_sweep(TRUE);
	}
	sweepmsg("Begin cursor sweep...");
	sel_extend(TRUE, (regionshape != rgn_RECTANGLE && sweephack));
	savedot = MK;
	TRACE(("MOUSE BEGIN DOT: %d.%d MK %d.%d\n",
	       line_no(curbp, DOT.l), DOT.o,
	       line_no(curbp, MK.l), MK.o));
	break;
    case FALSE:
	if (doingsweep != TRUE) {
	    do_sweep(TRUE);
	}
	sweepmsg("Begin cursor sweep...");
	(void) sel_begin();
	(void) sel_setshape(shape);
	break;
    }

    waserr = TRUE;		/* to force message "state-machine" */
    realdot = DOT;
    pasting = FALSE;

    while (doingsweep) {

	/* Fix up the screen    */
	(void) update(FALSE);

	/* get the next command from the keyboard */
	c = kbd_seq();

	if (ABORTED(c)
	    || curbp != origbp) {
	    return release_selection(FALSE);
	}

	f = FALSE;
	n = 1;

	do_repeats(&c, &f, &n);

	/* and execute the command */
	cfp = SelectKeyBinding(c);
	if ((cfp != NULL)
	    && ((cfp->c_flags & (GOAL | MOTION)) != 0)) {
	    MARK testdot;

	    wassweephack = sweephack;
	    sweephack = FALSE;
	    TRACE(("MOUSE TEST DOT: %d.%d MK %d.%d\n",
		   line_no(curbp, DOT.l), DOT.o,
		   line_no(curbp, MK.l), MK.o));
	    testdot = DOT;

	    status = execute(cfp, f, n);
	    switch (status) {
	    case SEL_RELEASE:
		TRACE(("MOUSE SEL_RELEASE %d.%d\n",
		       line_no(curbp, DOT.l), DOT.o));
		return release_selection(TRUE);

	    case SEL_PASTE:
		pasting = TRUE;
		/* FALLTHRU */

	    case SEL_FINISH:
		do_sweep(FALSE);
		break;

	    case SORTOFTRUE:
		TRACE(("MOUSE selection pending %d.%d -> %d.%d\n",
		       line_no(curbp, realdot.l), realdot.o,
		       line_no(curbp, testdot.l), testdot.o));
		realdot = testdot;
		break;

	    case SEL_BEGIN:
		savedot = MK;
		TRACE(("MOUSE SEL_BEGIN...\n"));
		/*FALLTHRU */

	    case SEL_EXTEND:
		TRACE(("MOUSE SEL_EXTEND from %d.%d to %d.%d\n",
		       line_no(curbp, savedot.l), savedot.o,
		       line_no(curbp, DOT.l), DOT.o));
		/*FALLTHRU */

	    case TRUE:
		if (waserr && doingsweep) {
		    sweepmsg("Sweeping...");
		    waserr = FALSE;
		}
		realdot = DOT;
		DOT = savedot;
		(void) sel_begin();
		DOT = realdot;
		TRACE(("MOUSE LOOP save: %d.%d real %d.%d, mark %d.%d\n",
		       line_no(curbp, savedot.l), savedot.o,
		       line_no(curbp, realdot.l), realdot.o,
		       line_no(curbp, MK.l), MK.o));
		(void) sel_setshape(shape);
		/* we sometimes want to include DOT.o in the
		   selection (unless it's a rectangle, in
		   which case it's taken care of elsewhere)
		 */
		sel_extend(TRUE, (regionshape != rgn_RECTANGLE &&
				  sweephack));
		break;

	    default:
		sweepmsg("Sweeping: Motion failed.");
		waserr = TRUE;
		break;
	    }
	} else {
	    sweepmsg("Sweeping: Only motions permitted");
	    waserr = TRUE;
	}

    }
    regionshape = shape;
    /* if sweephack is set here, it's because the last motion had
       it set */
    if (doingopcmd)
	pre_op_dot = savedot;

    savedot = DOT;
    savemark = MK;
    DOT = realdot;
    TRACE(("MOUSE SAVE DOT: %d.%d MK %d.%d\n",
	   line_no(curbp, DOT.l), DOT.o,
	   line_no(curbp, MK.l), MK.o));
    if ((regionshape != rgn_RECTANGLE) && sweephack) {
	if (dot_vs_mark() < 0)
	    MK.o += BytesAt(MK.l, MK.o);
	else
	    DOT.o += BytesAt(DOT.l, DOT.o);
    }
    status = yankregion();
    DOT = savedot;
    MK = savemark;

    sweephack = wassweephack = FALSE;

    if (status == TRUE && pasting)
	status = SEL_PASTE;

    return status;
}
Exemplo n.º 10
0
/*
 * On button press, we get an explicit number (1,2,3), and on release we don't
 * really know which button, but assume it is the last-pressed button.
 */
int
on_mouse_click(int button, int y, int x)
{
    static int first_x, first_y, pending;
    WINDOW *this_wp, *that_wp;
    int status;

    if (button > 0) {
	if (valid_window(this_wp = row2window(y))
	    && (y != mode_row(this_wp))) {
	    /*
	     * If we get a click on the "<" marking the left side
	     * of a shifted window, force the screen right. This
	     * makes it more consistent if there's a tab.
	     */
	    if (w_val(this_wp, WVAL_SIDEWAYS)
		&& x == 0) {
		mvleftwind(FALSE, 1);
	    }
	    if (!doingsweep) {
		if (button == BTN_EXTEND) {
		    first_x = offs2col(this_wp, this_wp->w_dot.l, this_wp->w_dot.o);
		    first_y = line_no(this_wp->w_bufp, this_wp->w_dot.l)
			- line_no(this_wp->w_bufp, this_wp->w_line.l);
		} else {
		    first_x = x;
		    first_y = y;
		}
	    }
	    status = setcursor(y, x);
	    /*
	     * Check for button1-down while we're in multimotion
	     * sweep, so we can suppress highlighting extension.
	     */
	    if (button != BTN_EXTEND
		&& status == TRUE
		&& doingsweep) {
		status = SORTOFTRUE;
		if (button == BTN_BEGIN) {
		    first_x = x;
		    first_y = y;
		}
	    }
	} else {		/* pressed button on modeline */
	    status = SORTOFTRUE;
	    first_x = x;
	    first_y = y;
	}
	pending = button;
    } else if (pending) {
	button = pending;
	pending = FALSE;
	this_wp = row2window(y);
	that_wp = row2window(first_y);
	if (this_wp == 0
	    || that_wp == 0
	    || reading_msg_line) {
	    TRACE(("MOUSE cannot move msg-line\n"));
	    status = FALSE;
	} else if (insertmode
		   && (this_wp != curwp || that_wp != curwp)) {
	    TRACE(("MOUSE cannot move from window while inserting\n"));
	    kbd_alarm();
	    status = ABORT;
	} else if (first_y == mode_row(that_wp)) {	/* drag modeline? */
	    if (first_y == y) {
		sel_release();
		status = SEL_RELEASE;
	    } else {
		WINDOW *save_wp = curwp;
		TRACE(("MOUSE dragging modeline\n"));
		set_curwp(that_wp);
		status = shrinkwind(FALSE, first_y - y);
		set_curwp(save_wp);
	    }
	} else if (y != first_y || x != first_x) {	/* drag selection */
	    if (button == BTN_PASTE) {
		(void) setcursor(y, x);
		status = paste_selection();
	    } else if (doingsweep) {
		switch (button) {
		case BTN_BEGIN:
		    (void) release_selection(TRUE);
		    status = setcursor(first_y, first_x);
		    if (status == TRUE) {
			MK = DOT;
			status = SEL_BEGIN;
			TRACE(("MOUSE setting SEL_BEGIN MK %d.%d\n",
			       line_no(curbp, MK.l), MK.o));
		    }
		    break;
		default:
		    (void) setcursor(y, x);
		    status = SEL_EXTEND;
		    TRACE(("MOUSE setting SEL_EXTEND DOT %d.%d MK %d.%d\n",
			   line_no(curbp, MK.l), MK.o,
			   line_no(curbp, DOT.l), DOT.o));
		    break;
		}
	    } else {
		TRACE(("MOUSE begin multimotion on button%d-up\n", button));
		if (button == BTN_EXTEND) {
		    (void) setcursor(y, x);
		    y = first_y;
		    x = first_x;
		}
		do_sweep(SORTOFTRUE);
		(void) sel_begin();
		(void) sel_setshape(rgn_EXACT);
		(void) setcursor(y, x);
		status = multimotion(TRUE, 1);
		TRACE(("MOUSE end multimotion after button%d-up\n", button));
		if (status == SEL_PASTE)
		    status = paste_selection();
	    }
	} else {		/* position the cursor */
	    TRACE(("MOUSE button %d position cursor\n", button));
	    (void) setcursor(y, x);
	    switch (button) {
	    case BTN_BEGIN:
		status = SEL_FINISH;
		break;
	    case BTN_PASTE:
		status = paste_selection();
		break;
	    default:
		status = release_selection(TRUE);
		break;
	    }
	}
    } else {
	TRACE(("MOUSE ignored (illegal state)\n"));
	status = FALSE;
    }

    if (status == TRUE || status >= SORTOFTRUE)
	(void) update(TRUE);

    TRACE(("MOUSE status:%d\n", status));
    return status;
}
Exemplo n.º 11
0
int
attributeregion(void)
{
    BUFFER *bp = curbp;
    int status;
    REGION region;
    AREGION *arp;

    if ((status = getregion(bp, &region)) == TRUE) {
	if (apply_attribute()) {
	    if (add_line_attrib(bp, &region, regionshape, videoattribute,
#if OPT_HYPERTEXT
				hypercmd
#else
				0
#endif
		)) {
		return TRUE;
	    }

	    /* add new attribute-region */
	    if ((arp = alloc_AREGION()) == NULL) {
		return FALSE;
	    }
	    arp->ar_region = region;
	    arp->ar_vattr = videoattribute;	/* include ownership */
	    arp->ar_shape = regionshape;
#if OPT_HYPERTEXT
	    arp->ar_hypercmd = 0;
	    if (tb_length(hypercmd) && *tb_values(hypercmd)) {
#if OPT_EXTRA_COLOR
		if (tb_length(hypercmd) > 4
		    && !memcmp(tb_values(hypercmd), "view ", (size_t) 4)) {
		    int *newVideo = lookup_extra_color(XCOLOR_HYPERTEXT);
		    if (!isEmpty(newVideo)) {
			arp->ar_vattr = (VIDEO_ATTR) * newVideo;
		    }
		}
#endif
		arp->ar_hypercmd = strmalloc(tb_values(hypercmd));
		tb_init(&hypercmd, 0);
	    }
#endif
	    attach_attrib(bp, arp);
	} else {		/* purge attributes in this region */
	    L_NUM rls = line_no(bp, region.r_orig.l);
	    L_NUM rle = line_no(bp, region.r_end.l);
	    C_NUM ros = region.r_orig.o;
	    C_NUM roe = region.r_end.o;
	    AREGION **pp;
	    AREGION **qq;
	    AREGION *p, *n;
	    int owner;

	    owner = VOWNER(videoattribute);

	    purge_line_attribs(bp, &region, regionshape, owner);

	    pp = &(bp->b_attribs);

	    for (p = *pp; p != 0; pp = qq, p = *pp) {
		L_NUM pls, ple;
		C_NUM pos, poe;

		if (interrupted())
		    return FALSE;

		qq = &(p->ar_next);

		if (owner != 0 && owner != VOWNER(p->ar_vattr))
		    continue;

		pls = line_no(bp, p->ar_region.r_orig.l);
		ple = line_no(bp, p->ar_region.r_end.l);
		pos = p->ar_region.r_orig.o;
		poe = p->ar_region.r_end.o;

		/* Earlier the overlapping region check was made based only
		 * on line numbers and so was right only for FULLINES shape
		 * changed it to be correct for rgn_EXACT and rgn_RECTANGLE also
		 * -kuntal 9/13/98
		 */
		/*
		 * check for overlap:
		 * for any shape of region 'p' things are fine as long as
		 * 'region' is above or below it
		 */
		if (ple < rls || pls > rle)
		    continue;
		/*
		 * for rgn_EXACT 'p' region
		 */
		if (p->ar_shape == rgn_EXACT) {
		    if (ple == rls && poe - 1 < ros)
			continue;
		    if (pls == rle && pos > roe)
			continue;
		}
		/*
		 * for rgn_RECTANGLE 'p' region
		 */
		if (p->ar_shape == rgn_RECTANGLE)
		    if (poe < ros || pos > roe)
			continue;

		/*
		 * FIXME: this removes the whole of an overlapping region;
		 * we really only want to remove the overlapping portion...
		 */

		/*
		 * we take care of this fix easily as long as neither of
		 * 'p' or 'region' are rgn_RECTANGLE. we will need to create
		 * at the most one new region in case 'region' is
		 * completely contained within 'p'
		 */
		if (p->ar_shape != rgn_RECTANGLE && regionshape != rgn_RECTANGLE) {
		    if ((rls > pls) || (rls == pls && ros > pos)) {
			p->ar_shape = rgn_EXACT;
			if ((rle < ple) || (rle == ple && roe < poe)) {
			    /* open a new region */
			    if ((n = alloc_AREGION()) == NULL) {
				return FALSE;
			    }
			    n->ar_region = p->ar_region;
			    n->ar_vattr = p->ar_vattr;
			    n->ar_shape = p->ar_shape;
#if OPT_HYPERTEXT
			    n->ar_hypercmd = p->ar_hypercmd;
#endif
			    n->ar_region.r_orig.l = (region.r_end.l);
			    n->ar_region.r_orig.o = (region.r_end.o);
			    attach_attrib(bp, n);
			}
			p->ar_region.r_end.l = (region.r_orig.l);
			p->ar_region.r_end.o = (region.r_orig.o);
			curwp->w_flag |= WFHARD;
			continue;
		    } else if ((rle < ple) || (rle == ple && roe < poe)) {
			p->ar_region.r_orig.l = (region.r_end.l);
			p->ar_region.r_orig.o = (region.r_end.o);
			curwp->w_flag |= WFHARD;
			continue;
		    }
		}

		free_attrib2(bp, pp);
		qq = pp;
	    }
	}
    }
    return status;
}