Changeset 10b866d


Ignore:
Timestamp:
Jul 8, 2002, 10:37:21 PM (19 years ago)
Author:
Erik Nygren <nygren@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
e1c4636
Parents:
8df36cc
Message:
* 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.
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r8df36cc r10b866d  
    2828        Always clear the command buffer before executing the command.
    2929                (So that interactive commands can sanely do start-command.)
    30 
     30        Fixed preservation of e->dotsend across owl_editwin_clear().
     31        Added history for multiline edit windows (eg, for zephyr composition).
     32                The M-n and M-p keys will cycle through the history ring.
     33                In particular, it is now possible to edit the command line
     34                of a zephyr being composed:  C-c it and restart it
     35                and then M-p to get the aborted composition back.
     36       
    31371.2.1-pre-1
    3238        Added RCS Id strings to all files.
  • commands.c

    r8df36cc r10b866d  
    593593
    594594  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next,
    595                   OWL_CTX_EDITLINE,
     595                  OWL_CTX_EDIT,
    596596                  "replaces the text with the previous history",
    597597                  "", ""),
    598598
    599599  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev,
    600                   OWL_CTX_EDITLINE,
     600                  OWL_CTX_EDIT,
    601601                  "replaces the text with the previous history",
    602602                  "", ""),
     
    14781478
    14791479void owl_command_edit_cancel(owl_editwin *e) {
     1480  owl_history *hist;
     1481
    14801482  owl_function_makemsg("Command cancelled.");
     1483
     1484  hist=owl_editwin_get_history(e);
     1485  owl_history_store(hist, owl_editwin_get_text(e));
     1486  owl_history_reset(hist);
     1487
    14811488  owl_editwin_fullclear(e);
    14821489  owl_global_set_needrefresh(&g);
    14831490  wnoutrefresh(owl_editwin_get_curswin(e));
    14841491  owl_global_set_typwin_inactive(&g);
    1485   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE);
     1492  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
    14861493}
    14871494
     
    14901497  char *ptr;
    14911498
    1492   hist=owl_global_get_history(&g);
     1499  hist=owl_editwin_get_history(e);
    14931500  if (!owl_history_is_touched(hist)) {
    14941501    owl_history_store(hist, owl_editwin_get_text(e));
     
    15101517  char *ptr;
    15111518
    1512   hist=owl_global_get_history(&g);
     1519  hist=owl_editwin_get_history(e);
    15131520  ptr=owl_history_get_next(hist);
    15141521  if (ptr) {
     
    15311538
    15321539void owl_command_editline_done(owl_editwin *e) {
    1533   owl_history *hist=owl_global_get_history(&g);
     1540  owl_history *hist=owl_editwin_get_history(e);
    15341541  char *rv, *cmd;
    15351542
    1536   owl_global_set_typwin_inactive(&g);
    15371543  owl_history_store(hist, owl_editwin_get_text(e));
    15381544  owl_history_reset(hist);
     1545  owl_global_set_typwin_inactive(&g);
    15391546  cmd = owl_strdup(owl_editwin_get_text(e));
    15401547  owl_editwin_fullclear(e);
     
    15521559
    15531560void owl_command_editmulti_done(owl_editwin *e) {
     1561  owl_history *hist=owl_editwin_get_history(e);
     1562
     1563  owl_history_store(hist, owl_editwin_get_text(e));
     1564  owl_history_reset(hist);
     1565
    15541566  owl_function_run_buffercommand();
    1555   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE);
     1567  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
    15561568  owl_editwin_fullclear(e);
    15571569  owl_global_set_typwin_inactive(&g);
  • context.c

    r1aee7d9 r10b866d  
    1616/* returns whether test matches the current context */
    1717int owl_context_matches(owl_context *ctx, int test) {
    18   owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);
     18  /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/
    1919  if ((((ctx->mode&OWL_CTX_MODE_BITS) & test)
    2020       || !(test&OWL_CTX_MODE_BITS))
  • editwin.c

    r217a43e r10b866d  
    33#include <unistd.h>
    44#include <string.h>
     5#include <ctype.h>
    56
    67static const char fileIdent[] = "$Id$";
     
    89#define INCR 5000
    910
    10 void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style) {
     11void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist) {
    1112  /* initialize the editwin e.
    1213   * 'win' is an already initialzed curses window that will be used by editwin
    1314   */
    14   e->buff=owl_malloc(INCR);
     15  e->buff=owl_malloc(INCR); 
    1516  e->buff[0]='\0';
    1617  e->bufflen=0;
     18  e->hist=hist;
    1719  e->allocated=INCR;
    1820  e->buffx=0;
     
    5052}
    5153
     54void owl_editwin_set_history(owl_editwin *e, owl_history *h) {
     55  e->hist = h;
     56}
     57
     58owl_history *owl_editwin_get_history(owl_editwin *e) {
     59  return e->hist;
     60}
     61
    5262void owl_editwin_set_dotsend(owl_editwin *e) {
    5363  e->dotsend=1;
     
    8595}
    8696
    87 void owl_editwin_new_style(owl_editwin *e, int newstyle) {
     97void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h) {
    8898  char *ptr;
    89  
     99
     100  owl_editwin_set_history(e, h);
    90101  if (e->style==newstyle) return;
    91102
     
    111122  /* completly reinitialize the buffer */
    112123  owl_free(e->buff);
    113   owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style);
     124  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
    114125}
    115126
     
    117128  /* clear all text except for locktext and put the cursor at the beginning */
    118129  int lock;
     130  int dotsend=e->dotsend;
    119131  char *locktext=NULL;
    120  
     132
    121133  lock=0;
    122134  if (e->lock > 0) {
     
    129141
    130142  owl_free(e->buff);
    131   owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style);
     143  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
    132144
    133145  if (lock > 0) {
    134146    owl_editwin_set_locktext(e, locktext);
     147  }
     148  if (dotsend) {
     149    owl_editwin_set_dotsend(e);
    135150  }
    136151
     
    742757/* returns if only whitespace remains */
    743758int owl_editwin_is_at_end(owl_editwin *e) {
    744   int i, cur; 
    745   cur=_owl_editwin_get_index_from_xy(e);
    746   if (cur >= e->bufflen) return(1);
    747   for (i=e->bufflen-1; i>cur; i--) {
    748     if (e->buff[i] != '\r'
    749         && e->buff[i] != '\n'
    750         && e->buff[i] != ' ') {
    751       return(0);
    752     }
    753   }
    754   if (cur==i) return(1);
    755   else return(0);
     759  int cur=_owl_editwin_get_index_from_xy(e);
     760  return only_whitespace(e->buff+cur);
    756761}
    757762
     
    768773      return(1);
    769774    }
    770     if (e->buff[i] != '\r'
    771         && e->buff[i] != '\n'
    772         && e->buff[i] != ' ') {
     775    if (!isspace(e->buff[i])) {
    773776      return(0);
    774777    }
  • functions.c

    r217a43e r10b866d  
    124124  /* create and setup the editwin */
    125125  e=owl_global_get_typwin(&g);
    126   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE);
     126  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE,
     127                        owl_global_get_msg_history(&g));
    127128
    128129  if (!owl_global_get_lockout_ctrld(&g)) {
     
    14161417
    14171418      if (enter) {
    1418         owl_history_store(owl_global_get_history(&g), buff);
    1419         owl_function_zwrite_setup(buff);
    1420         owl_global_set_buffercommand(&g, buff);
     1419        owl_history *hist = owl_global_get_cmd_history(&g);
     1420        owl_history_store(hist, buff);
     1421        owl_history_reset(hist);
     1422        owl_function_command_norv(buff);
    14211423      } else {
    14221424        owl_function_start_command(buff);
     
    14471449  tw=owl_global_get_typwin(&g);
    14481450  owl_global_set_typwin_active(&g);
     1451  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE,
     1452                        owl_global_get_cmd_history(&g));
     1453
    14491454  owl_editwin_set_locktext(tw, "command: ");
    14501455  owl_global_set_needrefresh(&g);
  • global.c

    r1aee7d9 r10b866d  
    4242  g->rightshift=0;
    4343
    44   owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE);
     44  owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
    4545
    4646  owl_keyhandler_init(&g->kh);
     
    6565  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
    6666  owl_global_set_no_have_config(g);
    67   owl_history_init(&(g->hist));
     67  owl_history_init(&(g->msghist));
     68  owl_history_init(&(g->cmdhist));
    6869  g->nextmsgid=0;
    6970
     
    486487/* history */
    487488
    488 owl_history *owl_global_get_history(owl_global *g) {
    489   return(&(g->hist));
     489owl_history *owl_global_get_msg_history(owl_global *g) {
     490  return(&(g->msghist));
     491}
     492
     493owl_history *owl_global_get_cmd_history(owl_global *g) {
     494  return(&(g->cmdhist));
    490495}
    491496
  • history.c

    r1aee7d9 r10b866d  
    55void owl_history_init(owl_history *h) {
    66  owl_list_create(&(h->hist));
    7   h->cur=0;
    8   h->touched=0;
    9   h->partial=0;
     7  h->cur=0;                     /* current position in history */
     8  h->touched=0;                 /* whether we've gone into history */
     9  h->partial=0;                 /* is the 0th element is partially composed? */
    1010}
    1111
    1212char *owl_history_get_prev(owl_history *h) {
     13
     14  if (!h) return NULL;
    1315  h->touched=1;
    1416
     
    2022
    2123  h->cur++;
     24
    2225  return(owl_list_get_element(&(h->hist), h->cur));
    2326}
    2427
    2528char *owl_history_get_next(owl_history *h) {
     29  if (!h) return NULL;
    2630  if (owl_list_get_size(&(h->hist))==0) return(NULL);
    27 
    2831  if (h->cur==0) {
    2932    return(NULL);
     
    3740  int size;
    3841
     42  if (!h) return;
     43
    3944  /* if partial is set, remove the first entry first */
    4045  if (h->partial) {
    4146    owl_list_remove_element(&(h->hist), 0);
    4247  }
    43    
     48
    4449  /* if we've reached the max history size, pop off the last element */
    4550  size=owl_list_get_size(&(h->hist));
     
    5459
    5560void owl_history_set_partial(owl_history *h) {
     61  if (!h) return;
    5662  h->partial=1;
    5763}
    5864
    5965void owl_history_reset(owl_history *h) {
     66  if (!h) return;
    6067  h->cur=0;
    6168  h->touched=0;
     
    6471
    6572int owl_history_is_touched(owl_history *h) {
     73  if (!h) return(0);
    6674  if (h->touched) return(1);
    6775  return(0);
  • keymap.c

    r1aee7d9 r10b866d  
    201201  }
    202202
    203   owl_function_debugmsg("processkey: got key %d, active keymap %s, stack at %d",
    204                         j, kh->active->name, kh->kpstackpos);
     203  /*
     204    owl_function_debugmsg("processkey: got key %d, active keymap %s, stack at %d",
     205    j, kh->active->name, kh->kpstackpos);
     206  */
    205207
    206208  /* deal with ESC prefixing */
     
    236238      match = owl_keybinding_match(kb, kh->kpstack);
    237239      if (match == 1) {         /* subset match */
    238         owl_function_debugmsg("processkey: found subset match in %s", km->name);
     240
     241        /* owl_function_debugmsg("processkey: found subset match in %s", km->name); */
    239242        return(0);
    240243      } else if (match == 2) {  /* exact match */
    241         owl_function_debugmsg("processkey: found exact match in %s", km->name);
     244        /* owl_function_debugmsg("processkey: found exact match in %s", km->name); */
    242245        owl_keybinding_execute(kb, j);
    243246        owl_keyhandler_reset(kh);
     
    252255  /* see if a default action exists for the active keymap */
    253256  if (kh->active->default_fn && kh->kpstackpos<1) {
    254     owl_function_debugmsg("processkey: executing default_fn");
     257    /*owl_function_debugmsg("processkey: executing default_fn");*/
     258
    255259    kh->active->default_fn(j);
    256260    owl_keyhandler_reset(kh);
  • keys.c

    r217a43e r10b866d  
    9393  /* This would be nice, but interferes with C-c to cancel */
    9494  /*BIND_CMD("C-c C-c", "editmulti:done", "sends the zephyr");*/
     95
     96  BIND_CMD("M-p",         "edit:history-prev", "");
     97  BIND_CMD("M-n",         "edit:history-next", "");
    9598
    9699  /* note that changing "disable-ctrl-d" to "on" will change this to
  • owl.h

    r1c7a4e0 r10b866d  
    238238} owl_mainwin;
    239239
    240 typedef struct _owl_editwin {
    241   char *buff;
    242   int bufflen;
    243   int allocated;
    244   int buffx, buffy;
    245   int topline;
    246   int winlines, wincols, fillcol, wrapcol;
    247   WINDOW *curswin;
    248   int style;
    249   int lock;
    250   int dotsend;
    251 } owl_editwin;
    252 
    253240typedef struct _owl_viewwin {
    254241  owl_fmtext fmtext;
     
    305292} owl_history;
    306293
     294typedef struct _owl_editwin {
     295  char *buff;
     296  owl_history *hist;
     297  int bufflen;
     298  int allocated;
     299  int buffx, buffy;
     300  int topline;
     301  int winlines, wincols, fillcol, wrapcol;
     302  WINDOW *curswin;
     303  int style;
     304  int lock;
     305  int dotsend;
     306} owl_editwin;
     307
    307308typedef struct _owl_keybinding {
    308309  int  *j;                      /* keypress stack (0-terminated) */ 
     
    334335  owl_mainwin mw;
    335336  owl_popwin pw;
    336   owl_history hist;
     337  owl_history cmdhist;          /* command history */
     338  owl_history msghist;          /* outgoing message history */
    337339  owl_keyhandler kh;
    338340  owl_list filterlist;
  • util.c

    r1c6c4d3 r10b866d  
    299299}
    300300
     301/* returns if a string is only whitespace */
     302int only_whitespace(char *s) {
     303  int i;
     304  for (i=0; s[i]; i++) {
     305    if (!isspace(s[i])) return(0);
     306  }
     307  return(1);
     308}
    301309
    302310void *owl_malloc(size_t size) {
Note: See TracChangeset for help on using the changeset viewer.