Changeset a556caa
- Timestamp:
- Jul 11, 2009, 1:14:24 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- bd1a1ae
- Parents:
- a45786e
- git-author:
- Karl Ramm <kcr@1ts.org> (07/07/09 23:03:19)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (07/11/09 13:14:24)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
r73ba824 ra556caa 2658 2658 owl_function_makemsg("Command cancelled."); 2659 2659 2660 if( e->echochar== 0) {2660 if(owl_editwin_get_echochar(e) == 0) { 2661 2661 hist=owl_editwin_get_history(e); 2662 2662 owl_history_store(hist, owl_editwin_get_text(e)); -
editwin.c
ra45786e ra556caa 7 7 static const char fileIdent[] = "$Id$"; 8 8 9 struct _owl_editwin { /*noproto*/ 10 char *buff; 11 owl_history *hist; 12 int bufflen; 13 int allocated; 14 int index; 15 int goal_column; 16 int topindex; 17 int winlines, wincols, fillcol, wrapcol; 18 WINDOW *curswin; 19 int style; 20 int lock; 21 int dotsend; 22 int echochar; 23 24 char *command; 25 void (*callback)(struct _owl_editwin*); 26 void *cbdata; 27 }; 28 29 typedef struct { /*noproto*/ 30 int index; 31 int goal_column; 32 } _owl_editwin_excursion; 33 9 34 #define INCR 5000 35 36 #define WHITESPACE " \n\t" 37 38 owl_editwin *owl_editwin_allocate(void) { 39 return owl_malloc(sizeof(owl_editwin)); 40 } 10 41 11 42 /* initialize the editwin e. … … 19 50 e->hist=hist; 20 51 e->allocated=INCR; 21 e-> buffx=0;22 e-> buffy=0;23 e->top line=0;52 e->index = 0; 53 e->goal_column = -1; 54 e->topindex=0; 24 55 e->winlines=winlines; 25 56 e->wincols=wincols; … … 106 137 } 107 138 108 void *owl_editwin_get_cbdata(owl_editwin *e) {139 void *owl_editwin_get_cbdata(owl_editwin *e) { 109 140 return e->cbdata; 110 141 } … … 135 166 void owl_editwin_set_locktext(owl_editwin *e, char *text) 136 167 { 137 e->buffx=0; 138 e->buffy=0; 168 e->index = 0; 139 169 owl_editwin_overwrite_string(e, text); 140 170 owl_editwin_overwrite_char(e, '\0'); 141 171 e->lock=strlen(text); 142 _owl_editwin_set_xy_by_index(e, e->lock);172 e->index = e->lock; 143 173 owl_editwin_redisplay(e, 0); 144 174 } … … 167 197 e->bufflen=ptr - e->buff; 168 198 e->buff[e->bufflen]='\0'; 169 e->buffx=0; 170 e->buffy=0; 199 e->index = 0; 171 200 } 172 201 } … … 223 252 e->buff=owl_realloc(e->buff, e->allocated+INCR); 224 253 if (!e->buff) { 225 /* error */ 254 /* error *//*XXXXXXXXXXXXXXXX*/ 226 255 return; 227 256 } … … 231 260 void owl_editwin_recenter(owl_editwin *e) 232 261 { 233 e->topline=e->buffy-(e->winlines/2); 234 if (e->topline<0) e->topline=0; 235 if (e->topline>owl_editwin_get_numlines(e)) e->topline=owl_editwin_get_numlines(e); 262 e->topindex = -1; 263 } 264 static void owl_editwin_reframe(owl_editwin *e) { /* noproto */ 265 e->topindex = 0; /*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ 236 266 } 237 267 … … 240 270 void owl_editwin_redisplay(owl_editwin *e, int update) 241 271 { 242 243 char *ptr1, *ptr2, *ptr3, *buff; 272 int x = 0, y = 0; 273 char *ptop, *ptr2, *pbot, *buff; 274 char *target; 244 275 int i; 245 276 … … 247 278 wmove(e->curswin, 0, 0); 248 279 249 /* start at topline */ 250 ptr1 = e->buff; 251 for (i = 0; i < e->topline; i++) { 252 ptr2 = strchr(ptr1, '\n'); 253 if (!ptr2) { 254 /* we're already on the last line */ 255 break; 256 } 257 ptr1 = ptr2 + 1; 258 } 259 /* ptr1 now stores the starting point */ 260 261 /* find the ending point and store it in ptr3 */ 262 ptr2 = ptr1; 263 ptr3 = ptr1; 280 if (e->topindex < 0 || e->index < e->topindex) 281 owl_editwin_reframe(e); 282 283 ptop = e->buff + e->topindex; 284 target = e->buff + e->index; 285 286 /* find the ending point and store it in pbot */ 287 ptr2 = ptop; 288 pbot = ptop; 264 289 for (i = 0; i < e->winlines; i++) { 265 p tr3= strchr(ptr2, '\n');266 if (!p tr3) {290 pbot = strchr(ptr2, '\n'); 291 if (!pbot) { 267 292 /* we've hit the last line */ 268 293 /* print everything to the end */ 269 p tr3= e->buff + e->bufflen - 1;270 p tr3--;294 pbot = e->buff + e->bufflen - 1; 295 pbot--; 271 296 break; 272 297 } 273 ptr2 = p tr3+ 1;274 } 275 p tr3+= 2;276 277 buff = owl_malloc(p tr3 - ptr1+ 50);278 strncpy(buff, pt r1, ptr3 - ptr1);279 buff[p tr3 - ptr1] = '\0';298 ptr2 = pbot + 1; 299 } 300 pbot += 2; 301 302 buff = owl_malloc(pbot - ptop + 50); 303 strncpy(buff, ptop, pbot - ptop); 304 buff[pbot - ptop] = '\0'; 280 305 if (e->echochar == '\0') { 281 306 waddstr(e->curswin, buff); … … 283 308 /* translate to echochar, *except* for the locktext */ 284 309 int len; 285 int dolocklen = e->lock - (pt r1- e->buff);310 int dolocklen = e->lock - (ptop - e->buff); 286 311 char *locktext; 287 312 char tmp = e->buff[dolocklen]; … … 298 323 } 299 324 } 300 wmove(e->curswin, e->buffy-e->topline, e->buffx + _owl_editwin_cursor_adjustment(e)); 325 { /* locates the point */ 326 char *ptr1, *ptr2; 327 gunichar c; 328 329 ptr1 = ptop; 330 /* target sanitizing */ 331 if ((target[0] & 0x80) && (~target[0] & 0x40)) { 332 /* middle of a utf-8 character, back up to previous character. */ 333 target = g_utf8_find_prev_char(e->buff, target); 334 } 335 c = g_utf8_get_char(target); 336 while (g_unichar_ismark(c) && target > e->buff) { 337 /* Adjust the target off of combining characters and the like. */ 338 target = g_utf8_find_prev_char(e->buff, target); 339 c = g_utf8_get_char(target); 340 } 341 /* If we start with a mark, something is wrong.*/ 342 if (g_unichar_ismark(c)) return; 343 344 /* Now our target should be acceptable. */ 345 ptr2 = strchr(ptr1, '\n'); 346 while (ptr2 != NULL && ptr2 < target) { 347 ++y; 348 ptr1 = ptr2 + 1; 349 ptr2 = strchr(ptr1, '\n'); 350 } 351 ptr2 = ptr1; 352 while (ptr2 != NULL && ptr2 < target) { 353 c = g_utf8_get_char(ptr2); 354 x += mk_wcwidth(c); 355 ptr2 = g_utf8_next_char(ptr2); 356 } 357 } 358 wmove(e->curswin, y, x); 301 359 wnoutrefresh(e->curswin); 302 if (update == 1) {360 if (update == 1) 303 361 doupdate(); 304 }305 362 owl_free(buff); 306 363 } … … 309 366 void _owl_editwin_remove_bytes(owl_editwin *e, int n) /*noproto*/ 310 367 { 311 int i = _owl_editwin_get_index_from_xy(e)+ n;368 int i = e->index + n; 312 369 for (; i < e->bufflen; i++) { 313 370 e->buff[i-n] = e->buff[i]; … … 321 378 void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/ 322 379 { 323 int i , z;380 int i; 324 381 325 382 if ((e->bufflen + n) > (e->allocated - 5)) { … … 327 384 } 328 385 329 z = _owl_editwin_get_index_from_xy(e); 330 331 if(z != e->bufflen) { 332 for (i = e->bufflen + n - 1; i > z; i--) { 386 if(e->index != e->bufflen) { 387 for (i = e->bufflen + n - 1; i > e->index; i--) { 333 388 e->buff[i] = e->buff[i - n]; 334 389 } … … 353 408 start = e->buff + e->lock; 354 409 355 ptr1 = e->buff + _owl_editwin_get_index_from_xy(e);410 ptr1 = e->buff + e->index; 356 411 ptr1 = g_utf8_find_prev_char(start, ptr1); 357 412 … … 361 416 if (c != ' ') { 362 417 i = ptr1 - e->buff; 363 _owl_editwin_set_xy_by_index(e, i);418 e->index = i; 364 419 _owl_editwin_insert_bytes(e, 1); 365 420 /* _owl_editwin_insert_bytes may move e->buff. */ … … 382 437 void owl_editwin_insert_char(owl_editwin *e, gunichar c) 383 438 { 384 int z,i, ret, len;439 int i, ret, len; 385 440 char tmp[6]; 386 441 memset(tmp, '\0', 6); … … 405 460 } 406 461 407 /* get the insertion point */408 z = _owl_editwin_get_index_from_xy(e);409 410 462 /* If we're going to insert at the last column do word wrapping, unless it's a \n */ 463 #if 0 /* XXX */ 411 464 if ((e->buffx + 1 == e->wrapcol) && (c != '\n')) { 412 465 ret = _owl_editwin_linewrap_word(e); … … 416 469 } 417 470 } 471 #endif 418 472 419 473 /* shift all the other characters right */ … … 422 476 /* insert the new character */ 423 477 for(i = 0; i < len; i++) { 424 e->buff[ z+ i] = tmp[i];478 e->buff[e->index + i] = tmp[i]; 425 479 } 426 480 427 481 /* advance the cursor */ 428 z += len; 429 _owl_editwin_set_xy_by_index(e, z); 482 e->index += len; 430 483 } 431 484 … … 433 486 void owl_editwin_overwrite_char(owl_editwin *e, gunichar c) 434 487 { 435 int z,oldlen, newlen, i;436 char tmp[6] ;488 int oldlen, newlen, i; 489 char tmp[6], *t; 437 490 memset(tmp, '\0', 6); 438 491 … … 451 504 newlen = strlen(tmp); 452 505 453 z = _owl_editwin_get_index_from_xy(e); 454 { 455 char *t = g_utf8_find_next_char(e->buff + z, NULL); 456 oldlen = (t ? (t - (e->buff + z)) : 0); 457 } 506 t = g_utf8_find_next_char(e->buff + e->index, NULL); 507 oldlen = (t ? (t - (e->buff + e->index)) : 0); 458 508 459 509 /* only if we are at the end of the buffer do we create new space here */ 460 if ( z== e->bufflen) {510 if (e->index == e->bufflen) { 461 511 if ((e->bufflen+newlen) > (e->allocated-5)) { 462 512 _owl_editwin_addspace(e); … … 472 522 /* Overwrite the old char*/ 473 523 for (i = 0; i < newlen; i++) { 474 e->buff[ z+i] = tmp[i];524 e->buff[e->index + i] = tmp[i]; 475 525 } 476 526 477 527 /* housekeeping */ 478 if ( z== e->bufflen) {528 if (e->index == e->bufflen) { 479 529 e->bufflen += newlen; 480 530 e->buff[e->bufflen] = '\0'; … … 482 532 483 533 /* advance the cursor */ 484 z += newlen; 485 _owl_editwin_set_xy_by_index(e, z); 534 e->index += newlen; 486 535 } 487 536 … … 491 540 void owl_editwin_delete_char(owl_editwin *e) 492 541 { 493 int z;494 542 char *p1, *p2; 495 543 gunichar c; … … 497 545 if (e->bufflen == 0) return; 498 546 499 /* get the deletion point */ 500 z = _owl_editwin_get_index_from_xy(e); 501 502 if (z == e->bufflen) return; 503 504 p1 = e->buff + z; 547 if (e->index == e->bufflen) return; 548 549 p1 = e->buff + e->index; 505 550 p2 = g_utf8_next_char(p1); 506 551 c = g_utf8_get_char(p2); … … 519 564 void owl_editwin_transpose_chars(owl_editwin *e) 520 565 { 521 int z;522 566 char *p1, *p2, *p3, *tmp; 523 567 524 568 if (e->bufflen == 0) return; 525 569 526 /* get the cursor point */ 527 z = _owl_editwin_get_index_from_xy(e); 528 529 if (z == e->bufflen) { 570 if (e->index == e->bufflen) { 530 571 /* point is after last character */ 531 z--;572 e->index--; 532 573 } 533 574 534 if ( z- 1 < e->lock) {575 if (e->index - 1 < e->lock) { 535 576 /* point is at beginning of buffer, do nothing */ 536 577 return; … … 538 579 539 580 /* Transpose two utf-8 unicode glyphs. */ 540 p1 = e->buff + z;581 p1 = e->buff + e->index; 541 582 542 583 p2 = g_utf8_find_next_char(p1, NULL); … … 558 599 strncpy(p3, tmp, p2 - p3); 559 600 owl_free(tmp); 560 _owl_editwin_set_xy_by_index(e, p3 - e->buff);601 e->index = p3 - e->buff; 561 602 } 562 603 … … 603 644 } 604 645 605 /* get the index into e->buff for the current cursor 606 * position. 607 */ 608 int _owl_editwin_get_index_from_xy(owl_editwin *e) 609 { 610 int i; 611 char *ptr1, *ptr2; 612 gunichar c; 613 614 if (e->bufflen == 0) return(0); 615 616 /* first go to the yth line */ 617 ptr1 = e->buff; 618 for (i = 0; i < e->buffy; i++) { 619 ptr2= strchr(ptr1, '\n'); 620 if (!ptr2) { 621 /* we're already on the last line */ 622 break; 623 } 624 ptr1 = ptr2 + 1; 625 } 626 627 /* now go to the xth cell */ 628 ptr2 = ptr1; 629 i = 0; 630 while (ptr2 != NULL && i < e->buffx && (ptr2 - e->buff) < e->bufflen) { 631 c = g_utf8_get_char(ptr2); 632 i += (c == '\n' ? 1 : mk_wcwidth(c)); 633 ptr2 = g_utf8_next_char(ptr2); 634 } 635 while(ptr2 != NULL && g_unichar_ismark(g_utf8_get_char(ptr2))) { 636 ptr2 = g_utf8_next_char(ptr2); 637 } 638 if (ptr2 == NULL) return e->bufflen; 639 return(ptr2 - e->buff); 640 } 641 642 /* We assume x,y are not set to point to a mid-char */ 643 gunichar _owl_editwin_get_char_at_xy(owl_editwin *e) 644 { 645 return g_utf8_get_char(e->buff + _owl_editwin_get_index_from_xy(e)); 646 } 647 648 649 void _owl_editwin_set_xy_by_index(owl_editwin *e, int index) 650 { 651 char *ptr1, *ptr2, *target; 652 gunichar c; 653 654 e->buffx = 0; 655 e->buffy = 0; 656 657 ptr1 = e->buff; 658 target = ptr1 + index; 659 /* target sanitizing */ 660 if ((target[0] & 0x80) && (~target[0] & 0x40)) { 661 /* middle of a utf-8 character, back up to previous character. */ 662 target = g_utf8_find_prev_char(e->buff, target); 663 } 664 c = g_utf8_get_char(target); 665 while (g_unichar_ismark(c) && target > e->buff) { 666 /* Adjust the target off of combining characters and the like. */ 667 target = g_utf8_find_prev_char(e->buff, target); 668 c = g_utf8_get_char(target); 669 } 670 /* If we start with a mark, something is wrong.*/ 671 if (g_unichar_ismark(c)) return; 672 673 /* Now our target should be acceptable. */ 674 ptr2 = strchr(ptr1, '\n'); 675 while (ptr2 != NULL && ptr2 < target) { 676 e->buffy++; 677 ptr1 = ptr2 + 1; 678 ptr2 = strchr(ptr1, '\n'); 679 } 680 ptr2 = ptr1; 681 while (ptr2 != NULL && ptr2 < target) { 682 c = g_utf8_get_char(ptr2); 683 e->buffx += mk_wcwidth(c); 684 ptr2 = g_utf8_next_char(ptr2); 685 } 686 } 687 688 int _owl_editwin_cursor_adjustment(owl_editwin *e) 689 { 690 char *ptr1, *ptr2; 691 gunichar c; 692 int x, i; 693 694 /* Find line */ 695 ptr1 = e->buff; 696 ptr2 = strchr(ptr1, '\n'); 697 for (i = 0; ptr2 != NULL && i < e->buffy; i++) { 698 ptr1 = ptr2 + 1; 699 ptr2 = strchr(ptr1, '\n'); 700 } 701 ptr2 = ptr1; 702 703 /* Find char */ 704 x = 0; 705 while (ptr2 != NULL && x < e->buffx) { 706 if (*ptr2 == '\n') return 0; 707 c = g_utf8_get_char(ptr2); 708 x += mk_wcwidth(c); 709 ptr2 = g_utf8_next_char(ptr2); 710 } 711 712 /* calculate x offset */ 713 return x - e->buffx; 646 /* We assume index is not set to point to a mid-char */ 647 gunichar _owl_editwin_get_char_at_point(owl_editwin *e) 648 { 649 return g_utf8_get_char(e->buff + e->index); 650 } 651 652 void owl_editwin_save_excursion(owl_editwin *e, _owl_editwin_excursion *x) /*noproto*/ 653 { 654 x->index = e->index; 655 x->goal_column = e->goal_column; 656 } 657 658 void owl_editwin_restore_excursion(owl_editwin *e, _owl_editwin_excursion *x) /*noproto*/ 659 { 660 e->index = x->index; 661 e->goal_column = x->goal_column; 714 662 } 715 663 … … 718 666 /* if we happen to have the cursor over locked text 719 667 * move it to be out of the locktext region */ 720 if (_owl_editwin_get_index_from_xy(e) < e->lock) { 721 _owl_editwin_set_xy_by_index(e, e->lock); 722 } 668 if (e->index < e->lock) { 669 e->index = e->lock; 670 } 671 } 672 673 int owl_editwin_point_move(owl_editwin *e, int delta) /*noproto*/ 674 { 675 char *p, *boundary; 676 int change, d = 0; 677 678 change = MAX(delta, - delta); 679 p = e->buff + e->index; 680 681 boundary = e->buff + (delta > 0 ? e->bufflen : e->lock); 682 683 while (d < change && p != NULL) { 684 if (delta > 0) { 685 p = g_utf8_find_next_char(p, boundary); 686 while (p && g_unichar_ismark(g_utf8_get_char(p))) 687 p = g_utf8_find_next_char(p, boundary); 688 } else { 689 p = g_utf8_find_prev_char(boundary, p); 690 while (p && g_unichar_ismark(g_utf8_get_char(p))) 691 p = g_utf8_find_prev_char(boundary, p); 692 } 693 if (p != NULL) { 694 e->index = p - e->buff; 695 d++; 696 } 697 } 698 699 if (delta) 700 e->goal_column = -1; 701 702 return delta > 0 ? d : -d; 703 } 704 705 int owl_editwin_at_beginning_of_buffer(owl_editwin *e) { 706 if (e->index == e->lock) 707 return 1; 708 709 return 0; 710 } 711 712 int owl_at_end_of_buffer(owl_editwin *e) { 713 if (e->index == e->bufflen) 714 return 1; 715 716 return 0; 717 } 718 719 int owl_editwin_at_beginning_of_line(owl_editwin *e) /*noproto*/ 720 { 721 _owl_editwin_excursion x; 722 int ret; 723 724 if (owl_editwin_at_beginning_of_buffer(e)) 725 return 1; 726 727 owl_editwin_save_excursion(e, &x); 728 owl_editwin_point_move(e, -1); 729 ret = (_owl_editwin_get_char_at_point(e) == '\n'); 730 owl_editwin_restore_excursion(e, &x); 731 732 return ret; 733 } 734 735 int _owl_editwin_is_char_in(owl_editwin *e, char *set) /*noproto*/ 736 { 737 char *p; 738 /* It would be awfully nice if we could do UTF-8 comparisons */ 739 for (p = set; *p != 0; p++) 740 if (_owl_editwin_get_char_at_point(e) == *p) 741 return 1; 742 return 0; 743 } 744 745 int owl_editwin_move_if_in(owl_editwin *e, int delta, char *set) /*noproto*/ 746 { 747 int change, distance = 0; 748 while (_owl_editwin_is_char_in(e, set)) { 749 change = owl_editwin_point_move(e, delta); 750 distance += change; 751 if (change == 0) 752 break; 753 } 754 return distance; 755 } 756 757 int owl_editwin_move_if_not_in(owl_editwin *e, int delta, char *set) /*noproto*/ 758 { 759 int change, distance = 0; 760 while (!_owl_editwin_is_char_in(e, set)) { 761 change = owl_editwin_point_move(e, delta); 762 distance += change; 763 if (change == 0) 764 break; 765 } 766 return distance; 767 } 768 769 int owl_editwin_move_to_beginning_of_line(owl_editwin *e) /* noproto */ 770 { 771 int distance = 0; 772 773 if (!owl_editwin_at_beginning_of_line(e)) { 774 /* move off the \n if were at the end of a line */ 775 distance += owl_editwin_point_move(e, -1); 776 distance += owl_editwin_move_if_not_in(e, -1, "\n"); 777 if (distance && !owl_editwin_at_beginning_of_buffer(e)) 778 distance += owl_editwin_point_move(e, 1); 779 } 780 781 return distance; 782 } 783 784 int owl_editwin_move_to_end_of_line(owl_editwin *e) /* noproto */ 785 { 786 return owl_editwin_move_if_not_in(e, 1, "\n"); 787 } 788 789 int owl_editwin_line_move(owl_editwin *e, int delta) /*noproto*/ 790 { 791 int goal_column, change, ll, count = 0, distance = 0; 792 793 if (e->goal_column == -1) { 794 if (owl_editwin_at_beginning_of_line(e)) 795 goal_column = 0; 796 else { 797 goal_column = -owl_editwin_move_if_not_in(e, -1, "\n"); 798 if (!owl_editwin_at_beginning_of_buffer(e)) 799 goal_column -= owl_editwin_point_move(e, 1); 800 } 801 } else 802 goal_column = e->goal_column; 803 804 change = MAX(delta, -delta); 805 806 distance += owl_editwin_move_to_beginning_of_line(e); 807 808 while(count < change) { 809 if (delta > 0) { 810 distance += owl_editwin_move_if_not_in(e, 1, "\n"); 811 distance += owl_editwin_point_move(e, 1); 812 } else { 813 /* I really want to assert delta < 0 here */ 814 distance += owl_editwin_point_move(e, -1); /* to the newline on 815 the previous line */ 816 distance += owl_editwin_move_to_beginning_of_line(e); 817 } 818 count++; 819 } 820 821 distance += (ll = owl_editwin_move_to_end_of_line(e)); 822 if (ll > goal_column) 823 distance += owl_editwin_point_move(e, goal_column - ll); 824 825 e->goal_column = goal_column; 826 827 return distance; 723 828 } 724 829 … … 728 833 * and shift later chars left 729 834 */ 730 if (_owl_editwin_get_index_from_xy(e) > e->lock) { 731 owl_editwin_key_left(e); 835 if(owl_editwin_point_move(e, -1)) 732 836 owl_editwin_delete_char(e); 733 }734 owl_editwin_adjust_for_locktext(e);735 837 } 736 838 737 839 void owl_editwin_key_up(owl_editwin *e) 738 840 { 739 if (e->buffy > 0) e->buffy--; 740 if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) { 741 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 742 } 743 744 /* do we need to scroll? */ 745 if (e->buffy-e->topline < 0) { 746 e->topline-=e->winlines/2; 747 } 748 749 owl_editwin_adjust_for_locktext(e); 841 owl_editwin_line_move(e, -1); 750 842 } 751 843 752 844 void owl_editwin_key_down(owl_editwin *e) 753 845 { 754 /* move down if we can */ 755 if (e->buffy+1 < owl_editwin_get_numlines(e)) e->buffy++; 756 757 /* if we're past the last character move back */ 758 if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) { 759 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 760 } 761 762 /* do we need to scroll? */ 763 if (e->buffy-e->topline > e->winlines) { 764 e->topline+=e->winlines/2; 765 } 766 767 /* adjust for locktext */ 768 owl_editwin_adjust_for_locktext(e); 846 owl_editwin_line_move(e, 1); 769 847 } 770 848 771 849 void owl_editwin_key_left(owl_editwin *e) 772 850 { 773 int i; 774 char * p; 775 i = _owl_editwin_get_index_from_xy(e); 776 p = e->buff + i; 777 p = g_utf8_find_prev_char(e->buff, p); 778 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 779 p = g_utf8_find_prev_char(e->buff, p); 780 } 781 if (p == NULL) p = e->buff; 782 _owl_editwin_set_xy_by_index(e, p - e->buff); 783 784 if (e->buffy - e->topline < 0) { 785 e->topline -= e->winlines / 2; 786 } 787 788 /* make sure to avoid locktext */ 789 owl_editwin_adjust_for_locktext(e); 851 owl_editwin_point_move(e, -1); 790 852 } 791 853 792 854 void owl_editwin_key_right(owl_editwin *e) 793 855 { 794 int i; 795 char * p; 796 i = _owl_editwin_get_index_from_xy(e); 797 p = e->buff + i; 798 p = g_utf8_find_next_char(p, NULL); 799 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 800 p = g_utf8_find_next_char(p, NULL); 801 } 802 if (p == NULL) { 803 _owl_editwin_set_xy_by_index(e, e->bufflen); 804 } 805 else { 806 _owl_editwin_set_xy_by_index(e, p - e->buff); 807 } 808 809 /* do we need to scroll down? */ 810 if (e->buffy - e->topline >= e->winlines) { 811 e->topline += e->winlines / 2; 812 } 856 owl_editwin_point_move(e, 1); 813 857 } 814 858 815 859 void owl_editwin_move_to_nextword(owl_editwin *e) 816 860 { 817 int i, x;818 gunichar c = '\0';819 820 861 /* if we're starting on a space, find the first non-space */ 821 i=_owl_editwin_get_index_from_xy(e); 822 if (e->buff[i]==' ') { 823 for (x=i; x<e->bufflen; x++) { 824 if (e->buff[x]!=' ' && e->buff[x]!='\n') { 825 _owl_editwin_set_xy_by_index(e, x); 826 break; 827 } 828 } 829 } 830 831 /* find the next space, newline or end of line and go 832 there, if already at the end of the line, continue on to the next */ 833 i=owl_editwin_get_numcells_on_line(e, e->buffy); 834 c = _owl_editwin_get_char_at_xy(e); 835 if (e->buffx < i) { 836 /* move right till end of line */ 837 while (e->buffx < i) { 838 owl_editwin_key_right(e); 839 c = _owl_editwin_get_char_at_xy(e); 840 if (c == ' ') return; 841 if (e->buffx == i) return; 842 } 843 } else if (e->buffx == i) { 844 /* try to move down */ 845 if (e->style==OWL_EDITWIN_STYLE_MULTILINE) { 846 if (e->buffy+1 < owl_editwin_get_numlines(e)) { 847 e->buffx=0; 848 e->buffy++; 849 owl_editwin_move_to_nextword(e); 850 } 851 } 852 } 862 owl_editwin_move_if_in(e, 1, WHITESPACE); 863 864 /* now find the end of this word */ 865 owl_editwin_move_if_not_in(e, 1, WHITESPACE); 853 866 } 854 867 … … 857 870 void owl_editwin_move_to_previousword(owl_editwin *e) 858 871 { 859 int i; 860 gunichar c; 861 char *ptr1, *ptr2; 862 863 /* are we already at the beginning of the word? */ 864 c = _owl_editwin_get_char_at_xy(e); 865 i = _owl_editwin_get_index_from_xy(e); 866 ptr1 = e->buff + i; 867 if (*ptr1 != ' ' && *ptr1 != '\n' && *ptr1 != '\0' ) { 868 ptr1 = g_utf8_find_prev_char(e->buff, ptr1); 869 c = g_utf8_get_char(ptr1); 870 if (c == ' ' || c == '\n') { 871 owl_editwin_key_left(e); 872 } 873 } 874 875 /* are we starting on a space character? */ 876 i = _owl_editwin_get_index_from_xy(e); 877 while (i > e->lock && (e->buff[i] == ' ' || e->buff[i] == '\n' || e->buff[i] == '\0')) { 878 /* find the first non-space */ 879 owl_editwin_key_left(e); 880 i = _owl_editwin_get_index_from_xy(e); 881 } 882 883 /* find the last non-space */ 884 ptr1 = e->buff + _owl_editwin_get_index_from_xy(e); 885 while (ptr1 >= e->buff + e->lock) { 886 ptr2 = g_utf8_find_prev_char(e->buff, ptr1); 887 if (!ptr2) break; 888 889 c = g_utf8_get_char(ptr2); 890 if (c == ' ' || c == '\n'){ 891 break; 892 } 893 owl_editwin_key_left(e); 894 ptr1 = e->buff + _owl_editwin_get_index_from_xy(e); 895 } 896 } 897 872 _owl_editwin_excursion x; 873 int beginning; 874 /* if in middle of word, beginning of word */ 875 876 /* if at beginning of a word, find beginning of previous word */ 877 878 if (_owl_editwin_is_char_in(e, WHITESPACE)) { 879 /* if in whitespace past end of word, find a word , the find the beginning*/ 880 owl_editwin_move_if_in(e, -1, WHITESPACE); /* leaves us on the last 881 character of the word */ 882 owl_editwin_save_excursion(e, &x); 883 /* are we at the beginning of a word? */ 884 owl_editwin_point_move(e, -1); 885 beginning = _owl_editwin_is_char_in(e, WHITESPACE); 886 owl_editwin_restore_excursion(e, &x); 887 if (beginning) 888 return; 889 } else { 890 /* in the middle of the word; */ 891 owl_editwin_save_excursion(e, &x); 892 owl_editwin_point_move(e, -1); 893 if (_owl_editwin_is_char_in(e, WHITESPACE)) { /* we were at the beginning */ 894 owl_editwin_move_to_previousword(e); /* previous case */ 895 return; 896 } else { 897 owl_editwin_restore_excursion(e, &x); 898 } 899 } 900 owl_editwin_move_if_not_in(e, -1, WHITESPACE); 901 /* will go past */ 902 if (e->index > e->lock) 903 owl_editwin_point_move(e, 1); 904 } 898 905 899 906 void owl_editwin_delete_nextword(owl_editwin *e) 900 907 { 901 char *ptr1, *start; 902 gunichar c; 903 904 if (e->bufflen==0) return; 905 906 start = ptr1 = e->buff + _owl_editwin_get_index_from_xy(e); 907 /* if we start out on a space character then jump past all the 908 spaces up first */ 909 while (*ptr1 == ' ' || *ptr1 == '\n') { 910 ++ptr1; 911 } 912 913 /* then jump past the next word */ 914 915 while (ptr1 && ptr1 - e->buff < e->bufflen) { 916 c = g_utf8_get_char(ptr1); 917 if (c == ' ' || c == '\n' || c == '\0') break; 918 ptr1 = g_utf8_find_next_char(ptr1, NULL); 919 } 920 921 if (ptr1) { /* We broke on a space, */ 922 ptr1 = g_utf8_find_next_char(ptr1, NULL); 923 if (ptr1) { /* and there's a character after it, */ 924 /* nuke everything back to our starting point. */ 925 _owl_editwin_remove_bytes(e, ptr1 - start); 926 return; 927 } 928 } 929 930 /* If we get here, we ran out of string, drop what's left. */ 931 *start = '\0'; 932 e->bufflen = start - e->buff; 908 _owl_editwin_excursion x; 909 int end; 910 911 owl_editwin_save_excursion(e, &x); 912 owl_editwin_move_to_nextword(e); 913 end = e->index; 914 owl_editwin_restore_excursion(e, &x); 915 _owl_editwin_remove_bytes(e, end - e->index); 933 916 } 934 917 … … 938 921 int startpos, endpos; 939 922 940 startpos = _owl_editwin_get_index_from_xy(e);923 startpos = e->index; 941 924 owl_editwin_move_to_previousword(e); 942 endpos = _owl_editwin_get_index_from_xy(e);925 endpos = e->index; 943 926 _owl_editwin_remove_bytes(e, startpos-endpos); 944 927 } 945 928 929 void owl_editwin_move_to_line_end(owl_editwin *e) 930 { 931 owl_editwin_move_to_end_of_line(e); 932 } 933 946 934 void owl_editwin_delete_to_endofline(owl_editwin *e) 947 935 { 948 int i; 949 950 if (owl_editwin_get_numchars_on_line(e, e->buffy) > e->buffx) { 951 /* normal line */ 952 i=_owl_editwin_get_index_from_xy(e); 953 while(i < e->bufflen) { 954 if (e->buff[i]!='\n') { 955 owl_editwin_delete_char(e); 956 } else if ((e->buff[i]=='\n') && (i==e->bufflen-1)) { 957 owl_editwin_delete_char(e); 958 } else { 959 return; 960 } 961 } 962 } else if (e->buffy+1 < owl_editwin_get_numlines(e)) { 963 /* line with cursor at the end but not on very last line */ 964 owl_editwin_key_right(e); 965 owl_editwin_backspace(e); 966 } 967 } 968 969 void owl_editwin_move_to_line_end(owl_editwin *e) 970 { 971 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 936 _owl_editwin_excursion x; 937 int end; 938 939 owl_editwin_save_excursion(e, &x); 940 owl_editwin_move_to_line_end(e); 941 end = e->index; 942 owl_editwin_restore_excursion(e, &x); 943 _owl_editwin_remove_bytes(e, end - e->index); 972 944 } 973 945 974 946 void owl_editwin_move_to_line_start(owl_editwin *e) 975 947 { 976 e->buffx=0; 977 owl_editwin_adjust_for_locktext(e); 948 owl_editwin_move_to_beginning_of_line(e); 978 949 } 979 950 980 951 void owl_editwin_move_to_end(owl_editwin *e) 981 952 { 982 /* go to last char */ 983 e->buffy=owl_editwin_get_numlines(e)-1; 984 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 985 owl_editwin_key_right(e); 986 987 /* do we need to scroll? */ 988 /* 989 if (e->buffy-e->topline > e->winlines) { 990 e->topline+=e->winlines/2; 991 } 992 */ 993 owl_editwin_recenter(e); 953 e->index = e->bufflen; 994 954 } 995 955 996 956 void owl_editwin_move_to_top(owl_editwin *e) 997 957 { 998 _owl_editwin_set_xy_by_index(e, 0); 999 1000 /* do we need to scroll? */ 1001 e->topline=0; 1002 1003 owl_editwin_adjust_for_locktext(e); 958 e->index = e->lock; 1004 959 } 1005 960 1006 961 void owl_editwin_fill_paragraph(owl_editwin *e) 1007 962 { 963 #if 0 /* XXX */ 964 _owl_editwin_excursion x; 1008 965 int i, save; 1009 966 1010 967 /* save our starting point */ 1011 save=_owl_editwin_get_index_from_xy(e); 968 owl_editwin_save_excursion(e, &x); 969 970 save = e->index; 1012 971 1013 972 /* scan back to the beginning of this paragraph */ … … 1015 974 if ( (i<=e->lock) || 1016 975 ((e->buff[i]=='\n') && (e->buff[i-1]=='\n'))) { 1017 _owl_editwin_set_xy_by_index(e, i+1);976 e->index = i + 1; 1018 977 break; 1019 978 } … … 1041 1000 /* we may have added a character. */ 1042 1001 if (i < save) save += e->bufflen - len; 1043 _owl_editwin_set_xy_by_index(e, i);1002 e->index = i; 1044 1003 } 1045 1004 … … 1072 1031 1073 1032 /* put cursor back at starting point */ 1074 _owl_editwin_set_xy_by_index(e, save); 1075 1076 /* do we need to scroll? */ 1077 if (e->buffy-e->topline < 0) { 1078 e->topline-=e->winlines/2; 1079 } 1033 owl_editwin_restore_excursion(e, &x); 1034 #endif 1080 1035 } 1081 1036 … … 1083 1038 int owl_editwin_is_at_end(owl_editwin *e) 1084 1039 { 1085 int cur=_owl_editwin_get_index_from_xy(e); 1086 return (only_whitespace(e->buff+cur)); 1040 return (only_whitespace(e->buff + e->index)); 1087 1041 } 1088 1042 … … 1117 1071 void owl_editwin_post_process_char(owl_editwin *e, owl_input j) 1118 1072 { 1119 /* check if we need to scroll down */ 1120 if (e->buffy-e->topline >= e->winlines) { 1121 e->topline+=e->winlines/2; 1122 } 1073 /* XXX force a redisplay? */ 1123 1074 if ((j.ch==13 || j.ch==10) && owl_editwin_check_dotsend(e)) { 1124 1075 owl_command_editmulti_done(e); … … 1179 1130 } 1180 1131 1181 int owl_editwin_get_numcells_on_line(owl_editwin *e, int line)1182 {1183 int i;1184 char *ptr1, *ptr2;1185 gunichar c;1186 1187 if (e->bufflen==0) return(0);1188 1189 /* first go to the yth line */1190 ptr1=e->buff;1191 for (i=0; i<line; i++) {1192 ptr2=strchr(ptr1, '\n');1193 if (!ptr2) {1194 /* we're already on the last line */1195 return(0);1196 }1197 ptr1=ptr2+1;1198 }1199 1200 /* now count cells */1201 i = 0;1202 ptr2 = ptr1;1203 while (ptr2 - e->buff < e->bufflen1204 && *ptr2 != '\n') {1205 c = g_utf8_get_char(ptr2);1206 i += mk_wcwidth(c);1207 ptr2 = g_utf8_next_char(ptr2);1208 }1209 return i;1210 }1211 1212 1132 int owl_editwin_get_numlines(owl_editwin *e) 1213 1133 { … … 1215 1135 } 1216 1136 1137 int owl_editwin_get_echochar(owl_editwin *e) { 1138 return e->echochar; 1139 } -
global.c
rbd783db ra556caa 47 47 g->rightshift=0; 48 48 49 owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL); 49 g->tw = owl_editwin_allocate(); 50 owl_editwin_init(g->tw, NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL); 50 51 51 52 owl_keyhandler_init(&g->kh); … … 147 148 g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0); 148 149 149 owl_editwin_set_curswin( &(g->tw), g->typwin, typwin_lines, g->cols);150 owl_editwin_set_curswin(g->tw, g->typwin, typwin_lines, g->cols); 150 151 151 152 idlok(g->typwin, FALSE); … … 261 262 262 263 owl_editwin *owl_global_get_typwin(owl_global *g) { 263 return( &(g->tw));264 return(g->tw); 264 265 } 265 266 … … 478 479 owl_mainwin_redisplay(&(g->mw)); 479 480 sepbar(NULL); 480 owl_editwin_redisplay( &(g->tw), 0);481 owl_editwin_redisplay(g->tw, 0); 481 482 owl_function_full_redisplay(&g); 482 483 -
owl.h
rd5cc1c5d ra556caa 424 424 } owl_history; 425 425 426 typedef struct _owl_editwin { 427 char *buff; 428 owl_history *hist; 429 int bufflen; 430 int allocated; 431 int buffx, buffy; 432 int topline; 433 int winlines, wincols, fillcol, wrapcol; 434 WINDOW *curswin; 435 int style; 436 int lock; 437 int dotsend; 438 int echochar; 439 440 char *command; 441 void (*callback)(struct _owl_editwin*); 442 void *cbdata; 443 } owl_editwin; 426 typedef struct _owl_editwin owl_editwin; 444 427 445 428 typedef struct _owl_keybinding { … … 556 539 int config_format; 557 540 void *buffercbdata; 558 owl_editwin tw;541 owl_editwin *tw; 559 542 owl_viewwin vw; 560 543 void *perl; -
perlconfig.c
rd1ae4a4 ra556caa 482 482 void owl_perlconfig_edit_callback(owl_editwin *e) 483 483 { 484 SV *cb = (SV*) (e->cbdata);484 SV *cb = (SV*)owl_editwin_get_cbdata(e); 485 485 SV *text; 486 486 dSP; … … 509 509 510 510 SvREFCNT_dec(cb); 511 e->cbdata = NULL;511 owl_editwin_set_cbdata(e, NULL); 512 512 } 513 513
Note: See TracChangeset
for help on using the changeset viewer.