changeset 83127:5182815e0ee1

Make terminal_coding and keyboard_coding display-local. src/coding.c: Include frame.h and termhooks.h. (terminal_coding, keyboard_coding): Remove. (Fset_terminal_coding_system_internal, Fterminal_coding_system): Use the selected frame's terminal coding system. (Fset_safe_terminal_coding_system_internal): Fix typo. (Fset_keyboard_coding_system_internal, Fkeyboard_coding_system): Use the selected frame's keyboard coding system. (init_coding_once): Don't initialize keyboard_coding and terminal_coding. src/coding.h (terminal_coding, keyboard_coding): Remove. src/termhooks.h (terminal_coding, keyboard_coding): New members of struct display. (FRAME_TERMINAL_CODING, FRAME_KEYBOARD_CODING): New macros. src/termchar.h (kboard): Cosmetic change. src/term.c (encode_terminal_code): Add coding parameter. (tty_write_glyphs): Use the display-local terminal coding system. (create_display): Allocate and initialize coding systems. (delete_display): Free coding systems. src/xdisp.c (decode_mode_spec): Use display-local coding systems. src/Makefile.in: Fix dependencies for termchar.h and termhooks.h. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-167
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 23 May 2004 01:53:23 +0000
parents 14e5707213a6
children 2ccd88cfde01
files src/Makefile.in src/coding.c src/coding.h src/term.c src/termchar.h src/termhooks.h src/xdisp.c
diffstat 7 files changed, 91 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.in	Sat May 22 22:52:43 2004 +0000
+++ b/src/Makefile.in	Sun May 23 01:53:23 2004 +0000
@@ -1061,7 +1061,7 @@
 ccl.o: ccl.c ccl.h charset.h coding.h $(config_h)
 charset.o: charset.c charset.h buffer.h coding.h composite.h disptab.h \
 	$(config_h)
-coding.o: coding.c coding.h ccl.h buffer.h charset.h intervals.h composite.h window.h $(config_h)
+coding.o: coding.c coding.h ccl.h buffer.h charset.h intervals.h composite.h window.h frame.h termhooks.h $(config_h)
 cm.o: cm.c frame.h cm.h termhooks.h termchar.h $(config_h)
 cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \
 	msdos.h dispextern.h
@@ -1089,8 +1089,8 @@
 filemode.o: filemode.c  $(config_h)
 frame.o: frame.c xterm.h window.h frame.h termhooks.h commands.h keyboard.h \
    blockinput.h atimer.h systime.h buffer.h charset.h fontset.h \
-   msdos.h dosfns.h dispextern.h $(config_h)
-fringe.o: fringe.c dispextern.h frame.h window.h buffer.h $(config_h)
+   msdos.h dosfns.h dispextern.h termchar.h $(config_h)
+fringe.o: fringe.c dispextern.h frame.h window.h buffer.h termhooks.h $(config_h)
 fontset.o: dispextern.h fontset.h fontset.c ccl.h buffer.h charset.h frame.h \
    keyboard.h termhooks.h $(config_h)
 getloadavg.o: getloadavg.c $(config_h)
@@ -1153,17 +1153,17 @@
 widget.o: widget.c xterm.h frame.h dispextern.h widgetprv.h \
    $(srcdir)/../lwlib/lwlib.h $(config_h)
 window.o: window.c indent.h commands.h frame.h window.h buffer.h termchar.h \
-   termhooks.h disptab.h keyboard.h dispextern.h msdos.h composite.h \
+   disptab.h keyboard.h dispextern.h msdos.h composite.h \
    $(config_h)
 xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h coding.h \
    termchar.h frame.h window.h disptab.h termhooks.h charset.h $(config_h) \
    msdos.h composite.h fontset.h blockinput.h atimer.h systime.h keymap.h
 xfaces.o: xfaces.c dispextern.h frame.h xterm.h buffer.h blockinput.h \
    window.h charset.h msdos.h dosfns.h composite.h atimer.h systime.h \
-   termchar.h $(config_h)
+   termchar.h termhooks.h $(config_h)
 xfns.o: xfns.c buffer.h frame.h window.h keyboard.h xterm.h dispextern.h \
    $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h epaths.h \
-   charset.h gtkutil.h termchar.h $(config_h)
+   charset.h gtkutil.h termchar.h termhooks.h $(config_h)
 xmenu.o: xmenu.c xterm.h termhooks.h window.h dispextern.h frame.h buffer.h \
    keyboard.h $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h \
    gtkutil.h msdos.h coding.h $(config_h)
@@ -1172,7 +1172,7 @@
   keyboard.h gnu.h charset.h ccl.h fontset.h composite.h \
   coding.h process.h gtkutil.h $(config_h)
 xselect.o: xselect.c process.h dispextern.h frame.h xterm.h blockinput.h \
-  buffer.h atimer.h systime.h $(config_h)
+  buffer.h atimer.h systime.h termhooks.h $(config_h)
 xrdb.o: xrdb.c $(config_h) epaths.h
 xsmfns.o: xsmfns.c $(config_h) systime.h sysselect.h termhooks.h xterm.h \
   lisp.h termopts.h
@@ -1209,7 +1209,7 @@
    OTHER_FILES and OBJECTS_MACHINE
    select which of these should be compiled.  */
 
-sunfns.o: sunfns.c buffer.h window.h dispextern.h $(config_h)
+sunfns.o: sunfns.c buffer.h window.h dispextern.h termhooks.h $(config_h)
 
 #ifdef HAVE_CARBON
 abbrev.o buffer.o callint.o cmds.o dispnew.o editfns.o fileio.o frame.o \
--- a/src/coding.c	Sat May 22 22:52:43 2004 +0000
+++ b/src/coding.c	Sun May 23 01:53:23 2004 +0000
@@ -346,6 +346,8 @@
 #include "coding.h"
 #include "window.h"
 #include "intervals.h"
+#include "frame.h"
+#include "termhooks.h"
 
 #else  /* not emacs */
 
@@ -428,16 +430,10 @@
 /* Flag to make buffer-file-coding-system inherit from process-coding.  */
 int inherit_process_coding_system;
 
-/* Coding system to be used to encode text for terminal display.  */
-struct coding_system terminal_coding;
-
 /* Coding system to be used to encode text for terminal display when
    terminal coding system is nil.  */
 struct coding_system safe_terminal_coding;
 
-/* Coding system of what is sent from terminal keyboard.  */
-struct coding_system keyboard_coding;
-
 /* Default coding system to be used to write a file.  */
 struct coding_system default_buffer_file_coding;
 
@@ -7184,16 +7180,17 @@
      (coding_system)
      Lisp_Object coding_system;
 {
+  struct coding_system *terminal_coding = FRAME_TERMINAL_CODING (SELECTED_FRAME ());
   CHECK_SYMBOL (coding_system);
-  setup_coding_system (Fcheck_coding_system (coding_system), &terminal_coding);
+  setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding);
   /* We had better not send unsafe characters to terminal.  */
-  terminal_coding.mode |= CODING_MODE_INHIBIT_UNENCODABLE_CHAR;
+  terminal_coding->mode |= CODING_MODE_INHIBIT_UNENCODABLE_CHAR;
   /* Character composition should be disabled.  */
-  terminal_coding.composing = COMPOSITION_DISABLED;
+  terminal_coding->composing = COMPOSITION_DISABLED;
   /* Error notification should be suppressed.  */
-  terminal_coding.suppress_error = 1;
-  terminal_coding.src_multibyte = 1;
-  terminal_coding.dst_multibyte = 0;
+  terminal_coding->suppress_error = 1;
+  terminal_coding->src_multibyte = 1;
+  terminal_coding->dst_multibyte = 0;
   return Qnil;
 }
 
@@ -7209,7 +7206,7 @@
   /* Character composition should be disabled.  */
   safe_terminal_coding.composing = COMPOSITION_DISABLED;
   /* Error notification should be suppressed.  */
-  terminal_coding.suppress_error = 1;
+  safe_terminal_coding.suppress_error = 1;
   safe_terminal_coding.src_multibyte = 1;
   safe_terminal_coding.dst_multibyte = 0;
   return Qnil;
@@ -7220,7 +7217,7 @@
        doc: /* Return coding system specified for terminal output.  */)
      ()
 {
-  return terminal_coding.symbol;
+  return FRAME_TERMINAL_CODING (SELECTED_FRAME ())->symbol;
 }
 
 DEFUN ("set-keyboard-coding-system-internal", Fset_keyboard_coding_system_internal,
@@ -7230,9 +7227,10 @@
      Lisp_Object coding_system;
 {
   CHECK_SYMBOL (coding_system);
-  setup_coding_system (Fcheck_coding_system (coding_system), &keyboard_coding);
+  setup_coding_system (Fcheck_coding_system (coding_system),
+                       FRAME_KEYBOARD_CODING (SELECTED_FRAME ()));
   /* Character composition should be disabled.  */
-  keyboard_coding.composing = COMPOSITION_DISABLED;
+  FRAME_KEYBOARD_CODING (SELECTED_FRAME ())->composing = COMPOSITION_DISABLED;
   return Qnil;
 }
 
@@ -7241,7 +7239,7 @@
        doc: /* Return coding system specified for decoding keyboard input.  */)
      ()
 {
-  return keyboard_coding.symbol;
+  return FRAME_KEYBOARD_CODING (SELECTED_FRAME ())->symbol;
 }
 
 
@@ -7488,8 +7486,6 @@
   iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3;
   iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer;
 
-  setup_coding_system (Qnil, &keyboard_coding);
-  setup_coding_system (Qnil, &terminal_coding);
   setup_coding_system (Qnil, &safe_terminal_coding);
   setup_coding_system (Qnil, &default_buffer_file_coding);
 
--- a/src/coding.h	Sat May 22 22:52:43 2004 +0000
+++ b/src/coding.h	Sun May 23 01:53:23 2004 +0000
@@ -688,20 +688,10 @@
    the subprocess output.  */
 extern int inherit_process_coding_system;
 
-/* Coding-system to be used for encoding terminal output.  This
-   structure contains information of a coding-system specified by the
-   function `set-terminal-coding-system'.  */
-extern struct coding_system terminal_coding;
-
 /* Coding system to be used to encode text for terminal display when
    terminal coding system is nil.  */
 extern struct coding_system safe_terminal_coding;
 
-/* Coding-system of what is sent from terminal keyboard.  This
-   structure contains information of a coding-system specified by the
-   function `set-keyboard-coding-system'.  */
-extern struct coding_system keyboard_coding;
-
 /* Default coding system to be used to write a file.  */
 extern struct coding_system default_buffer_file_coding;
 
--- a/src/term.c	Sat May 22 22:52:43 2004 +0000
+++ b/src/term.c	Sun May 23 01:53:23 2004 +0000
@@ -619,7 +619,8 @@
    return value is the number of bytes store in DST.  */
 
 int
-encode_terminal_code (src, dst, src_len, dst_len, consumed)
+encode_terminal_code (coding, src, dst, src_len, dst_len, consumed)
+     struct coding_system *coding;
      struct glyph *src;
      int src_len;
      unsigned char *dst;
@@ -634,13 +635,12 @@
   register int tlen = GLYPH_TABLE_LENGTH;
   register Lisp_Object *tbase = GLYPH_TABLE_BASE;
   int result;
-  struct coding_system *coding;
-
-  /* If terminal_coding does any conversion, use it, otherwise use
+
+  /* If the specified coding does any conversion, use it, otherwise use
      safe_terminal_coding.  We can't use CODING_REQUIRE_ENCODING here
-     because it always return 1 if the member src_multibyte is 1.  */
-  coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK
-	    ? &terminal_coding
+     because it always returns 1 if the member src_multibyte is 1.  */
+  coding = (coding->common_flags & CODING_REQUIRE_ENCODING_MASK
+	    ? coding
 	    : &safe_terminal_coding);
 
   while (src < src_end)
@@ -757,7 +757,7 @@
 
   /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
      the tail.  */
-  terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK;
+  FRAME_TERMINAL_CODING (f)->mode &= ~CODING_MODE_LAST_BLOCK;
 
   while (len > 0)
     {
@@ -778,7 +778,8 @@
 	  /* We use a fixed size (1024 bytes) of conversion buffer.
 	     Usually it is sufficient, but if not, we just repeat the
 	     loop.  */
-	  produced = encode_terminal_code (string, conversion_buffer,
+	  produced = encode_terminal_code (FRAME_TERMINAL_CODING (f),
+                                           string, conversion_buffer,
 					   n, conversion_buffer_size,
 					   &consumed);
 	  if (produced > 0)
@@ -802,19 +803,21 @@
     }
 
   /* We may have to output some codes to terminate the writing.  */
-  if (CODING_REQUIRE_FLUSHING (&terminal_coding))
+  if (CODING_REQUIRE_FLUSHING (FRAME_TERMINAL_CODING (f)))
     {
-      terminal_coding.mode |= CODING_MODE_LAST_BLOCK;
-      encode_coding (&terminal_coding, "", conversion_buffer,
-		     0, conversion_buffer_size);
-      if (terminal_coding.produced > 0)
+      FRAME_TERMINAL_CODING (f)->mode |= CODING_MODE_LAST_BLOCK;
+      encode_coding (FRAME_TERMINAL_CODING (f), "",
+                     conversion_buffer, 0, conversion_buffer_size);
+      if (FRAME_TERMINAL_CODING (f)->produced > 0)
 	{
-	  fwrite (conversion_buffer, 1, terminal_coding.produced,
+	  fwrite (conversion_buffer, 1,
+                  FRAME_TERMINAL_CODING (f)->produced,
                   tty->output);
 	  if (ferror (tty->output))
 	    clearerr (tty->output);
 	  if (tty->termscript)
-	    fwrite (conversion_buffer, 1, terminal_coding.produced,
+	    fwrite (conversion_buffer, 1,
+                    FRAME_TERMINAL_CODING (f)->produced,
 		    tty->termscript);
 	}
     }
@@ -859,7 +862,7 @@
   turn_on_insert (tty);
   cmplus (tty, len);
   /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail.  */
-  terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK;
+  FRAME_TERMINAL_CODING (f)->mode &= ~CODING_MODE_LAST_BLOCK;
   while (len-- > 0)
     {
       int produced, consumed;
@@ -888,7 +891,7 @@
 
 	  if (len <= 0)
 	    /* This is the last glyph.  */
-	    terminal_coding.mode |= CODING_MODE_LAST_BLOCK;
+	    FRAME_TERMINAL_CODING (f)->mode |= CODING_MODE_LAST_BLOCK;
 
 	  /* The size of conversion buffer (1024 bytes) is surely
 	     sufficient for just one glyph.  */
@@ -3105,19 +3108,27 @@
 struct display *
 create_display (void)
 {
-  struct display *dev = (struct display *) xmalloc (sizeof (struct display));
+  struct display *display = (struct display *) xmalloc (sizeof (struct display));
   
-  bzero (dev, sizeof (struct display));
-  dev->next_display = display_list;
-  display_list = dev;
-
-  return dev;
+  bzero (display, sizeof (struct display));
+  display->next_display = display_list;
+  display_list = display;
+
+  display->keyboard_coding =
+    (struct coding_system *) xmalloc (sizeof (struct coding_system));
+  display->terminal_coding =
+    (struct coding_system *) xmalloc (sizeof (struct coding_system));
+  
+  setup_coding_system (Qnil, display->keyboard_coding);
+  setup_coding_system (Qnil, display->terminal_coding);
+  
+  return display;
 }
 
 /* Remove a display from the display list and free its memory. */
 
 void
-delete_display (struct display *dev)
+delete_display (struct display *display)
 {
   struct display **dp;
   Lisp_Object tail, frame;
@@ -3127,19 +3138,24 @@
   FOR_EACH_FRAME (tail, frame)
     {
       struct frame *f = XFRAME (frame);
-      if (FRAME_LIVE_P (f) && f->display == dev)
+      if (FRAME_LIVE_P (f) && f->display == display)
         {
           Fdelete_frame (frame, Qt);
         }
     }
 
-  for (dp = &display_list; *dp != dev; dp = &(*dp)->next_display)
+  for (dp = &display_list; *dp != display; dp = &(*dp)->next_display)
     if (! *dp)
       abort ();
-  *dp = dev->next_display;
-
-  bzero (dev, sizeof (struct display));
-  xfree (dev);
+  *dp = display->next_display;
+
+  if (display->keyboard_coding)
+    xfree (display->keyboard_coding);
+  if (display->terminal_coding)
+    xfree (display->terminal_coding);
+
+  bzero (display, sizeof (struct display));
+  xfree (display);
 }
 
 
--- a/src/termchar.h	Sat May 22 22:52:43 2004 +0000
+++ b/src/termchar.h	Sun May 23 01:53:23 2004 +0000
@@ -70,6 +70,11 @@
   /* The previous terminal frame we displayed on this tty.  */
   struct frame *previous_terminal_frame;
 
+#ifdef MULTI_KBOARD
+  /* The terminal's keyboard object. */
+  struct kboard *kboard;
+#endif  
+
   /* Strings, numbers and flags taken from the termcap entry.  */
 
   char *TS_ins_line;		/* "al" */
@@ -185,10 +190,6 @@
   /* Nonzero means use ^S/^Q for flow control.  */
   int flow_control;
 
-#ifdef MULTI_KBOARD
-  /* The terminal's keyboard object. */
-  struct kboard *kboard;
-#endif  
 };
 
 /* A chain of structures for all tty devices currently in use. */
--- a/src/termhooks.h	Sat May 22 22:52:43 2004 +0000
+++ b/src/termhooks.h	Sun May 23 01:53:23 2004 +0000
@@ -296,6 +296,17 @@
   } display_info;
 
 
+  /* Coding-system to be used for encoding terminal output.  This
+     structure contains information of a coding-system specified by
+     the function `set-terminal-coding-system'.  Also see
+     `safe_terminal_coding' in coding.h.  */
+  struct coding_system *terminal_coding;
+
+  /* Coding-system of what is sent from terminal keyboard.  This
+     structure contains information of a coding-system specified by
+     the function `set-keyboard-coding-system'.  */
+  struct coding_system *keyboard_coding;
+
   /* Terminal characteristics. */
   /* XXX Are these really used on non-termcap displays? */
   
@@ -529,6 +540,9 @@
 #define FRAME_SCROLL_REGION_COST(f) ((f)->display->scroll_region_cost)
 #define FRAME_MEMORY_BELOW_FRAME(f) ((f)->display->memory_below_frame)
 
+#define FRAME_TERMINAL_CODING(f) ((f)->display->terminal_coding)
+#define FRAME_KEYBOARD_CODING(f) ((f)->display->keyboard_coding)
+
 #define FRAME_RIF(f) ((f)->display->rif)
 
 #define FRAME_DISPLAY(f) ((f)->display)
--- a/src/xdisp.c	Sat May 22 22:52:43 2004 +0000
+++ b/src/xdisp.c	Sun May 23 01:53:23 2004 +0000
@@ -16357,8 +16357,8 @@
 	  {
 	    /* No need to mention EOL here--the terminal never needs
 	       to do EOL conversion.  */
-	    p = decode_mode_spec_coding (keyboard_coding.symbol, p, 0);
-	    p = decode_mode_spec_coding (terminal_coding.symbol, p, 0);
+	    p = decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f)->symbol, p, 0);
+	    p = decode_mode_spec_coding (FRAME_TERMINAL_CODING (f)->symbol, p, 0);
 	  }
 	p = decode_mode_spec_coding (b->buffer_file_coding_system,
 				     p, eol_flag);