Beispiel #1
0
/*
 * Set fill column to n.
 */
int
setfillcol (int f, int n, int k)
{
  extern int getcolpos ();

  fillcol = ((f == FALSE) ? getcolpos () : n);
  if (kbdmop == NULL)
    eprintf ("[Fill column set to %d]", fillcol);
  return (TRUE);
}
Beispiel #2
0
/*
 * Set the current goal column, which is saved in the external variable
 * "curgoal", to the current cursor column. The column is never off
 * the edge of the screen; it's more like display then show position.
 */
void
setgoal(void)
{
	curgoal = getcolpos(curwp);	/* Get the position. */
	/* we can now display past end of display, don't chop! */
}
Beispiel #3
0
/*
 * Fill the current paragraph according to the current fill column.
 */
int
fillpara (int f, int n, int k)
{
  register int c;		/* current char durring scan    */
  register int wordlen;		/* length of current word       */
  register int clength;		/* position on line during fill */
  register 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           */
  LINE *eopline;		/* pointer to line just past EOP */
  char wbuf[MAXWORD];		/* buffer for current word      */

  /* Record the pointer to the line just past the
   * end of the paragraph.
   */
  gotoeop (FALSE, 1, KRANDOM);
  eopline = curwp->w_dot.p;
  if (lforw (eopline) == curbp->b_linep)
    eopline = curbp->b_linep;

  /* Move to the begining of the paragraph.
   */
  gotobop (FALSE, 1, KRANDOM);

  /* Skip to the start of the first word in the paragraph,
   * and set our current column position.
   */
  while (!inword ())
    if (forwchar (FALSE, 1, KRANDOM) == FALSE)
      break;
  clength = getcolpos () - 1;
  wordlen = 0;

  /* scan through lines, filling words
   */
  firstflag = TRUE;
  eopflag = FALSE;
  while (!eopflag)
    {
      /* get the next character in the paragraph
       */
      if ((eolflag = (curwp->w_dot.o == llength (curwp->w_dot.p))) == TRUE)
	{
	  c = ' ';
	  if (lforw (curwp->w_dot.p) == eopline)
	    eopflag = TRUE;
	}
      else
	c = lgetc (curwp->w_dot.p, curwp->w_dot.o);

      /* and then delete it
       */
      if (ldelete (1, FALSE) == FALSE)
	return (FALSE);

      /* 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 to long. I'm to lazy to fix it now; it
	       * just silently truncated the word before, so
	       * I get to feel smug.
	       */
	      eprintf ("Word too long!");
	    }
	}
      else if (wordlen)
	{
	  /* calculate tenatitive 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.
	   */
	  if ((eolflag || curwp->w_dot.o == llength (curwp->w_dot.p)
	       || (c = lgetc (curwp->w_dot.p, curwp->w_dot.o)) == ' '
	       || c == '\t')
	      && ISEOSP (wbuf[wordlen - 1]) && wordlen < MAXWORD - 1)
	    wbuf[wordlen++] = ' ';

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

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

  /* we realy 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
   * begining of the blank line.
   */
  backchar (FALSE, 1, KRANDOM);
  return (TRUE);
}