Beispiel #1
0
Datei: cmds.c Projekt: hankem/jed
int backward_delete_char_untabify()
{
   unsigned char *p;
   int n;

   /* CHECK_READ_ONLY */

#if JED_HAS_LINE_ATTRIBUTES
   if (check_line_attr_no_modify (CLine))
     return 0;
#endif
   p = CLine->data + (Point - 1);

   if (!Point || (*p != '\t') || !Buffer_Local.tab)
     return backward_delete_char_cmd();

   n = calculate_column() - 1;
   jed_left (1);
   if (-1 == jed_del_wchar ())
     return -1;

   n = n - calculate_column();
   (void) jed_insert_wchar_n_times (' ', n);

   return(1);
}
Beispiel #2
0
Datei: cmds.c Projekt: hankem/jed
/* goto to column c, returns actual column */
int goto_column1(int *cp)
{
   int c1, c = *cp;
   if (c <= 0) c = 1;
   eol();
   c1 = calculate_column();
   if (c1 > c)
     {
	point_column(c);
	c1 = calculate_column();
     }
   return(c1);
}
Beispiel #3
0
Datei: cmds.c Projekt: hankem/jed
int indent_line ()
{
   int n, n1;
   static int in_function;

   if (in_function) return -1;

   if ((CBuf->buffer_hooks != NULL)
       && (CBuf->buffer_hooks->indent_hook != NULL))
     {
	in_function = 1;
	SLexecute_function(CBuf->buffer_hooks->indent_hook);
	in_function = 0;
	return 1;
     }

   /* CHECK_READ_ONLY */

   if (CLine == CBuf->beg) return(0);

   push_spot();
   CLine = CLine->prev;
   get_current_indent (&n);
   CLine = CLine->next;
   indent_to(n);
   pop_spot();

   /* This moves the cursor to the first non whitspace char if we are
    before it.  Otherwise leave it alone */

   n1 = calculate_column();
   get_current_indent(&n);
   if (n1 <= n) point_column(n + 1);
   return 1;
}
Beispiel #4
0
Datei: io.c Projekt: aosm/X11
int
LispSwrite(LispString *string, void *data, int size)
{
    if (size < 0)
	return (EOF);

    if (string->output + size >= string->space) {
	if (string->fixed) {
	    /* leave space for a ending nul character */
	    size = string->space - string->output - 1;

	    if (size <= 0)
		return (-1);
	}
	else {
	    char *tmp = realloc(string->string, string->space +
				(size / pagesize) * pagesize + pagesize);

	    if (tmp == NULL)
		return (-1);

	    string->string = tmp;
	    string->space += pagesize;
	}
    }
    memcpy(string->string + string->output, data, size);
    string->output += size;
    if (string->length < string->output)
	string->length = string->output;

    if (!string->binary)
	string->column = calculate_column(data, size, string->column);

    return (size);
}
Beispiel #5
0
void point_cursor (int c)
{
   int r, row;
   Line *tthis, *cline;

   if (JWindow->trashed) return;

   cline = CLine;
#if JED_HAS_LINE_ATTRIBUTES
   if (cline->flags & JED_LINE_HIDDEN)
     {
	cline = jed_find_non_hidden_line (cline);
	if (cline != NULL)
	  c = Non_Hidden_Point;
     }
#endif

   r = JWindow->sy + 1;
   Point_Cursor_Flag = 0;
   for (row = r; row < r + JWindow->rows; row++)
     {
	tthis = JScreen[row-1].line;
	if (tthis == NULL) break;
	if ((tthis == cline) || (tthis == &Eob_Line))
	  {
	     r = row;
	     break;
	  }
     }

   if (Point >= CLine->len)
     {
	Point = CLine->len - 1;

	if (Point < 0) Point = 0;
	else if ((*(CLine->data + Point) != '\n')
		 || (CBuf == MiniBuffer)) Point++;
     }

   if (c == 0)
     c = calculate_column ();
   c -= (JWindow->hscroll_column - 1);

   if (cline == HScroll_Line) c -= HScroll;
   if (c < 1) c = 1; else if (c > JWindow->width) c = JWindow->width;

   c += JWindow->sx;
#if JED_HAS_DISPLAY_LINE_NUMBERS
   c += CBuf->line_num_display_size;
#endif

   SLsmg_gotorc (r - 1, c - 1);
   Screen_Row = r;
   Screen_Col = c;

   SLsmg_refresh ();

   if (!Cursor_Motion) Goal_Column = c;
}
Beispiel #6
0
Datei: cmds.c Projekt: hankem/jed
/* the page up/down commands set cursor_motion to -1 because we do not
 want to use any goal column information */
int pagedown_cmd()
{
   int col, this_line, this_point;
   int n;

   Cursor_Motion = -1;
   if (IN_MINI_WINDOW)
     {
	scroll_completion (1);
	return 1;
     }

   if (eobp())
     {
	eob_bob_error (3);
	return 1;
     }

   n = JWindow->rows;
   if ((CBuf != JWindow->buffer) || (n == 1))
     {
	return next_visible_lines (n);
     }

   if (JWindow->trashed)
     {
	update (NULL, 0, 0, 1);
	if (JWindow->trashed) return next_visible_lines (n);
     }

   /* This is ugly. */

   this_line = LineNum;
   this_point = Point;

   col = calculate_column ();
   if (goto_bottom_of_window ())
     {
	recenter (&Number_One);
     }

   goto_column1 (&col);

   if ((Last_Key_Function == (FVOID_STAR) pageup_cmd)
       && (Jed_This_Key_Function == (FVOID_STAR) pagedown_cmd))
     {
	goto_line (&Last_Page_Line);
	if (Last_Page_Point < CLine->len)
	  Point = Last_Page_Point;
     }
   else if (CLine->next == NULL) eol();
   else bol ();

   Last_Page_Line = this_line;
   Last_Page_Point = this_point;

   return(1);
}
Beispiel #7
0
Datei: text.c Projekt: hankem/jed
/* returns 0 if to wrapped, 1 if wrapped, -1 if error */
static int wrap_line1(int format, int trim) /*{{{*/
{
   unsigned char *p, *pmin;
   int col;

   if (format)
     pmin = text_format_line();
   else
     {
	bol ();
	/* Ignore leading whitespace */
	pmin = jed_skip_whitespace ();
	/* pmin = CLine->data; */
     }
   if (pmin == NULL)
     return -1;

   point_column(Buffer_Local.wrap_column - 1);
   col = calculate_column();
   if ((col < Buffer_Local.wrap_column) && eolp ())
     return 0;

   p = CLine->data + Point;

   while(p > pmin)
     {
	if ((*p == ' ') || (*p == '\t')) break;
	p--;
     }

   if (p == pmin)
     {
	/* that failed, so go the other way */
	p = CLine->data + CLine->len;
	while(pmin < p)
	  {
	     if ((*pmin == ' ') || (*pmin == '\t')) break;
	     pmin++;
	  }
	if (p == pmin) return 0;
	p = pmin;
     }

   jed_position_point (p);

   if (trim && (-1 == jed_trim_whitespace()))
     return -1;

   if (-1 == jed_insert_newline())
     return -1;

   jed_up(1);
   return 1;
}
Beispiel #8
0
Datei: cmds.c Projekt: hankem/jed
int pageup_cmd (void)
{
   int col, this_line, this_point;
   int n;

   Cursor_Motion = -1;

   if (IN_MINI_WINDOW)
     {
	scroll_completion (-1);
	return 1;
     }

   if (bobp())
     {
	eob_bob_error (-3);
	return 1;
     }

   n = JWindow->rows;
   if ((CBuf != JWindow->buffer) || (n == 1))
     {
	return prev_visible_lines (n);
     }

   if (JWindow->trashed)
     {
	update (NULL, 0, 0, 1);
	if (JWindow->trashed) return prev_visible_lines (n);
     }

   this_line = LineNum;
   this_point = Point;
   col = calculate_column ();
   goto_top_of_window ();
   (void) goto_column1(&col);
   recenter(&JWindow->rows);

   if ((Last_Key_Function == (FVOID_STAR) pagedown_cmd)
       && (Jed_This_Key_Function == (FVOID_STAR) pageup_cmd))
     {
	goto_line (&Last_Page_Line);
	if (Last_Page_Point < CLine->len)
	  Point = Last_Page_Point;
     }
   else
     bol (); /* something like: Point = point_column(JWindow->column) better? */
   Last_Page_Line = this_line;
   Last_Page_Point = this_point;
   return(1);
}
Beispiel #9
0
Datei: cmds.c Projekt: hankem/jed
int next_char_cmd ()
{
   Cursor_Motion = 1;

   /* check_last_key_function ((FVOID_STAR) next_char_cmd); */

   if (1 != next_visible_chars (1))
     {
	eob_bob_error (2);
	return 1;
     }

   Goal_Column = calculate_column ();
   return JWindow->trashed || bolp ();  /* Point = 0 ==> moved a line */
}
Beispiel #10
0
Datei: cmds.c Projekt: hankem/jed
int previous_char_cmd (void)
{
   int b;
   Cursor_Motion = 1;

   /* check_last_key_function ((FVOID_STAR) previous_char_cmd); */
   b = bolp ();
   if (1 != prev_visible_chars (1))
     {
	eob_bob_error (-2);
	return 1;
     }

   Goal_Column = calculate_column();
   return b || JWindow->trashed;
}
Beispiel #11
0
Datei: cmds.c Projekt: hankem/jed
void insert_whitespace(int *n)
{
   int tab = Buffer_Local.tab;
   int c1, c2, i, k, nspace;

   if ((nspace = *n) <= 0) return;
   CHECK_READ_ONLY_VOID
     c1 = calculate_column() - 1;
   c2 = c1 + nspace;

   if (tab && Jed_Use_Tabs)
     {
	i = c1 / tab;
	k = c2 / tab - i;
	if (k) nspace = c2 - (i + k) * tab;
	(void) jed_insert_wchar_n_times('\t', k);
     }
   (void) jed_insert_wchar_n_times(' ', nspace);
}
Beispiel #12
0
Datei: cmds.c Projekt: hankem/jed
static void next_line_prev_line_helper (int *gcp, int *ret, int dr, FVOID_STAR f)
{
   int gc;

   (void) dr;
   check_line();
   gc = calculate_column();
   if (Cursor_Motion <= 0) Goal_Column = gc;
   else if (Goal_Column < gc) Goal_Column = gc;
   *gcp = gc;

   Cursor_Motion = 2;

   check_last_key_function (f);
   *ret = 1;
#if 0
   *ret = (JWindow->trashed
	   || (CLine == JScreen[JWindow->sy + dr].line)
#if JED_HAS_LINE_ATTRIBUTES
	   || (CLine->flags & JED_LINE_IS_READONLY)
#endif
	   );
#endif
}
Beispiel #13
0
static void finish_status(int col_flag)
{
   char *v, ch;
   Line *l;
   int top, rows, narrows;
   char buf[256];
   char *str;

   v = CBuf->status_line;
   if (*v == 0) v = Default_Status_Line;

   while (1)
     {
	char *v0 = v;
	while (1)
	  {
	     ch = *v;
	     if (ch == 0)
	       {
		  SLsmg_write_nchars (v0, (unsigned int) (v-v0));
		  return;
	       }
	     if (ch == '%')
	       {
		  SLsmg_write_nchars (v0, (unsigned int) (v-v0));
		  break;
	       }
	     v++;
	  }

	/* At this point *v == '%' */
	v++;
	ch = *v++;

	switch (ch)
	  {
	   case 'F':
	     SLsmg_write_string (CBuf->dir);
	     str = CBuf->file;
	     break;

	   case 'S':
	     /* stack depth */
	     sprintf(buf, "%03d", SLstack_depth());
	     str = buf;
	     break;

	   case 'a':
	     if (CBuf->flags & ABBREV_MODE) str = " abbrev"; else str = NULL;
	     break;
	   case 'f': str = CBuf->file; break;
	   case 'n':
	     narrows = jed_count_narrows ();
	     if (narrows)
	       {
		  sprintf (buf, " Narrow[%d]", narrows);
		  str = buf;
	       }
	     else str = NULL;
	     break;

	   case 'o':
	     if (CBuf->flags & OVERWRITE_MODE) str = " Ovwrt"; else str = NULL;
	     break;
	   case 'O':
	     if (CBuf->flags & OVERWRITE_MODE) str = " ovr"; else str = " ins";
	     break;

	   case 'b': str = CBuf->name; break;

	   case 'p':
	     str = buf;
	     if (0 == User_Prefers_Line_Numbers)
	       {
		  top = JWindow->sy;
		  rows = JWindow->rows - 1;
		  l = JScreen[top + rows].line;
		  if (l == CBuf->end) l = NULL;
		  if (JScreen[top].line == CBuf->beg)
		    {
		       if (l == NULL) str = "All";
		       else str = "Top";
		    }
		  else if (l == NULL) str = "Bot";
		  else
		    {
		       sprintf(buf, "%d%%",
			       (int) ((LineNum * 100L) / (long) Max_LineNum));
		    }
	       }
	     else
	       {
		  if (User_Prefers_Line_Numbers == 1)
		    sprintf(buf, "%u/%u", LineNum, Max_LineNum);
		  else
		    {
		       if (col_flag) (void) calculate_column ();
		       sprintf(buf, "%u/%u,%d", LineNum, Max_LineNum, Absolute_Column);
		    }
	       }
	     break;

	   case 'l':
	     sprintf(buf, "%u", LineNum);
	     str=buf;
	     break;

	   case 'L':
	     sprintf(buf, "%u", Max_LineNum);
	     str=buf;
	     break;

	   case 'v':
	     SLsmg_write_string (Jed_Version_String);
	     if (Jed_UTF8_Mode)
	       str = "U";
	     else
	       str = NULL;
	     break;

	   case 'm': str = CBuf->mode_string; break;
	   case 't': str = status_get_time(); break;
	   case 'c':
	     if (col_flag) (void) calculate_column ();
	     sprintf(buf, "%d",  Absolute_Column);
	     str = buf;
	     break;

	   case '0': case '1': case '2': case '3': case '4':
	   case '5': case '6': case '7': case '8': case '9':
	       {
		  char fmt[16];
		  int num = ch - '0';
		  while (isdigit(*v))
		    {
		       num = num * 10 + (*v - '0');
		       v++;
		    }

		  if ((num < 0)
		      || (-1 == SLsnprintf (fmt, sizeof(fmt), "%s%du", ((ch == '0') ? "%0" : "%"), num)))
		    strcpy (fmt, "%u");

		  str = "*";
		  switch (*v++)
		    {
		     default:
		       v--;
		       break;

		     case 'c':
		       if (col_flag) (void) calculate_column ();
		       if (-1 != SLsnprintf (buf, sizeof (buf), fmt, (unsigned int)Absolute_Column))
			 str = buf;
		       break;

		     case 'l':
		       if (-1 != SLsnprintf (buf, sizeof (buf), fmt, LineNum))
			 str = buf;
		       break;

		     case 'L':
		       if (-1 != SLsnprintf (buf, sizeof (buf), fmt, Max_LineNum))
			 str = buf;
		       break;
		    }
	       }
	     break;

	   case '%': str = "%"; break;
	   case 0:
	     return;

	   default:
	     str = NULL;
	  }
	if (str != NULL)
	  SLsmg_write_string (str);
     }
}
Beispiel #14
0
Datei: io.c Projekt: aosm/X11
int
LispFwrite(LispFile *file, void *data, int size)
{
    if (!file->writable || size < 0)
	return (EOF);

    if (!file->binary)
	file->column = calculate_column(data, size, file->column);

    if (file->buffered) {
	int length, bytes;
	char *buffer = (char*)data;

	length = 0;
	if (size + file->length > pagesize) {
	    /* fill remaining space in buffer and flush */
	    bytes = pagesize - file->length;
	    memcpy(file->buffer + file->length, buffer, bytes);
	    file->length += bytes;
	    LispFflush(file);

	    /* check if all data was written */
	    if (file->length)
		return (pagesize - file->length);

	    length = bytes;
	    buffer += bytes;
	    size -= bytes;
	}

	while (size > pagesize) {
	    /* write multiple of pagesize */
	    bytes = (*file->io_write)(file->descriptor, buffer,
				      size - (size % pagesize));
	    if (bytes <= 0)
		return (length);

	    length += bytes;
	    buffer += bytes;
	    size -= bytes;
	}

	if (size) {
	    /* keep remaining data in buffer */
	    switch (size) {
		case 8:
		    file->buffer[file->length++] = *buffer++;
		case 7:
		    file->buffer[file->length++] = *buffer++;
		case 6:
		    file->buffer[file->length++] = *buffer++;
		case 5:
		    file->buffer[file->length++] = *buffer++;
		case 4:
		    file->buffer[file->length++] = *buffer++;
		case 3:
		    file->buffer[file->length++] = *buffer++;
		case 2:
		    file->buffer[file->length++] = *buffer++;
		case 1:
		    file->buffer[file->length++] = *buffer++;
		    break;
		default:
		    memcpy(file->buffer + file->length, buffer, size);
		    file->length += size;
		    break;
	    }
	    length += size;
	}

	return (length);
    }

    return ((*file->io_write)(file->descriptor, data, size));
}
Beispiel #15
0
/* This routine is a mess and it, do_dialog, and the Mini_Ghost flag needs
 * to be totally redesigned.
 */
void update(Line *line, int force, int flag, int run_update_hook)
{
   int pc_flag = 1;
   int col;
   static unsigned long last_time;
   Line *hscroll_line_save;

   if (0 == Jed_Display_Initialized)
     return;

#if JED_HAS_SUBPROCESSES
   if (Child_Status_Changed_Flag)
     {
	jed_get_child_status ();
	force = 1;
     }
#endif

   if (Batch) return;

   if (!force && !SLang_get_error () && !SLKeyBoard_Quit && (!*Error_Buffer))
     {
	if (screen_input_pending (0))
	  {
	     JWindow->trashed = 1;
	     return;
	  }
     }

   if (last_time + 30 < Status_This_Time)
     {
	if (last_time == 0) last_time = Status_This_Time;
	else
	  {
	     last_time = Status_This_Time;
	     if (SLang_run_hooks ("update_timer_hook", 0))
	       flag = 0;
	  }
     }

   if (run_update_hook
       && (CBuf->buffer_hooks != NULL)
       && (CBuf->buffer_hooks->update_hook != NULL)
       && (SLang_get_error () == 0))
     {
	Suspend_Screen_Update = 1;
	SLexecute_function (CBuf->buffer_hooks->update_hook);
	if (SLang_get_error ()) CBuf->buffer_hooks->update_hook = NULL;
     }

   if (Suspend_Screen_Update != 0)
     {
	Suspend_Screen_Update = 0;
	touch_screen ();
     }

   if (X_Update_Open_Hook != NULL) (*X_Update_Open_Hook) ();
#ifdef FIX_CHAR_WIDTH
   FIX_CHAR_WIDTH;
#endif
   col = calculate_column ();
   HScroll_Line = NULL;
   if (Wants_HScroll) set_hscroll(col); else HScroll = 0;
   hscroll_line_save = HScroll_Line;

   if (SLang_get_error ()) flag = 0;	       /* update hook invalidates flag */

   if (SLang_get_error () && !(*Error_Buffer || SLKeyBoard_Quit))
     {
	SLang_verror (0, "%s", SLerr_strerror (0));
     }

   if (!flag && (*Error_Buffer || SLKeyBoard_Quit))
     {
	do_dialog(Error_Buffer);
#if 0
	SLKeyBoard_Quit = 0;
	SLang_restart(0);
	SLang_set_error (0);
#endif
	Mini_Ghost = 1;
	(void) update_1(line, 1);
	update_minibuffer();
     }
   else if ((flag == 0) && *Message_Buffer)
     {
	if (!update_1(line, force))
	  goto done;

	do_dialog(Message_Buffer);
	Mini_Ghost = 1;
	update_minibuffer();
     }
   else
     {
	pc_flag = JWindow->trashed || (JWindow != JWindow->next) || Cursor_Motion;
	if (!flag) update_minibuffer();
	if (!update_1(line, force)) goto done;
     }
   if (!flag) *Error_Buffer = *Message_Buffer = 0;

#if JED_HAS_MENUS
   update_top_screen_line ();
#else
   if ((Top_Window_SY > 0) && JScreen[0].is_modified)
     {
	update_top_screen_line ();
     }
#endif
   done:

   HScroll_Line = hscroll_line_save;

   if (MiniBuf_Get_Response_String != NULL)
     {
	do_dialog (MiniBuf_Get_Response_String);
	Mini_Ghost = 1;
     }
   else if (Point_Cursor_Flag || pc_flag)
     point_cursor(col);

   if (X_Update_Close_Hook != NULL) (*X_Update_Close_Hook) ();

   SLsmg_refresh ();
}
Beispiel #16
0
Datei: cmds.c Projekt: hankem/jed
/*{{{ ins_char_cmd */
int ins_char_cmd (void)
{
   unsigned char ch;
   int wrap = Buffer_Local.wrap_column;
   int do_blink;
   int did_abbrev = 0;
   SLang_Name_Type *wrapok_hook;

   CHECK_READ_ONLY
#if 0
     ;
#endif
#if JED_HAS_LINE_ATTRIBUTES
   if (check_line_attr_no_modify (CLine))
     return 0;
#endif

   ch = SLang_Last_Key_Char;

   if (ch == '\n')
     {
	newline();
	return(1);
     }

#if JED_HAS_ABBREVS
   if (CBuf->flags & ABBREV_MODE)
     {
	if (-1 == (did_abbrev = jed_expand_abbrev (ch)))
	  return -1;
     }
#endif

   if ((CBuf->flags & OVERWRITE_MODE) && !eolp())
     {
	/* FIXME: jed_del_wchar should be called for the last byte of a
	 * UTF-8 sequence
	 */
	if ((did_abbrev == 0)
	    && (-1 == jed_del_wchar ()))
	  return -1;
     }

   /* It is ok to use Point as an estimator of the current column.  This
    * avoids the more expensive call to calculate_column.
    */
   if (CBuf->buffer_hooks != NULL)
     wrapok_hook = CBuf->buffer_hooks->wrapok_hook;
   else
     wrapok_hook = NULL;

   if (((ch == ' ') || (Point >= wrap))
       && ((CBuf->modes & WRAP_MODE) || (wrapok_hook != NULL))
       && (calculate_column() > wrap)
       && ((wrapok_hook == NULL)
	   || (1 == execute_is_ok_hook (wrapok_hook))))
     {
	unsigned int this_line_num = LineNum;

	if ((did_abbrev == 0)
	    && (-1 == jed_insert_byte (ch)))
	  return -1;

	if (1 != wrap_line(0))	       /* do not format--- just wrap */
	  return -1;		       /* line isn't wrapable */

	/* There is a bug involving wrapping a very long line containing
	 * no whitespace and then we try to insert a character.  This work
	 * arounds the bug.
	 */
	if ((this_line_num == LineNum)
	    && (ch == ' '))
	    /* && (calculate_column () > wrap)) */
	  {
	     if (0 == jed_right (1))
	       newline ();
	  }

	if ((CBuf->buffer_hooks != NULL)
	    && (CBuf->buffer_hooks->wrap_hook != NULL))
	  SLexecute_function(CBuf->buffer_hooks->wrap_hook);
	else if (Indented_Text_Mode) indent_line ();

	return(1);
     }

   do_blink = ((((CBuf->syntax_table != NULL)
		 && ((CBuf->syntax_table->char_syntax[(unsigned char) ch] & CLOSE_DELIM_SYNTAX)))
		|| ((ch == ')') || (ch == '}') || (ch == ']')))
	       && !input_pending(&Number_Zero));
   if (did_abbrev == 0)
     (void) jed_insert_byte (ch);
   if (do_blink) blink_match ();
   return 1;
}
Beispiel #17
0
Datei: text.c Projekt: hankem/jed
/* format paragraph and if Prefix argument justify_hook is called. */
int text_format_paragraph () /*{{{*/
{
   unsigned char *p;
   int indent_col, col;
   Line *end, *beg, *next;
   Jed_Buffer_Hook_Type *h = CBuf->buffer_hooks;

   CHECK_READ_ONLY

     if ((h != NULL)
	 && (h->format_paragraph_hook != NULL))
       return SLexecute_function (h->format_paragraph_hook);

   push_spot();

   get_current_indent(&indent_col);
   if (indent_col + 1 >= Buffer_Local.wrap_column)
     indent_col = 0;

   if (-1 == mark_paragraph (&beg, &end))
     goto return_error;

   get_current_indent (&col);
   /* col is the indentation of the first line of the paragraph-- don't change it */

   bol ();
   while (CLine != end)
     {
	if (-1 == wrap_line1 (0, 0))
	  goto return_error;

	if (0 == jed_down (1))
	  break;
     }

   while ((CLine != beg)
	  && (0 != jed_up (1)))
     ;

   if (col + 1 >= Buffer_Local.wrap_column)
     indent_to (indent_col);

   bol ();

   /* Now loop formatting as we go until the end is reached */
   while(CLine != end)
     {
	int status;

	/* eol(); */
	if (CLine != beg) indent_to(indent_col);
	status = wrap_line1(1, 1);
	if (status == -1)
	  goto return_error;

	if (status == 1)
	  {
	     (void) jed_down(1);
	     /* indent_to(indent_col); */
	     continue;
	  }
	else if (CLine->next == end)
	  break;

	next = CLine->next;
	if (next != end)
	  {
	     unsigned char *pmax;

	     /* Now count the length of the word on the next line. */
	     (void) jed_down(1);       /* at bol too */

	     if (-1 == jed_trim_whitespace())
	       goto return_error;

	     p = CLine->data;
	     pmax = jed_eol_position (CLine);

	     /* FIXME for other multibyte whitespace chars */
	     while ((p < pmax) && (*p > ' '))
	       p++;

	     jed_up(1);		       /* at eol too */

	     col = calculate_column();

	     /* FIXME for multibyte */
	     if ((p - next->data) + col < Buffer_Local.wrap_column - 1)
	       {
		  if (-1 == _jed_replace_wchar (' '))
		    goto return_error;
	       }
	     else
	       {
		  (void) jed_down(1);
	       }
	  }
     }
   if (Repeat_Factor != NULL)
     {
	SLang_run_hooks("format_paragraph_hook", 0);
	Repeat_Factor = NULL;
     }
   pop_spot();
   return(1);

return_error:
   pop_spot ();
   return -1;
}