aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa1997-05-10 03:37:01 +0000
committerKenichi Handa1997-05-10 03:37:01 +0000
commitcdfb0f1d9b94869b052680bcbee9ef3ffd35397f (patch)
tree161f7460d1007fe84be328481ba2348fd76984a1
parent477f8642b90ddb8dc66132728961d965e39ed5d0 (diff)
downloademacs-cdfb0f1d9b94869b052680bcbee9ef3ffd35397f.tar.gz
emacs-cdfb0f1d9b94869b052680bcbee9ef3ffd35397f.zip
(Fwrite_region): Add 7th optional arg
CODING_SYSTEM. Move gap after a newline code if we are encoding in a coding system which requires designation sequences to be put at beginning of line. Set coding.last_block to 1 before calling a_write for an empty file. (build_annotations): Code tuned up for handling pre_write_conversion of a coding system. (e_write): Delete code for handling carryover of code conversion. It is now handled in encode_coding. (auto_save_1): Supply 7th new arg CODING_SYSTEM as Qnil to Fwrite_region.
-rw-r--r--src/fileio.c116
1 files changed, 60 insertions, 56 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 628179be0bc..f6541062f99 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3746,8 +3746,8 @@ build_annotations_unwind (buf)
3746 return Qnil; 3746 return Qnil;
3747} 3747}
3748 3748
3749DEFUN ("write-region", Fwrite_region, Swrite_region, 3, 6, 3749DEFUN ("write-region", Fwrite_region, Swrite_region, 3, 7,
3750 "r\nFWrite region to file: ", 3750 "r\nFWrite region to file: \ni\ni\ni\nZCoding system: ",
3751 "Write current region into specified file.\n\ 3751 "Write current region into specified file.\n\
3752When called from a program, takes three arguments:\n\ 3752When called from a program, takes three arguments:\n\
3753START, END and FILENAME. START and END are buffer positions.\n\ 3753START, END and FILENAME. START and END are buffer positions.\n\
@@ -3763,13 +3763,17 @@ If VISIT is neither t nor nil nor a string,\n\
3763 that means do not print the \"Wrote file\" message.\n\ 3763 that means do not print the \"Wrote file\" message.\n\
3764The optional sixth arg LOCKNAME, if non-nil, specifies the name to\n\ 3764The optional sixth arg LOCKNAME, if non-nil, specifies the name to\n\
3765 use for locking and unlocking, overriding FILENAME and VISIT.\n\ 3765 use for locking and unlocking, overriding FILENAME and VISIT.\n\
3766The optional seventh arg CODING-SYSTEM, if non-nil, specifies the coding\n\
3767 system to be used for encoding characters. For interactive use,\n\
3768 you can specify it by giving a prefix argument. If no coding system\n\
3769 is specified, the current region is encoded according to the value of\n\
3770 `coding-system-for-write' or `coding-system-alist'. The variable\n\
3771 `last-coding-system-used' is set the coding system actually used.\n\
3766Kludgy feature: if START is a string, then that string is written\n\ 3772Kludgy feature: if START is a string, then that string is written\n\
3767to the file, instead of any buffer contents, and END is ignored.\n\ 3773to the file, instead of any buffer contents, and END is ignored.")
3768This does code conversion according to the value of\n\ 3774 (start, end, filename, append, visit, lockname, coding_system_symbol)
3769 `coding-system-for-write' or `coding-system-alist', and sets the variable\n\
3770 `last-coding-system-used' to the coding system actually used.")
3771 (start, end, filename, append, visit, lockname)
3772 Lisp_Object start, end, filename, append, visit, lockname; 3775 Lisp_Object start, end, filename, append, visit, lockname;
3776 Lisp_Object coding_system_symbol;
3773{ 3777{
3774 register int desc; 3778 register int desc;
3775 int failure; 3779 int failure;
@@ -3800,7 +3804,42 @@ This does code conversion according to the value of\n\
3800 if (!NILP (start) && !STRINGP (start)) 3804 if (!NILP (start) && !STRINGP (start))
3801 validate_region (&start, &end); 3805 validate_region (&start, &end);
3802 3806
3803 GCPRO4 (start, filename, visit, lockname); 3807 GCPRO5 (start, filename, visit, lockname, coding_system_symbol);
3808
3809 /* Decide the coding-system to be encoded to. */
3810 {
3811 Lisp_Object val;
3812
3813 if (auto_saving || NILP (current_buffer->enable_multibyte_characters))
3814 val = Qnil;
3815 else if (!NILP (coding_system_symbol))
3816 val = coding_system_symbol;
3817 else if (!NILP (Vcoding_system_for_write))
3818 val = Vcoding_system_for_write;
3819 else if (!NILP (Flocal_variable_if_set_p (Qbuffer_file_coding_system,
3820 Qnil)))
3821 val = Fsymbol_value (Qbuffer_file_coding_system);
3822 else
3823 {
3824 Lisp_Object args[7], coding_systems;
3825
3826 args[0] = Qwrite_region, args[1] = start, args[2] = end,
3827 args[3] = filename, args[4] = append, args[5] = visit,
3828 args[6] = lockname;
3829 coding_systems = Ffind_coding_system (7, args);
3830 val = (CONSP (coding_systems)
3831 ? XCONS (coding_systems)->cdr
3832 : Fsymbol_value (Qbuffer_file_coding_system));
3833 }
3834 setup_coding_system (Fcheck_coding_system (val), &coding);
3835 if (!STRINGP (start) && !NILP (current_buffer->selective_display))
3836 coding.selective = 1;
3837#ifdef DOS_NT
3838 if (!NILP (current_buffer->buffer_file_type))
3839 coding.eol_type = CODING_EOL_LF;
3840#endif /* DOS_NT */
3841 }
3842
3804 filename = Fexpand_file_name (filename, Qnil); 3843 filename = Fexpand_file_name (filename, Qnil);
3805 if (STRINGP (visit)) 3844 if (STRINGP (visit))
3806 visit_file = Fexpand_file_name (visit, Qnil); 3845 visit_file = Fexpand_file_name (visit, Qnil);
@@ -3841,38 +3880,6 @@ This does code conversion according to the value of\n\
3841 return val; 3880 return val;
3842 } 3881 }
3843 3882
3844 /* Decide the coding-system to be encoded to. */
3845 {
3846 Lisp_Object val;
3847
3848 if (auto_saving || NILP (current_buffer->enable_multibyte_characters))
3849 val = Qnil;
3850 else if (!NILP (Vcoding_system_for_write))
3851 val = Vcoding_system_for_write;
3852 else if (!NILP (Flocal_variable_if_set_p (Qbuffer_file_coding_system,
3853 Qnil)))
3854 val = Fsymbol_value (Qbuffer_file_coding_system);
3855 else
3856 {
3857 Lisp_Object args[7], coding_systems;
3858
3859 args[0] = Qwrite_region, args[1] = start, args[2] = end,
3860 args[3] = filename, args[4] = append, args[5] = visit,
3861 args[6] = lockname;
3862 coding_systems = Ffind_coding_system (7, args);
3863 val = (CONSP (coding_systems)
3864 ? XCONS (coding_systems)->cdr
3865 : Fsymbol_value (Qbuffer_file_coding_system));
3866 }
3867 setup_coding_system (Fcheck_coding_system (val), &coding);
3868 if (!STRINGP (start) && !NILP (current_buffer->selective_display))
3869 coding.selective = 1;
3870#ifdef DOS_NT
3871 if (!NILP (current_buffer->buffer_file_type))
3872 coding.eol_type = CODING_EOL_LF;
3873#endif /* DOS_NT */
3874 }
3875
3876 /* Special kludge to simplify auto-saving. */ 3883 /* Special kludge to simplify auto-saving. */
3877 if (NILP (start)) 3884 if (NILP (start))
3878 { 3885 {
@@ -4009,6 +4016,14 @@ This does code conversion according to the value of\n\
4009 */ 4016 */
4010 if (GPT > BEG && GPT_ADDR[-1] != '\n') 4017 if (GPT > BEG && GPT_ADDR[-1] != '\n')
4011 move_gap (find_next_newline (GPT, 1)); 4018 move_gap (find_next_newline (GPT, 1));
4019#else
4020 /* Whether VMS or not, we must move the gap to the next of newline
4021 when we must put designation sequences at beginning of line. */
4022 if (INTEGERP (start)
4023 && coding.type == coding_type_iso2022
4024 && coding.flags & CODING_FLAG_ISO_DESIGNATE_AT_BOL
4025 && GPT > BEG && GPT_ADDR[-1] != '\n')
4026 move_gap (find_next_newline (GPT, 1));
4012#endif 4027#endif
4013 4028
4014 failure = 0; 4029 failure = 0;
@@ -4047,6 +4062,7 @@ This does code conversion according to the value of\n\
4047 else 4062 else
4048 { 4063 {
4049 /* If file was empty, still need to write the annotations */ 4064 /* If file was empty, still need to write the annotations */
4065 coding.last_block = 1;
4050 failure = 0 > a_write (desc, "", 0, XINT (start), &annotations, &coding); 4066 failure = 0 > a_write (desc, "", 0, XINT (start), &annotations, &coding);
4051 save_errno = errno; 4067 save_errno = errno;
4052 } 4068 }
@@ -4227,14 +4243,10 @@ build_annotations (start, end, pre_write_conversion)
4227 struct buffer *given_buffer = current_buffer; 4243 struct buffer *given_buffer = current_buffer;
4228 Vwrite_region_annotations_so_far = annotations; 4244 Vwrite_region_annotations_so_far = annotations;
4229 res = call2 (pre_write_conversion, start, end); 4245 res = call2 (pre_write_conversion, start, end);
4230 if (current_buffer != given_buffer)
4231 {
4232 start = BEGV;
4233 end = ZV;
4234 annotations = Qnil;
4235 }
4236 Flength (res); 4246 Flength (res);
4237 annotations = merge (annotations, res, Qcar_less_than_car); 4247 annotations = (current_buffer != given_buffer
4248 ? res
4249 : merge (annotations, res, Qcar_less_than_car));
4238 } 4250 }
4239 4251
4240 UNGCPRO; 4252 UNGCPRO;
@@ -4309,14 +4321,6 @@ e_write (desc, addr, len, coding)
4309 produced = encode_coding (coding, addr, buf, len, WRITE_BUF_SIZE, 4321 produced = encode_coding (coding, addr, buf, len, WRITE_BUF_SIZE,
4310 &consumed); 4322 &consumed);
4311 len -= consumed, addr += consumed; 4323 len -= consumed, addr += consumed;
4312 if (produced == 0 && len > 0)
4313 {
4314 /* There was a carry over because of invalid codes in the source.
4315 We just write out them as is. */
4316 bcopy (addr, buf, len);
4317 produced = len;
4318 len = 0;
4319 }
4320 if (produced > 0) 4324 if (produced > 0)
4321 { 4325 {
4322 produced -= write (desc, buf, produced); 4326 produced -= write (desc, buf, produced);
@@ -4453,7 +4457,7 @@ auto_save_1 ()
4453 return 4457 return
4454 Fwrite_region (Qnil, Qnil, 4458 Fwrite_region (Qnil, Qnil,
4455 current_buffer->auto_save_file_name, 4459 current_buffer->auto_save_file_name,
4456 Qnil, Qlambda, Qnil); 4460 Qnil, Qlambda, Qnil, Qnil);
4457} 4461}
4458 4462
4459static Lisp_Object 4463static Lisp_Object