Changeset e20d8179
- Timestamp:
- Jul 11, 2009, 1:14:33 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:
- 19f765d
- Parents:
- bd1a1ae
- git-author:
- Karl Ramm <kcr@1ts.org> (06/07/09 15:24:15)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (07/11/09 13:14:33)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
editwin.c
rbd1a1ae re20d8179 32 32 } _owl_editwin_excursion; 33 33 34 static int owl_editwin_is_char_in(owl_editwin *e, char *set); 35 static void oe_reframe(owl_editwin *e); 36 34 37 #define INCR 5000 35 38 … … 45 48 void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist) 46 49 { 47 e->buff=owl_malloc(INCR); 50 e->buff=owl_malloc(INCR); 48 51 e->buff[0]='\0'; 49 52 e->bufflen=0; … … 262 265 e->topindex = -1; 263 266 } 264 static void owl_editwin_reframe(owl_editwin *e) { /* noproto */ 267 268 static inline char *oe_next_point(owl_editwin *e, char *p) 269 { 270 char *boundary = e->buff + e->bufflen + 1; 271 char *q; 272 273 q = g_utf8_find_next_char(p, boundary); 274 while (q && g_unichar_ismark(g_utf8_get_char(q))) 275 q = g_utf8_find_next_char(q, boundary); 276 277 if (q == p) 278 return NULL; 279 return q; 280 } 281 282 static inline char *oe_prev_point(owl_editwin *e, char *p) 283 { 284 char *boundary = e->buff + e->lock; 285 286 p = g_utf8_find_prev_char(boundary, p); 287 while (p && g_unichar_ismark(g_utf8_get_char(p))) 288 p = g_utf8_find_prev_char(boundary, p); 289 290 return p; 291 } 292 293 static void oe_reframe(owl_editwin *e) { 265 294 e->topindex = 0; /*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ 266 295 } … … 278 307 do { 279 308 if (e->topindex == -1 || e->index < e->topindex) 280 o wl_editwin_reframe(e);281 309 oe_reframe(e); 310 282 311 line = 0; 283 312 index = e->topindex; … … 299 328 break; 300 329 width += cw; 301 p = g_utf8_find_next_char(e->buff + index, e->buff + e->bufflen);330 p = oe_next_point(e, e->buff + index); 302 331 if (p == NULL) /* we ran off the end */ 303 332 break; … … 323 352 } 324 353 } while(x == -1); 325 354 326 355 if (x != -1) 327 356 wmove(e->curswin, y, x); … … 338 367 e->buff[i-n] = e->buff[i]; 339 368 } 340 369 341 370 e->bufflen -= n; 342 371 e->buff[e->bufflen] = '\0'; … … 462 491 c = '\n'; 463 492 } 464 493 465 494 if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { 466 495 /* perhaps later this will change some state that allows the string … … 481 510 } 482 511 } 483 /* if not at the end of the buffer, adjust based in char size difference. */ 512 /* if not at the end of the buffer, adjust based in char size difference. */ 484 513 else if (oldlen > newlen) { 485 514 _owl_editwin_remove_bytes(e, oldlen-newlen); … … 492 521 e->buff[e->index + i] = tmp[i]; 493 522 } 494 523 495 524 /* housekeeping */ 496 525 if (e->index == e->bufflen) { … … 498 527 e->buff[e->bufflen] = '\0'; 499 528 } 500 529 501 530 /* advance the cursor */ 502 531 e->index += newlen; … … 505 534 /* delete the character at the current point, following chars 506 535 * shift left. 507 */ 536 */ 508 537 void owl_editwin_delete_char(owl_editwin *e) 509 538 { … … 512 541 513 542 if (e->bufflen == 0) return; 514 543 515 544 if (e->index == e->bufflen) return; 516 545 … … 528 557 * advance the pointer. If point is at beginning of buffer do 529 558 * nothing. If point is after the last character swap point-1 with 530 * point-2. (Behaves as observed in tcsh and emacs). 559 * point-2. (Behaves as observed in tcsh and emacs). 531 560 */ 532 561 void owl_editwin_transpose_chars(owl_editwin *e) … … 535 564 536 565 if (e->bufflen == 0) return; 537 566 538 567 if (e->index == e->bufflen) { 539 568 /* point is after last character */ 540 569 e->index--; 541 } 570 } 542 571 543 572 if (e->index - 1 < e->lock) { … … 549 578 p1 = e->buff + e->index; 550 579 551 p2 = g_utf8_find_next_char(p1, NULL); 552 while (p2 != NULL && g_unichar_ismark(g_utf8_get_char(p2))) { 553 p2 = g_utf8_find_next_char(p2, NULL); 554 } 555 if (p2 == NULL) return; 556 557 p3 = g_utf8_find_prev_char(e->buff, p1); 558 while (p3 != NULL && g_unichar_ismark(g_utf8_get_char(p3))) { 559 p3 = g_utf8_find_prev_char(p3, NULL); 560 } 561 if (p3 == NULL) return; 580 p2 = oe_next_point(e, p1); /* XXX make sure we can't transpose past the end 581 of the buffer */ 582 if (p2 == NULL) 583 return; 584 585 p3 = oe_prev_point(e, p1); 586 if (p3 == NULL) 587 return; 562 588 563 589 tmp = owl_malloc(p2 - p3 + 5); … … 639 665 } 640 666 641 int owl_editwin_point_move(owl_editwin *e, int delta) /*noproto*/642 { 643 char *p , *boundary;667 int owl_editwin_point_move(owl_editwin *e, int delta) 668 { 669 char *p; 644 670 int change, index, d = 0; 645 671 … … 647 673 p = e->buff + e->index; 648 674 649 boundary = e->buff + (delta > 0 ? (e->bufflen + 1) : e->lock);650 651 675 while (d < change && p != NULL) { 652 if (delta > 0) { 653 p = g_utf8_find_next_char(p, boundary); 654 while (p && g_unichar_ismark(g_utf8_get_char(p))) 655 p = g_utf8_find_next_char(p, boundary); 656 } else { 657 p = g_utf8_find_prev_char(boundary, p); 658 while (p && g_unichar_ismark(g_utf8_get_char(p))) 659 p = g_utf8_find_prev_char(boundary, p); 660 } 661 if (p != NULL) { 662 index = p - e->buff; 663 if (index != e->index) { /* XXX rethink the loop termination condition 664 above */ 665 e->index = index; 666 d++; 667 } else 668 break; 676 if (delta > 0) 677 p = oe_next_point(e, p); 678 else 679 p = oe_prev_point(e, p); 680 if (p != NULL) { 681 e->index = p - e->buff; 682 d++; 669 683 } 670 684 } … … 706 720 } 707 721 708 int _owl_editwin_is_char_in(owl_editwin *e, char *set) /*noproto*/ 722 static int owl_editwin_is_char_in(owl_editwin *e, char *set) 709 723 { 710 724 char *p; … … 716 730 } 717 731 718 int owl_editwin_move_if_in(owl_editwin *e, int delta, char *set) /*noproto*/732 int owl_editwin_move_if_in(owl_editwin *e, int delta, char *set) 719 733 { 720 734 int change, distance = 0; 721 while ( _owl_editwin_is_char_in(e, set)) {735 while (owl_editwin_is_char_in(e, set)) { 722 736 change = owl_editwin_point_move(e, delta); 723 737 distance += change; … … 728 742 } 729 743 730 int owl_editwin_move_if_not_in(owl_editwin *e, int delta, char *set) /*noproto*/744 int owl_editwin_move_if_not_in(owl_editwin *e, int delta, char *set) 731 745 { 732 746 int change, distance = 0; 733 while (! _owl_editwin_is_char_in(e, set)) {747 while (!owl_editwin_is_char_in(e, set)) { 734 748 change = owl_editwin_point_move(e, delta); 735 749 distance += change; … … 740 754 } 741 755 742 int owl_editwin_move_to_beginning_of_line(owl_editwin *e) /* noproto */756 int owl_editwin_move_to_beginning_of_line(owl_editwin *e) 743 757 { 744 758 int distance = 0; … … 754 768 return distance; 755 769 } 756 757 int owl_editwin_move_to_end_of_line(owl_editwin *e) /* noproto */770 771 int owl_editwin_move_to_end_of_line(owl_editwin *e) 758 772 { 759 773 return owl_editwin_move_if_not_in(e, 1, "\n"); 760 774 } 761 775 762 int owl_editwin_line_move(owl_editwin *e, int delta) /*noproto*/776 int owl_editwin_line_move(owl_editwin *e, int delta) 763 777 { 764 778 int goal_column, change, ll, count = 0, distance = 0; … … 849 863 /* if at beginning of a word, find beginning of previous word */ 850 864 851 if ( _owl_editwin_is_char_in(e, WHITESPACE)) {865 if (owl_editwin_is_char_in(e, WHITESPACE)) { 852 866 /* if in whitespace past end of word, find a word , the find the beginning*/ 853 867 owl_editwin_move_if_in(e, -1, WHITESPACE); /* leaves us on the last … … 856 870 /* are we at the beginning of a word? */ 857 871 owl_editwin_point_move(e, -1); 858 beginning = _owl_editwin_is_char_in(e, WHITESPACE);872 beginning = owl_editwin_is_char_in(e, WHITESPACE); 859 873 owl_editwin_restore_excursion(e, &x); 860 874 if (beginning) … … 864 878 owl_editwin_save_excursion(e, &x); 865 879 owl_editwin_point_move(e, -1); 866 if ( _owl_editwin_is_char_in(e, WHITESPACE)) { /* we were at the beginning */880 if (owl_editwin_is_char_in(e, WHITESPACE)) { /* we were at the beginning */ 867 881 owl_editwin_move_to_previousword(e); /* previous case */ 868 882 return; … … 1049 1063 return; 1050 1064 } 1051 owl_editwin_redisplay(e, 0); 1065 owl_editwin_redisplay(e, 0); 1052 1066 } 1053 1067 … … 1064 1078 if (j.ch == ERR) return; 1065 1079 /* Ignore ncurses control characters. */ 1066 if (j.ch < 0x100) { 1080 if (j.ch < 0x100) { 1067 1081 _owl_editwin_process_char(e, j.uch); 1068 1082 } … … 1080 1094 1081 1095 if (e->bufflen==0) return(0); 1082 1096 1083 1097 /* first go to the yth line */ 1084 1098 ptr1=e->buff; … … 1111 1125 return e->echochar; 1112 1126 } 1127 1128 void owl_editwin_set_goal_column(owl_editwin *e, int column) 1129 { 1130 e->goal_column = column; 1131 } 1132 1133 int owl_editwin_get_goal_column(owl_editwin *e) 1134 { 1135 return e->goal_column; 1136 }
Note: See TracChangeset
for help on using the changeset viewer.