diff src/coding.c @ 83353:532e0a9335a9

Merged in changes from CVS trunk. Plus added lisp/term tweaks. Patches applied: * lorentey@elte.hu--2004/emacs--cvs-trunk--0--base-0 tag of miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-474 * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-1 Add CVS metadata files. * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-2 Update from CVS. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-393
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 04 Sep 2005 03:48:17 +0000
parents 9216636c02fc a0d1312ede66
children d84f940244dc
line wrap: on
line diff
--- a/src/coding.c	Thu Aug 25 12:03:34 2005 +0000
+++ b/src/coding.c	Sun Sep 04 03:48:17 2005 +0000
@@ -1,7 +1,7 @@
 /* Coding system handler (conversion, detection, and etc).
    Copyright (C) 1995,97,1998,2002,2003  Electrotechnical Laboratory, JAPAN.
    Licensed to the Free Software Foundation.
-   Copyright (C) 2001,2002,2003  Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -365,7 +365,7 @@
 Lisp_Object Qvalid_codes;
 
 extern Lisp_Object Qinsert_file_contents, Qwrite_region;
-Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
+Lisp_Object Qcall_process, Qcall_process_region;
 Lisp_Object Qstart_process, Qopen_network_stream;
 Lisp_Object Qtarget_idx;
 
@@ -5349,12 +5349,17 @@
       }									\
   } while (0)
 
+/* ARG is (CODING . BUFFER) where CODING is what to be set in
+   Vlast_coding_system_used and BUFFER if non-nil is a buffer to
+   kill.  */
 static Lisp_Object
 code_convert_region_unwind (arg)
      Lisp_Object arg;
 {
   inhibit_pre_post_conversion = 0;
-  Vlast_coding_system_used = arg;
+  Vlast_coding_system_used = XCAR (arg);
+  if (! NILP (XCDR (arg)))
+    Fkill_buffer (XCDR (arg));
   return Qnil;
 }
 
@@ -5607,7 +5612,7 @@
       Lisp_Object new;
 
       record_unwind_protect (code_convert_region_unwind,
-			     Vlast_coding_system_used);
+			     Fcons (Vlast_coding_system_used, Qnil));
       /* We should not call any more pre-write/post-read-conversion
          functions while this pre-write-conversion is running.  */
       inhibit_pre_post_conversion = 1;
@@ -5975,7 +5980,7 @@
 	TEMP_SET_PT_BOTH (from, from_byte);
       prev_Z = Z;
       record_unwind_protect (code_convert_region_unwind,
-			     Vlast_coding_system_used);
+			     Fcons (Vlast_coding_system_used, Qnil));
       saved_coding_system = Vlast_coding_system_used;
       Vlast_coding_system_used = coding->symbol;
       /* We should not call any more pre-write/post-read-conversion
@@ -6021,17 +6026,31 @@
 
 /* Set the current buffer to the working buffer prepared for
    code-conversion.  MULTIBYTE specifies the multibyteness of the
-   buffer.  */
-
-static struct buffer *
+   buffer.  Return the buffer we set if it must be killed after use.
+   Otherwise return Qnil.  */
+
+static Lisp_Object
 set_conversion_work_buffer (multibyte)
      int multibyte;
 {
-  Lisp_Object buffer;
+  Lisp_Object buffer, buffer_to_kill;
   struct buffer *buf;
 
   buffer = Fget_buffer_create (Vcode_conversion_workbuf_name);
   buf = XBUFFER (buffer);
+  if (buf == current_buffer)
+    {
+      /* As we are already in the work buffer, we must generate a new
+	 buffer for the work.  */
+      Lisp_Object name;
+	
+      name = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil);
+      buffer = buffer_to_kill = Fget_buffer_create (name);
+      buf = XBUFFER (buffer);
+    }
+  else
+    buffer_to_kill = Qnil;
+
   delete_all_overlays (buf);
   buf->directory = current_buffer->directory;
   buf->read_only = Qnil;
@@ -6044,7 +6063,7 @@
     Fwiden ();
   del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0);
   buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
-  return buf;
+  return buffer_to_kill;
 }
 
 Lisp_Object
@@ -6057,10 +6076,9 @@
   struct gcpro gcpro1, gcpro2;
   int multibyte = STRING_MULTIBYTE (str);
   Lisp_Object old_deactivate_mark;
+  Lisp_Object buffer_to_kill;
 
   record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
-  record_unwind_protect (code_convert_region_unwind,
-			 Vlast_coding_system_used);
   /* It is not crucial to specbind this.  */
   old_deactivate_mark = Vdeactivate_mark;
   GCPRO2 (str, old_deactivate_mark);
@@ -6068,7 +6086,9 @@
   /* We must insert the contents of STR as is without
      unibyte<->multibyte conversion.  For that, we adjust the
      multibyteness of the working buffer to that of STR.  */
-  set_conversion_work_buffer (multibyte);
+  buffer_to_kill = set_conversion_work_buffer (multibyte);
+  record_unwind_protect (code_convert_region_unwind,
+			 Fcons (Vlast_coding_system_used, buffer_to_kill));
 
   insert_from_string (str, 0, 0,
 		      SCHARS (str), SBYTES (str), 0);
@@ -6111,6 +6131,7 @@
   struct buffer *cur = current_buffer;
   Lisp_Object old_deactivate_mark, old_last_coding_system_used;
   Lisp_Object args[3];
+  Lisp_Object buffer_to_kill;
 
   /* It is not crucial to specbind this.  */
   old_deactivate_mark = Vdeactivate_mark;
@@ -6120,7 +6141,7 @@
   /* We must insert the contents of STR as is without
      unibyte<->multibyte conversion.  For that, we adjust the
      multibyteness of the working buffer to that of STR.  */
-  set_conversion_work_buffer (coding->src_multibyte);
+  buffer_to_kill = set_conversion_work_buffer (coding->src_multibyte);
   insert_1_both (*str, nchars, nbytes, 0, 0, 0);
   UNGCPRO;
   inhibit_pre_post_conversion = 1;
@@ -6144,6 +6165,8 @@
   coding->src_multibyte
     = ! NILP (current_buffer->enable_multibyte_characters);
   set_buffer_internal (cur);
+  if (! NILP (buffer_to_kill))
+    Fkill_buffer (buffer_to_kill);
 }