diff options
| author | Gerd Moellmann | 2001-07-11 12:04:09 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2001-07-11 12:04:09 +0000 |
| commit | 55587f8a5c6a4588946e13fc70db006d2bdaf51a (patch) | |
| tree | 7da9cbfedc97ad5e2fe4da37721adb7510e0a44e /src | |
| parent | 0b725d8cbd58f8b27dc808c9310c441a7fa6bcfd (diff) | |
| download | emacs-55587f8a5c6a4588946e13fc70db006d2bdaf51a.tar.gz emacs-55587f8a5c6a4588946e13fc70db006d2bdaf51a.zip | |
(unwind_read): New function.
(Finsert_file_contents): Record it as unwind-function for
the case that reading is interrupted by C-g.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/fileio.c b/src/fileio.c index 9987cbfd343..becdc9ce008 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -3418,6 +3418,53 @@ decide_coding_unwind (unwind_data) | |||
| 3418 | return Qnil; | 3418 | return Qnil; |
| 3419 | } | 3419 | } |
| 3420 | 3420 | ||
| 3421 | |||
| 3422 | /* Unwind-function for reading from a file in insert-file-contents. | ||
| 3423 | |||
| 3424 | INFO is a pair (INSERTED-BYTES . VISIT). INSERTED-BYTES is the | ||
| 3425 | number of bytes successfully inserted into current_buffer. VISIT | ||
| 3426 | is the same as the parameter VISIT Of insert-file-contents. | ||
| 3427 | |||
| 3428 | When reading is interrupted by C-g, this leaves the newly read part | ||
| 3429 | of the current buffer undecoded. If this happens in a multibyte | ||
| 3430 | buffer, prevent invalid characters by either discarding what has | ||
| 3431 | been read or switching the buffer to unibyte. | ||
| 3432 | |||
| 3433 | PT GPT | ||
| 3434 | +-----------------------------------------------------+ | ||
| 3435 | | | inserted bytes | GAP_SIZE | | | ||
| 3436 | +-----------------------------------------------------+ | ||
| 3437 | \ / | ||
| 3438 | +--------- the gap ---------+ */ | ||
| 3439 | |||
| 3440 | static Lisp_Object | ||
| 3441 | unwind_read (info) | ||
| 3442 | Lisp_Object info; | ||
| 3443 | { | ||
| 3444 | if (!NILP (current_buffer->enable_multibyte_characters)) | ||
| 3445 | { | ||
| 3446 | int nbytes = XINT (XCAR (info)); | ||
| 3447 | int visit = !NILP (XCDR (info)); | ||
| 3448 | |||
| 3449 | if (visit || Z == nbytes) | ||
| 3450 | current_buffer->enable_multibyte_characters = Qnil; | ||
| 3451 | else | ||
| 3452 | { | ||
| 3453 | ZV -= nbytes; | ||
| 3454 | ZV_BYTE -= nbytes; | ||
| 3455 | Z -= nbytes; | ||
| 3456 | Z_BYTE -= nbytes; | ||
| 3457 | |||
| 3458 | GPT = PT; | ||
| 3459 | GPT_BYTE = PT_BYTE; | ||
| 3460 | GAP_SIZE = nbytes + GAP_SIZE; | ||
| 3461 | } | ||
| 3462 | } | ||
| 3463 | |||
| 3464 | return Qnil; | ||
| 3465 | } | ||
| 3466 | |||
| 3467 | |||
| 3421 | DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, | 3468 | DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, |
| 3422 | 1, 5, 0, | 3469 | 1, 5, 0, |
| 3423 | "Insert contents of file FILENAME after point.\n\ | 3470 | "Insert contents of file FILENAME after point.\n\ |
| @@ -4131,17 +4178,22 @@ actually used.") | |||
| 4131 | /* try is reserved in some compilers (Microsoft C) */ | 4178 | /* try is reserved in some compilers (Microsoft C) */ |
| 4132 | int trytry = min (total - how_much, READ_BUF_SIZE); | 4179 | int trytry = min (total - how_much, READ_BUF_SIZE); |
| 4133 | int this; | 4180 | int this; |
| 4181 | int count = BINDING_STACK_SIZE (); | ||
| 4134 | 4182 | ||
| 4135 | /* For a special file, GAP_SIZE should be checked every time. */ | 4183 | /* For a special file, GAP_SIZE should be checked every time. */ |
| 4136 | if (not_regular && GAP_SIZE < trytry) | 4184 | if (not_regular && GAP_SIZE < trytry) |
| 4137 | make_gap (total - GAP_SIZE); | 4185 | make_gap (total - GAP_SIZE); |
| 4138 | 4186 | ||
| 4139 | /* Allow quitting out of the actual I/O. */ | 4187 | /* Allow quitting out of the actual I/O. If we do, |
| 4188 | remove 's */ | ||
| 4189 | record_unwind_protect (unwind_read, | ||
| 4190 | Fcons (make_number (inserted), visit)); | ||
| 4140 | immediate_quit = 1; | 4191 | immediate_quit = 1; |
| 4141 | QUIT; | 4192 | QUIT; |
| 4142 | this = emacs_read (fd, BYTE_POS_ADDR (PT_BYTE + inserted - 1) + 1, | 4193 | this = emacs_read (fd, BYTE_POS_ADDR (PT_BYTE + inserted - 1) + 1, |
| 4143 | trytry); | 4194 | trytry); |
| 4144 | immediate_quit = 0; | 4195 | immediate_quit = 0; |
| 4196 | --specpdl_ptr; | ||
| 4145 | 4197 | ||
| 4146 | if (this <= 0) | 4198 | if (this <= 0) |
| 4147 | { | 4199 | { |