Example #1
0
static int
attribute_directly(void)
{
    BUFFER *bp = curbp;
    int code = FALSE;

#if OPT_MAJORMODE
    if (valid_buffer(bp)) {
#if OPT_AUTOCOLOR
	VL_ELAPSED begin_time;
	(void) vl_elapsed(&begin_time, TRUE);
#endif
	discard_syntax_highlighting();
	if (b_val(bp, MDHILITE)) {
	    char *filtername = 0;
	    TBUFF *token = 0;

	    if (clexec || isnamedcmd)
		filtername = mac_unquotedarg(&token);

	    if (filtername == 0
		&& bp->majr != 0)
		filtername = bp->majr->shortname;

	    if (filtername != 0
		&& flt_start(filtername)) {
		TRACE(("attribute_directly(%s) using %s\n",
		       bp->b_bname,
		       filtername));
		flt_finish();
		code = TRUE;
	    }
	    tb_free(&token);
	}
	attach_attrib(selbufp, &selregion);
	attach_attrib(startbufp, &startregion);
#if OPT_HILITEMATCH
	if (bp->b_highlight & HILITE_ON) {
	    bp->b_highlight |= HILITE_DIRTY;
	    attrib_matches();
	}
#endif
#if OPT_AUTOCOLOR
	bp->last_autocolor_time = vl_elapsed(&begin_time, FALSE);
	bp->next_autocolor_time = 0;
#endif
    }
#endif
    return code;
}
Example #2
0
/* For the "operator" commands -- the following command is a motion, or
 *  the operator itself is repeated.  All operate on regions.
 */
int
vile_op(int f, int n, OpsFunc fn, const char *str)
{
    int c = 0;
    int thiskey;
    int status;
    const CMDFUNC *cfp;		/* function to execute */
    const CMDFUNC *save_cmd_motion = cmd_motion;
    BUFFER *ourbp;
#if OPT_MOUSE
    WINDOW *wp0 = curwp;
#endif

    TRACE((T_CALLED "vile_op(%s)\n", str));

    doingopcmd = TRUE;

    pre_op_dot = DOT;
    ourbp = curbp;

    if (havemotion != NULL) {
	cfp = havemotion;
	havemotion = NULL;
    } else {
	TBUFF *tok = 0;

	mlwrite("%s operation pending...", str);
	(void) update(FALSE);

	/* get the next command from the keyboard */
	/* or a command line, as approp. */
	if (clexec) {
	    char *value = mac_unquotedarg(&tok);	/* get the next token */
	    if (value != 0 && strcmp(value, "lines"))
		cfp = engl2fnc(value);
	    else
		cfp = &f_godotplus;
	} else {
	    thiskey = lastkey;
	    c = kbd_seq();

#if OPT_MOUSE
	    if (curwp != wp0) {
		unkeystroke(c);
		doingopcmd = FALSE;
		returnCode(FALSE);
	    }
#endif
	    /* allow second chance for entering counts */
	    do_repeats(&c, &f, &n);

	    if (thiskey == lastkey)
		cfp = &f_godotplus;
	    else
		cfp = DefaultKeyBinding(c);

	}
	if (cfp != 0) {
	    mlerase();
	} else {
	    if (!clexec) {
		char temp[NSTRING];
		lsprintf(temp, "(%d)", c);
		tb_scopy(&tok, temp);
	    }
	    (void) no_such_function(tb_values(tok));
	}
	tb_free(&tok);
    }

    if (!cfp) {
	status = FALSE;
    } else if ((cfp->c_flags & MOTION) == 0) {
	kbd_alarm();
	status = ABORT;
    } else {
	/* motion is interpreted as affecting full lines */
	if (regionshape == rgn_EXACT) {
	    if (cfp->c_flags & FL)
		regionshape = rgn_FULLLINE;
	    if (cfp->c_flags & VL_RECT)
		regionshape = rgn_RECTANGLE;
	}

	/* and execute the motion */
	if ((status = execute(cfp, f, n)) == TRUE) {
	    post_op_dot = DOT;
	} else {
	    mlforce("[Motion failed]");
	    status = FALSE;
	}
    }

    if (status == TRUE) {
	opcmd = 0;

	MK = pre_op_dot;

	/* we've successfully set up a region */
	if (!fn) {		/* be defensive */
	    mlforce("BUG -- null func pointer in operator");
	    status = FALSE;
	} else if (fn == user_operator) {
	    swapmark();
	    cmd_motion = cfp;
	    status = dobuf(find_b_name(str), 1, f ? n : 1);
	} else {
	    status = (fn) ();
	}

	if (ourbp == curbp)	/* in case the func switched buffers on us */
	    swapmark();

	if (regionshape == rgn_FULLLINE)
	    (void) firstnonwhite(FALSE, 1);
    }

    regionshape = rgn_EXACT;
    doingopcmd = FALSE;
    haveregion = FALSE;
    cmd_motion = save_cmd_motion;

    returnCode(status);
}