diff options
| author | Richard M. Stallman | 1994-02-23 00:33:13 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-02-23 00:33:13 +0000 |
| commit | a1d2b64a3366cd9a5b8fd840bf3de498099cf67b (patch) | |
| tree | 3ed7b14be8060ec7376de8731869eefc3007d9dd /src | |
| parent | 5170c9cbebb94c12aa4f61927736c6b3dfb50019 (diff) | |
| download | emacs-a1d2b64a3366cd9a5b8fd840bf3de498099cf67b.tar.gz emacs-a1d2b64a3366cd9a5b8fd840bf3de498099cf67b.zip | |
(Finsert_file_contents): If REPLACE, always do lseek.
Exit main loop if INSERTED reaches TOTAL.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/fileio.c b/src/fileio.c index acee2e7d73c..b4cec454163 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -154,6 +154,15 @@ close_file_unwind (fd) | |||
| 154 | { | 154 | { |
| 155 | close (XFASTINT (fd)); | 155 | close (XFASTINT (fd)); |
| 156 | } | 156 | } |
| 157 | |||
| 158 | /* Restore point, having saved it as a marker. */ | ||
| 159 | |||
| 160 | restore_point_unwind (location) | ||
| 161 | Lisp_Object location; | ||
| 162 | { | ||
| 163 | SET_PT (marker_position (location)); | ||
| 164 | Fset_marker (location, Qnil, Qnil); | ||
| 165 | } | ||
| 157 | 166 | ||
| 158 | Lisp_Object Qexpand_file_name; | 167 | Lisp_Object Qexpand_file_name; |
| 159 | Lisp_Object Qdirectory_file_name; | 168 | Lisp_Object Qdirectory_file_name; |
| @@ -2551,6 +2560,10 @@ and (2) it puts less data in the undo list.") | |||
| 2551 | goto notfound; | 2560 | goto notfound; |
| 2552 | } | 2561 | } |
| 2553 | 2562 | ||
| 2563 | /* Replacement should preserve point as it preserves markers. */ | ||
| 2564 | if (!NILP (replace)) | ||
| 2565 | record_unwind_protect (restore_point_unwind, Fpoint_marker ()); | ||
| 2566 | |||
| 2554 | record_unwind_protect (close_file_unwind, make_number (fd)); | 2567 | record_unwind_protect (close_file_unwind, make_number (fd)); |
| 2555 | 2568 | ||
| 2556 | #ifdef S_IFSOCK | 2569 | #ifdef S_IFSOCK |
| @@ -2623,7 +2636,7 @@ and (2) it puts less data in the undo list.") | |||
| 2623 | if (same_at_start == ZV) | 2636 | if (same_at_start == ZV) |
| 2624 | { | 2637 | { |
| 2625 | close (fd); | 2638 | close (fd); |
| 2626 | specpdl_ptr = specpdl + count; | 2639 | specpdl_ptr--; |
| 2627 | goto handled; | 2640 | goto handled; |
| 2628 | } | 2641 | } |
| 2629 | immediate_quit = 1; | 2642 | immediate_quit = 1; |
| @@ -2670,6 +2683,8 @@ and (2) it puts less data in the undo list.") | |||
| 2670 | XFASTINT (end) = st.st_size - (ZV - same_at_end); | 2683 | XFASTINT (end) = st.st_size - (ZV - same_at_end); |
| 2671 | /* Delete the nonmatching middle part of the buffer. */ | 2684 | /* Delete the nonmatching middle part of the buffer. */ |
| 2672 | Fdelete_region (make_number (same_at_start), make_number (same_at_end)); | 2685 | Fdelete_region (make_number (same_at_start), make_number (same_at_end)); |
| 2686 | /* Insert from the file at the proper position. */ | ||
| 2687 | SET_PT (same_at_start); | ||
| 2673 | } | 2688 | } |
| 2674 | 2689 | ||
| 2675 | total = XINT (end) - XINT (beg); | 2690 | total = XINT (end) - XINT (beg); |
| @@ -2690,13 +2705,14 @@ and (2) it puts less data in the undo list.") | |||
| 2690 | if (GAP_SIZE < total) | 2705 | if (GAP_SIZE < total) |
| 2691 | make_gap (total - GAP_SIZE); | 2706 | make_gap (total - GAP_SIZE); |
| 2692 | 2707 | ||
| 2693 | if (XINT (beg) != 0) | 2708 | if (XINT (beg) != 0 || !NILP (replace)) |
| 2694 | { | 2709 | { |
| 2695 | if (lseek (fd, XINT (beg), 0) < 0) | 2710 | if (lseek (fd, XINT (beg), 0) < 0) |
| 2696 | report_file_error ("Setting file position", Fcons (filename, Qnil)); | 2711 | report_file_error ("Setting file position", Fcons (filename, Qnil)); |
| 2697 | } | 2712 | } |
| 2698 | 2713 | ||
| 2699 | while (1) | 2714 | how_much = 0; |
| 2715 | while (inserted < total) | ||
| 2700 | { | 2716 | { |
| 2701 | int try = min (total - inserted, 64 << 10); | 2717 | int try = min (total - inserted, 64 << 10); |
| 2702 | int this; | 2718 | int this; |
| @@ -2734,8 +2750,8 @@ and (2) it puts less data in the undo list.") | |||
| 2734 | XFASTINT (current_buffer->buffer_file_type) = XFASTINT (code); | 2750 | XFASTINT (current_buffer->buffer_file_type) = XFASTINT (code); |
| 2735 | if (XFASTINT (current_buffer->buffer_file_type) == 0) | 2751 | if (XFASTINT (current_buffer->buffer_file_type) == 0) |
| 2736 | { | 2752 | { |
| 2737 | int reduced_size = | 2753 | int reduced_size |
| 2738 | inserted - crlf_to_lf (inserted, &FETCH_CHAR (point - 1) + 1); | 2754 | = inserted - crlf_to_lf (inserted, &FETCH_CHAR (point - 1) + 1); |
| 2739 | ZV -= reduced_size; | 2755 | ZV -= reduced_size; |
| 2740 | Z -= reduced_size; | 2756 | Z -= reduced_size; |
| 2741 | GPT -= reduced_size; | 2757 | GPT -= reduced_size; |
| @@ -2756,8 +2772,8 @@ and (2) it puts less data in the undo list.") | |||
| 2756 | 2772 | ||
| 2757 | close (fd); | 2773 | close (fd); |
| 2758 | 2774 | ||
| 2759 | /* Discard the unwind protect */ | 2775 | /* Discard the unwind protect for closing the file. */ |
| 2760 | specpdl_ptr = specpdl + count; | 2776 | specpdl_ptr--; |
| 2761 | 2777 | ||
| 2762 | if (how_much < 0) | 2778 | if (how_much < 0) |
| 2763 | error ("IO error reading %s: %s", | 2779 | error ("IO error reading %s: %s", |
| @@ -2814,11 +2830,12 @@ and (2) it puts less data in the undo list.") | |||
| 2814 | } | 2830 | } |
| 2815 | } | 2831 | } |
| 2816 | 2832 | ||
| 2817 | if (!NILP (val)) | 2833 | if (NILP (val)) |
| 2818 | RETURN_UNGCPRO (val); | 2834 | val = Fcons (filename, |
| 2819 | RETURN_UNGCPRO (Fcons (filename, | 2835 | Fcons (make_number (inserted), |
| 2820 | Fcons (make_number (inserted), | 2836 | Qnil)); |
| 2821 | Qnil))); | 2837 | |
| 2838 | RETURN_UNGCPRO (unbind_to (count, val)); | ||
| 2822 | } | 2839 | } |
| 2823 | 2840 | ||
| 2824 | static Lisp_Object build_annotations (); | 2841 | static Lisp_Object build_annotations (); |