Changeset e20d8179


Ignore:
Timestamp:
Jul 11, 2009, 1:14:33 PM (15 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
19f765d
Parents:
bd1a1ae
git-author:
Karl Ramm <kcr@1ts.org> (06/07/09 15:24:15)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/11/09 13:14:33)
Message:
misc refactoring & cleanup
(including a nuke-trailing-whitespace)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    rbd1a1ae re20d8179  
    3232} _owl_editwin_excursion;
    3333
     34static int owl_editwin_is_char_in(owl_editwin *e, char *set);
     35static void oe_reframe(owl_editwin *e);
     36
    3437#define INCR 5000
    3538
     
    4548void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
    4649{
    47   e->buff=owl_malloc(INCR); 
     50  e->buff=owl_malloc(INCR);
    4851  e->buff[0]='\0';
    4952  e->bufflen=0;
     
    262265  e->topindex = -1;
    263266}
    264 static void owl_editwin_reframe(owl_editwin *e) { /* noproto */
     267
     268static inline char *oe_next_point(owl_editwin *e, char *p)
     269{
     270  char *boundary = e->buff + e->bufflen + 1;
     271  char *q;
     272
     273  q = g_utf8_find_next_char(p, boundary);
     274  while (q && g_unichar_ismark(g_utf8_get_char(q)))
     275    q = g_utf8_find_next_char(q, boundary);
     276
     277  if (q == p)
     278    return NULL;
     279  return q;
     280}
     281
     282static inline char *oe_prev_point(owl_editwin *e, char *p)
     283{
     284  char *boundary = e->buff + e->lock;
     285
     286  p = g_utf8_find_prev_char(boundary, p);
     287  while (p && g_unichar_ismark(g_utf8_get_char(p)))
     288    p = g_utf8_find_prev_char(boundary, p);
     289
     290  return p;
     291}
     292
     293static void oe_reframe(owl_editwin *e) {
    265294  e->topindex = 0; /*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/
    266295}
     
    278307  do {
    279308    if (e->topindex == -1 || e->index < e->topindex)
    280       owl_editwin_reframe(e);
    281    
     309      oe_reframe(e);
     310
    282311    line = 0;
    283312    index = e->topindex;
     
    299328          break;
    300329        width += cw;
    301         p = g_utf8_find_next_char(e->buff + index, e->buff + e->bufflen);
     330        p = oe_next_point(e, e->buff + index);
    302331        if (p == NULL) /* we ran off the end */
    303332          break;
     
    323352    }
    324353  } while(x == -1);
    325  
     354
    326355  if (x != -1)
    327356    wmove(e->curswin, y, x);
     
    338367    e->buff[i-n] = e->buff[i];
    339368  }
    340  
     369
    341370  e->bufflen -= n;
    342371  e->buff[e->bufflen] = '\0';
     
    462491    c = '\n';
    463492  }
    464  
     493
    465494  if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
    466495    /* perhaps later this will change some state that allows the string
     
    481510    }
    482511  }
    483   /* if not at the end of the buffer, adjust based in char size difference. */ 
     512  /* if not at the end of the buffer, adjust based in char size difference. */
    484513  else if (oldlen > newlen) {
    485514    _owl_editwin_remove_bytes(e, oldlen-newlen);
     
    492521    e->buff[e->index + i] = tmp[i];
    493522  }
    494        
     523
    495524  /* housekeeping */
    496525  if (e->index == e->bufflen) {
     
    498527    e->buff[e->bufflen] = '\0';
    499528  }
    500  
     529
    501530  /* advance the cursor */
    502531  e->index += newlen;
     
    505534/* delete the character at the current point, following chars
    506535 * shift left.
    507  */ 
     536 */
    508537void owl_editwin_delete_char(owl_editwin *e)
    509538{
     
    512541
    513542  if (e->bufflen == 0) return;
    514  
     543
    515544  if (e->index == e->bufflen) return;
    516545
     
    528557 * advance the pointer.  If point is at beginning of buffer do
    529558 * nothing.  If point is after the last character swap point-1 with
    530  * point-2.  (Behaves as observed in tcsh and emacs). 
     559 * point-2.  (Behaves as observed in tcsh and emacs).
    531560 */
    532561void owl_editwin_transpose_chars(owl_editwin *e)
     
    535564
    536565  if (e->bufflen == 0) return;
    537  
     566
    538567  if (e->index == e->bufflen) {
    539568    /* point is after last character */
    540569    e->index--;
    541   } 
     570  }
    542571
    543572  if (e->index - 1 < e->lock) {
     
    549578  p1 = e->buff + e->index;
    550579
    551   p2 = g_utf8_find_next_char(p1, NULL);
    552   while (p2 != NULL && g_unichar_ismark(g_utf8_get_char(p2))) {
    553     p2 = g_utf8_find_next_char(p2, NULL);
    554   }
    555   if (p2 == NULL) return;
    556 
    557   p3 = g_utf8_find_prev_char(e->buff, p1);
    558   while (p3 != NULL && g_unichar_ismark(g_utf8_get_char(p3))) {
    559     p3 = g_utf8_find_prev_char(p3, NULL);
    560   }
    561   if (p3 == NULL) return;
     580  p2 = oe_next_point(e, p1); /* XXX make sure we can't transpose past the end
     581                                of the buffer */
     582  if (p2 == NULL)
     583    return;
     584
     585  p3 = oe_prev_point(e, p1);
     586  if (p3 == NULL)
     587    return;
    562588
    563589  tmp = owl_malloc(p2 - p3 + 5);
     
    639665}
    640666
    641 int owl_editwin_point_move(owl_editwin *e, int delta) /*noproto*/
    642 {
    643   char *p, *boundary;
     667int owl_editwin_point_move(owl_editwin *e, int delta)
     668{
     669  char *p;
    644670  int change, index, d = 0;
    645671
     
    647673  p = e->buff + e->index;
    648674
    649   boundary = e->buff + (delta > 0 ? (e->bufflen + 1) : e->lock);
    650 
    651675  while (d < change && p != NULL) {
    652     if (delta > 0) {
    653       p = g_utf8_find_next_char(p, boundary);
    654       while (p && g_unichar_ismark(g_utf8_get_char(p)))
    655         p = g_utf8_find_next_char(p, boundary);
    656     } else {
    657       p = g_utf8_find_prev_char(boundary, p);
    658       while (p && g_unichar_ismark(g_utf8_get_char(p)))
    659         p = g_utf8_find_prev_char(boundary, p);
    660     }
    661     if (p != NULL) {
    662       index = p - e->buff;
    663       if (index != e->index) { /* XXX rethink the loop termination condition
    664                                   above */
    665         e->index = index;
    666         d++;
    667       } else
    668         break;
     676    if (delta > 0)
     677      p = oe_next_point(e, p);
     678    else
     679      p = oe_prev_point(e, p);
     680    if (p != NULL) {
     681      e->index = p - e->buff;
     682      d++;
    669683    }
    670684  }
     
    706720}
    707721
    708 int _owl_editwin_is_char_in(owl_editwin *e, char *set) /*noproto*/
     722static int owl_editwin_is_char_in(owl_editwin *e, char *set)
    709723{
    710724  char *p;
     
    716730}
    717731
    718 int owl_editwin_move_if_in(owl_editwin *e, int delta, char *set) /*noproto*/
     732int owl_editwin_move_if_in(owl_editwin *e, int delta, char *set)
    719733{
    720734  int change, distance = 0;
    721   while (_owl_editwin_is_char_in(e, set)) {
     735  while (owl_editwin_is_char_in(e, set)) {
    722736    change = owl_editwin_point_move(e, delta);
    723737    distance += change;
     
    728742}
    729743
    730 int owl_editwin_move_if_not_in(owl_editwin *e, int delta, char *set) /*noproto*/
     744int owl_editwin_move_if_not_in(owl_editwin *e, int delta, char *set)
    731745{
    732746  int change, distance = 0;
    733   while (!_owl_editwin_is_char_in(e, set)) {
     747  while (!owl_editwin_is_char_in(e, set)) {
    734748    change = owl_editwin_point_move(e, delta);
    735749    distance += change;
     
    740754}
    741755
    742 int owl_editwin_move_to_beginning_of_line(owl_editwin *e) /* noproto */
     756int owl_editwin_move_to_beginning_of_line(owl_editwin *e)
    743757{
    744758  int distance = 0;
     
    754768  return distance;
    755769}
    756  
    757 int owl_editwin_move_to_end_of_line(owl_editwin *e) /* noproto */
     770
     771int owl_editwin_move_to_end_of_line(owl_editwin *e)
    758772{
    759773  return owl_editwin_move_if_not_in(e, 1, "\n");
    760774}
    761775
    762 int owl_editwin_line_move(owl_editwin *e, int delta) /*noproto*/
     776int owl_editwin_line_move(owl_editwin *e, int delta)
    763777{
    764778  int goal_column, change, ll, count = 0, distance = 0;
     
    849863  /* if at beginning of a word, find beginning of previous word */
    850864
    851   if (_owl_editwin_is_char_in(e, WHITESPACE)) {
     865  if (owl_editwin_is_char_in(e, WHITESPACE)) {
    852866    /* if in whitespace past end of word, find a word , the find the beginning*/
    853867    owl_editwin_move_if_in(e, -1, WHITESPACE); /* leaves us on the last
     
    856870    /* are we at the beginning of a word? */
    857871    owl_editwin_point_move(e, -1);
    858     beginning = _owl_editwin_is_char_in(e, WHITESPACE);
     872    beginning = owl_editwin_is_char_in(e, WHITESPACE);
    859873    owl_editwin_restore_excursion(e, &x);
    860874    if (beginning)
     
    864878    owl_editwin_save_excursion(e, &x);
    865879    owl_editwin_point_move(e, -1);
    866     if (_owl_editwin_is_char_in(e, WHITESPACE)) { /* we were at the beginning */
     880    if (owl_editwin_is_char_in(e, WHITESPACE)) { /* we were at the beginning */
    867881      owl_editwin_move_to_previousword(e); /* previous case */
    868882      return;
     
    10491063    return;
    10501064  }
    1051   owl_editwin_redisplay(e, 0); 
     1065  owl_editwin_redisplay(e, 0);
    10521066}
    10531067
     
    10641078  if (j.ch == ERR) return;
    10651079  /* Ignore ncurses control characters. */
    1066   if (j.ch < 0x100) { 
     1080  if (j.ch < 0x100) {
    10671081    _owl_editwin_process_char(e, j.uch);
    10681082  }
     
    10801094
    10811095  if (e->bufflen==0) return(0);
    1082  
     1096
    10831097  /* first go to the yth line */
    10841098  ptr1=e->buff;
     
    11111125  return e->echochar;
    11121126}
     1127
     1128void owl_editwin_set_goal_column(owl_editwin *e, int column)
     1129{
     1130  e->goal_column = column;
     1131}
     1132
     1133int owl_editwin_get_goal_column(owl_editwin *e)
     1134{
     1135  return e->goal_column;
     1136}
Note: See TracChangeset for help on using the changeset viewer.