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