/[emacs]/emacs/src/fileio.c
ViewVC logotype

Diff of /emacs/src/fileio.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.424 by rms, Wed Nov 14 00:09:27 2001 UTC revision 1.425 by monnier, Fri Nov 16 14:49:20 2001 UTC
# Line 4535  build_annotations_unwind (buf) Line 4535  build_annotations_unwind (buf)
4535    return Qnil;    return Qnil;
4536  }  }
4537    
4538    /* Decide the coding-system to encode the data with.  */
4539    
4540    void
4541    choose_write_coding_system (start, end, filename,
4542                                append, visit, lockname, coding)
4543         Lisp_Object start, end, filename, append, visit, lockname;
4544         struct coding_system *coding;
4545    {
4546      Lisp_Object val;
4547    
4548      if (auto_saving)
4549        val = Qnil;
4550      else if (!NILP (Vcoding_system_for_write))
4551        val = Vcoding_system_for_write;
4552      else
4553        {
4554          /* If the variable `buffer-file-coding-system' is set locally,
4555             it means that the file was read with some kind of code
4556             conversion or the variable is explicitly set by users.  We
4557             had better write it out with the same coding system even if
4558             `enable-multibyte-characters' is nil.
4559    
4560             If it is not set locally, we anyway have to convert EOL
4561             format if the default value of `buffer-file-coding-system'
4562             tells that it is not Unix-like (LF only) format.  */
4563          int using_default_coding = 0;
4564          int force_raw_text = 0;
4565    
4566          val = current_buffer->buffer_file_coding_system;
4567          if (NILP (val)
4568              || NILP (Flocal_variable_p (Qbuffer_file_coding_system, Qnil)))
4569            {
4570              val = Qnil;
4571              if (NILP (current_buffer->enable_multibyte_characters))
4572                force_raw_text = 1;
4573            }
4574            
4575          if (NILP (val))
4576            {
4577              /* Check file-coding-system-alist.  */
4578              Lisp_Object args[7], coding_systems;
4579    
4580              args[0] = Qwrite_region; args[1] = start; args[2] = end;
4581              args[3] = filename; args[4] = append; args[5] = visit;
4582              args[6] = lockname;
4583              coding_systems = Ffind_operation_coding_system (7, args);
4584              if (CONSP (coding_systems) && !NILP (XCDR (coding_systems)))
4585                val = XCDR (coding_systems);
4586            }
4587    
4588          if (NILP (val)
4589              && !NILP (current_buffer->buffer_file_coding_system))
4590            {
4591              /* If we still have not decided a coding system, use the
4592                 default value of buffer-file-coding-system.  */
4593              val = current_buffer->buffer_file_coding_system;
4594              using_default_coding = 1;
4595            }
4596                
4597          if (!force_raw_text
4598              && !NILP (Ffboundp (Vselect_safe_coding_system_function)))
4599            /* Confirm that VAL can surely encode the current region.  */
4600            val = call3 (Vselect_safe_coding_system_function, start, end, val);
4601    
4602          setup_coding_system (Fcheck_coding_system (val), coding);
4603          if (coding->eol_type == CODING_EOL_UNDECIDED
4604              && !using_default_coding)
4605            {
4606              if (! EQ (default_buffer_file_coding.symbol,
4607                        buffer_defaults.buffer_file_coding_system))
4608                setup_coding_system (buffer_defaults.buffer_file_coding_system,
4609                                     &default_buffer_file_coding);
4610              if (default_buffer_file_coding.eol_type != CODING_EOL_UNDECIDED)
4611                {
4612                  Lisp_Object subsidiaries;
4613    
4614                  coding->eol_type = default_buffer_file_coding.eol_type;
4615                  subsidiaries = Fget (coding->symbol, Qeol_type);
4616                  if (VECTORP (subsidiaries)
4617                      && XVECTOR (subsidiaries)->size == 3)
4618                    coding->symbol
4619                      = XVECTOR (subsidiaries)->contents[coding->eol_type];
4620                }
4621            }
4622    
4623          if (force_raw_text)
4624            setup_raw_text_coding_system (coding);
4625          goto done_setup_coding;
4626        }
4627    
4628      setup_coding_system (Fcheck_coding_system (val), coding);
4629    
4630     done_setup_coding:
4631      if (!STRINGP (start) && !NILP (current_buffer->selective_display))
4632        coding->mode |= CODING_MODE_SELECTIVE_DISPLAY;
4633    }
4634    
4635  DEFUN ("write-region", Fwrite_region, Swrite_region, 3, 7,  DEFUN ("write-region", Fwrite_region, Swrite_region, 3, 7,
4636         "r\nFWrite region to file: \ni\ni\ni\np",         "r\nFWrite region to file: \ni\ni\ni\np",
4637         doc: /* Write current region into specified file.         doc: /* Write current region into specified file.
# Line 4582  This does code conversion according to t Line 4679  This does code conversion according to t
4679  #endif /* VMS */  #endif /* VMS */
4680    Lisp_Object handler;    Lisp_Object handler;
4681    Lisp_Object visit_file;    Lisp_Object visit_file;
4682    Lisp_Object annotations;    Lisp_Object annotations = Qnil;
4683    Lisp_Object encoded_filename;    Lisp_Object encoded_filename;
4684    int visiting = (EQ (visit, Qt) || STRINGP (visit));    int visiting = (EQ (visit, Qt) || STRINGP (visit));
4685    int quietly = !NILP (visit);    int quietly = !NILP (visit);
# Line 4602  This does code conversion according to t Line 4699  This does code conversion according to t
4699    GCPRO4 (start, filename, visit, lockname);    GCPRO4 (start, filename, visit, lockname);
4700    
4701    /* Decide the coding-system to encode the data with.  */    /* Decide the coding-system to encode the data with.  */
4702    {    choose_write_coding_system (start, end, filename,
4703      Lisp_Object val;                                append, visit, lockname, &coding);
   
     if (auto_saving)  
       val = Qnil;  
     else if (!NILP (Vcoding_system_for_write))  
       val = Vcoding_system_for_write;  
     else  
       {  
         /* If the variable `buffer-file-coding-system' is set locally,  
            it means that the file was read with some kind of code  
            conversion or the variable is explicitly set by users.  We  
            had better write it out with the same coding system even if  
            `enable-multibyte-characters' is nil.  
   
            If it is not set locally, we anyway have to convert EOL  
            format if the default value of `buffer-file-coding-system'  
            tells that it is not Unix-like (LF only) format.  */  
         int using_default_coding = 0;  
         int force_raw_text = 0;  
   
         val = current_buffer->buffer_file_coding_system;  
         if (NILP (val)  
             || NILP (Flocal_variable_p (Qbuffer_file_coding_system, Qnil)))  
           {  
             val = Qnil;  
             if (NILP (current_buffer->enable_multibyte_characters))  
               force_raw_text = 1;  
           }  
           
         if (NILP (val))  
           {  
             /* Check file-coding-system-alist.  */  
             Lisp_Object args[7], coding_systems;  
   
             args[0] = Qwrite_region; args[1] = start; args[2] = end;  
             args[3] = filename; args[4] = append; args[5] = visit;  
             args[6] = lockname;  
             coding_systems = Ffind_operation_coding_system (7, args);  
             if (CONSP (coding_systems) && !NILP (XCDR (coding_systems)))  
               val = XCDR (coding_systems);  
           }  
   
         if (NILP (val)  
             && !NILP (current_buffer->buffer_file_coding_system))  
           {  
             /* If we still have not decided a coding system, use the  
                default value of buffer-file-coding-system.  */  
             val = current_buffer->buffer_file_coding_system;  
             using_default_coding = 1;  
           }  
               
         if (!force_raw_text  
             && !NILP (Ffboundp (Vselect_safe_coding_system_function)))  
           /* Confirm that VAL can surely encode the current region.  */  
           val = call3 (Vselect_safe_coding_system_function, start, end, val);  
   
         setup_coding_system (Fcheck_coding_system (val), &coding);  
         if (coding.eol_type == CODING_EOL_UNDECIDED  
             && !using_default_coding)  
           {  
             if (! EQ (default_buffer_file_coding.symbol,  
                       buffer_defaults.buffer_file_coding_system))  
               setup_coding_system (buffer_defaults.buffer_file_coding_system,  
                                    &default_buffer_file_coding);  
             if (default_buffer_file_coding.eol_type != CODING_EOL_UNDECIDED)  
               {  
                 Lisp_Object subsidiaries;  
   
                 coding.eol_type = default_buffer_file_coding.eol_type;  
                 subsidiaries = Fget (coding.symbol, Qeol_type);  
                 if (VECTORP (subsidiaries)  
                     && XVECTOR (subsidiaries)->size == 3)  
                   coding.symbol  
                     = XVECTOR (subsidiaries)->contents[coding.eol_type];  
               }  
           }  
   
         if (force_raw_text)  
           setup_raw_text_coding_system (&coding);  
         goto done_setup_coding;  
       }  
   
     setup_coding_system (Fcheck_coding_system (val), &coding);  
   
   done_setup_coding:  
     if (!STRINGP (start) && !NILP (current_buffer->selective_display))  
       coding.mode |= CODING_MODE_SELECTIVE_DISPLAY;  
   }  
   
4704    Vlast_coding_system_used = coding.symbol;    Vlast_coding_system_used = coding.symbol;
4705    
4706    filename = Fexpand_file_name (filename, Qnil);    filename = Fexpand_file_name (filename, Qnil);

Legend:
Removed from v.1.424  
changed lines
  Added in v.1.425

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26