diff options
| author | Richard M. Stallman | 1996-12-16 05:46:37 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-12-16 05:46:37 +0000 |
| commit | 4d2a0879ff9931b65cde2edd8e1b18f56fc3fa30 (patch) | |
| tree | dc5ed0011fddcdcc0aa460f5f15ade494765d361 | |
| parent | ddbe99e0399865cf539947533f4176e81be17b5d (diff) | |
| download | emacs-4d2a0879ff9931b65cde2edd8e1b18f56fc3fa30.tar.gz emacs-4d2a0879ff9931b65cde2edd8e1b18f56fc3fa30.zip | |
(Finsert_file_contents): Handle BEG and END non-nil
when REPLACE is non-nil.
| -rw-r--r-- | src/fileio.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/fileio.c b/src/fileio.c index 20419fe394a..9b09b0e32c0 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -3117,8 +3117,6 @@ and (2) it puts less data in the undo list.") | |||
| 3117 | if (!NILP (replace)) | 3117 | if (!NILP (replace)) |
| 3118 | { | 3118 | { |
| 3119 | replace = Qnil; | 3119 | replace = Qnil; |
| 3120 | XSETFASTINT (beg, 0); | ||
| 3121 | XSETFASTINT (end, st.st_size); | ||
| 3122 | del_range_1 (BEGV, ZV, 0); | 3120 | del_range_1 (BEGV, ZV, 0); |
| 3123 | } | 3121 | } |
| 3124 | #else /* not DOS_NT */ | 3122 | #else /* not DOS_NT */ |
| @@ -3129,6 +3127,13 @@ and (2) it puts less data in the undo list.") | |||
| 3129 | int same_at_end = ZV; | 3127 | int same_at_end = ZV; |
| 3130 | int overlap; | 3128 | int overlap; |
| 3131 | 3129 | ||
| 3130 | if (XINT (beg) != 0) | ||
| 3131 | { | ||
| 3132 | if (lseek (fd, XINT (beg), 0) < 0) | ||
| 3133 | report_file_error ("Setting file position", | ||
| 3134 | Fcons (filename, Qnil)); | ||
| 3135 | } | ||
| 3136 | |||
| 3132 | immediate_quit = 1; | 3137 | immediate_quit = 1; |
| 3133 | QUIT; | 3138 | QUIT; |
| 3134 | /* Count how many chars at the start of the file | 3139 | /* Count how many chars at the start of the file |
| @@ -3155,7 +3160,7 @@ and (2) it puts less data in the undo list.") | |||
| 3155 | immediate_quit = 0; | 3160 | immediate_quit = 0; |
| 3156 | /* If the file matches the buffer completely, | 3161 | /* If the file matches the buffer completely, |
| 3157 | there's no need to replace anything. */ | 3162 | there's no need to replace anything. */ |
| 3158 | if (same_at_start - BEGV == st.st_size) | 3163 | if (same_at_start - BEGV == XINT (end)) |
| 3159 | { | 3164 | { |
| 3160 | close (fd); | 3165 | close (fd); |
| 3161 | specpdl_ptr--; | 3166 | specpdl_ptr--; |
| @@ -3172,7 +3177,7 @@ and (2) it puts less data in the undo list.") | |||
| 3172 | int total_read, nread, bufpos, curpos, trial; | 3177 | int total_read, nread, bufpos, curpos, trial; |
| 3173 | 3178 | ||
| 3174 | /* At what file position are we now scanning? */ | 3179 | /* At what file position are we now scanning? */ |
| 3175 | curpos = st.st_size - (ZV - same_at_end); | 3180 | curpos = XINT (end) - (ZV - same_at_end); |
| 3176 | /* If the entire file matches the buffer tail, stop the scan. */ | 3181 | /* If the entire file matches the buffer tail, stop the scan. */ |
| 3177 | if (curpos == 0) | 3182 | if (curpos == 0) |
| 3178 | break; | 3183 | break; |
| @@ -3216,8 +3221,8 @@ and (2) it puts less data in the undo list.") | |||
| 3216 | same_at_end += overlap; | 3221 | same_at_end += overlap; |
| 3217 | 3222 | ||
| 3218 | /* Arrange to read only the nonmatching middle part of the file. */ | 3223 | /* Arrange to read only the nonmatching middle part of the file. */ |
| 3219 | XSETFASTINT (beg, same_at_start - BEGV); | 3224 | XSETFASTINT (beg, XINT (beg) + (same_at_start - BEGV)); |
| 3220 | XSETFASTINT (end, st.st_size - (ZV - same_at_end)); | 3225 | XSETFASTINT (end, XINT (end) - (ZV - same_at_end)); |
| 3221 | 3226 | ||
| 3222 | del_range_1 (same_at_start, same_at_end, 0); | 3227 | del_range_1 (same_at_start, same_at_end, 0); |
| 3223 | /* Insert from the file at the proper position. */ | 3228 | /* Insert from the file at the proper position. */ |