source: editwin.c @ 7ba7d66

release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7ba7d66 was 21dd391, checked in by Nelson Elhage <nelhage@mit.edu>, 11 years ago
Remove the defunct oe_count_glyphs. We may want this again later, but we can always grab it from git history.
  • Property mode set to 100644
File size: 29.9 KB
RevLine 
[7d4fbcd]1#include "owl.h"
2#include <stdlib.h>
3#include <unistd.h>
4#include <string.h>
[10b866d]5#include <ctype.h>
[7d4fbcd]6
[ebf0128]7#define VALID_EXCURSION (0x9a2b4729)
8
[a88f35a]9typedef struct _owl_editwin_excursion { /*noproto*/
[ebf0128]10  int valid;
11  int index;
[16cfd12a]12  int mark;
[ebf0128]13  int goal_column;
14  int lock;
[a88f35a]15  struct _owl_editwin_excursion *next;
[ebf0128]16} oe_excursion;
17
[a556caa]18struct _owl_editwin { /*noproto*/
19  char *buff;
20  owl_history *hist;
21  int bufflen;
22  int allocated;
23  int index;
[16cfd12a]24  int mark;
[a60edf2]25  char *killbuf;
[a556caa]26  int goal_column;
27  int topindex;
[ebf0128]28  int cursorx;
[a556caa]29  int winlines, wincols, fillcol, wrapcol;
30  WINDOW *curswin;
31  int style;
32  int lock;
33  int dotsend;
34  int echochar;
[ebf0128]35  oe_excursion *excursions;
[a556caa]36
37  void (*callback)(struct _owl_editwin*);
[1b1cd2c]38  void (*destroy_cbdata)(void *);
[a556caa]39  void *cbdata;
40};
41
[e20d8179]42static void oe_reframe(owl_editwin *e);
[bab52da]43static void oe_save_excursion(owl_editwin *e, oe_excursion *x);
[ebf0128]44static void oe_release_excursion(owl_editwin *e, oe_excursion *x);
[bab52da]45static void oe_restore_excursion(owl_editwin *e, oe_excursion *x);
[a60edf2]46static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x);
[ebf0128]47static int oe_char_width(gunichar c, int column);
[16cfd12a]48static int oe_region_width(owl_editwin *e, int start, int end, int width);
[bab52da]49static int oe_find_display_line(owl_editwin *e, int *x, int index);
[ebf0128]50static void oe_insert_char(owl_editwin *e, gunichar c);
[bab52da]51static int owl_editwin_limit_maxcols(int v, int maxv);
52static int owl_editwin_check_dotsend(owl_editwin *e);
[e19eb97]53static int owl_editwin_is_char_in(owl_editwin *e, const char *set);
[bab52da]54static gunichar owl_editwin_get_char_at_point(owl_editwin *e);
[e19eb97]55static int owl_editwin_replace_internal(owl_editwin *e, int replace, const char *s);
56static const char *oe_copy_buf(owl_editwin *e, const char *buf, int len);
[a60edf2]57static int oe_copy_region(owl_editwin *e);
[77f605d]58static char *oe_chunk(owl_editwin *e, int start, int end);
[1b1cd2c]59static void oe_destroy_cbdata(owl_editwin *e);
[bab52da]60
[5b5f3e6]61#define INCR 4096
[7d4fbcd]62
[a556caa]63#define WHITESPACE " \n\t"
64
[38cc669]65static owl_editwin *owl_editwin_allocate(void)
[bab52da]66{
[8321cb7]67  owl_editwin *e;
68  e = owl_malloc(sizeof(owl_editwin));
69  memset(e, 0, sizeof(*e));
70  return e;
[a556caa]71}
72
[30bb10a]73void owl_editwin_delete(owl_editwin *e)
[6211c76]74{
75  owl_free(e->buff);
76  owl_free(e->killbuf);
77  /* just in case someone forgot to clean up */
78  while (e->excursions) {
79    oe_release_excursion(e, e->excursions);
80  }
[38cc669]81  oe_destroy_cbdata(e);
[6211c76]82
83  owl_free(e);
84}
85
[bab52da]86static inline void oe_set_index(owl_editwin *e, int index)
87{
[ebf0128]88  if (index != e->index) {
89    e->goal_column = -1;
90    e->cursorx = -1;
91  }
[521bc84]92  e->index = index;
93}
94
[7f0c26f]95static inline void oe_set_mark(owl_editwin *e, int mark)
96{
97  e->mark = mark;
98}
99
100void owl_editwin_set_mark(owl_editwin *e)
101{
102  oe_set_mark(e, e->index);
103  /* owl_function_makemsg("Mark set."); */
104}
105
[38cc669]106static void _owl_editwin_init(owl_editwin *e,
107                              WINDOW *win,
108                              int winlines,
109                              int wincols,
110                              int style,
111                              owl_history *hist)
[c9334b1]112{
[e20d8179]113  e->buff=owl_malloc(INCR);
[7d4fbcd]114  e->buff[0]='\0';
115  e->bufflen=0;
[10b866d]116  e->hist=hist;
[7d4fbcd]117  e->allocated=INCR;
[521bc84]118  oe_set_index(e, 0);
[7f0c26f]119  oe_set_mark(e, -1);
[a60edf2]120  if (e->killbuf != NULL)
[27f6487]121    owl_free(e->killbuf);
[a60edf2]122  e->killbuf = NULL;
[a556caa]123  e->goal_column = -1;
[ebf0128]124  e->cursorx = -1;
125  e->topindex = 0;
126  e->excursions = NULL;
127  owl_editwin_set_curswin(e, win, winlines, wincols);
[7d4fbcd]128  e->style=style;
129  if ((style!=OWL_EDITWIN_STYLE_MULTILINE) &&
130      (style!=OWL_EDITWIN_STYLE_ONELINE)) {
131    e->style=OWL_EDITWIN_STYLE_MULTILINE;
132  }
133  e->lock=0;
134  e->dotsend=0;
[c9334b1]135  e->echochar='\0';
[e74c01c]136
[7d4fbcd]137  if (win) werase(win);
138}
139
[38cc669]140owl_editwin *owl_editwin_new(WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
141{
142  owl_editwin *e = owl_editwin_allocate();
143
144  _owl_editwin_init(e, win, winlines, wincols, style, hist);
145  return e;
146}
147
[c9334b1]148void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols)
149{
[7d4fbcd]150  e->curswin=w;
151  e->winlines=winlines;
152  e->wincols=wincols;
[9a6cc40]153  e->fillcol=owl_editwin_limit_maxcols(wincols-7, owl_global_get_edit_maxfillcols(&g));
154  e->wrapcol=owl_editwin_limit_maxcols(wincols-7, owl_global_get_edit_maxwrapcols(&g));
[7d4fbcd]155}
156
[c9334b1]157/* echo the character 'ch' for each normal character keystroke,
158 * excepting locktext.  This is useful for entering passwords etc.  If
159 * ch=='\0' characters are echo'd normally
160 */
161void owl_editwin_set_echochar(owl_editwin *e, int ch)
162{
163  e->echochar=ch;
164}
165
166WINDOW *owl_editwin_get_curswin(owl_editwin *e)
167{
[060b3b4]168  return(e->curswin);
[7d4fbcd]169}
170
[c9334b1]171owl_history *owl_editwin_get_history(owl_editwin *e)
172{
[060b3b4]173  return(e->hist);
[10b866d]174}
175
[c9334b1]176void owl_editwin_set_dotsend(owl_editwin *e)
177{
[7d4fbcd]178  e->dotsend=1;
179}
180
[bab52da]181void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin*))
182{
[e74c01c]183  e->callback = cb;
184}
185
[bab52da]186void (*owl_editwin_get_callback(owl_editwin *e))(owl_editwin*)
187{
[e74c01c]188  return e->callback;
189}
190
[1b1cd2c]191static void oe_destroy_cbdata(owl_editwin *e) {
192  if (e->destroy_cbdata)
193    e->destroy_cbdata(e->cbdata);
194  e->cbdata = NULL;
195  e->destroy_cbdata = NULL;
196}
197
198void owl_editwin_set_cbdata(owl_editwin *e, void *data, void (*destroy)(void *))
[bab52da]199{
[1b1cd2c]200  oe_destroy_cbdata(e);
[e74c01c]201  e->cbdata = data;
[1b1cd2c]202  e->destroy_cbdata = destroy;
[e74c01c]203}
204
[a556caa]205void *owl_editwin_get_cbdata(owl_editwin *e) {
[e74c01c]206  return e->cbdata;
207}
208
209void owl_editwin_do_callback(owl_editwin *e) {
210  void (*cb)(owl_editwin*);
211  cb=owl_editwin_get_callback(e);
212  if(!cb) {
213    owl_function_error("Internal error: No editwin callback!");
214  } else {
[af1920fd]215    /* owl_function_error("text: |%s|", owl_editwin_get_text(e)); */
[e74c01c]216    cb(e);
217  }
218}
219
[bab52da]220static int owl_editwin_limit_maxcols(int v, int maxv)
[c9334b1]221{
[ebf0128]222  /* maxv > 5 ? MAX(v, vax) : v */
[d36f2cb]223  if (maxv > 5 && v > maxv) {
[060b3b4]224    return(maxv);
[d36f2cb]225  } else {
[060b3b4]226    return(v);
[d36f2cb]227  }
228}
229
[c9334b1]230/* set text to be 'locked in' at the beginning of the buffer, any
231 * previous text (including locked text) will be overwritten
232 */
[e19eb97]233void owl_editwin_set_locktext(owl_editwin *e, const char *text)
[c9334b1]234{
[521bc84]235  oe_set_index(e, 0);
[5b5f3e6]236  e->lock = 0;
237  owl_editwin_replace(e, e->bufflen, text);
238  e->buff[e->bufflen] = 0;
239  e->lock=e->bufflen;
[521bc84]240  oe_set_index(e, e->lock);
[2ee9e8d]241  owl_editwin_redisplay(e);
[7d4fbcd]242}
243
[c9334b1]244int owl_editwin_get_style(owl_editwin *e)
245{
[7d4fbcd]246  return(e->style);
247}
248
[c9334b1]249/* clear all text except for locktext and put the cursor at the
250 * beginning
251 */
252void owl_editwin_clear(owl_editwin *e)
253{
254
[6073462]255  int lock = e->lock;
[10b866d]256  int dotsend=e->dotsend;
[7d4fbcd]257  char *locktext=NULL;
[cc6f009]258  char echochar=e->echochar;
[10b866d]259
[6073462]260  if (lock > 0) {
[5b5f3e6]261    locktext = owl_malloc(lock+1);
262    strncpy(locktext, e->buff, lock);
263    locktext[lock] = 0;
[7d4fbcd]264  }
265
266  owl_free(e->buff);
[38cc669]267  _owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
[7d4fbcd]268
269  if (lock > 0) {
270    owl_editwin_set_locktext(e, locktext);
271  }
[10b866d]272  if (dotsend) {
273    owl_editwin_set_dotsend(e);
274  }
[cc6f009]275  if (echochar) {
276    owl_editwin_set_echochar(e, echochar);
277  }
[7d4fbcd]278
[5b5f3e6]279  if (locktext)
280    owl_free(locktext);
[6073462]281
[521bc84]282  oe_set_index(e, lock);
[7d4fbcd]283}
284
[c9334b1]285void owl_editwin_recenter(owl_editwin *e)
286{
[a556caa]287  e->topindex = -1;
288}
[e20d8179]289
[a0fbdee]290static void oe_save_excursion(owl_editwin *e, oe_excursion *x)
291{
292  x->index = e->index;
[7f0c26f]293  x->mark = e->mark;
[a0fbdee]294  x->goal_column = e->goal_column;
295  x->lock = e->lock;
[ebf0128]296
297  x->valid = VALID_EXCURSION;
298  x->next = e->excursions;
299  e->excursions = x;
300}
301
302static void oe_release_excursion(owl_editwin *e, oe_excursion *x)
303{
[a85d225]304  oe_excursion **px;
[ebf0128]305
306  x->valid = 0;
[a85d225]307  for (px = &e->excursions; *px != NULL; px = &(*px)->next)
308    if (*px == x) {
309      *px = x->next;
310      return;
311    }
312  abort();
[a0fbdee]313}
314
315static void oe_restore_excursion(owl_editwin *e, oe_excursion *x)
316{
[ebf0128]317  if (x->valid == VALID_EXCURSION) {
318    oe_set_index(e, x->index);
319    e->goal_column = x->goal_column;
[7f0c26f]320    e->mark = x->mark;
[ebf0128]321    e->lock = x->lock;
322
323    oe_release_excursion(e, x);
324  }
[a0fbdee]325}
326
[a60edf2]327static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x)
328{
329  if (x->valid == VALID_EXCURSION) {
330    e->mark = x->mark;
331
332    oe_release_excursion(e, x);
333  }
334}
335
[a88f35a]336/* External interface to oe_save_excursion */
337owl_editwin_excursion *owl_editwin_begin_excursion(owl_editwin *e)
338{
339  owl_editwin_excursion *x = owl_malloc(sizeof *x);
340  oe_save_excursion(e, x);
341  return x;
342}
343
344void owl_editwin_end_excursion(owl_editwin *e, owl_editwin_excursion *x)
345{
346  oe_restore_excursion(e, x);
347  owl_free(x);
348}
349
[e19eb97]350static inline const char *oe_next_point(owl_editwin *e, const char *p)
[e20d8179]351{
[e19eb97]352  const char *boundary = e->buff + e->bufflen + 1;
353  const char *q;
[e20d8179]354
355  q = g_utf8_find_next_char(p, boundary);
356  while (q && g_unichar_ismark(g_utf8_get_char(q)))
357    q = g_utf8_find_next_char(q, boundary);
358
359  if (q == p)
360    return NULL;
361  return q;
362}
363
[e19eb97]364static inline const char *oe_prev_point(owl_editwin *e, const char *p)
[e20d8179]365{
[e19eb97]366  const char *boundary = e->buff + e->lock;
[e20d8179]367
368  p = g_utf8_find_prev_char(boundary, p);
369  while (p && g_unichar_ismark(g_utf8_get_char(p)))
370    p = g_utf8_find_prev_char(boundary, p);
371
372  return p;
373}
374
[ebf0128]375static int oe_char_width(gunichar c, int column)
376{
377  int cw;
378
379  if (c == 9) /* TAB */
380    return TABSIZE - column % TABSIZE;
381
382  cw = mk_wcwidth(c);
383
384  if (cw < 0) /* control characters */
385    cw = 0;
386
387  return cw;
388}
389
[19f765d]390static int oe_find_display_line(owl_editwin *e, int *x, int index)
391{
392  int width = 0, cw;
[ebf0128]393  gunichar c;
[e19eb97]394  const char *p;
[19f765d]395
[77d4402]396  while(1) {
397    /* note the position of the dot */
[2021bea]398    if (x != NULL && index == e->index && width < e->wincols)
[19f765d]399      *x = width;
[77d4402]400
[19f765d]401    /* get the current character */
402    c = g_utf8_get_char(e->buff + index);
403
404    /* figure out how wide it is */
[ebf0128]405    cw = oe_char_width(c, width);
[19f765d]406
[77d4402]407    if (width + cw > e->wincols) {
408      if (x != NULL && *x == width)
409        *x = -1;
[19f765d]410      break;
[77d4402]411    }
[19f765d]412    width += cw;
413
414    if (c == '\n') {
[77d4402]415      if (width < e->wincols)
416        ++index; /* skip the newline */
[19f765d]417      break;
418    }
419
420    /* find the next character */
421    p = oe_next_point(e, e->buff + index);
422    if (p == NULL) { /* we ran off the end */
423      if (x != NULL && e->index > index)
424        *x = width + 1;
425      break;
426    }
427    index = p - e->buff;
[cedc95c]428
[19f765d]429  }
430  return index;
431}
432
[e20d8179]433static void oe_reframe(owl_editwin *e) {
[cedc95c]434  oe_excursion x;
[460fbe8]435  int goal = 1 + e->winlines / 2;
[cedc95c]436  int index;
437  int count = 0;
438  int n, i;
439  int last;
440
441  oe_save_excursion(e, &x);
442  /* step back line-by-line through the buffer until we have >= goal lines of
443     display text */
444  e->lock = 0; /* we can (must) tread on the locktext */
445
446  last = -1;
447  while (count < goal) {
448    index = e->index;
449    owl_editwin_move_to_beginning_of_line(e);
450    if (last == e->index)
451      break;
452    last = e->index;
453    for (n = 0, i = e->index; i < index; n++)
454      i = oe_find_display_line(e, NULL, i);
455    count += n == 0 ? 1 : n;
456    if (count < goal)
457      owl_editwin_point_move(e, -1);
458  }
459
460  e->topindex = e->index;
[521bc84]461  /* if we overshot, backtrack */
462  for (n = 0; n < (count - goal); n++)
463    e->topindex = oe_find_display_line(e, NULL, e->topindex);
[cedc95c]464
465  oe_restore_excursion(e, &x);
[7d4fbcd]466}
467
[3e36085]468static void oe_addnec(owl_editwin *e, int count)
469{
470  int i;
471
472  for (i = 0; i < count; i++)
473    waddch(e->curswin, e->echochar);
474}
475
476static void oe_mvaddnec(owl_editwin *e, int y, int x, int count)
477{
478  wmove(e->curswin, y, x);
479  oe_addnec(e, count);
480}
481
[c9334b1]482/* regenerate the text on the curses window */
[2ee9e8d]483void owl_editwin_redisplay(owl_editwin *e)
[c9334b1]484{
[19f765d]485  int x = -1, y = -1, t;
[77d4402]486  int line, index, lineindex, times = 0;
[7d4fbcd]487
[bd1a1ae]488  do {
[cedc95c]489    werase(e->curswin);
[36a16fc]490
491    if (e->topindex == -1 || e->index < e->topindex)
[e20d8179]492      oe_reframe(e);
493
[bd1a1ae]494    line = 0;
495    index = e->topindex;
496    while(line < e->winlines) {
497      lineindex = index;
[19f765d]498      t = -1;
499      index = oe_find_display_line(e, &t, lineindex);
500      if (x == -1 && t != -1)
501        x = t, y = line;
[3e36085]502      if (index - lineindex) {
503        if (!e->echochar)
504          mvwaddnstr(e->curswin, line, 0,
505                     e->buff + lineindex,
506                     index - lineindex);
507        else {
508          if(lineindex < e->lock) {
509            mvwaddnstr(e->curswin, line, 0,
510                       e->buff + lineindex,
511                       MIN(index - lineindex,
512                           e->lock - lineindex));
513            if (e->lock < index)
514              oe_addnec(e,
515                        oe_region_width(e, e->lock, index,
516                                        oe_region_width(e, lineindex, e->lock, 0)));
517          } else
518            oe_mvaddnec(e, line, 0, oe_region_width(e, line, index, 0));
519        }
520      }
[bd1a1ae]521      line++;
[a556caa]522    }
[19f765d]523    if (x == -1)
[bd1a1ae]524        e->topindex = -1; /* force a reframe */
[77d4402]525    times++;
526  } while(x == -1 && times < 3);
[e20d8179]527
[19f765d]528  wmove(e->curswin, y, x);
[ebf0128]529  e->cursorx = x;
[7d4fbcd]530}
531
[7f0c26f]532static inline void oe_fixup(int *target, int start, int end, int change) {
533  if (*target > start) {
[0d9c90c]534    if (*target <= end)
[8459609]535      *target = end + change;
[7f0c26f]536    else
537      *target += change;
538  }
539}
540
[e19eb97]541int owl_editwin_replace_region(owl_editwin *e, const char *s)
[a88f35a]542{
543  oe_excursion x;
544  int ret;
[5ebc202]545  oe_save_excursion(e, &x);
[a88f35a]546
547  if(e->index > e->mark) {
548    owl_editwin_exchange_point_and_mark(e);
549  }
550
551  ret = owl_editwin_replace_internal(e, e->mark - e->index, s);
552
553  oe_restore_excursion(e, &x);
554
555  return ret;
556}
557
[19a023f]558/* replace 'replace' characters at the point with s, returning the change in size */
[e19eb97]559int owl_editwin_replace(owl_editwin *e, int replace, const char *s)
[ebf0128]560{
[19a023f]561  int start, end, i;
[e19eb97]562  const char *p;
[e9bb404]563
[5b5f3e6]564  if (!g_utf8_validate(s, -1, NULL)) {
565    owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string.");
[ebf0128]566    return 0;
[47519e1b]567  }
568
[5b5f3e6]569  start = e->index;
570  for (i = 0, p = e->buff + start; i < replace && p != NULL; i++)
571    p = oe_next_point(e, p);
572  if (p != NULL)
573    end = p - e->buff;
574  else
575    end = e->bufflen;
576
[19a023f]577  return owl_editwin_replace_internal(e, end - start, s);
578}
579
[e19eb97]580static int owl_editwin_replace_internal(owl_editwin *e, int replace, const char *s)
[19a023f]581{
582  int start, end, free, need, size, change;
583  oe_excursion *x;
584
585  start = e->index;
586  end   = start + replace;
587
[5b5f3e6]588  free = e->allocated - e->bufflen + end - start;
589
590  need = strlen(s) - free;
591  if (need > 0) {
592    size = e->allocated + need + INCR - (need % INCR);
[b644688]593    e->buff = owl_realloc(e->buff, size);
[5b5f3e6]594    e->allocated = size;
[47519e1b]595  }
[e9bb404]596
[5b5f3e6]597  memmove(e->buff + start + strlen(s), e->buff + end, e->bufflen + 1 - end);
598  memcpy(e->buff + start, s, strlen(s));
[ebf0128]599  change = start - end + strlen(s);
600  e->bufflen += change;
[5b5f3e6]601  e->index += strlen(s);
[ebf0128]602
[7f0c26f]603  /* fix up the mark */
[3e36085]604  oe_fixup(&e->mark, start, end, change);
605  oe_fixup(&e->topindex, start, end, change);
[ebf0128]606  /* fix up any saved points after the replaced area */
[7f0c26f]607  for (x = e->excursions; x != NULL; x = x->next) {
608    oe_fixup(&x->index, start, end, change);
[3e36085]609    oe_fixup(&x->mark, start, end, change);
[7f0c26f]610  }
[ebf0128]611
[c471e85]612  /* recenter if needed */
613  if (start <= e->topindex)
614    owl_editwin_recenter(e);
615
[ebf0128]616  return change;
[47519e1b]617}
618
[c9334b1]619/* linewrap the word just before the cursor.
620 * returns 0 on success
621 * returns -1 if we could not wrap.
622 */
[fc2677b]623static void _owl_editwin_linewrap_word(owl_editwin *e)
[c9334b1]624{
[fc2677b]625  oe_excursion x;
[84027015]626  gunichar c;
[7d4fbcd]627
[fc2677b]628  oe_save_excursion(e, &x);
[84027015]629
[fc2677b]630  while (owl_editwin_point_move(e, -1)) {
631    c = owl_editwin_get_char_at_point(e);
632    if (owl_util_can_break_after(c) || c == '\n') {
633      if (c != '\n')
634        owl_editwin_replace(e, c != ' ' ? 0 : 1, "\n");
635      break;
[2d4ff14]636    }
[7d4fbcd]637  }
[fc2677b]638
639  oe_restore_excursion(e, &x);
[7d4fbcd]640}
641
[c9334b1]642/* delete the character at the current point, following chars
643 * shift left.
[e20d8179]644 */
[c9334b1]645void owl_editwin_delete_char(owl_editwin *e)
646{
[5b5f3e6]647  owl_editwin_replace(e, 1, "");
[7d4fbcd]648}
649
[c9334b1]650/* Swap the character at point with the character at point-1 and
651 * advance the pointer.  If point is at beginning of buffer do
652 * nothing.  If point is after the last character swap point-1 with
[e20d8179]653 * point-2.  (Behaves as observed in tcsh and emacs).
[c9334b1]654 */
655void owl_editwin_transpose_chars(owl_editwin *e)
656{
[e19eb97]657  const char *middle, *end, *start;
[65b2173]658  char *tmp;
[f2e36b5]659
[47519e1b]660  if (e->bufflen == 0) return;
[e20d8179]661
[5b5f3e6]662  if (e->index == e->bufflen)
663    owl_editwin_point_move(e, -1);     /* point is after last character */
[f2e36b5]664
[5b5f3e6]665  if (owl_editwin_at_beginning_of_buffer(e))
666    return;     /* point is at beginning of buffer, do nothing */
[f2e36b5]667
[47519e1b]668  /* Transpose two utf-8 unicode glyphs. */
[5b5f3e6]669  middle = e->buff + e->index;
[47519e1b]670
[5b5f3e6]671  end = oe_next_point(e, middle);
672  if (end == NULL)
[e20d8179]673    return;
[47519e1b]674
[5b5f3e6]675  start = oe_prev_point(e, middle);
676  if (start == NULL)
[e20d8179]677    return;
[47519e1b]678
[5b5f3e6]679  tmp = owl_malloc((end - start) + 1);
680  tmp[(end - start)] = 0;
681  memcpy(tmp, middle, end - middle);
682  memcpy(tmp + (end - middle), start, middle - start);
683
684  owl_editwin_point_move(e, -1);
685  owl_editwin_replace(e, 2, tmp);
[f2e36b5]686}
687
[c9334b1]688/* insert 'string' at the current point, later text is shifted
689 * right
690 */
[e19eb97]691void owl_editwin_insert_string(owl_editwin *e, const char *s)
[c9334b1]692{
[5b5f3e6]693  owl_editwin_replace(e, 0, s);
[7d4fbcd]694}
695
[a556caa]696/* We assume index is not set to point to a mid-char */
[bab52da]697static gunichar owl_editwin_get_char_at_point(owl_editwin *e)
[c9334b1]698{
[a556caa]699  return g_utf8_get_char(e->buff + e->index);
700}
[7d4fbcd]701
[7f0c26f]702void owl_editwin_exchange_point_and_mark(owl_editwin *e) {
703  int tmp;
704
705  if (e->mark != -1) {
706    tmp = e->mark;
707    owl_editwin_set_mark(e);
708    oe_set_index(e, tmp);
709  }
710}
711
[e20d8179]712int owl_editwin_point_move(owl_editwin *e, int delta)
[84027015]713{
[e19eb97]714  const char *p;
[19f765d]715  int change, d = 0;
[a556caa]716
717  change = MAX(delta, - delta);
718  p = e->buff + e->index;
719
720  while (d < change && p != NULL) {
[e20d8179]721    if (delta > 0)
722      p = oe_next_point(e, p);
723    else
724      p = oe_prev_point(e, p);
725    if (p != NULL) {
[521bc84]726      oe_set_index(e, p - e->buff);
[e20d8179]727      d++;
[a556caa]728    }
729  }
730
731  return delta > 0 ? d : -d;
[84027015]732}
733
[a556caa]734int owl_editwin_at_beginning_of_buffer(owl_editwin *e) {
735  if (e->index == e->lock)
736    return 1;
[84027015]737
[a556caa]738  return 0;
739}
740
741int owl_at_end_of_buffer(owl_editwin *e) {
742  if (e->index == e->bufflen)
743    return 1;
744
745  return 0;
746}
747
[e9c6fc8]748static int owl_editwin_at_beginning_of_line(owl_editwin *e)
[c9334b1]749{
[a0fbdee]750  oe_excursion x;
[a556caa]751  int ret;
[47519e1b]752
[a556caa]753  if (owl_editwin_at_beginning_of_buffer(e))
754    return 1;
[47519e1b]755
[a0fbdee]756  oe_save_excursion(e, &x);
[a556caa]757  owl_editwin_point_move(e, -1);
[bab52da]758  ret = (owl_editwin_get_char_at_point(e) == '\n');
[a0fbdee]759  oe_restore_excursion(e, &x);
[a556caa]760
761  return ret;
762}
763
[e19eb97]764static int owl_editwin_is_char_in(owl_editwin *e, const char *set)
[a556caa]765{
[e19eb97]766  const char *p;
[5b5f3e6]767
768  for (p = set; *p != 0; p = g_utf8_find_next_char(p, NULL))
769    if (owl_editwin_get_char_at_point(e) == g_utf8_get_char(p))
[a556caa]770      return 1;
771  return 0;
772}
773
[e19eb97]774int owl_editwin_move_if_in(owl_editwin *e, int delta, const char *set)
[a556caa]775{
776  int change, distance = 0;
[e20d8179]777  while (owl_editwin_is_char_in(e, set)) {
[a556caa]778    change = owl_editwin_point_move(e, delta);
779    distance += change;
780    if (change == 0)
781      break;
[47519e1b]782  }
[a556caa]783  return distance;
784}
785
[e19eb97]786int owl_editwin_move_if_not_in(owl_editwin *e, int delta, const char *set)
[a556caa]787{
788  int change, distance = 0;
[e20d8179]789  while (!owl_editwin_is_char_in(e, set)) {
[a556caa]790    change = owl_editwin_point_move(e, delta);
791    distance += change;
792    if (change == 0)
793      break;
[7d4fbcd]794  }
[a556caa]795  return distance;
[7d4fbcd]796}
797
[e20d8179]798int owl_editwin_move_to_beginning_of_line(owl_editwin *e)
[47519e1b]799{
[a556caa]800  int distance = 0;
[47519e1b]801
[a556caa]802  if (!owl_editwin_at_beginning_of_line(e)) {
803    /* move off the \n if were at the end of a line */
804    distance += owl_editwin_point_move(e, -1);
805    distance += owl_editwin_move_if_not_in(e, -1, "\n");
806    if (distance && !owl_editwin_at_beginning_of_buffer(e))
807      distance += owl_editwin_point_move(e, 1);
[47519e1b]808  }
[77d4402]809  e->goal_column = 0; /* subtleties */
[84027015]810
[a556caa]811  return distance;
812}
[e20d8179]813
814int owl_editwin_move_to_end_of_line(owl_editwin *e)
[a556caa]815{
816  return owl_editwin_move_if_not_in(e, 1, "\n");
[47519e1b]817}
818
[e20d8179]819int owl_editwin_line_move(owl_editwin *e, int delta)
[c9334b1]820{
[d7043b4]821  int goal_column, change, ll, distance;
822  int count = 0;
[a556caa]823
824  change = MAX(delta, -delta);
825
[d7043b4]826  goal_column = e->goal_column;
827  distance = owl_editwin_move_to_beginning_of_line(e);
828  goal_column = goal_column == -1 ? -distance : goal_column;
[a556caa]829
830  while(count < change) {
831    if (delta > 0) {
832      distance += owl_editwin_move_if_not_in(e, 1, "\n");
833      distance += owl_editwin_point_move(e, 1);
834    } else {
835      /* I really want to assert delta < 0 here */
836      distance += owl_editwin_point_move(e, -1); /* to the newline on
837                                                    the previous line */
838      distance += owl_editwin_move_to_beginning_of_line(e);
839    }
840    count++;
[7d4fbcd]841  }
[a556caa]842
843  distance += (ll = owl_editwin_move_to_end_of_line(e));
844  if (ll > goal_column)
845    distance += owl_editwin_point_move(e, goal_column - ll);
846
847  e->goal_column = goal_column;
848
849  return distance;
[7d4fbcd]850}
851
[c9334b1]852void owl_editwin_backspace(owl_editwin *e)
853{
[7d4fbcd]854  /* delete the char before the current one
855   * and shift later chars left
856   */
[a556caa]857  if(owl_editwin_point_move(e, -1))
[7d4fbcd]858    owl_editwin_delete_char(e);
859}
860
[c9334b1]861void owl_editwin_key_up(owl_editwin *e)
862{
[a556caa]863  owl_editwin_line_move(e, -1);
[7d4fbcd]864}
865
[c9334b1]866void owl_editwin_key_down(owl_editwin *e)
867{
[a556caa]868  owl_editwin_line_move(e, 1);
[7d4fbcd]869}
870
[c9334b1]871void owl_editwin_key_left(owl_editwin *e)
872{
[a556caa]873  owl_editwin_point_move(e, -1);
[7d4fbcd]874}
875
[c9334b1]876void owl_editwin_key_right(owl_editwin *e)
877{
[a556caa]878  owl_editwin_point_move(e, 1);
[7d4fbcd]879}
880
[5b5f3e6]881int owl_editwin_forward_word(owl_editwin *e)
[c9334b1]882{
[5b5f3e6]883  int distance;
[7d4fbcd]884  /* if we're starting on a space, find the first non-space */
[5b5f3e6]885  distance = owl_editwin_move_if_in(e, 1, WHITESPACE);
[7d4fbcd]886
[a556caa]887  /* now find the end of this word */
[5b5f3e6]888  distance += owl_editwin_move_if_not_in(e, 1, WHITESPACE);
889
890  return distance;
891}
892
893void owl_editwin_move_to_nextword(owl_editwin *e)
894{
895  owl_editwin_forward_word(e);
[7d4fbcd]896}
897
[c9334b1]898/* go backwards to the last non-space character
899 */
[5b5f3e6]900int owl_editwin_backward_word(owl_editwin *e)
[c9334b1]901{
[a0fbdee]902  oe_excursion x;
[5b5f3e6]903  int distance = 0;
904  int further = 0;
[a556caa]905  int beginning;
906  /* if in middle of word, beginning of word */
907
908  /* if at beginning of a word, find beginning of previous word */
909
[e20d8179]910  if (owl_editwin_is_char_in(e, WHITESPACE)) {
[a556caa]911    /* if in whitespace past end of word, find a word , the find the beginning*/
[5b5f3e6]912    distance += owl_editwin_move_if_in(e, -1, WHITESPACE); /* leaves us on the last
913                                                              character of the word */
[a0fbdee]914    oe_save_excursion(e, &x);
[a556caa]915    /* are we at the beginning of a word? */
916    owl_editwin_point_move(e, -1);
[e20d8179]917    beginning = owl_editwin_is_char_in(e, WHITESPACE);
[a0fbdee]918    oe_restore_excursion(e, &x);
[a556caa]919    if (beginning)
[5b5f3e6]920      return distance;
[a556caa]921   } else {
922    /* in the middle of the word; */
[a0fbdee]923    oe_save_excursion(e, &x);
[5b5f3e6]924    further += owl_editwin_point_move(e, -1);
[e20d8179]925    if (owl_editwin_is_char_in(e, WHITESPACE)) { /* we were at the beginning */
[5b5f3e6]926      distance += owl_editwin_backward_word(e); /* previous case */
[8321cb7]927      oe_release_excursion(e, &x);
[5b5f3e6]928      return distance + further;
[a556caa]929    } else {
[a0fbdee]930      oe_restore_excursion(e, &x);
[7d4fbcd]931    }
932  }
[5b5f3e6]933  distance += owl_editwin_move_if_not_in(e, -1, WHITESPACE);
[a556caa]934  /* will go past */
935  if (e->index > e->lock)
[5b5f3e6]936    distance += owl_editwin_point_move(e, 1);
937  return distance;
938}
939
940void owl_editwin_move_to_previousword(owl_editwin *e)
941{
942  owl_editwin_backward_word(e);
[7d4fbcd]943}
944
[c9334b1]945void owl_editwin_delete_nextword(owl_editwin *e)
946{
[a0fbdee]947  oe_excursion x;
[a556caa]948
[a0fbdee]949  oe_save_excursion(e, &x);
[a60edf2]950  oe_set_mark(e, e->index);
951  owl_editwin_forward_word(e);
952  owl_editwin_kill_region(e);
953  oe_restore_mark_only(e, &x);
[7d4fbcd]954}
955
[c9334b1]956void owl_editwin_delete_previousword(owl_editwin *e)
957{
[a60edf2]958  oe_excursion x;
[b68f9cd]959
[a60edf2]960  oe_save_excursion(e, &x);
961  oe_set_mark(e, e->index);
962  owl_editwin_backward_word(e);
963  owl_editwin_kill_region(e);
964  oe_restore_mark_only(e, &x);
[b68f9cd]965}
966
[a556caa]967void owl_editwin_move_to_line_end(owl_editwin *e)
[c9334b1]968{
[a556caa]969  owl_editwin_move_to_end_of_line(e);
[7d4fbcd]970}
971
[a556caa]972void owl_editwin_delete_to_endofline(owl_editwin *e)
[c9334b1]973{
[a0fbdee]974  oe_excursion x;
[5b5f3e6]975  int distance;
[a556caa]976
[a0fbdee]977  oe_save_excursion(e, &x);
[a60edf2]978  owl_editwin_set_mark(e);
[5b5f3e6]979  distance = owl_editwin_move_to_end_of_line(e);
[a60edf2]980  if (distance)
981    owl_editwin_kill_region(e);
982  else
983    owl_editwin_replace(e, 1, "");
[a0fbdee]984  oe_restore_excursion(e, &x);
[a60edf2]985}
986
987void owl_editwin_yank(owl_editwin *e)
988{
989  if (e->killbuf != NULL)
990    owl_editwin_replace(e, 0, e->killbuf);
991}
992
[e19eb97]993static const char *oe_copy_buf(owl_editwin *e, const char *buf, int len)
[a60edf2]994{
995  char *p;
996
997  p = owl_malloc(len + 1);
998
999  if (p != NULL) {
1000    owl_free(e->killbuf);
1001    e->killbuf = p;
1002    memcpy(e->killbuf, buf, len);
1003    e->killbuf[len] = 0;
1004  }
1005
1006  return p;
1007}
1008
1009static int oe_copy_region(owl_editwin *e)
1010{
[e19eb97]1011  const char *p;
[a60edf2]1012  int start, end;
1013
1014  if (e->mark == -1)
1015    return 0;
1016
1017  start = MIN(e->index, e->mark);
1018  end = MAX(e->index, e->mark);
1019
1020  p = oe_copy_buf(e, e->buff + start, end - start);
1021  if (p != NULL)
1022    return end - start;
1023  return 0;
1024}
1025
1026void owl_editwin_copy_region_as_kill(owl_editwin *e)
1027{
1028  oe_copy_region(e);
1029}
1030
1031void owl_editwin_kill_region(owl_editwin *e)
1032{
1033  if (e->index > e->mark)
1034    owl_editwin_exchange_point_and_mark(e);
1035
[2184001]1036  owl_editwin_replace_internal(e, oe_copy_region(e), "");
[7d4fbcd]1037}
1038
[c9334b1]1039void owl_editwin_move_to_line_start(owl_editwin *e)
1040{
[a556caa]1041  owl_editwin_move_to_beginning_of_line(e);
[7d4fbcd]1042}
1043
[c9334b1]1044void owl_editwin_move_to_end(owl_editwin *e)
1045{
[521bc84]1046  oe_set_index(e, e->bufflen);
[7d4fbcd]1047}
1048
[c9334b1]1049void owl_editwin_move_to_top(owl_editwin *e)
1050{
[521bc84]1051  oe_set_index(e, e->lock);
[7d4fbcd]1052}
1053
[2fc8397]1054void owl_editwin_backward_paragraph(owl_editwin *e)
1055{
1056  owl_editwin_point_move(e, -1);
1057  for (; e->index >= e->lock; owl_editwin_point_move(e, -1)) {
1058    if (e->index <= e->lock ||
1059        ((e->buff[e->index] == '\n') && (e->buff[e->index - 1]=='\n')))
1060      break;
1061  }
1062}
1063
1064void owl_editwin_forward_paragraph(owl_editwin *e)
1065{
1066  owl_editwin_point_move(e, 1);
1067  /* scan forward to the start of the next paragraph */
1068  for(; e->index < e->bufflen; owl_editwin_point_move(e, 1)) {
1069    if (e->buff[e->index -1] == '\n' && e->buff[e->index] == '\n')
1070      break;
1071  }
1072}
1073
[d41294a]1074int owl_editwin_current_column(owl_editwin *e)
[c9334b1]1075{
[a0fbdee]1076  oe_excursion x;
[fc2677b]1077  int lineindex;
[7d4fbcd]1078
[a0fbdee]1079  oe_save_excursion(e, &x);
[fc2677b]1080  owl_editwin_move_to_beginning_of_line(e);
1081  lineindex = e->index;
1082  oe_restore_excursion(e, &x);
1083  return oe_region_width(e, lineindex, e->index, 0);
1084}
[a556caa]1085
[fc2677b]1086void owl_editwin_fill_paragraph(owl_editwin *e)
1087{
1088  oe_excursion x;
1089  gunichar ch;
1090  int sentence;
[7d4fbcd]1091
[fc2677b]1092  oe_save_excursion(e, &x);
[7d4fbcd]1093
[fc2677b]1094  /* Mark the end of the paragraph */
1095  owl_editwin_forward_paragraph(e);
1096  /* Skip the trailing newline */
1097  owl_editwin_point_move(e, -1);
1098  owl_editwin_set_mark(e);
[7d4fbcd]1099
[fc2677b]1100  owl_editwin_backward_paragraph(e);
[7d4fbcd]1101
[fc2677b]1102  /* Don't mess with the leading newline */
1103  if (owl_editwin_get_char_at_point(e) == '\n')
1104    owl_editwin_point_move(e, 1);
[7d4fbcd]1105
[fc2677b]1106  /*
1107   * First pass: Scan forward replacing all series of spaces with ' '
1108   * (or nothing after CJK ideograms)
1109   */
1110  sentence = 0;
1111  for(;e->index < e->mark; owl_editwin_point_move(e, 1)) {
[50e671c]1112    /* bail if we hit a trailing dot on the buffer */
[fc2677b]1113    if (strcmp(e->buff + e->index, "\n.") == 0) {
1114      owl_editwin_set_mark(e);
[50e671c]1115      break;
[7d4fbcd]1116    }
1117
[fc2677b]1118    ch = owl_editwin_get_char_at_point(e);
[b2c1bd4]1119
[fc2677b]1120    if (owl_util_can_break_after(ch) || ch == '\n') {
1121      if (g_unichar_isspace(ch)) {
1122        owl_editwin_replace(e, 1, " ");
1123      }
1124
[f9d257b]1125      if (sentence && g_unichar_isspace(owl_editwin_get_char_at_point(e))
1126          && e->index < e->mark)
[fc2677b]1127        owl_editwin_point_move(e, 1);
1128
1129      while(g_unichar_isspace(owl_editwin_get_char_at_point(e))
1130            && e->index < e->mark) {
1131        owl_editwin_delete_char(e);
[7d4fbcd]1132      }
1133    }
[fc2677b]1134
1135    if(ch == '.' || ch == '!' || ch == '?')
1136      sentence = 1;
1137    else
1138      sentence = 0;
1139  }
1140
1141  owl_editwin_backward_paragraph(e);
1142
1143  /* Now go through inserting newlines as needed */
1144  while(e->index < e->mark) {
1145    /* if we've travelled too far, linewrap */
[d41294a]1146    if (owl_editwin_current_column(e) >= e->fillcol)
[fc2677b]1147      _owl_editwin_linewrap_word(e);
1148    owl_editwin_point_move(e, 1);
[7d4fbcd]1149  }
1150
[a0fbdee]1151  oe_restore_excursion(e, &x);
[7d4fbcd]1152}
1153
[cf83b7a]1154/* returns true if only whitespace remains */
[c9334b1]1155int owl_editwin_is_at_end(owl_editwin *e)
1156{
[a556caa]1157  return (only_whitespace(e->buff + e->index));
[217a43e]1158}
1159
[bab52da]1160static int owl_editwin_check_dotsend(owl_editwin *e)
[c9334b1]1161{
[dc7884d]1162  int zdot = 0;
[72ab15f]1163  oe_excursion x;
[7d4fbcd]1164
1165  if (!e->dotsend) return(0);
[4ccd92c]1166  if (!owl_editwin_is_at_end(e)) return (0);
[47519e1b]1167
[72ab15f]1168  oe_save_excursion(e, &x);
1169
1170  owl_editwin_point_move(e, -3);
1171
[4ccd92c]1172  if(strncmp(e->buff + e->index, "\n.\n", 3) == 0) {
[dc7884d]1173    owl_editwin_point_move(e, 1);
1174    zdot = 1;
[0509efc]1175  } else if(e->index == e->lock &&
[4ccd92c]1176            strncmp(e->buff + e->index, ".\n", 2) == 0) {
[0509efc]1177    zdot = 1;
1178  }
1179
1180  if(zdot) {
[4ccd92c]1181    owl_editwin_set_mark(e);
1182    owl_editwin_move_to_end(e);
1183    owl_editwin_replace_region(e, "");
[dc7884d]1184  }
[72ab15f]1185
1186  oe_restore_excursion(e, &x);
1187
1188  return zdot;
[7d4fbcd]1189}
1190
[fac5463]1191void owl_editwin_post_process_char(owl_editwin *e, owl_input j)
[c9334b1]1192{
[a556caa]1193  /* XXX force a redisplay? */
[fac5463]1194  if ((j.ch==13 || j.ch==10) && owl_editwin_check_dotsend(e)) {
[435d6b2]1195    owl_command_edit_done(e);
[7d4fbcd]1196    return;
1197  }
[2ee9e8d]1198  owl_editwin_redisplay(e);
[7d4fbcd]1199}
1200
[3e36085]1201static int oe_region_width(owl_editwin *e, int start, int end, int offset)
[16cfd12a]1202{
[e19eb97]1203  const char *p;
[3e36085]1204  int width = offset;
1205 
[16cfd12a]1206  for(p = e->buff + start;
1207      p < e->buff + end;
1208      p = g_utf8_find_next_char(p, NULL))
1209    width += oe_char_width(g_utf8_get_char(p), width);
1210
[3e36085]1211  return width - offset;
[16cfd12a]1212}
1213
[ebf0128]1214static void oe_insert_char(owl_editwin *e, gunichar c)
[fac5463]1215{
[16cfd12a]1216  oe_excursion x;
[5b5f3e6]1217  char tmp[7];
[16cfd12a]1218  int replaced = -1;
[5b5f3e6]1219
[ebf0128]1220  if (c == '\r') /* translate CRs to NLs */
1221    c = '\n';
1222
[16cfd12a]1223  if (!g_unichar_iscntrl(c) || c == '\n' || c== '\t' ) {
[ebf0128]1224    if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
1225      return;
1226    }
1227
[16cfd12a]1228    if (e->cursorx != -1 && e->cursorx + oe_char_width(c, e->cursorx) > e->wrapcol) {
1229      /* XXX this is actually wrong:
1230       * + If the line has been been wrapped, we can be past the wrap column but
1231       *   e->cursorx be much smaller.
1232       * + If the user went back and inserted a bunch of stuff in the middle of
1233       *   the line, there may be more than one word past the wrap column.
1234       */
1235      oe_save_excursion(e, &x);
1236
1237      if (c == ' ' || c == '\t') {
1238        owl_editwin_point_move(e, -1);
1239        replaced = -owl_editwin_move_if_in(e, -1, " \t");
1240        if (!replaced) {
1241          c = '\n';
1242          replaced = -1;
1243        }
1244      } else {
1245        while(!owl_editwin_at_beginning_of_line(e)) {
1246          owl_editwin_point_move(e, -1);
1247          if (owl_util_can_break_after(owl_editwin_get_char_at_point(e))) {
1248            replaced = -owl_editwin_move_if_in(e, -1, " \t");
1249            break;
1250          }
1251        }
1252        if (owl_editwin_at_beginning_of_line(e))
1253          replaced = -1;
1254      }
1255      if (replaced && !owl_editwin_at_beginning_of_line(e))
1256        owl_editwin_point_move(e, 1);
1257      if (replaced >= 0) {
1258        owl_editwin_replace(e, replaced, "\n");
1259      }
1260      oe_restore_excursion(e, &x);
1261    }
1262
1263    if (replaced >= 0 && (c == ' ' || c == '\t'))
1264      return; /* our work here is done */
1265
[6c171f1]1266    tmp[g_unichar_to_utf8(c, tmp)] = '\0';
[ebf0128]1267    owl_editwin_replace(e, 0, tmp);
1268  }
1269}
1270
1271void owl_editwin_process_char(owl_editwin *e, owl_input j)
1272{
[5b5f3e6]1273  if (j.ch == ERR)
1274    return;
[fac5463]1275  /* Ignore ncurses control characters. */
[e20d8179]1276  if (j.ch < 0x100) {
[ebf0128]1277    oe_insert_char(e, j.uch);
[fac5463]1278  }
1279}
1280
[e19eb97]1281const char *owl_editwin_get_text(owl_editwin *e)
[c9334b1]1282{
[7d4fbcd]1283  return(e->buff+e->lock);
1284}
1285
[d41294a]1286char *owl_editwin_get_region(owl_editwin *e)
1287{
1288  int start, end;
1289  start = e->index;
1290  end   = e->mark;
1291  if(start > end) {
1292    int tmp = end;
1293    end = start;
1294    start = tmp;
1295  }
1296
1297  return oe_chunk(e, start, end);
1298}
1299
[77f605d]1300int owl_editwin_get_echochar(owl_editwin *e)
1301{
[a556caa]1302  return e->echochar;
1303}
[77f605d]1304
1305static char *oe_chunk(owl_editwin *e, int start, int end)
1306{
1307  char *p;
1308 
1309  p = owl_malloc(end - start + 1);
1310  memcpy(p, e->buff + start, end - start);
1311  p[end - start] = 0;
1312
1313  return p;
1314}
1315
[d41294a]1316/*
1317 * The only guarantee made about these values is that comparisons
1318 * between them, as well as comparison between multiple calls to these
1319 * functions without modifying the editwin in-between, are meaningful.
1320 */
1321
1322int owl_editwin_get_point(owl_editwin *e)
1323{
1324  return e->index;
1325}
1326
1327int owl_editwin_get_mark(owl_editwin *e)
1328{
1329  return e->mark;
1330}
1331
[2f21a41]1332
1333/*
1334 * Local Variables:
1335 * mode:C
1336 * c-basic-offset:2
1337 * End:
1338 */
Note: See TracBrowser for help on using the repository browser.