diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/Makefile.in readline-4.2/Makefile.in
--- readline-4.2-orig/Makefile.in	Mon Nov 27 17:57:09 2000
+++ readline-4.2/Makefile.in	Mon Jul  9 17:26:14 2001
@@ -94,20 +94,23 @@ CSOURCES = $(srcdir)/readline.c $(srcdir
 	   $(srcdir)/history.c $(srcdir)/histsearch.c $(srcdir)/histexpand.c \
 	   $(srcdir)/histfile.c $(srcdir)/nls.c $(srcdir)/search.c \
 	   $(srcdir)/shell.c $(srcdir)/savestring.c $(srcdir)/tilde.c \
-	   $(srcdir)/compat.c
+	   $(srcdir)/compat.c \
+ 	   $(srcdir)/formatregion.c
 
 # The header files for this library.
 HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \
 	   posixstat.h posixdir.h posixjmp.h tilde.h rlconf.h rltty.h \
 	   ansi_stdlib.h tcap.h rlstdc.h xmalloc.h rlprivate.h rlshell.h \
-	   rltypedefs.h
+	   rltypedefs.h \
+	   formatregion.h
+
 
 HISTOBJ = history.o histexpand.o histfile.o histsearch.o shell.o 
 TILDEOBJ = tilde.o
 OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \
 	  rltty.o complete.o bind.o isearch.o display.o signals.o \
 	  util.o kill.o undo.o macro.o input.o callback.o terminal.o \
-	  nls.o compat.o xmalloc.o $(HISTOBJ) $(TILDEOBJ)
+	  nls.o compat.o xmalloc.o formatregion.o $(HISTOBJ) $(TILDEOBJ)
 
 # The texinfo files which document this library.
 DOCSOURCE = doc/rlman.texinfo doc/rltech.texinfo doc/rluser.texinfo
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/complete.c readline-4.2/complete.c
--- readline-4.2-orig/complete.c	Wed Feb 14 13:47:18 2001
+++ readline-4.2/complete.c	Mon Jul  9 17:29:03 2001
@@ -519,8 +519,8 @@ rl_quote_filename (s, rtype, qcp)
    quote, or backslash) anywhere in the string.  DP, if non-null, is set to
    the value of the delimiter character that caused a word break. */
 
-static char
-find_completion_word (fp, dp)
+char
+_rl_find_completion_word (fp, dp)
      int *fp, *dp;
 {
   int scan, end, found_quote, delimiter, pass_next, isbrk;
@@ -819,7 +819,9 @@ postprocess_matches (matchesp, matching_
   int nmatch, i;
 
   matches = *matchesp;
-
+  if(!matches)
+    return 0;
+  
   /* It seems to me that in all the cases we handle we would like
      to ignore duplicate possiblilities.  Scan for the text to
      insert being identical to the other completions. */
@@ -1186,17 +1188,50 @@ insert_all_matches (matches, point, qc)
   rl_end_undo_group ();
 }
 
-static void
-free_match_list (matches)
+void
+_rl_free_match_list (matches)
      char **matches;
 {
   register int i;
-
+  if(!matches)
+    return;
+  
   for (i = 0; matches[i]; i++)
     free (matches[i]);
   free (matches);
 }
 
+char**
+_rl_available_completions(start,end,found_quote,quote_char)
+     int start;
+     int end;
+     int found_quote;
+     char quote_char;
+{
+  Function *our_func;
+  char *text;
+  char**matches;
+  
+  our_func = rl_completion_entry_function
+		? rl_completion_entry_function
+		: (Function *)rl_filename_completion_function;
+  text = rl_copy_text (start, end);
+  matches = gen_completion_matches (text, start, end, our_func, found_quote, quote_char);
+  free (text);
+
+  /* If we are matching filenames, the attempted completion function will
+     have set rl_filename_completion_desired to a non-zero value.  The basic
+     filename_completion_function does this. */
+  if(!matches)
+    return 0;
+  
+  if(!postprocess_matches (&matches, rl_filename_completion_desired))
+    return 0; /* matches is freed by this function on error */
+  
+  return matches;
+}
+
+
 /* Complete the word at or before point.
    WHAT_TO_DO says what to do with the completion.
    `?' means list the possible completions.
@@ -1209,9 +1244,8 @@ rl_complete_internal (what_to_do)
      int what_to_do;
 {
   char **matches;
-  rl_compentry_func_t *our_func;
   int start, end, delimiter, found_quote, i;
-  char *text, *saved_line_buffer;
+  char *saved_line_buffer;
   char quote_char;
 
   RL_SETSTATE(RL_STATE_COMPLETING);
@@ -1221,9 +1255,6 @@ rl_complete_internal (what_to_do)
   rl_completion_type = what_to_do;
 
   saved_line_buffer = rl_line_buffer ? savestring (rl_line_buffer) : (char *)NULL;
-  our_func = rl_completion_entry_function
-		? rl_completion_entry_function
-		: rl_filename_completion_function;
 
   /* We now look backwards for the start of a filename/variable word. */
   end = rl_point;
@@ -1233,14 +1264,12 @@ rl_complete_internal (what_to_do)
   if (rl_point)
     /* This (possibly) changes rl_point.  If it returns a non-zero char,
        we know we have an open quote. */
-    quote_char = find_completion_word (&found_quote, &delimiter);
+    quote_char = _rl_find_completion_word (&found_quote, &delimiter);
 
   start = rl_point;
   rl_point = end;
 
-  text = rl_copy_text (start, end);
-  matches = gen_completion_matches (text, start, end, our_func, found_quote, quote_char);
-  free (text);
+  matches = _rl_available_completions(start,end,found_quote,quote_char);
 
   if (matches == 0)
     {
@@ -1311,7 +1340,7 @@ rl_complete_internal (what_to_do)
       return 1;
     }
 
-  free_match_list (matches);
+  _rl_free_match_list (matches);
 
   /* Check to see if the line has changed through all of this manipulation. */
   if (saved_line_buffer)
@@ -1667,7 +1696,7 @@ rl_menu_complete (count, ignore)
       /* Clean up from previous call, if any. */
       FREE (orig_text);
       if (matches)
-	free_match_list (matches);
+	_rl_free_match_list (matches);
 
       match_list_index = match_list_size = 0;
       matches = (char **)NULL;
@@ -1689,7 +1718,7 @@ rl_menu_complete (count, ignore)
       if (rl_point)
 	/* This (possibly) changes rl_point.  If it returns a non-zero char,
 	   we know we have an open quote. */
-	quote_char = find_completion_word (&found_quote, &delimiter);
+	quote_char = _rl_find_completion_word (&found_quote, &delimiter);
 
       orig_start = rl_point;
       rl_point = orig_end;
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/display.c readline-4.2/display.c
--- readline-4.2-orig/display.c	Fri Feb  2 19:25:10 2001
+++ readline-4.2/display.c	Mon Jul  9 17:26:14 2001
@@ -52,6 +52,7 @@
 #include "history.h"
 
 #include "rlprivate.h"
+#include "formatregion.h"
 #include "xmalloc.h"
 
 #if !defined (strchr) && !defined (__STDC__)
Binary files readline-4.2-orig/doc/rluserman.dvi and readline-4.2/doc/rluserman.dvi differ
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/examples/Makefile.in readline-4.2/examples/Makefile.in
--- readline-4.2-orig/examples/Makefile.in	Mon Apr  2 20:27:34 2001
+++ readline-4.2/examples/Makefile.in	Mon Jul  9 17:26:13 2001
@@ -52,13 +52,13 @@ OBJECTS = fileman.o rltest.o rl.o rlvers
 all: $(EXECUTABLES)
 everything: all rlfe
 
-rl: rl.o
+rl: rl.o $(READLINE_LIB)
 	$(CC) $(LDFLAGS) -o $@ rl.o -lreadline $(TERMCAP_LIB)
 
-fileman: fileman.o
+fileman: fileman.o $(READLINE_LIB)
 	$(CC) $(LDFLAGS) -o $@ fileman.o -lreadline $(TERMCAP_LIB)
 
-rltest: rltest.o
+rltest: rltest.o $(READLINE_LIB)
 	$(CC) $(LDFLAGS) -o $@ rltest.o -lreadline $(TERMCAP_LIB)
 
 rlversion: rlversion.o $(READLINE_LIB)
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/formatregion.c readline-4.2/formatregion.c
--- readline-4.2-orig/formatregion.c	Thu Jan  1 01:00:00 1970
+++ readline-4.2/formatregion.c	Mon Jul  9 17:26:14 2001
@@ -0,0 +1,595 @@
+#define READLINE_LIBRARY
+
+#if defined (HAVE_CONFIG_H)
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include "readline.h"
+#include "rlprivate.h"
+#include "rldefs.h"
+#include "xmalloc.h"
+
+#include "formatregion.h"
+
+#define DEBUG_FORMATREGION
+
+#ifdef DEBUG_FORMATREGION
+static FILE*debout = 0;
+#define debug(x...)  do { if(debout) {fprintf(debout,x);fflush(debout);} } while(0)
+#else
+static inline void debug(format) 
+      char*format; 
+ {  } 
+#endif
+
+static struct rl_fr_region* fr_regions = 0;
+
+#define fr_tail_completer(fr)			((struct rl_fr_region*)(fr)->private[0])
+#define fr_completer_tail(fr)			((struct rl_fr_region*)(fr)->private[0])
+#define fr_completer_generator(fr)		((rl_fr_completer_generator)(fr)->private[1])
+#define fr_completer_matcher(fr)		((rl_fr_completer_matcher)(fr)->private[2])
+#define fr_completer_user(fr)		((fr)->private[3])
+
+static inline void fr_add_tail __P((struct rl_fr_region*));
+
+static char* minimal_suffix(start,end,suffix)
+     char*start;
+     char*end;
+     char*suffix;
+{
+  char*p,*b,*s;
+  
+  for(p=start;p<end;p++)
+    {
+      if(*p==*suffix){
+	for(b=p,s=suffix;;b++,s++)
+	  {
+	    if(!*b || b>=end)
+	      return s;
+	    
+	    if((*b!=*s) || (!*s))
+	      break;
+	  }
+      }
+  }
+  
+  return 0; /* no match at all: probably an expansion like $HOME ->
+	       /home/john where we don't want to print
+	       $HOME/home/john */
+}
+
+static inline void safeappend(char **buffer, unsigned*len, unsigned* pos, char*str, unsigned slen)
+{
+  if(!str || !slen)
+    return;
+  *len+=slen;
+  (*buffer)=(char*)xrealloc(*buffer,*len);
+
+  {
+    char*i=(*buffer+*pos);
+    char*end=(*buffer+*pos+slen);
+    *pos += slen;
+
+    while(i!=end)*i++=*str++;
+  }
+}
+
+static inline void expand_append(char **buffer, unsigned*len, unsigned* pos, char*str, int*new_point)
+{
+  unsigned slen;
+  
+  if(!str || !str[0]) return;
+
+  slen = strlen(str);
+
+  if(*new_point>*pos)
+    (*new_point)+=slen;
+  
+  safeappend(buffer,len,pos,str,slen);
+}
+
+static void inline debug_dump_regions()
+{
+  struct rl_fr_region* fr;
+  debug("dumping state; line is \"%s\"\n",rl_line_buffer);
+  for(fr=fr_regions;fr;fr=fr->next)
+    {
+      debug("format at %x (start %d, end %d)\n",(unsigned)fr,fr->start,fr->end);
+    }
+}
+      
+static inline short fr_holds_insertwise(fr,point)
+     struct rl_fr_region* fr;
+     int point;
+{
+  if(fr->end==0 && point==0)return 1;
+  return (point > fr->start && point <= fr->end);
+	/* Unexpectedly different in/exclusive rules apply: something
+	   inserted at the end belongs to *this* region */
+}
+static inline void fr_shr(fr,step)
+     struct rl_fr_region* fr;
+     int step;
+{
+  fr->start += step;
+  fr->end += step;
+}
+
+static inline void fr_shl(fr,step)
+     struct rl_fr_region* fr;
+     int step;
+{
+  fr_shr(fr,-step);
+}
+
+
+inline void rl_fr_remove(fr)
+     struct rl_fr_region* fr;
+{
+  if(fr->next)
+    fr->next->prev = fr->prev;
+  if(fr->prev)
+    fr->prev->next = fr->next;
+  if(fr==fr_regions)
+    fr_regions=fr->next;
+
+  fr->dtor(fr);
+  
+  xfree(fr);
+}
+
+static inline short fr_remove_empty(fr)
+     struct rl_fr_region* fr;
+{
+  if(fr->end <= fr->start)
+    {
+      debug("removing %x from %d - %d\n",(unsigned)fr,fr->start,fr->end);
+      rl_fr_remove(fr);
+      return 1;
+    }
+  else return 0;
+}
+
+static inline void fr_add(fr)
+     struct rl_fr_region* fr;
+{
+  fr->prev = 0;
+  fr->next = fr_regions;
+
+  debug("adding %x\n",(unsigned)fr);
+  
+  if(fr_regions)
+    fr_regions->prev = fr;
+  
+  fr_regions = fr;
+  debug_dump_regions();
+}
+
+static inline void fr_start(fr,start)
+     struct rl_fr_region* fr;
+     int start;
+{
+  fr->start = start;
+}
+
+static inline void fr_end(fr,end)
+     struct rl_fr_region* fr;
+     int end;
+{
+  fr->end = end;
+}
+
+static void fr_std_ins(fr,start,length)
+     struct rl_fr_region* fr;
+     int start;
+     int length;
+{
+}
+
+static void fr_std_del(fr,start,length)
+     struct rl_fr_region* fr;
+     int start;
+     int length;
+{
+}
+
+static void fr_std_ponder(fr,buffer)
+     struct rl_fr_region*fr;
+     const char*buffer;
+{
+}
+
+char** rl_fr_tail_matcher(fr)
+     struct rl_fr_region* fr;
+{
+  if(fr->start >= fr->end)
+    return 0;
+      
+  return
+    fr_completer_generator(fr) ?
+    fr_completer_generator(fr)(fr,fr->start,fr->end) : 0;
+}
+
+char** rl_fr_word_matcher(fr)
+     struct rl_fr_region* fr;
+{
+  int start = fr->start;
+  int end = fr->end;
+
+  if(end)
+    {
+      int saved = rl_point;
+      
+      rl_point = end;
+      
+      debug("completing word finding in %s from %d to %d\n",rl_line_buffer,start,end);
+      _rl_find_completion_word (0,0);
+      start = rl_point; /* (semantics) should it be checked that this is *after* fr->start? */
+      debug("completing word found %d to %d: \"",start,end);
+      for(rl_point = start; rl_point < end; rl_point++){
+	debug("%c",rl_line_buffer[rl_point]);
+      }
+      debug("\"\n");
+      rl_point = saved;
+    }
+  if(start>=end||!rl_line_buffer[start])return 0;
+  return
+    fr_completer_generator(fr) ?
+    fr_completer_generator(fr)(fr,start,end) : 0;
+}
+
+
+static void fr_tail_complete(fr)
+     struct rl_fr_region* fr;
+{
+  struct rl_fr_region* completer = fr_tail_completer(fr);
+  int os=fr->start,oe=fr->end,op=rl_point;
+  int ocs=completer->start, oce=completer->end;
+  char**matches= fr_completer_matcher(completer) ?
+    fr_completer_matcher(completer)(completer) : 0;
+  char*match;
+  
+  debug("--- avoiding insert and delete events\n");
+
+  completer->start = fr->start = -2;
+  completer->end = fr->end = -1;
+
+  if(oe>0)
+    rl_delete_text(oce,oce + (oe-os));
+  
+  if(matches && (match=*matches) && *match) {
+    debug("match selected was \"%s\"\n",match);
+    match = minimal_suffix(rl_line_buffer+ocs,rl_line_buffer+oce,match);
+
+    debug("the minimal suffix was \"%s\"\n", match?match:"<null>");
+    
+    if(match) {
+      rl_point = oce;
+      rl_insert_text(match);
+      fr->end = oce+strlen(match);
+
+      if(oe > 0 && op > oe)
+	rl_point = op-oe + fr->end;
+      else
+	rl_point = op;
+    }
+    else
+      fr->end = oce;
+  }
+  else
+    fr->end = oce;
+
+  _rl_free_match_list (matches);
+  
+  completer->start = ocs;
+  completer->end = oce;
+  fr->start = oce;
+  
+  debug("+++ no longer avoiding insert and delete events\n");
+  debug_dump_regions();
+}
+
+static void fr_tail_ins(fr,start,length)
+     struct rl_fr_region* fr;
+     int start;
+     int length;
+{
+  struct rl_fr_region* completer = fr_tail_completer(fr);
+  fr_end(completer,start); /* length will be added on by rl_fr_inserted */
+}
+
+static void fr_tail_del(fr,start,length)
+     struct rl_fr_region* fr;
+     int start;
+     int length;
+{
+  struct rl_fr_region* completer = fr_tail_completer(fr);
+
+  if(start >= completer->end)
+      completer->end = start; /* for future syntax coloring, otherwise a NOP */
+}
+
+
+static void fr_tail_dtor(fr)
+     struct rl_fr_region* fr;
+{
+  if(fr_tail_completer(fr))
+    fr_completer_tail(fr_tail_completer(fr)) = 0;
+}
+
+
+static void fr_completer_ins(fr,start,length)
+     struct rl_fr_region* fr;
+     int start;
+     int length;
+{
+  fr_std_ins(fr,start,length);
+  if(!fr_completer_tail(fr))fr_add_tail(fr);
+
+  fr_tail_complete(fr_completer_tail(fr));
+}
+
+static void fr_completer_del(fr,start,length)
+     struct rl_fr_region* fr;
+     int start;
+     int length;
+{
+  fr_std_del(fr,start,length);
+  if(!fr_completer_tail(fr))fr_add_tail(fr);
+
+  if(start + length <= fr->end)
+    fr_tail_complete(fr_completer_tail(fr));
+}
+
+static void fr_std_clear(fr)
+     struct rl_fr_region* fr;
+{
+  rl_fr_remove(fr);
+}
+
+static void fr_std_dtor(fr)
+     struct rl_fr_region* fr;
+{
+}
+
+static void fr_completer_dtor(fr)
+     struct rl_fr_region* fr;
+{
+  if(fr_completer_tail(fr))
+    fr_tail_completer(fr_completer_tail(fr)) = 0;
+}
+
+static void fr_persist_clear(fr)
+     struct rl_fr_region* fr;
+{
+  fr->start = 0;
+  fr->end = rl_end;
+}
+
+void rl_fr_inserted(start,length)
+     int start;
+     int length;
+{
+  struct rl_fr_region* fr;
+
+  debug("inserted at %d length %d\n",start,length);
+  debug_dump_regions();
+    
+  for(fr=fr_regions;fr;fr=fr->next){
+    if((fr->start || start) && fr->start >= start){
+      fr_shr(fr,length);
+      continue;
+    }
+    if(fr->end < start)
+      continue;
+    fr->end+=length;
+    debug("->ins to %x\n",(unsigned)fr);
+    fr->ins(fr,start,length);
+  }
+  
+  debug("post insert\n");
+  debug_dump_regions();
+}
+
+void rl_fr_deleted(start,length)
+     int start;
+     int length;
+{
+  struct rl_fr_region* fr;
+
+  debug("deleted from %d length %d\n",start,length);
+  debug_dump_regions();
+  if(!length) return;
+  
+  for(fr=fr_regions;fr;fr=fr->next)
+    {
+      if(fr->end <= start)
+	continue;
+	
+      if(fr->start >= start+length)
+	{
+	  fr_shl(fr,length);
+	  continue;
+	}
+
+      if(fr->start <= start) /* fr->end > start */
+	{
+	  if(start+length < fr->end)
+	    {
+	      fr->end -= length;
+	    }
+	  else
+	    {
+	      fr->end = start;
+	    }
+	}
+      else /* fr->start > start */
+	{
+	  if(start+length < fr->end)
+	    {
+	      fr->end -= length - (fr->start - start);
+	      fr->start = start;
+	    }
+	  else /* start+length >= fr-> end && fr->start < start*/
+	    {
+	      fr->start = start;
+	      fr->end = start;
+	    }
+	}
+      debug("->del to %x\n",(unsigned)fr);
+      fr->del(fr,start,length);
+    }
+  debug("post delete\n");
+  debug_dump_regions();
+}
+
+
+inline static void fr_std_init(fr)
+     struct rl_fr_region*fr;
+{
+  fr->on = 0;
+  fr->off = 0;
+  fr->start = 0;
+  fr->end = 0;
+  fr->ponder = fr_std_ponder;
+  fr->ins = fr_std_ins;
+  fr->del = fr_std_del;
+  fr->dtor = fr_std_dtor;
+  fr->clear = fr_std_clear;
+  
+  fr->next = fr->prev = 0;
+}
+
+inline static void fr_tail_init(fr,completer)
+     struct rl_fr_region*fr;
+     struct rl_fr_region*completer;
+{
+  fr_std_init(fr);
+  fr->ins = fr_tail_ins;
+  fr->del = fr_tail_del;
+  fr->dtor = fr_tail_dtor;
+  
+  fr_tail_completer(fr) = completer;
+  fr_completer_tail(completer) = fr;
+}
+
+inline static void fr_add_tail(completer)
+     struct rl_fr_region*completer;
+{
+  struct rl_fr_region*fr=(struct rl_fr_region*)xmalloc(sizeof(struct rl_fr_region));
+
+  fr_tail_init(fr,completer);
+  fr_start(fr,-1);
+  fr_end(fr,-1);
+  
+  fr_add(fr);
+}
+
+inline static void fr_completer_init(fr,matcher,generator,userhook)
+     struct rl_fr_region*fr;
+     rl_fr_completer_matcher matcher;
+     rl_fr_completer_generator generator;
+     void* userhook;
+{
+  fr_std_init(fr);
+
+  fr->ins = fr_completer_ins;
+  fr->del = fr_completer_del;
+
+  fr_completer_matcher(fr) = matcher;
+  fr_completer_generator(fr) = generator;
+  fr_completer_user(fr) = userhook;
+  fr_completer_tail(fr) = 0;
+
+  fr->dtor = fr_completer_dtor;
+}
+
+void rl_fr_add_completer(start,end,matcher,generator,userhook)
+     int start;
+     int end;
+     rl_fr_completer_matcher matcher;
+     rl_fr_completer_generator generator;
+     void* userhook;
+{
+  struct rl_fr_region*fr=(struct rl_fr_region*)xmalloc(sizeof(struct rl_fr_region));
+
+  fr_completer_init(fr,matcher,generator,userhook);
+  fr_start(fr,start);
+  fr_end(fr,end);
+  
+  fr_add(fr);
+}
+
+static void init_fr()
+{
+#ifdef DEBUG_FORMATREGION
+  if(!debout){
+    debout = fopen("/tmp/debout","w");
+  }
+#endif
+  if(!fr_regions){
+    rl_fr_add_completer(0,0,
+			rl_fr_word_matcher,
+			rl_fr_cppfunction_generator,
+			rl_fr_default_matches);
+    rl_fr_persist(fr_regions);
+  }
+}
+
+
+void rl_fr_clear()
+     /* called when a new line appears */
+{
+  struct rl_fr_region *fr, *next;
+  init_fr();
+
+  debug("clearing\n");
+  debug_dump_regions();
+  for(fr=fr_regions;fr;fr=next)
+    {
+      debug("clearing format at %x (start %d, end %d)\n",(unsigned)fr,fr->start,fr->end);
+      next=fr->next;
+      fr->clear(fr); /* most probably will delete the poor thing */
+    }
+}
+
+void rl_fr_persist(fr)
+     struct rl_fr_region*fr;
+{
+  fr->clear = fr_persist_clear;
+}
+
+char** rl_fr_cpfunction_generator(fr,start,end)
+     struct rl_fr_region* fr;
+     int start;
+     int end;
+{
+  char*text = rl_copy_text(start,end);
+  char**matches = completion_matches (text,(CPFunction*)fr_completer_user(fr));
+  debug("cpfunction generator\n");
+  xfree(text);
+  return matches;
+}
+
+char** rl_fr_cppfunction_generator(fr,start,end)
+     struct rl_fr_region* fr;
+     int start;
+     int end;
+{
+  debug("cppfunction generator\n");
+
+  return ((CPPFunction*)fr_completer_user(fr))(rl_line_buffer,start,end);
+}
+ 
+
+char** rl_fr_default_matches(text,start,end)
+     char*text;
+     int start;
+     int end;
+{
+  if(text != rl_line_buffer)abort();
+  
+  return _rl_available_completions(start,end,0,0);
+}
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/formatregion.h readline-4.2/formatregion.h
--- readline-4.2-orig/formatregion.h	Thu Jan  1 01:00:00 1970
+++ readline-4.2/formatregion.h	Mon Jul  9 17:26:14 2001
@@ -0,0 +1,71 @@
+#ifndef _FORMATREGION_H_
+#define _FORMATREGION_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+  /* **************************************************************** */
+  /*								    */
+  /*		      Special format region support    		    */
+  /*								    */
+  /* **************************************************************** */
+
+  struct rl_fr_region;
+  
+  typedef void (*rl_fr_ponder) __P((struct rl_fr_region*,const char*));
+  typedef void (*rl_fr_ins_handler) __P((struct rl_fr_region*,int,int));
+  typedef void (*rl_fr_del_handler) __P((struct rl_fr_region*,int,int));
+  typedef void (*rl_fr_clear_handler) __P((struct rl_fr_region*));
+  typedef void (*rl_fr_dtor) __P((struct rl_fr_region*));
+  
+  struct rl_fr_region {
+    int start; /* inclusive */
+    int end; /* exclusive */
+
+    /* terminal commands */
+    char* on;
+    char* off;
+    
+    rl_fr_ponder ponder;
+    rl_fr_ins_handler ins;
+    rl_fr_del_handler del;
+    rl_fr_dtor dtor;
+    rl_fr_clear_handler clear;
+    
+    struct rl_fr_region* next;
+    struct rl_fr_region* prev;
+
+    void*private[8];
+  };
+
+  typedef char** (*rl_fr_completer_matcher)  __P((struct rl_fr_region*));
+  typedef char** (*rl_fr_completer_generator) __P((struct rl_fr_region*,int,int));
+
+  extern void rl_fr_add_completer __P((int,int,rl_fr_completer_matcher,rl_fr_completer_generator,void*));
+
+  /* A selection of rl_fr_completer_matchers: */
+  extern char** rl_fr_tail_matcher __P((struct rl_fr_region*));
+  extern char** rl_fr_word_matcher __P((struct rl_fr_region*));
+
+  /* A selection of rl_fr_completer_generators: */
+  extern char** rl_fr_cpfunction_generator __P((struct rl_fr_region*,int,int));
+  extern char** rl_fr_cppfunction_generator __P((struct rl_fr_region*,int,int));
+  
+  extern void rl_fr_persist __P((struct rl_fr_region*));
+  
+  extern void rl_fr_remove __P((struct rl_fr_region*));
+  extern void rl_fr_inserted __P((int,int));
+  extern void rl_fr_deleted __P((int,int));
+  extern void rl_fr_clear __P((void));
+
+  extern char** rl_fr_default_matches __P((char*,int,int));
+
+  /*  extern void rl_fr_expand __P((char**,int*,int*));*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_FORMATREGION_H_ */
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/isearch.c readline-4.2/isearch.c
--- readline-4.2-orig/isearch.c	Wed Feb 14 13:37:01 2001
+++ readline-4.2/isearch.c	Mon Jul  9 17:26:14 2001
@@ -304,9 +304,8 @@ rl_search_history (direction, invoking_k
 	  break;
 
 	case CTRL ('G'):
-	  strcpy (rl_line_buffer, lines[orig_line]);
+	  rl_replace_line(lines[orig_line]);
 	  rl_point = orig_point;
-	  rl_end = strlen (rl_line_buffer);
 	  rl_restore_prompt();
 	  rl_clear_message ();
 	  if (allocated_line)
@@ -402,17 +401,11 @@ rl_search_history (direction, invoking_k
 	 the location. */
       if (found)
 	{
-	  int line_len;
-
 	  prev_line_found = lines[i];
-	  line_len = strlen (lines[i]);
 
-	  if (line_len >= rl_line_buffer_len)
-	    rl_extend_line_buffer (line_len);
+	  rl_replace_line(lines[i]);
 
-	  strcpy (rl_line_buffer, lines[i]);
 	  rl_point = line_index;
-	  rl_end = line_len;
 	  last_found_line = i;
 	  rl_display_search (search_string, reverse, (i == orig_line) ? -1 : i);
 	}
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/readline.c readline-4.2/readline.c
--- readline-4.2-orig/readline.c	Mon Apr  2 21:56:20 2001
+++ readline-4.2/readline.c	Mon Jul  9 17:27:24 2001
@@ -65,6 +65,7 @@
 #include "rlprivate.h"
 #include "rlshell.h"
 #include "xmalloc.h"
+#include "formatregion.h"
 
 #ifndef RL_LIBRARY_VERSION
 #  define RL_LIBRARY_VERSION "4.2"
@@ -495,6 +496,8 @@ _rl_init_line_state ()
   rl_point = rl_end = 0;
   the_line = rl_line_buffer;
   the_line[0] = 0;
+  
+  rl_fr_clear();
 }
 
 void
@@ -946,7 +949,7 @@ rl_universal_argument (count, key)
 
 /* **************************************************************** */
 /*								    */
-/*			Insert and Delete			    */
+/*			Insert, replace and Delete		    */
 /*								    */
 /* **************************************************************** */
 
@@ -979,12 +982,31 @@ rl_insert_text (string)
       else
 	rl_add_undo (UNDO_INSERT, rl_point, rl_point + l, (char *)NULL);
     }
-  rl_point += l;
   rl_end += l;
   the_line[rl_end] = '\0';
+
+  rl_fr_inserted(rl_point,l);
+  rl_point += l;
+
   return l;
 }
 
+/* This is the only way in which the_line should be overwritten */
+
+void rl_replace_line(string)
+     char*string;
+{
+  int len=strlen(string);
+  
+  if (len >= rl_line_buffer_len)
+    rl_extend_line_buffer (len);
+
+  strcpy(the_line, string);
+  rl_end = len;
+
+  rl_fr_clear();
+}
+
 /* Delete the string between FROM and TO.  FROM is
    inclusive, TO is not. */
 int
@@ -1003,7 +1025,7 @@ rl_delete_text (from, to)
     {
       to = rl_end;
       if (from > to)
-        from = to;
+	return 0;
     }
 
   text = rl_copy_text (from, to);
@@ -1021,6 +1043,9 @@ rl_delete_text (from, to)
 
   rl_end -= diff;
   the_line[rl_end] = '\0';
+
+  rl_fr_deleted(from,diff);
+
   return (diff);
 }
 
@@ -1908,6 +1933,7 @@ rl_maybe_replace_line ()
       free (temp->line);
       free (temp);
     }
+
   return 0;
 }
 
@@ -1919,16 +1945,12 @@ rl_maybe_unsave_line ()
 
   if (_rl_saved_line_for_history)
     {
-      line_len = strlen (_rl_saved_line_for_history->line);
-
-      if (line_len >= rl_line_buffer_len)
-	rl_extend_line_buffer (line_len);
-
-      strcpy (the_line, _rl_saved_line_for_history->line);
+      rl_replace_line(_rl_saved_line_for_history->line);
+       
       rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data;
       _rl_free_history_entry (_rl_saved_line_for_history);
       _rl_saved_line_for_history = (HIST_ENTRY *)NULL;
-      rl_end = rl_point = strlen (the_line);
+      rl_point = rl_end;
     }
   else
     rl_ding ();
@@ -1984,13 +2006,31 @@ rl_end_of_history (count, key)
   return 0;
 }
 
+/* Replace the current line with one from the history */
+void
+rl_become_history(temp)
+     HIST_ENTRY* temp;
+{
+  int line_len;
+  
+  rl_replace_line(temp->line);
+  
+  rl_undo_list = (UNDO_LIST *)temp->data;
+  rl_point = rl_end;
+  
+#if defined (VI_MODE)
+  if (rl_editing_mode == vi_mode)
+    rl_point = 0;
+#endif /* VI_MODE */
+}
+
+
 /* Move down to the next history line. */
 int
 rl_get_next_history (count, key)
      int count, key;
 {
   HIST_ENTRY *temp;
-  int line_len;
 
   if (count < 0)
     return (rl_get_previous_history (-count, key));
@@ -2012,20 +2052,7 @@ rl_get_next_history (count, key)
   if (temp == 0)
     rl_maybe_unsave_line ();
   else
-    {
-      line_len = strlen (temp->line);
-
-      if (line_len >= rl_line_buffer_len)
-	rl_extend_line_buffer (line_len);
-
-      strcpy (the_line, temp->line);
-      rl_undo_list = (UNDO_LIST *)temp->data;
-      rl_end = rl_point = strlen (the_line);
-#if defined (VI_MODE)
-      if (rl_editing_mode == vi_mode)
-	rl_point = 0;
-#endif /* VI_MODE */
-    }
+    rl_become_history(temp);
   return 0;
 }
 
@@ -2036,7 +2063,6 @@ rl_get_previous_history (count, key)
      int count, key;
 {
   HIST_ENTRY *old_temp, *temp;
-  int line_len;
 
   if (count < 0)
     return (rl_get_next_history (-count, key));
@@ -2069,21 +2095,7 @@ rl_get_previous_history (count, key)
   if (temp == 0)
     rl_ding ();
   else
-    {
-      line_len = strlen (temp->line);
-
-      if (line_len >= rl_line_buffer_len)
-	rl_extend_line_buffer (line_len);
-
-      strcpy (the_line, temp->line);
-      rl_undo_list = (UNDO_LIST *)temp->data;
-      rl_end = rl_point = line_len;
-
-#if defined (VI_MODE)
-      if (rl_editing_mode == vi_mode)
-	rl_point = 0;
-#endif /* VI_MODE */
-    }
+    rl_become_history(temp);
   return 0;
 }
 
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/readline.h readline-4.2/readline.h
--- readline-4.2-orig/readline.h	Wed Feb 14 22:27:54 2001
+++ readline-4.2/readline.h	Mon Jul  9 17:26:14 2001
@@ -361,6 +361,7 @@ extern void rl_restore_prompt __P((void)
 
 /* Modifying text. */
 extern int rl_insert_text __P((const char *));
+extern void rl_replace_line __P((char*));  
 extern int rl_delete_text __P((int, int));
 extern int rl_kill_text __P((int, int));
 extern char *rl_copy_text __P((int, int));
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/rlprivate.h readline-4.2/rlprivate.h
--- readline-4.2-orig/rlprivate.h	Wed Feb 14 13:43:14 2001
+++ readline-4.2/rlprivate.h	Mon Jul  9 17:26:14 2001
@@ -34,6 +34,11 @@
  *									 *
  *************************************************************************/
 
+/* complete.c */
+extern char** _rl_available_completions __P((int,int,int,char));
+extern char _rl_find_completion_word  __P((int*, int*));
+extern void _rl_free_match_list __P((char**));
+
 /* terminal.c */
 extern char *rl_get_termcap __P((const char *));
 
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/search.c readline-4.2/search.c
--- readline-4.2-orig/search.c	Thu Nov  2 19:13:25 2000
+++ readline-4.2/search.c	Mon Jul  9 17:26:14 2001
@@ -73,15 +73,8 @@ static void
 make_history_line_current (entry)
      HIST_ENTRY *entry;
 {
-  int line_len;
-
-  line_len = strlen (entry->line);
-  if (line_len >= rl_line_buffer_len)
-    rl_extend_line_buffer (line_len);
-  strcpy (rl_line_buffer, entry->line);
-
+  rl_replace_line(entry->line);
   rl_undo_list = (UNDO_LIST *)entry->data;
-  rl_end = line_len;
 
   if (_rl_saved_line_for_history)
     _rl_free_history_entry (_rl_saved_line_for_history);
@@ -184,6 +177,7 @@ noninc_search (dir, pchar)
   /* Use the line buffer to read the search string. */
   rl_line_buffer[0] = 0;
   rl_end = rl_point = 0;
+  rl_fr_clear();
 
   p = _rl_make_prompt_for_search (pchar ? pchar : ':');
   rl_message (p, 0, 0);
@@ -365,6 +359,7 @@ rl_history_search_internal (count, dir)
       if (rl_point > rl_history_search_len)
         {
           rl_point = rl_end = rl_history_search_len;
+	  rl_fr_clear();
           rl_line_buffer[rl_end] = '\0';
         }
 #else
diff --new-file --exclude *~ --exclude *.orig --exclude *.rej -p -r -u readline-4.2-orig/shlib/Makefile.in readline-4.2/shlib/Makefile.in
--- readline-4.2-orig/shlib/Makefile.in	Mon Nov 27 18:03:27 2000
+++ readline-4.2/shlib/Makefile.in	Mon Jul  9 17:26:13 2001
@@ -111,19 +111,22 @@ CSOURCES = $(topdir)/readline.c $(topdir
 	   $(topdir)/history.c $(topdir)/histsearch.c $(topdir)/histexpand.c \
 	   $(topdir)/histfile.c $(topdir)/nls.c $(topdir)/search.c \
 	   $(topdir)/shell.c $(topdir)/savestring.c $(topdir)/compat.c \
-	   $(topdir)/tilde.c
+	   $(topdir)/tilde.c \
+ 	   $(srcdir)/formatregion.c
 
 # The header files for this library.
 HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \
 	   posixstat.h posixdir.h posixjmp.h tilde.h rlconf.h rltty.h \
-	   ansi_stdlib.h tcap.h xmalloc.h rlprivate.h rlshell.h
+	   ansi_stdlib.h tcap.h xmalloc.h rlprivate.h rlshell.h \
+	   formatregion.h
 
 SHARED_HISTOBJ = history.so histexpand.so histfile.so histsearch.so shell.so
 SHARED_TILDEOBJ = tilde.so
 SHARED_OBJ = readline.so vi_mode.so funmap.so keymaps.so parens.so search.so \
 	  rltty.so complete.so bind.so isearch.so display.so signals.so \
 	  util.so kill.so undo.so macro.so input.so callback.so terminal.so \
-	  nls.so xmalloc.so $(SHARED_HISTOBJ) $(SHARED_TILDEOBJ) compat.so
+	  nls.so xmalloc.so $(SHARED_HISTOBJ) $(SHARED_TILDEOBJ) compat.so \
+	  formatregion.so
 
 ##########################################################################
 

