diff -rwu '--exclude=Makefile.in' mc-4.8.1/src/editor/edit.c mc-4.8.1-lbr/src/editor/edit.c
old
|
new
|
|
87 | 87 | int option_cursor_beyond_eol = 0; |
88 | 88 | int option_line_state = 0; |
89 | 89 | int option_line_state_width = 0; |
| 90 | int option_autodetect_lb = 0; |
90 | 91 | |
91 | 92 | int option_edit_right_extreme = 0; |
92 | 93 | int option_edit_left_extreme = 0; |
… |
… |
|
423 | 424 | |
424 | 425 | /* --------------------------------------------------------------------------------------------- */ |
425 | 426 | /** |
| 427 | * detect type of line breaks of loaded file by lead BUF_MEDIUM bytes |
| 428 | * |
| 429 | */ |
| 430 | static LineBreaks |
| 431 | detect_lb_type (char *filename) |
| 432 | { |
| 433 | char buf[BUF_MEDIUM]; |
| 434 | ssize_t file, sz; |
| 435 | |
| 436 | file = mc_open (filename, O_RDONLY | O_BINARY); |
| 437 | if (file == -1) |
| 438 | return LB_ASIS; |
| 439 | |
| 440 | memset (buf, 0, sizeof (buf)); |
| 441 | sz = mc_read (file, buf, sizeof (buf) - 1); |
| 442 | if (sz < 0) |
| 443 | return LB_ASIS; |
| 444 | mc_close (file); |
| 445 | |
| 446 | buf[(size_t) sz] = '\0'; |
| 447 | if (strstr (buf, "\r\n") != NULL) |
| 448 | return LB_WIN; |
| 449 | if (strchr (buf, '\r') != NULL) |
| 450 | return LB_MAC; |
| 451 | return LB_ASIS; |
| 452 | } |
| 453 | |
| 454 | /* --------------------------------------------------------------------------------------------- */ |
| 455 | /** |
426 | 456 | * Open the file and load it into the buffers, either directly or using |
427 | 457 | * a filter. Return 0 on success, 1 on error. |
428 | 458 | * |
… |
… |
|
436 | 466 | edit_load_file (WEdit * edit) |
437 | 467 | { |
438 | 468 | int fast_load = 1; |
| 469 | LineBreaks lb_type = LB_ASIS; |
439 | 470 | vfs_path_t *vpath = vfs_path_from_str (edit->filename); |
440 | 471 | |
441 | 472 | /* Cannot do fast load if a filter is used */ |
… |
… |
|
460 | 491 | /* If we are dealing with a real file, check that it exists */ |
461 | 492 | if (check_file_access (edit, edit->filename, &edit->stat1)) |
462 | 493 | return 1; |
| 494 | |
| 495 | if (option_autodetect_lb) |
| 496 | lb_type = detect_lb_type(edit->filename); |
| 497 | else |
| 498 | lb_type = LB_ASIS; |
| 499 | |
| 500 | if (lb_type != LB_ASIS && lb_type != LB_UNIX) |
| 501 | fast_load = 0; |
463 | 502 | } |
464 | 503 | else |
465 | 504 | { |
… |
… |
|
482 | 521 | if (*edit->filename) |
483 | 522 | { |
484 | 523 | edit->undo_stack_disable = 1; |
485 | | if (edit_insert_file (edit, edit->filename) == 0) |
| 524 | if (edit_insert_file (edit, edit->filename, lb_type) == 0) |
486 | 525 | { |
487 | 526 | edit_clean (edit); |
488 | 527 | return 1; |
489 | 528 | } |
| 529 | edit_set_markers (edit, 0, 0, 0, 0); |
490 | 530 | edit->undo_stack_disable = 0; |
491 | 531 | } |
492 | 532 | } |
493 | | edit->lb = LB_ASIS; |
| 533 | edit->lb = lb_type; |
494 | 534 | return 0; |
495 | 535 | } |
496 | 536 | |
… |
… |
|
1855 | 1895 | { |
1856 | 1896 | long ins_len; |
1857 | 1897 | |
1858 | | ins_len = edit_insert_file (edit, block_file); |
| 1898 | ins_len = edit_insert_file (edit, block_file, LB_ASIS); |
1859 | 1899 | if (nomark == 0 && ins_len > 0) |
1860 | 1900 | edit_set_markers (edit, start_mark, start_mark + ins_len, 0, 0); |
1861 | 1901 | } |
… |
… |
|
2071 | 2111 | /* --------------------------------------------------------------------------------------------- */ |
2072 | 2112 | /** inserts a file at the cursor, returns count of inserted bytes on success */ |
2073 | 2113 | long |
2074 | | edit_insert_file (WEdit * edit, const char *filename) |
| 2114 | edit_insert_file (WEdit * edit, const char *filename, LineBreaks lb_type) |
2075 | 2115 | { |
2076 | 2116 | char *p; |
2077 | 2117 | long ins_len = 0; |
… |
… |
|
2146 | 2186 | while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0) |
2147 | 2187 | { |
2148 | 2188 | for (i = 0; i < blocklen; i++) |
| 2189 | { |
| 2190 | if (buf[i] == '\r') |
| 2191 | { |
| 2192 | if (lb_type == LB_MAC) |
| 2193 | edit_insert (edit, '\n'); |
| 2194 | else if (lb_type == LB_WIN) |
| 2195 | /* just skip */; |
| 2196 | else |
| 2197 | edit_insert (edit, '\r'); |
| 2198 | } |
| 2199 | else |
2149 | 2200 | edit_insert (edit, buf[i]); |
2150 | 2201 | } |
| 2202 | } |
2151 | 2203 | /* highlight inserted text then not persistent blocks */ |
2152 | 2204 | if (!option_persistent_selections && edit->modified) |
2153 | 2205 | { |
… |
… |
|
2245 | 2297 | edit->redo_stack_size = START_STACK_SIZE; |
2246 | 2298 | edit->redo_stack_size_mask = START_STACK_SIZE - 1; |
2247 | 2299 | edit->redo_stack = g_malloc0 ((edit->redo_stack_size + 10) * sizeof (long)); |
2248 | | |
| 2300 | edit->highlight = 0; |
2249 | 2301 | edit->utf8 = 0; |
2250 | 2302 | edit->converter = str_cnv_from_term; |
2251 | 2303 | edit_set_codeset (edit); |
… |
… |
|
4367 | 4419 | } |
4368 | 4420 | |
4369 | 4421 | /* --------------------------------------------------------------------------------------------- */ |
| 4422 | |
diff -rwu '--exclude=Makefile.in' mc-4.8.1/src/editor/editcmd.c mc-4.8.1-lbr/src/editor/editcmd.c
old
|
new
|
|
348 | 348 | g_free (msg); |
349 | 349 | goto error_save; |
350 | 350 | } |
| 351 | |
| 352 | /* Update the file information, especially the mtime. */ |
| 353 | if (mc_stat (savename, &edit->stat1) == -1) |
| 354 | goto error_save; |
351 | 355 | } |
352 | 356 | |
353 | 357 | if (filelen != edit->last_byte) |
… |
… |
|
432 | 436 | { |
433 | 437 | char *fname; |
434 | 438 | |
| 439 | /* Don't change current LB type (possibly autodetected), unless user asked to. */ |
| 440 | if (cur_lb != LB_ASIS) |
435 | 441 | edit->lb = cur_lb; |
436 | 442 | fname = tilde_expand (filename); |
437 | 443 | g_free (filename); |
… |
… |
|
2684 | 2690 | /* try use external clipboard utility */ |
2685 | 2691 | mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", NULL); |
2686 | 2692 | tmp = mc_config_get_full_path (EDIT_CLIP_FILE); |
2687 | | edit_insert_file (edit, tmp); |
| 2693 | edit_insert_file (edit, tmp, LB_ASIS); |
2688 | 2694 | g_free (tmp); |
2689 | 2695 | } |
2690 | 2696 | |
… |
… |
|
2800 | 2806 | } |
2801 | 2807 | else |
2802 | 2808 | { |
2803 | | if (edit_insert_file (edit, exp) != 0) |
| 2809 | if (edit_insert_file (edit, exp, LB_ASIS) != 0) |
2804 | 2810 | { |
2805 | 2811 | g_free (exp); |
2806 | 2812 | edit->force |= REDRAW_COMPLETELY; |
… |
… |
|
2878 | 2884 | if (edit_block_delete_cmd (edit)) |
2879 | 2885 | return 1; |
2880 | 2886 | tmp = mc_config_get_full_path (EDIT_TEMP_FILE); |
2881 | | edit_insert_file (edit, tmp); |
| 2887 | edit_insert_file (edit, tmp, LB_ASIS); |
2882 | 2888 | g_free (tmp); |
2883 | 2889 | return 0; |
2884 | 2890 | } |
… |
… |
|
2917 | 2923 | |
2918 | 2924 | edit->force |= REDRAW_COMPLETELY; |
2919 | 2925 | tmp = mc_config_get_full_path (EDIT_TEMP_FILE); |
2920 | | edit_insert_file (edit, tmp); |
| 2926 | edit_insert_file (edit, tmp, LB_ASIS); |
2921 | 2927 | g_free (tmp); |
2922 | 2928 | return 0; |
2923 | 2929 | } |
diff -rwu '--exclude=Makefile.in' mc-4.8.1/src/editor/editdraw.c mc-4.8.1-lbr/src/editor/editdraw.c
old
|
new
|
|
108 | 108 | unsigned int cur_utf = 0; |
109 | 109 | int cw = 1; |
110 | 110 | |
| 111 | static const char *lb_names[LB_NAMES] = { |
| 112 | "", |
| 113 | "LF", |
| 114 | "CRLF", |
| 115 | "CR" |
| 116 | }; |
| 117 | |
111 | 118 | /* |
112 | 119 | * If we are at the end of file, print <EOF>, |
113 | 120 | * otherwise print the current character as is (if printable), |
… |
… |
|
147 | 154 | /* The field lengths just prevent the status line from shortening too much */ |
148 | 155 | if (simple_statusbar) |
149 | 156 | g_snprintf (s, w, |
150 | | "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s", |
| 157 | "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s %s", |
151 | 158 | edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-', |
152 | 159 | edit->modified ? 'M' : '-', |
153 | 160 | macro_index < 0 ? '-' : 'R', |
… |
… |
|
157 | 164 | edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str, |
158 | 165 | #ifdef HAVE_CHARSET |
159 | 166 | mc_global.source_codepage >= |
160 | | 0 ? get_codepage_id (mc_global.source_codepage) : "" |
| 167 | 0 ? get_codepage_id (mc_global.source_codepage) : "", |
161 | 168 | #else |
162 | | "" |
| 169 | "", |
163 | 170 | #endif |
| 171 | lb_names[edit->lb] |
164 | 172 | ); |
165 | 173 | else |
166 | 174 | g_snprintf (s, w, |
… |
… |
|
176 | 184 | edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str, |
177 | 185 | #ifdef HAVE_CHARSET |
178 | 186 | mc_global.source_codepage >= |
179 | | 0 ? get_codepage_id (mc_global.source_codepage) : "" |
| 187 | 0 ? get_codepage_id (mc_global.source_codepage) : "", |
180 | 188 | #else |
181 | | "" |
| 189 | "", |
182 | 190 | #endif |
| 191 | lb_names[edit->lb] |
183 | 192 | ); |
184 | 193 | } |
185 | 194 | |
diff -rwu '--exclude=Makefile.in' mc-4.8.1/src/editor/edit.h mc-4.8.1-lbr/src/editor/edit.h
old
|
new
|
|
36 | 36 | extern int option_fill_tabs_with_spaces; |
37 | 37 | extern int option_return_does_auto_indent; |
38 | 38 | extern int option_backspace_through_tabs; |
| 39 | extern int option_autodetect_lb; |
39 | 40 | extern int option_fake_half_tabs; |
40 | 41 | extern int option_persistent_selections; |
41 | 42 | extern int option_cursor_beyond_eol; |
diff -rwu '--exclude=Makefile.in' mc-4.8.1/src/editor/edit-impl.h mc-4.8.1-lbr/src/editor/edit-impl.h
old
|
new
|
|
245 | 245 | void edit_insert_over (WEdit * edit); |
246 | 246 | int edit_insert_column_of_text_from_file (WEdit * edit, int file, |
247 | 247 | long *start_pos, long *end_pos, int *col1, int *col2); |
248 | | long edit_insert_file (WEdit * edit, const char *filename); |
| 248 | long edit_insert_file (WEdit * edit, const char *filename, LineBreaks lb_type); |
249 | 249 | int edit_load_back_cmd (WEdit * edit); |
250 | 250 | int edit_load_forward_cmd (WEdit * edit); |
251 | 251 | void edit_block_process_cmd (WEdit * edit, int macro_number); |
diff -rwu '--exclude=Makefile.in' mc-4.8.1/src/editor/editoptions.c mc-4.8.1-lbr/src/editor/editoptions.c
old
|
new
|
|
109 | 109 | N_("Confir&m before saving"), &edit_confirm_save), |
110 | 110 | /* 12 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 3, OPT_DLG_H, |
111 | 111 | N_("&Return does autoindent"), &option_return_does_auto_indent), |
112 | | /* 13 */ QUICK_LABEL (3, OPT_DLG_W, 11, OPT_DLG_H, N_("Tab spacing:")), |
113 | | /* 14 */ QUICK_INPUT (3 + 24, OPT_DLG_W, 11, OPT_DLG_H, |
| 112 | /* 13 */ QUICK_LABEL (3, OPT_DLG_W, 12, OPT_DLG_H, N_("Tab spacing:")), |
| 113 | /* 14 */ QUICK_INPUT (3 + 24, OPT_DLG_W, 12, OPT_DLG_H, |
114 | 114 | tab_spacing, OPT_DLG_W / 2 - 4 - 24, 0, "edit-tab-spacing", &q), |
115 | | /* 15 */ QUICK_CHECKBOX (3, OPT_DLG_W, 10, OPT_DLG_H, |
| 115 | /* 15 */ QUICK_CHECKBOX (3, OPT_DLG_W, 11, OPT_DLG_H, |
116 | 116 | N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces), |
117 | | /* 16 */ QUICK_CHECKBOX (3, OPT_DLG_W, 9, OPT_DLG_H, |
| 117 | /* 16 */ QUICK_CHECKBOX (3, OPT_DLG_W, 10, OPT_DLG_H, |
118 | 118 | N_("&Backspace through tabs"), &option_backspace_through_tabs), |
119 | | /* 17 */ QUICK_CHECKBOX (3, OPT_DLG_W, 8, OPT_DLG_H, |
| 119 | /* 17 */ QUICK_CHECKBOX (3, OPT_DLG_W, 9, OPT_DLG_H, |
120 | 120 | N_("&Fake half tabs"), &option_fake_half_tabs), |
121 | | /* 18 */ QUICK_RADIO (4, OPT_DLG_W, 4, OPT_DLG_H, 3, wrap_str, &wrap_mode), |
122 | | /* 19 */ QUICK_LABEL (3, OPT_DLG_W, 3, OPT_DLG_H, N_("Wrap mode")), |
| 121 | /* 18 */ QUICK_CHECKBOX (3, OPT_DLG_W, 8, OPT_DLG_H, |
| 122 | N_("&Autodetect line break"), &option_autodetect_lb), |
| 123 | /* 19 */ QUICK_RADIO (4, OPT_DLG_W, 4, OPT_DLG_H, 3, wrap_str, &wrap_mode), |
| 124 | /* 20 */ QUICK_LABEL (3, OPT_DLG_W, 3, OPT_DLG_H, N_("Wrap mode")), |
123 | 125 | QUICK_END |
124 | 126 | }; |
125 | 127 | |
diff -rwu '--exclude=Makefile.in' mc-4.8.1/src/setup.c mc-4.8.1-lbr/src/setup.c
old
|
new
|
|
298 | 298 | { "editor_word_wrap_line_length", &option_word_wrap_line_length }, |
299 | 299 | { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces }, |
300 | 300 | { "editor_return_does_auto_indent", &option_return_does_auto_indent }, |
| 301 | { "editor_autodetect_linebreak", &option_autodetect_lb }, |
301 | 302 | { "editor_backspace_through_tabs", &option_backspace_through_tabs }, |
302 | 303 | { "editor_fake_half_tabs", &option_fake_half_tabs }, |
303 | 304 | { "editor_option_save_mode", &option_save_mode }, |
… |
… |
|
1377 | 1378 | } |
1378 | 1379 | |
1379 | 1380 | /* --------------------------------------------------------------------------------------------- */ |
| 1381 | |