Index: ChangeLog
===================================================================
--- ChangeLog	(revision 8df36cc2631c7dbc8f5ac107c698deb731eafead)
+++ ChangeLog	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -28,5 +28,11 @@
 	Always clear the command buffer before executing the command.
 	        (So that interactive commands can sanely do start-command.)
-
+	Fixed preservation of e->dotsend across owl_editwin_clear().
+	Added history for multiline edit windows (eg, for zephyr composition).
+	        The M-n and M-p keys will cycle through the history ring.
+		In particular, it is now possible to edit the command line
+		of a zephyr being composed:  C-c it and restart it 
+		and then M-p to get the aborted composition back.
+	
 1.2.1-pre-1
 	Added RCS Id strings to all files.
Index: commands.c
===================================================================
--- commands.c	(revision 8df36cc2631c7dbc8f5ac107c698deb731eafead)
+++ commands.c	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -593,10 +593,10 @@
 
   OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
-		  OWL_CTX_EDITLINE,
+		  OWL_CTX_EDIT,
 		  "replaces the text with the previous history",
 		  "", ""),
 
   OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
-		  OWL_CTX_EDITLINE,
+		  OWL_CTX_EDIT,
 		  "replaces the text with the previous history",
 		  "", ""),
@@ -1478,10 +1478,17 @@
 
 void owl_command_edit_cancel(owl_editwin *e) {
+  owl_history *hist;
+
   owl_function_makemsg("Command cancelled.");
+
+  hist=owl_editwin_get_history(e);
+  owl_history_store(hist, owl_editwin_get_text(e));
+  owl_history_reset(hist);
+
   owl_editwin_fullclear(e);
   owl_global_set_needrefresh(&g);
   wnoutrefresh(owl_editwin_get_curswin(e));
   owl_global_set_typwin_inactive(&g);
-  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE);
+  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
 }
 
@@ -1490,5 +1497,5 @@
   char *ptr;
 
-  hist=owl_global_get_history(&g);
+  hist=owl_editwin_get_history(e);
   if (!owl_history_is_touched(hist)) {
     owl_history_store(hist, owl_editwin_get_text(e));
@@ -1510,5 +1517,5 @@
   char *ptr;
 
-  hist=owl_global_get_history(&g);
+  hist=owl_editwin_get_history(e);
   ptr=owl_history_get_next(hist);
   if (ptr) {
@@ -1531,10 +1538,10 @@
 
 void owl_command_editline_done(owl_editwin *e) {
-  owl_history *hist=owl_global_get_history(&g);
+  owl_history *hist=owl_editwin_get_history(e);
   char *rv, *cmd;
 
-  owl_global_set_typwin_inactive(&g);
   owl_history_store(hist, owl_editwin_get_text(e));
   owl_history_reset(hist);
+  owl_global_set_typwin_inactive(&g);
   cmd = owl_strdup(owl_editwin_get_text(e));
   owl_editwin_fullclear(e);
@@ -1552,6 +1559,11 @@
 
 void owl_command_editmulti_done(owl_editwin *e) {
+  owl_history *hist=owl_editwin_get_history(e);
+
+  owl_history_store(hist, owl_editwin_get_text(e));
+  owl_history_reset(hist);
+
   owl_function_run_buffercommand();
-  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE);
+  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
   owl_editwin_fullclear(e);
   owl_global_set_typwin_inactive(&g);
Index: context.c
===================================================================
--- context.c	(revision 1aee7d914de75510e7cf09c452bad63b2dad2166)
+++ context.c	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -16,5 +16,5 @@
 /* returns whether test matches the current context */
 int owl_context_matches(owl_context *ctx, int test) {
-  owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);
+  /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/
   if ((((ctx->mode&OWL_CTX_MODE_BITS) & test)
        || !(test&OWL_CTX_MODE_BITS))
Index: editwin.c
===================================================================
--- editwin.c	(revision 217a43edbf201d330595640b4d5c648d09e4b753)
+++ editwin.c	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -3,4 +3,5 @@
 #include <unistd.h>
 #include <string.h>
+#include <ctype.h>
 
 static const char fileIdent[] = "$Id$";
@@ -8,11 +9,12 @@
 #define INCR 5000
 
-void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style) {
+void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist) {
   /* initialize the editwin e.
    * 'win' is an already initialzed curses window that will be used by editwin
    */
-  e->buff=owl_malloc(INCR);
+  e->buff=owl_malloc(INCR);  
   e->buff[0]='\0';
   e->bufflen=0;
+  e->hist=hist;
   e->allocated=INCR;
   e->buffx=0;
@@ -50,4 +52,12 @@
 }
 
+void owl_editwin_set_history(owl_editwin *e, owl_history *h) {
+  e->hist = h;
+}
+
+owl_history *owl_editwin_get_history(owl_editwin *e) {
+  return e->hist;
+}
+
 void owl_editwin_set_dotsend(owl_editwin *e) {
   e->dotsend=1;
@@ -85,7 +95,8 @@
 }
 
-void owl_editwin_new_style(owl_editwin *e, int newstyle) {
+void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h) {
   char *ptr;
-  
+
+  owl_editwin_set_history(e, h);
   if (e->style==newstyle) return;
 
@@ -111,5 +122,5 @@
   /* completly reinitialize the buffer */
   owl_free(e->buff);
-  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style);
+  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
 }
 
@@ -117,6 +128,7 @@
   /* clear all text except for locktext and put the cursor at the beginning */
   int lock;
+  int dotsend=e->dotsend;
   char *locktext=NULL;
-  
+
   lock=0;
   if (e->lock > 0) {
@@ -129,8 +141,11 @@
 
   owl_free(e->buff);
-  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style);
+  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
 
   if (lock > 0) {
     owl_editwin_set_locktext(e, locktext);
+  }
+  if (dotsend) {
+    owl_editwin_set_dotsend(e);
   }
 
@@ -742,16 +757,6 @@
 /* returns if only whitespace remains */
 int owl_editwin_is_at_end(owl_editwin *e) {
-  int i, cur;  
-  cur=_owl_editwin_get_index_from_xy(e);
-  if (cur >= e->bufflen) return(1);
-  for (i=e->bufflen-1; i>cur; i--) {
-    if (e->buff[i] != '\r'
-	&& e->buff[i] != '\n'
-	&& e->buff[i] != ' ') {
-      return(0);
-    }
-  }
-  if (cur==i) return(1);
-  else return(0);
+  int cur=_owl_editwin_get_index_from_xy(e);
+  return only_whitespace(e->buff+cur);
 }
 
@@ -768,7 +773,5 @@
       return(1);
     }
-    if (e->buff[i] != '\r'
-	&& e->buff[i] != '\n'
-	&& e->buff[i] != ' ') {
+    if (!isspace(e->buff[i])) {
       return(0);
     }
Index: functions.c
===================================================================
--- functions.c	(revision 217a43edbf201d330595640b4d5c648d09e4b753)
+++ functions.c	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -124,5 +124,6 @@
   /* create and setup the editwin */
   e=owl_global_get_typwin(&g);
-  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE);
+  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE,
+			owl_global_get_msg_history(&g));
 
   if (!owl_global_get_lockout_ctrld(&g)) {
@@ -1416,7 +1417,8 @@
 
       if (enter) {
-	owl_history_store(owl_global_get_history(&g), buff);
-	owl_function_zwrite_setup(buff);
-	owl_global_set_buffercommand(&g, buff);
+	owl_history *hist = owl_global_get_cmd_history(&g);
+	owl_history_store(hist, buff);
+	owl_history_reset(hist);
+	owl_function_command_norv(buff);
       } else {
 	owl_function_start_command(buff);
@@ -1447,4 +1449,7 @@
   tw=owl_global_get_typwin(&g);
   owl_global_set_typwin_active(&g);
+  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, 
+			owl_global_get_cmd_history(&g));
+
   owl_editwin_set_locktext(tw, "command: ");
   owl_global_set_needrefresh(&g);
Index: global.c
===================================================================
--- global.c	(revision 1aee7d914de75510e7cf09c452bad63b2dad2166)
+++ global.c	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -42,5 +42,5 @@
   g->rightshift=0;
 
-  owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE);
+  owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
 
   owl_keyhandler_init(&g->kh);
@@ -65,5 +65,6 @@
   owl_global_set_userclue(g, OWL_USERCLUE_NONE);
   owl_global_set_no_have_config(g);
-  owl_history_init(&(g->hist));
+  owl_history_init(&(g->msghist));
+  owl_history_init(&(g->cmdhist));
   g->nextmsgid=0;
 
@@ -486,6 +487,10 @@
 /* history */
 
-owl_history *owl_global_get_history(owl_global *g) {
-  return(&(g->hist));
+owl_history *owl_global_get_msg_history(owl_global *g) {
+  return(&(g->msghist));
+}
+
+owl_history *owl_global_get_cmd_history(owl_global *g) {
+  return(&(g->cmdhist));
 }
 
Index: history.c
===================================================================
--- history.c	(revision 1aee7d914de75510e7cf09c452bad63b2dad2166)
+++ history.c	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -5,10 +5,12 @@
 void owl_history_init(owl_history *h) {
   owl_list_create(&(h->hist));
-  h->cur=0;
-  h->touched=0;
-  h->partial=0;
+  h->cur=0;			/* current position in history */
+  h->touched=0;			/* whether we've gone into history */
+  h->partial=0;			/* is the 0th element is partially composed? */
 }
 
 char *owl_history_get_prev(owl_history *h) {
+
+  if (!h) return NULL;
   h->touched=1;
 
@@ -20,10 +22,11 @@
 
   h->cur++;
+
   return(owl_list_get_element(&(h->hist), h->cur));
 }
 
 char *owl_history_get_next(owl_history *h) {
+  if (!h) return NULL;
   if (owl_list_get_size(&(h->hist))==0) return(NULL);
-
   if (h->cur==0) {
     return(NULL);
@@ -37,9 +40,11 @@
   int size;
 
+  if (!h) return;
+
   /* if partial is set, remove the first entry first */
   if (h->partial) {
     owl_list_remove_element(&(h->hist), 0);
   }
-    
+
   /* if we've reached the max history size, pop off the last element */
   size=owl_list_get_size(&(h->hist));
@@ -54,8 +59,10 @@
 
 void owl_history_set_partial(owl_history *h) {
+  if (!h) return;
   h->partial=1;
 }
 
 void owl_history_reset(owl_history *h) {
+  if (!h) return;
   h->cur=0;
   h->touched=0;
@@ -64,4 +71,5 @@
 
 int owl_history_is_touched(owl_history *h) {
+  if (!h) return(0);
   if (h->touched) return(1);
   return(0);
Index: keymap.c
===================================================================
--- keymap.c	(revision 1aee7d914de75510e7cf09c452bad63b2dad2166)
+++ keymap.c	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -201,6 +201,8 @@
   }
 
-  owl_function_debugmsg("processkey: got key %d, active keymap %s, stack at %d",
-			j, kh->active->name, kh->kpstackpos);
+  /*
+    owl_function_debugmsg("processkey: got key %d, active keymap %s, stack at %d",
+    j, kh->active->name, kh->kpstackpos);
+  */
 
   /* deal with ESC prefixing */
@@ -236,8 +238,9 @@
       match = owl_keybinding_match(kb, kh->kpstack);
       if (match == 1) {		/* subset match */
-	owl_function_debugmsg("processkey: found subset match in %s", km->name);
+
+	/* owl_function_debugmsg("processkey: found subset match in %s", km->name); */
 	return(0);
       } else if (match == 2) {	/* exact match */
-	owl_function_debugmsg("processkey: found exact match in %s", km->name);
+	/* owl_function_debugmsg("processkey: found exact match in %s", km->name); */
 	owl_keybinding_execute(kb, j);
 	owl_keyhandler_reset(kh);
@@ -252,5 +255,6 @@
   /* see if a default action exists for the active keymap */
   if (kh->active->default_fn && kh->kpstackpos<1) {
-    owl_function_debugmsg("processkey: executing default_fn");
+    /*owl_function_debugmsg("processkey: executing default_fn");*/
+
     kh->active->default_fn(j);
     owl_keyhandler_reset(kh);
Index: keys.c
===================================================================
--- keys.c	(revision 217a43edbf201d330595640b4d5c648d09e4b753)
+++ keys.c	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -93,4 +93,7 @@
   /* This would be nice, but interferes with C-c to cancel */
   /*BIND_CMD("C-c C-c", "editmulti:done", "sends the zephyr");*/
+
+  BIND_CMD("M-p",         "edit:history-prev", "");
+  BIND_CMD("M-n",         "edit:history-next", "");
 
   /* note that changing "disable-ctrl-d" to "on" will change this to 
Index: owl.h
===================================================================
--- owl.h	(revision 1c7a4e01f25bb2fae17ec297a02deae08a0e92e6)
+++ owl.h	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -238,17 +238,4 @@
 } owl_mainwin;
 
-typedef struct _owl_editwin {
-  char *buff;
-  int bufflen;
-  int allocated;
-  int buffx, buffy;
-  int topline;
-  int winlines, wincols, fillcol, wrapcol;
-  WINDOW *curswin;
-  int style;
-  int lock;
-  int dotsend;
-} owl_editwin;
-
 typedef struct _owl_viewwin {
   owl_fmtext fmtext;
@@ -305,4 +292,18 @@
 } owl_history;
 
+typedef struct _owl_editwin {
+  char *buff;
+  owl_history *hist;
+  int bufflen;
+  int allocated;
+  int buffx, buffy;
+  int topline;
+  int winlines, wincols, fillcol, wrapcol;
+  WINDOW *curswin;
+  int style;
+  int lock;
+  int dotsend;
+} owl_editwin;
+
 typedef struct _owl_keybinding {
   int  *j;			/* keypress stack (0-terminated) */  
@@ -334,5 +335,6 @@
   owl_mainwin mw;
   owl_popwin pw;
-  owl_history hist;
+  owl_history cmdhist;		/* command history */
+  owl_history msghist;		/* outgoing message history */
   owl_keyhandler kh;
   owl_list filterlist;
Index: util.c
===================================================================
--- util.c	(revision 1c6c4d32e1e8e1d158e1586d924d0c440edc8a8b)
+++ util.c	(revision 10b866d633f70e1c8778b601ad1cc1b6596e8563)
@@ -299,4 +299,12 @@
 }
 
+/* returns if a string is only whitespace */
+int only_whitespace(char *s) {
+  int i;
+  for (i=0; s[i]; i++) {
+    if (!isspace(s[i])) return(0);
+  }
+  return(1);
+}
 
 void *owl_malloc(size_t size) {
