]> code.delx.au - gnu-emacs/blobdiff - src/fileio.c
Merge branch 'emacs-25-merge'
[gnu-emacs] / src / fileio.c
index 15bebdf09facc212072d5bd84b316412082113c4..e18ddb1a7aa482a6ee7eafc1cf4442364a0c3a1a 100644 (file)
@@ -43,7 +43,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <c-ctype.h>
 
 #include "lisp.h"
-#include "intervals.h"
+#include "composite.h"
 #include "character.h"
 #include "buffer.h"
 #include "coding.h"
@@ -51,7 +51,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "blockinput.h"
 #include "region-cache.h"
 #include "frame.h"
-#include "dispextern.h"
 
 #ifdef WINDOWSNT
 #define NOMINMAX 1
@@ -451,7 +450,7 @@ DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory,
 A `directly usable' directory name is one that may be used without the
 intervention of any file handler.
 If FILENAME is a directly usable file itself, return
-(file-name-directory FILENAME).
+(file-name-as-directory FILENAME).
 If FILENAME refers to a file which is not accessible from a local process,
 then this should return nil.
 The `call-process' and `start-process' functions use this function to
@@ -470,7 +469,7 @@ get a current directory to run processes in.  */)
       return STRINGP (handled_name) ? handled_name : Qnil;
     }
 
-  return Ffile_name_directory (filename);
+  return Ffile_name_as_directory (filename);
 }
 
 /* Maximum number of bytes that DST will be longer than SRC
@@ -3471,6 +3470,7 @@ by calling `format-decode', which see.  */)
       st.st_size = -1;
       if (!NILP (Vcoding_system_for_read))
        {
+         /* Don't let invalid values into buffer-file-coding-system.  */
          CHECK_CODING_SYSTEM (Vcoding_system_for_read);
          Fset (Qbuffer_file_coding_system, Vcoding_system_for_read);
        }
@@ -4263,9 +4263,14 @@ by calling `format-decode', which see.  */)
       if (CODING_FOR_UNIBYTE (&coding)
          /* Can't do this if part of the buffer might be preserved.  */
          && NILP (replace))
-       /* Visiting a file with these coding system makes the buffer
-          unibyte.  */
-       bset_enable_multibyte_characters (current_buffer, Qnil);
+       {
+         /* Visiting a file with these coding system makes the buffer
+            unibyte.  */
+         if (inserted > 0)
+           bset_enable_multibyte_characters (current_buffer, Qnil);
+         else
+           Fset_buffer_multibyte (Qnil);
+       }
     }
 
   coding.dst_multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
@@ -4529,7 +4534,6 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file
   else if (!NILP (Vcoding_system_for_write))
     {
       val = Vcoding_system_for_write;
-      CHECK_CODING_SYSTEM (val);
       if (coding_system_require_warning
          && !NILP (Ffboundp (Vselect_safe_coding_system_function)))
        /* Confirm that VAL can surely encode the current region.  */
@@ -4573,18 +4577,16 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file
       if (NILP (val))
        {
          /* If we still have not decided a coding system, use the
-            default value of buffer-file-coding-system.  */
+            current buffer's value of buffer-file-coding-system.  */
          val = BVAR (current_buffer, buffer_file_coding_system);
          using_default_coding = 1;
        }
 
-      if (!NILP (val))
-       CHECK_CODING_SYSTEM (val);
-
       if (! NILP (val) && ! force_raw_text)
        {
          Lisp_Object spec, attrs;
 
+         CHECK_CODING_SYSTEM (val);
          CHECK_CODING_SYSTEM_GET_SPEC (val, spec);
          attrs = AREF (spec, 0);
          if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text))
@@ -4597,7 +4599,11 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file
          /* Confirm that VAL can surely encode the current region.  */
          val = call5 (Vselect_safe_coding_system_function,
                       start, end, val, Qnil, filename);
-         CHECK_CODING_SYSTEM (val);
+         /* As the function specified by select-safe-coding-system-function
+            is out of our control, make sure we are not fed by bogus
+            values.  */
+         if (!NILP (val))
+           CHECK_CODING_SYSTEM (val);
        }
 
       /* If the decided coding-system doesn't specify end-of-line
@@ -4608,10 +4614,7 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file
          Lisp_Object dflt = BVAR (&buffer_defaults, buffer_file_coding_system);
 
          if (! NILP (dflt))
-           {
-             CHECK_CODING_SYSTEM (dflt);
-             val = (coding_inherit_eol_type (val, dflt));
-           }
+           val = coding_inherit_eol_type (val, dflt);
        }
 
       /* If we decide not to encode text, use `raw-text' or one of its