Mercurial > emacs
comparison src/fileio.c @ 38367:bcff6c46ee05
(unwind_read): Print a message when discarding inserted
text or switching the buffer to unibyte. Change parameter.
(Finsert_file_contents): Don't pass VISIT to unwind_read.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Wed, 11 Jul 2001 15:42:07 +0000 |
parents | cb65022a3abb |
children | 8416a4627a13 |
comparison
equal
deleted
inserted
replaced
38366:cb65022a3abb | 38367:bcff6c46ee05 |
---|---|
3419 } | 3419 } |
3420 | 3420 |
3421 | 3421 |
3422 /* Unwind-function for reading from a file in insert-file-contents. | 3422 /* Unwind-function for reading from a file in insert-file-contents. |
3423 | 3423 |
3424 INFO is a pair (INSERTED-BYTES . VISIT). INSERTED-BYTES is the | 3424 INSERTED_BYTES is the number of bytes successfully inserted into |
3425 number of bytes successfully inserted into current_buffer. VISIT | 3425 current_buffer. |
3426 is the same as the parameter VISIT Of insert-file-contents. | |
3427 | 3426 |
3428 When reading is interrupted by C-g, this leaves the newly read part | 3427 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 | 3428 of the current buffer undecoded. If this happens in a multibyte |
3430 buffer, prevent invalid characters by either discarding what has | 3429 buffer, prevent invalid characters by either discarding what has |
3431 been read or switching the buffer to unibyte. | 3430 been read or switching the buffer to unibyte. |
3436 +-----------------------------------------------------+ | 3435 +-----------------------------------------------------+ |
3437 \ / | 3436 \ / |
3438 +--------- the gap ---------+ */ | 3437 +--------- the gap ---------+ */ |
3439 | 3438 |
3440 static Lisp_Object | 3439 static Lisp_Object |
3441 unwind_read (info) | 3440 unwind_read (inserted_bytes) |
3442 Lisp_Object info; | 3441 Lisp_Object inserted_bytes; |
3443 { | 3442 { |
3444 if (!NILP (current_buffer->enable_multibyte_characters)) | 3443 if (!NILP (current_buffer->enable_multibyte_characters)) |
3445 { | 3444 { |
3446 int nbytes = XINT (XCAR (info)); | 3445 int nbytes = XINT (inserted_bytes); |
3447 int visit = !NILP (XCDR (info)); | 3446 Lisp_Object args[3]; |
3448 | 3447 char *action; |
3449 if (visit || Z == nbytes) | 3448 |
3450 current_buffer->enable_multibyte_characters = Qnil; | 3449 if (Z == nbytes) |
3450 { | |
3451 /* Buffer was previously empty. Switch it to unibyte | |
3452 because newly inserted text is not decoded. */ | |
3453 current_buffer->enable_multibyte_characters = Qnil; | |
3454 action = "buffer made unibyte"; | |
3455 } | |
3451 else | 3456 else |
3452 { | 3457 { |
3453 ZV -= nbytes; | 3458 ZV -= nbytes; |
3454 ZV_BYTE -= nbytes; | 3459 ZV_BYTE -= nbytes; |
3455 Z -= nbytes; | 3460 Z -= nbytes; |
3456 Z_BYTE -= nbytes; | 3461 Z_BYTE -= nbytes; |
3457 | 3462 |
3458 GPT = PT; | 3463 GPT = PT; |
3459 GPT_BYTE = PT_BYTE; | 3464 GPT_BYTE = PT_BYTE; |
3460 GAP_SIZE = nbytes + GAP_SIZE; | 3465 GAP_SIZE = nbytes + GAP_SIZE; |
3461 } | 3466 |
3467 action = "no text inserted"; | |
3468 } | |
3469 | |
3470 | |
3471 args[0] = build_string ("Quit while inserting text in buffer `%s': %s"); | |
3472 args[1] = current_buffer->name; | |
3473 args[2] = build_string (action); | |
3474 Fmessage (3, args); | |
3462 } | 3475 } |
3463 | 3476 |
3464 return Qnil; | 3477 return Qnil; |
3465 } | 3478 } |
3466 | 3479 |
4185 make_gap (total - GAP_SIZE); | 4198 make_gap (total - GAP_SIZE); |
4186 | 4199 |
4187 /* Allow quitting out of the actual I/O. If a C-g interrupts | 4200 /* Allow quitting out of the actual I/O. If a C-g interrupts |
4188 this, make sure that no invalid characters remain | 4201 this, make sure that no invalid characters remain |
4189 in the undecoded part read. */ | 4202 in the undecoded part read. */ |
4190 record_unwind_protect (unwind_read, | 4203 record_unwind_protect (unwind_read, make_number (inserted)); |
4191 Fcons (make_number (inserted), visit)); | |
4192 immediate_quit = 1; | 4204 immediate_quit = 1; |
4193 QUIT; | 4205 QUIT; |
4194 this = emacs_read (fd, BYTE_POS_ADDR (PT_BYTE + inserted - 1) + 1, | 4206 this = emacs_read (fd, BYTE_POS_ADDR (PT_BYTE + inserted - 1) + 1, |
4195 trytry); | 4207 trytry); |
4196 immediate_quit = 0; | 4208 immediate_quit = 0; |