Example #1
0
File: yank.c Project: sctb/em
/* ARGSUSED */
int
yank(int f, int n)
{
	struct line	*lp;
	int	 c, i, nline;

	if (n < 0)
		return (FALSE);

	/* newline counting */
	nline = 0;

	undo_boundary_enable(FFRAND, 0);
	while (n--) {
		/* mark around last yank */
		isetmark();
		i = 0;
		while ((c = kremove(i)) >= 0) {
			if (c == '\n') {
				if (newline(FFRAND, 1) == FALSE)
					return (FALSE);
				++nline;
			} else {
				if (linsert(1, c) == FALSE)
					return (FALSE);
			}
			++i;
		}
	}
	/* cosmetic adjustment */
	lp = curwp->w_linep;

	/* if offscreen insert */
	if (curwp->w_dotp == lp) {
		while (nline-- && lback(lp) != curbp->b_headp)
			lp = lback(lp);
		/* adjust framing */
		curwp->w_linep = lp;
		curwp->w_rflag |= WFFULL;
	}
	undo_boundary_enable(FFRAND, 1);
	return (TRUE);
}
Example #2
0
/* ARGSUSED */
int
transposepara(int f, int n)
{
	int	i = 0, status;
	char	flg;

	if (n == 0)
		return (TRUE);

	undo_boundary_enable(FFRAND, 0);

	/* find a paragraph, set mark, then goto the end */
	gotobop(FFRAND, 1);
	curwp->w_markp = curwp->w_dotp;
	curwp->w_marko = curwp->w_doto;
	(void)gotoeop(FFRAND, 1);

	/* take a note of buffer flags - we may need them */
	flg = curbp->b_flag;	

	/* clean out kill buffer then kill region */
	kdelete();
	if ((status = killregion(FFRAND, 1)) != TRUE)
		return (status);

	/* 
	 * Now step through n paragraphs. If we reach the end of buffer,
	 * stop and paste the killed region back, then display a message.
	 */
	if (do_gotoeop(FFRAND, n, &i) == FALSE) {
		ewprintf("Cannot transpose paragraph, end of buffer reached.");
		(void)gotobop(FFRAND, i);
		(void)yank(FFRAND, 1);
		curbp->b_flag = flg;	
		return (FALSE);
	}
	(void)yank(FFRAND, 1);

	undo_boundary_enable(FFRAND, 1);

	return (TRUE);
}
Example #3
0
/*
 * Attempt to indent current line according to KNF rules.
 */
int
cc_indent(int f, int n)
{
	int pi, mi;			/* Previous indents */
	int ci, dci;			/* current indent, don't care */
	struct line *lp;
	int ret;
	
	if (n < 0)
		return (FALSE);

	undo_boundary_enable(FFRAND, 0);
	if (cc_strip_trailp)
		deltrailwhite(FFRAND, 1);

	/*
	 * Search backwards for a non-blank, non-preprocessor,
	 * non-comment line
	 */

	lp = findnonblank(curwp->w_dotp);

	pi = getindent(lp, &mi);

	/* Strip leading space on current line */
	delleadwhite(FFRAND, 1);
	/* current indent is computed only to current position */
	dci = getindent(curwp->w_dotp, &ci);
	
	if (pi + ci < 0)
		ret = indent(FFOTHARG, 0);
	else
		ret = indent(FFOTHARG, pi + ci);
	
	undo_boundary_enable(FFRAND, 1);
	
	return (ret);
}
Example #4
0
/* ARGSUSED */
int
fillpara(int f, int n)
{
    int	 c;		/* current char during scan		*/
    int	 wordlen;	/* length of current word		*/
    int	 clength;	/* position on line during fill		*/
    int	 i;		/* index during word copy		*/
    int	 eopflag;	/* Are we at the End-Of-Paragraph?	*/
    int	 firstflag;	/* first word? (needs no space)		*/
    int	 newlength;	/* tentative new line length		*/
    int	 eolflag;	/* was at end of line			*/
    int	 retval;	/* return value				*/
    struct line	*eopline;	/* pointer to line just past EOP	*/
    char	 wbuf[MAXWORD];	/* buffer for current word		*/

    if (n == 0)
        return (TRUE);

    undo_boundary_enable(FFRAND, 0);

    /* record the pointer to the line just past the EOP */
    (void)gotoeop(FFRAND, 1);
    if (curwp->w_doto != 0) {
        /* paragraph ends at end of buffer */
        (void)lnewline();
        eopline = lforw(curwp->w_dotp);
    } else
        eopline = curwp->w_dotp;

    /* and back top the beginning of the paragraph */
    (void)gotobop(FFRAND, 1);

    /* initialize various info */
    while (inword() == 0 && forwchar(FFRAND, 1));

    clength = curwp->w_doto;
    wordlen = 0;

    /* scan through lines, filling words */
    firstflag = TRUE;
    eopflag = FALSE;
    while (!eopflag) {

        /* get the next character in the paragraph */
        if ((eolflag = (curwp->w_doto == llength(curwp->w_dotp)))) {
            c = ' ';
            if (lforw(curwp->w_dotp) == eopline)
                eopflag = TRUE;
        } else
            c = lgetc(curwp->w_dotp, curwp->w_doto);

        /* and then delete it */
        if (ldelete((RSIZE) 1, KNONE) == FALSE && !eopflag) {
            retval = FALSE;
            goto cleanup;
        }

        /* if not a separator, just add it in */
        if (c != ' ' && c != '\t') {
            if (wordlen < MAXWORD - 1)
                wbuf[wordlen++] = c;
            else {
                /*
                 * You lose chars beyond MAXWORD if the word
                 * is too long. I'm too lazy to fix it now; it
                 * just silently truncated the word before,
                 * so I get to feel smug.
                 */
                ewprintf("Word too long!");
            }
        } else if (wordlen) {

            /* calculate tentative new length with word added */
            newlength = clength + 1 + wordlen;

            /*
             * if at end of line or at doublespace and previous
             * character was one of '.','?','!' doublespace here.
             * behave the same way if a ')' is preceded by a
             * [.?!] and followed by a doublespace.
             */
            if (dblspace && (!eopflag && ((eolflag ||
                                           curwp->w_doto == llength(curwp->w_dotp) ||
                                           (c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' '
                                           || c == '\t') && (ISEOSP(wbuf[wordlen - 1]) ||
                                                   (wbuf[wordlen - 1] == ')' && wordlen >= 2 &&
                                                    ISEOSP(wbuf[wordlen - 2])))) &&
                             wordlen < MAXWORD - 1))
                wbuf[wordlen++] = ' ';

            /* at a word break with a word waiting */
            if (newlength <= fillcol) {
                /* add word to current line */
                if (!firstflag) {
                    (void)linsert(1, ' ');
                    ++clength;
                }
                firstflag = FALSE;
            } else {
                if (curwp->w_doto > 0 &&
                        lgetc(curwp->w_dotp, curwp->w_doto - 1) == ' ') {
                    curwp->w_doto -= 1;
                    (void)ldelete((RSIZE) 1, KNONE);
                }
                /* start a new line */
                (void)lnewline();
                clength = 0;
            }

            /* and add the word in in either case */
            for (i = 0; i < wordlen; i++) {
                (void)linsert(1, wbuf[i]);
                ++clength;
            }
            wordlen = 0;
        }
    }
    /* and add a last newline for the end of our new paragraph */
    (void)lnewline();

    /*
     * We really should wind up where we started, (which is hard to keep
     * track of) but I think the end of the last line is better than the
     * beginning of the blank line.
     */
    (void)backchar(FFRAND, 1);
    retval = TRUE;
cleanup:
    undo_boundary_enable(FFRAND, 1);
    return (retval);
}