Changeset a60edf2
- Timestamp:
- Jul 11, 2009, 1:14:35 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:
- 2da7348
- Parents:
- 7f0c26f
- git-author:
- Nelson Elhage <nelhage@mit.edu> (07/07/09 22:49:21)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (07/11/09 13:14:35)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
r7f0c26f ra60edf2 889 889 OWL_CTX_EDIT, 890 890 "exchanges the point and the mark", 891 "", ""), 892 893 OWLCMD_VOID_CTX("edit:copy-region-as-kill", owl_editwin_copy_region_as_kill, 894 OWL_CTX_EDIT, 895 "copy the text between the point and the mark", 896 "", ""), 897 898 OWLCMD_VOID_CTX("edit:kill-region", owl_editwin_kill_region, 899 OWL_CTX_EDIT, 900 "kill text between the point and the mark", 901 "", ""), 902 903 OWLCMD_VOID_CTX("edit:yank", owl_editwin_yank, 904 OWL_CTX_EDIT, 905 "insert the current text from the kill buffer", 891 906 "", ""), 892 907 -
editwin.c
r7f0c26f ra60edf2 25 25 int index; 26 26 int mark; 27 char *killbuf; 27 28 int goal_column; 28 29 int topindex; … … 41 42 }; 42 43 43 44 44 static void oe_reframe(owl_editwin *e); 45 45 static void oe_save_excursion(owl_editwin *e, oe_excursion *x); 46 46 static void oe_release_excursion(owl_editwin *e, oe_excursion *x); 47 47 static void oe_restore_excursion(owl_editwin *e, oe_excursion *x); 48 static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x); 48 49 static int oe_count_glyphs(char *s); 49 50 static int oe_char_width(gunichar c, int column); … … 56 57 static gunichar owl_editwin_get_char_at_point(owl_editwin *e); 57 58 static int owl_editwin_replace(owl_editwin *e, int count, char *s); 59 static char *oe_copy_buf(owl_editwin *e, char *buf, int len); 60 static int oe_copy_region(owl_editwin *e); 58 61 59 62 #define INCR 4096 … … 113 116 oe_set_index(e, 0); 114 117 oe_set_mark(e, -1); 118 if (e->killbuf != NULL) 119 free(e->killbuf); 120 e->killbuf = NULL; 115 121 e->goal_column = -1; 116 122 e->cursorx = -1; … … 345 351 e->mark = x->mark; 346 352 e->lock = x->lock; 353 354 oe_release_excursion(e, x); 355 } 356 } 357 358 static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x) 359 { 360 if (x->valid == VALID_EXCURSION) { 361 e->mark = x->mark; 347 362 348 363 oe_release_excursion(e, x); … … 544 559 if (need > 0) { 545 560 size = e->allocated + need + INCR - (need % INCR); 546 p = realloc(e->buff, size);561 p = owl_realloc(e->buff, size); 547 562 if (p == NULL) { 548 563 /* XXX signal impending doom somehow and don't do anything */ … … 915 930 { 916 931 oe_excursion x; 917 int distance;918 932 919 933 oe_save_excursion(e, &x); 920 distance = owl_editwin_forward_word(e); 921 oe_restore_excursion(e, &x); 922 owl_editwin_replace(e, distance, ""); 934 oe_set_mark(e, e->index); 935 owl_editwin_forward_word(e); 936 owl_editwin_kill_region(e); 937 oe_restore_mark_only(e, &x); 923 938 } 924 939 925 940 void owl_editwin_delete_previousword(owl_editwin *e) 926 941 { 927 /* go backwards to the last non-space character, then delete chars */ 928 int distance; 929 930 distance = owl_editwin_backward_word(e); 931 owl_editwin_replace(e, -distance, ""); 942 oe_excursion x; 943 944 oe_save_excursion(e, &x); 945 oe_set_mark(e, e->index); 946 owl_editwin_backward_word(e); 947 owl_editwin_kill_region(e); 948 oe_restore_mark_only(e, &x); 932 949 } 933 950 … … 943 960 944 961 oe_save_excursion(e, &x); 962 owl_editwin_set_mark(e); 945 963 distance = owl_editwin_move_to_end_of_line(e); 964 if (distance) 965 owl_editwin_kill_region(e); 966 else 967 owl_editwin_replace(e, 1, ""); 946 968 oe_restore_excursion(e, &x); 947 owl_editwin_replace(e, distance ? distance : 1, ""); 969 } 970 971 void owl_editwin_yank(owl_editwin *e) 972 { 973 if (e->killbuf != NULL) 974 owl_editwin_replace(e, 0, e->killbuf); 975 } 976 977 static char *oe_copy_buf(owl_editwin *e, char *buf, int len) 978 { 979 char *p; 980 981 p = owl_malloc(len + 1); 982 983 if (p != NULL) { 984 owl_free(e->killbuf); 985 e->killbuf = p; 986 memcpy(e->killbuf, buf, len); 987 e->killbuf[len] = 0; 988 } 989 990 return p; 991 } 992 993 static int oe_copy_region(owl_editwin *e) 994 { 995 char *p; 996 int start, end; 997 998 if (e->mark == -1) 999 return 0; 1000 1001 start = MIN(e->index, e->mark); 1002 end = MAX(e->index, e->mark); 1003 1004 p = oe_copy_buf(e, e->buff + start, end - start); 1005 if (p != NULL) 1006 return end - start; 1007 return 0; 1008 } 1009 1010 void owl_editwin_copy_region_as_kill(owl_editwin *e) 1011 { 1012 oe_copy_region(e); 1013 } 1014 1015 void owl_editwin_kill_region(owl_editwin *e) 1016 { 1017 if (e->index > e->mark) 1018 owl_editwin_exchange_point_and_mark(e); 1019 1020 owl_editwin_replace(e, oe_copy_region(e), ""); 948 1021 } 949 1022 -
keys.c
r7f0c26f ra60edf2 86 86 BIND_CMD("C-@", "edit:set-mark", ""); 87 87 BIND_CMD("C-x C-x", "edit:exchange-point-and-mark", ""); 88 89 BIND_CMD("M-w", "edit:copy-region-as-kill", ""); 90 BIND_CMD("C-w", "edit:kill-region", ""); 91 BIND_CMD("C-y", "edit:yank", ""); 88 92 89 93 BIND_CMD("C-l", "( edit:recenter ; redisplay )", "");
Note: See TracChangeset
for help on using the changeset viewer.