Ticket #319: 0001-flow-column-insertion.patch
File 0001-flow-column-insertion.patch, 11.1 KB (added by vit_r, 16 years ago) |
---|
-
edit/ChangeLog
From d1854925692e2efa9e21272c70f697dc4e15e3d9 Mon Sep 17 00:00:00 2001 From: Vit Rosin <vit_r@list.ru> Date: Tue, 7 Apr 2009 21:17:45 +0100 Subject: [PATCH] flow column insertion --- edit/ChangeLog | 13 +++++++++ edit/edit.c | 73 +++++++++++++++++++++++++++++++++++++++++++++------ edit/edit.h | 2 + edit/editcmd.c | 79 +++++++++++++++++++++++++++++++++---------------------- 4 files changed, 126 insertions(+), 41 deletions(-) diff --git a/edit/ChangeLog b/edit/ChangeLog index a663358..241e173 100644
a b 1 2009-04-05 Vit Rosin <vit_r@list.ru> 2 flow column insertion: 3 * edit.h, edit.c (Add edit_flow_insert_col ()): 4 * edit.c (edit_insert_file): 5 * edit.c (edit_execute_key_command): 6 * editcmd.c (edit_copy_to_X_buf_cmd): 7 * editcmd.c (edit_cut_to_X_buf_cmd): 8 When chars are inserted place cursor after inserted chars. 9 If after insertion cursor changes line 10 (<Up-arrow>, <Down-arrow>, <PageUp>, <PageDown>, 11 <BeginText> or <EndText>), - 12 move cursor to the insert-start column. 13 1 14 2007-11-02 Vladimir Nadvornik <nadvornik@suse.cz> 2 15 3 16 * editlock.c (lock_build_name): Check the return value of getpwuid(). -
edit/edit.c
diff --git a/edit/edit.c b/edit/edit.c index eb61c29..ede9890 100644
a b 50 50 what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL 51 51 or EDIT_KEY_EMULATION_EMACS 52 52 */ 53 static int flow_insert_col = -1; 53 54 int edit_key_emulation = EDIT_KEY_EMULATION_NORMAL; 54 55 55 56 int option_word_wrap_line_length = 72; … … int 265 266 edit_insert_file (WEdit *edit, const char *filename) 266 267 { 267 268 char *p; 269 int tmp_curr_col; 270 edit->force |= REDRAW_COMPLETELY; 271 edit_update_screen (edit); 272 edit_update_curs_col (edit); 273 tmp_curr_col = edit_get_col (edit); 274 flow_insert_col = -1; 268 275 if ((p = edit_get_filter (filename))) { 269 276 FILE *f; 270 long current = edit->curs1;271 277 f = (FILE *) popen (p, "r"); 272 278 if (f) { 273 279 edit_insert_stream (edit, f); 274 edit_cursor_move (edit, current - edit->curs1);275 280 if (pclose (f) > 0) { 276 281 GString *errmsg = g_string_new (NULL); 277 282 g_string_sprintf (errmsg, _(" Error reading from pipe: %s "), p); … … edit_insert_file (WEdit *edit, const char *filename) 291 296 g_free (p); 292 297 } else { 293 298 int i, file, blocklen; 294 long current = edit->curs1;295 299 unsigned char *buf; 296 300 if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1) 297 301 return 0; … … edit_insert_file (WEdit *edit, const char *filename) 300 304 for (i = 0; i < blocklen; i++) 301 305 edit_insert (edit, buf[i]); 302 306 } 303 edit_cursor_move (edit, current - edit->curs1);304 307 g_free (buf); 305 308 mc_close (file); 306 309 if (blocklen) 307 310 return 0; 308 311 } 312 flow_insert_col = tmp_curr_col; 309 313 return 1; 310 314 } 311 315 … … static void edit_tab_cmd (WEdit * edit) 2017 2021 2018 2022 static void check_and_wrap_line (WEdit * edit) 2019 2023 { 2020 int curs, c; 2024 int c; 2025 long curs; 2021 2026 if (!option_typewriter_wrap) 2022 2027 return; 2023 2028 edit_update_curs_col (edit); … … static void check_and_wrap_line (WEdit * edit) 2032 2037 return; 2033 2038 } 2034 2039 if (c == ' ' || c == '\t') { 2035 intcurrent = edit->curs1;2040 long current = edit->curs1; 2036 2041 edit_cursor_move (edit, curs - edit->curs1 + 1); 2037 2042 edit_insert (edit, '\n'); 2038 2043 edit_cursor_move (edit, current - edit->curs1 + 1); … … void edit_execute_key_command (WEdit *edit, int command, int char_for_insertion) 2150 2155 edit_push_key_press (edit); 2151 2156 2152 2157 edit_execute_cmd (edit, command, char_for_insertion); 2158 edit_flow_insert_col (edit, command); 2153 2159 if (column_highlighting) 2154 2160 edit->force |= REDRAW_PAGE; 2155 2161 } … … edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 2512 2518 case CK_Move: 2513 2519 edit_block_move_cmd (edit); 2514 2520 break; 2515 2516 2521 case CK_XStore: 2517 edit_copy_to_X_buf_cmd (edit); 2522 if (edit_copy_to_X_buf_cmd (edit)) { 2523 flow_insert_col = get_flowing_col (edit); 2524 edit_mark_cmd (edit, 1); 2525 } 2518 2526 break; 2519 2527 case CK_XCut: 2520 edit_cut_to_X_buf_cmd (edit); 2528 if (edit_cut_to_X_buf_cmd (edit)) { 2529 flow_insert_col = edit_get_col (edit); 2530 edit_mark_cmd (edit, 1); 2531 } 2521 2532 break; 2522 2533 case CK_XPaste: 2534 flow_insert_col = edit_get_col (edit); 2523 2535 edit_paste_from_X_buf_cmd (edit); 2524 2536 break; 2525 2537 case CK_Selection_History: … … user_menu (WEdit * edit) 2772 2784 cleanup: 2773 2785 g_free (block_file); 2774 2786 } 2787 2788 int get_flowing_col (WEdit * edit) 2789 { 2790 long start_mark, end_mark; 2791 edit->force |= REDRAW_COMPLETELY; 2792 edit_update_screen (edit); 2793 if ( ! eval_marks (edit, &start_mark, &end_mark)) { 2794 if (start_mark == edit->mark1) 2795 return edit->column1; 2796 else 2797 return edit->column2; 2798 } 2799 return (-1); 2800 } 2801 2802 void edit_flow_insert_col (WEdit * edit, const int command) 2803 { 2804 if (command == CK_Mark && edit->mark2 >= 0 2805 || command == CK_Copy || command == CK_Move) 2806 flow_insert_col = get_flowing_col (edit); 2807 2808 if (command == CK_Beginning_Of_Text || command == CK_End_Of_Text 2809 || command == CK_Page_Up || command == CK_Page_Down 2810 || command == CK_Up || command == CK_Down) { 2811 if (flow_insert_col >= 0) { 2812 edit->force |= REDRAW_COMPLETELY; 2813 edit_update_screen (edit); 2814 if ((edit_eol (edit, edit->curs1) - edit_bol (edit, edit->curs1)) >= flow_insert_col) { 2815 edit_cursor_move (edit, flow_insert_col - edit->curs_col); 2816 edit->force |= REDRAW_COMPLETELY; 2817 edit_update_screen (edit); 2818 } 2819 } 2820 } else if (command == CK_Copy || command == CK_Move 2821 || command == CK_XCut || command == CK_XPaste 2822 || command == CK_XStore) { 2823 /* */ 2824 } else if (edit->mark2 >= 0) { 2825 /* */ 2826 } else { 2827 flow_insert_col = -1; 2828 } 2829 } -
edit/edit.h
diff --git a/edit/edit.h b/edit/edit.h index 783bcd5..cdf0371 100644
a b void format_paragraph (WEdit *edit, int force); 244 244 245 245 /* either command or char_for_insertion must be passed as -1 */ 246 246 void edit_execute_cmd (WEdit *edit, int command, int char_for_insertion); 247 void edit_flow_insert_col (WEdit * edit, const int command); 248 int get_flowing_col (WEdit * edit); 247 249 248 250 #define get_sys_error(s) (s) 249 251 -
edit/editcmd.c
diff --git a/edit/editcmd.c b/edit/editcmd.c index d3f8ecf..ff81aa2 100644
a b edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int wid 970 970 void 971 971 edit_block_copy_cmd (WEdit *edit) 972 972 { 973 long start_mark, end_mark, current = edit->curs1;974 int size ;973 long start_mark, end_mark, start_curs1, current = edit->curs1; 974 int size, start_col; 975 975 unsigned char *copy_buf; 976 976 977 977 edit_update_curs_col (edit); … … edit_block_copy_cmd (WEdit *edit) 988 988 edit_insert_column_of_text (edit, copy_buf, size, 989 989 abs (edit->column2 - edit->column1)); 990 990 } else { 991 edit_scroll_screen_over_cursor (edit); 992 edit->force |= REDRAW_COMPLETELY; 993 edit_update_screen (edit); 994 edit_update_curs_col (edit); 995 start_col = edit_get_col (edit); 996 start_curs1 = edit->curs1; 991 997 while (size--) 992 998 edit_insert_ahead (edit, copy_buf[size]); 993 999 } … … edit_block_copy_cmd (WEdit *edit) 999 1005 edit_set_markers (edit, 0, 0, 0, 0); 1000 1006 edit_push_action (edit, COLUMN_ON); 1001 1007 column_highlighting = 0; 1002 } else if (start_mark < current && end_mark > current) 1008 } else if (current >= start_mark && current < end_mark) { 1009 edit_cursor_move (edit, end_mark + end_mark - start_mark - edit->curs1); 1003 1010 edit_set_markers (edit, start_mark, 1004 end_mark + end_mark - start_mark, 0, 0); 1005 1011 end_mark + end_mark - start_mark, start_col, edit->curs_col); 1012 } else { 1013 edit_cursor_move (edit, end_mark - start_mark); 1014 edit_set_markers (edit, start_curs1, 1015 edit->curs1, start_col, edit->curs_col); 1016 } 1017 edit_scroll_screen_over_cursor (edit); 1006 1018 edit->force |= REDRAW_PAGE; 1007 1019 } 1008 1020 1009 1010 1021 void 1011 1022 edit_block_move_cmd (WEdit *edit) 1012 1023 { 1013 1024 long count; 1014 1025 long current; 1015 1026 unsigned char *copy_buf; 1016 long start_mark, end_mark ;1027 long start_mark, end_mark, start_curs1; 1017 1028 int deleted = 0; 1018 int x = 0;1029 int start_col, x = 0; 1019 1030 1020 1031 if (eval_marks (edit, &start_mark, &end_mark)) 1021 1032 return; … … edit_block_move_cmd (WEdit *edit) 1073 1084 edit_push_action (edit, COLUMN_ON); 1074 1085 column_highlighting = 0; 1075 1086 } else { 1076 copy_buf = g_malloc (end_mark - start_mark); 1077 edit_cursor_move (edit, start_mark - edit->curs1); 1078 edit_scroll_screen_over_cursor (edit); 1079 count = start_mark; 1080 while (count < end_mark) { 1081 copy_buf[end_mark - count - 1] = edit_delete (edit); 1082 count++; 1083 } 1084 edit_scroll_screen_over_cursor (edit); 1085 edit_cursor_move (edit, 1086 current - edit->curs1 - 1087 (((current - edit->curs1) > 1088 0) ? end_mark - start_mark : 0)); 1089 edit_scroll_screen_over_cursor (edit); 1090 while (count-- > start_mark) 1091 edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); 1092 edit_set_markers (edit, edit->curs1, 1093 edit->curs1 + end_mark - start_mark, 0, 0); 1087 copy_buf = g_malloc (end_mark - start_mark); 1088 edit_cursor_move (edit, start_mark - edit->curs1); 1089 edit_scroll_screen_over_cursor (edit); 1090 count = start_mark; 1091 while (count < end_mark) { 1092 copy_buf[end_mark - count - 1] = edit_delete (edit); 1093 count++; 1094 } 1095 edit_scroll_screen_over_cursor (edit); 1096 edit_cursor_move (edit, 1097 current - edit->curs1 - 1098 (((current - edit->curs1) > 1099 0) ? end_mark - start_mark : 0)); 1100 edit_scroll_screen_over_cursor (edit); 1101 edit->force |= REDRAW_COMPLETELY; 1102 edit_update_screen (edit); 1103 edit_update_curs_col (edit); 1104 start_col = edit_get_col (edit); 1105 start_curs1 = edit->curs1; 1106 while (count-- > start_mark) 1107 edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); 1108 edit_cursor_move (edit, end_mark - start_mark); 1109 edit_set_markers (edit, start_curs1, 1110 edit->curs1, start_col, edit->curs_col); 1094 1111 } 1095 1112 edit_scroll_screen_over_cursor (edit); 1096 1113 g_free (copy_buf); … … int edit_copy_to_X_buf_cmd (WEdit * edit) 2276 2293 return 0; 2277 2294 if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) { 2278 2295 edit_error_dialog (_(" Copy to clipboard "), get_sys_error (_(" Unable to save to file. "))); 2279 return 1;2296 return 0; 2280 2297 } 2281 edit_mark_cmd (edit, 1); 2282 return 0; 2298 return 1; 2283 2299 } 2284 2300 2285 2301 int edit_cut_to_X_buf_cmd (WEdit * edit) … … int edit_cut_to_X_buf_cmd (WEdit * edit) 2289 2305 return 0; 2290 2306 if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) { 2291 2307 edit_error_dialog (_(" Cut to clipboard "), _(" Unable to save to file. ")); 2292 return 1;2308 return 0; 2293 2309 } 2294 2310 edit_block_delete_cmd (edit); 2295 edit_mark_cmd (edit, 1); 2296 return 0; 2311 return 1; 2297 2312 } 2298 2313 2299 2314 void edit_paste_from_X_buf_cmd (WEdit * edit)