changeset 83298:ed09a89e2b25

Fix UTF-8 tty input when first frame is an X frame. Steps towards multiple tty locale support. * lisp/international/mule-cmds.el (set-locale-environment): Ignore window-system; always set the keyboard coding system. * src/termhooks.h (DISPLAY_TERMINAL_CODING, DISPLAY_KEYBOARD_CODING): New macros. * src/coding.c (Fset_terminal_coding_system_internal, Fterminal_coding_system) (Fset_keyboard_coding_system_internal, Fkeyboard_coding_system): Add DISPLAY parameter. * src/term.c (get_display): Add THROW parameter. (get_tty_display, Fdisplay_name, Fdisplay_tty_type, Fdisplay_controlling_tty_p) (Fdelete_display, Fdisplay_live_p): Update callers. * src/xfns.c (check_x_display_info): Ditto. * src/frame.c (Fmake_terminal_frame, Fframe_display): Ditto. * src/dispextern.h (get_display): Update prototype. * lisp/international/mule.el (set-terminal-coding-system) (set-keyboard-coding-system): Add DISPLAY parameter. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-338
author Karoly Lorentey <lorentey@elte.hu>
date Tue, 03 May 2005 01:49:33 +0000
parents 8e357d90cc9f
children 4a6a96fe8480
files README.multi-tty lisp/international/mule-cmds.el lisp/international/mule.el lisp/term/lk201.el src/coding.c src/dispextern.h src/frame.c src/term.c src/termhooks.h src/xfns.c
diffstat 10 files changed, 112 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/README.multi-tty	Tue May 03 01:38:40 2005 +0000
+++ b/README.multi-tty	Tue May 03 01:49:33 2005 +0000
@@ -383,18 +383,19 @@
    Update: selecting a region with the mouse enables single_kboard
    under X.  This is very confusing.
 
-   Update: After discussions with Richard, this will be resolved by
-   having locked displays warn the user to wait, and introducing a
-   complex protocol to remotely bail out of single-kboard mode by
-   pressing C-g.
+   Update: After discussions with Richard Stallman, this will be
+   resolved by having locked displays warn the user to wait, and
+   introducing a complex protocol to remotely bail out of
+   single-kboard mode by pressing C-g.
 
    Update: Warning the user is not trivial to implement, as Emacs has
-   only one echo area.  Ideally the warning should not be displayed on
-   the display that is locking the others.  Perhaps the high
-   probability of user confusion caused by single_kboard mode deserves
-   a special case in the display code.  Alternatively, it might be
-   good enough to signal single_kboard mode by changing the modelines
-   or some other frame-local display element on the locked out displays.
+   only one echo area, shared by all frames.  Ideally the warning
+   should not be displayed on the display that is locking the others.
+   Perhaps the high probability of user confusion caused by
+   single_kboard mode deserves a special case in the display code.
+   Alternatively, it might be good enough to signal single_kboard mode
+   by changing the modelines or some other frame-local display element
+   on the locked out displays.
 
 ** normal-erase-is-backspace-mode in simple.el needs to be updated for
    multi-tty (rep. by Dan Waber).
@@ -405,6 +406,22 @@
 ** rif->flush_display_optional (NULL) calls should be replaced by a
    new global function.
 
+** Support multiple character locales.  
+
+	(1) A version of `set-locale-environment' needs to be written
+	    for setting up display-local settings on ttys.  I think
+	    calling set-display-table-and-terminal-coding-system and
+	    set-keyboard-coding-system would be enough.  The language
+	    environment itself should remain a global setting.
+
+	(2) Have a look at Vlocale_coding_system.  Seems like it would
+	    be a tedious job to localize it, although most references
+	    use it for interfacing with libc and are therefore OK with
+	    the global definition.
+
+            Exceptions found so far: x-select-text and
+            x-cut-buffer-or-selection-value.
+
 ** Have a look at fatal_error_hook.
 
 ** Have a look at set_frame_matrix_frame.
@@ -429,7 +446,8 @@
 
 ** The terminal customization files in term/*.el tend to change global
    parameters, which may confuse Emacs with multiple displays.  Change
-   them to tweak only frame-local settings, if possible.
+   them to tweak only frame-local settings, if possible.  (They tend
+   to call define-key to set function key sequences a lot.)
 
 ** Dan Nicolaescu suggests that -nw should be added as an alias for -t
    in emacsclient.  Good idea.  (Alas, implementing this is not
@@ -449,9 +467,6 @@
    terminals in xterm and konsole.  The screen does flicker a bit,
    but it's so quick it isn't noticable.
 
-** Clean up the frame-local variable system.  I think it's ugly and
-   error-prone.  But maybe I just haven't yet fully understood it.
-
 ** Move baud_rate to struct display.
 
 ** Implement support for starting an interactive Emacs session without
@@ -963,7 +978,7 @@
 
    (Fixed.  Emacs now uses the locale settings as seen by the
    emacsclient process for server tty frames.)
-
+   (Update: Not really; Vlocale_coding_system is still global.)
 
 -- Make `struct display' accessible to Lisp programs.  Accessor functions:
 
@@ -1022,5 +1037,9 @@
 
    (Done.  This is the new default.  No complaints so far.)
 
+-- Clean up the frame-local variable system.  I think it's ugly and
+   error-prone.  But maybe I just haven't yet fully understood it.
+
+   (Nothing to do.  It doesn't seem ugly any more.  It's rather clever.)
 
 ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d
--- a/lisp/international/mule-cmds.el	Tue May 03 01:38:40 2005 +0000
+++ b/lisp/international/mule-cmds.el	Tue May 03 01:49:33 2005 +0000
@@ -2470,11 +2470,14 @@
 	  ;; Set the `keyboard-coding-system' if appropriate (tty
 	  ;; only).  At least X and MS Windows can generate
 	  ;; multilingual input.
-	  (unless window-system
-	    (let ((kcs (or coding-system
-			   (car (get-language-info language-name
-						   'coding-system)))))
-	      (if kcs (set-keyboard-coding-system kcs))))
+	  ;; XXX This was disabled unless `window-system', but that
+	  ;; leads to buggy behaviour when a tty frame is opened
+	  ;; later.  Setting the keyboard coding system has no adverse
+	  ;; effect on X, so let's do it anyway. -- Lorentey
+	  (let ((kcs (or coding-system
+			 (car (get-language-info language-name
+						 'coding-system)))))
+	    (if kcs (set-keyboard-coding-system kcs)))
 
 	  (setq locale-coding-system
 		(car (get-language-info language-name 'coding-priority))))
--- a/lisp/international/mule.el	Tue May 03 01:38:40 2005 +0000
+++ b/lisp/international/mule.el	Tue May 03 01:49:33 2005 +0000
@@ -1199,13 +1199,17 @@
 This is normally set according to the selected language environment.
 See also the command `set-terminal-coding-system'.")
 
-(defun set-terminal-coding-system (coding-system)
-  "Set coding system of your terminal to CODING-SYSTEM.
-All text output to the terminal will be encoded
+(defun set-terminal-coding-system (coding-system &optional display)
+  "Set coding system of terminal output to CODING-SYSTEM.
+All text output to DISPLAY will be encoded
 with the specified coding system.
+
 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
 The default is determined by the selected language environment
-or by the previous use of this command."
+or by the previous use of this command.
+
+DISPLAY may be a display id, a frame, or nil for the selected frame's display.
+The setting has no effect on graphical displays."
   (interactive
    (list (let ((default (if (and (not (terminal-coding-system))
 				 default-terminal-coding-system)
@@ -1219,7 +1223,7 @@
       (setq coding-system default-terminal-coding-system))
   (if coding-system
       (setq default-terminal-coding-system coding-system))
-  (set-terminal-coding-system-internal coding-system)
+  (set-terminal-coding-system-internal coding-system display)
   (redraw-frame (selected-frame)))
 
 (defvar default-keyboard-coding-system nil
@@ -1227,14 +1231,18 @@
 This is normally set according to the selected language environment.
 See also the command `set-keyboard-coding-system'.")
 
-(defun set-keyboard-coding-system (coding-system)
-  "Set coding system for keyboard input to CODING-SYSTEM.
+(defun set-keyboard-coding-system (coding-system &optional display)
+  "Set coding system for keyboard input on DISPLAY to CODING-SYSTEM.
 In addition, this command enables Encoded-kbd minor mode.
 \(If CODING-SYSTEM is nil, Encoded-kbd mode is turned off -- see
 `encoded-kbd-mode'.)
+
 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
 The default is determined by the selected language environment
-or by the previous use of this command."
+or by the previous use of this command.
+
+DISPLAY may be a display id, a frame, or nil for the selected frame's display.
+The setting has no effect on graphical displays."
   (interactive
    (list (let ((default (if (and (not (keyboard-coding-system))
 				 default-keyboard-coding-system)
@@ -1248,7 +1256,7 @@
       (setq coding-system default-keyboard-coding-system))
   (if coding-system
       (setq default-keyboard-coding-system coding-system))
-  (set-keyboard-coding-system-internal coding-system)
+  (set-keyboard-coding-system-internal coding-system display)
   (setq keyboard-coding-system coding-system)
   (encoded-kbd-mode (if coding-system 1 0)))
 
--- a/lisp/term/lk201.el	Tue May 03 01:38:40 2005 +0000
+++ b/lisp/term/lk201.el	Tue May 03 01:49:33 2005 +0000
@@ -1,6 +1,8 @@
 ;; -*- no-byte-compile: t -*-
 ;; Define function key sequences for DEC terminals.
 
+;; XXX We need to find a way to have these define-keys be display-local. -- Lorentey
+
 ;; Termcap or terminfo should set these.
 ;; (define-key function-key-map "\e[A" [up])
 ;; (define-key function-key-map "\e[B" [down])
--- a/src/coding.c	Tue May 03 01:38:40 2005 +0000
+++ b/src/coding.c	Tue May 03 01:49:33 2005 +0000
@@ -7305,12 +7305,13 @@
 }
 
 DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_internal,
-       Sset_terminal_coding_system_internal, 1, 1, 0,
+       Sset_terminal_coding_system_internal, 1, 2, 0,
        doc: /* Internal use only.  */)
-     (coding_system)
+     (coding_system, display)
      Lisp_Object coding_system;
+     Lisp_Object display;
 {
-  struct coding_system *terminal_coding = FRAME_TERMINAL_CODING (SELECTED_FRAME ());
+  struct coding_system *terminal_coding = DISPLAY_TERMINAL_CODING (get_display (display, 1));
   CHECK_SYMBOL (coding_system);
   setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding);
   /* We had better not send unsafe characters to terminal.  */
@@ -7343,33 +7344,39 @@
 }
 
 DEFUN ("terminal-coding-system", Fterminal_coding_system,
-       Sterminal_coding_system, 0, 0, 0,
-       doc: /* Return coding system specified for terminal output.  */)
-     ()
+       Sterminal_coding_system, 0, 1, 0,
+       doc: /* Return coding system specified for terminal output on the given display.
+DISPLAY may be a display id, a frame, or nil for the selected frame's display.  */)
+     (display)
+     Lisp_Object display;
 {
-  return FRAME_TERMINAL_CODING (SELECTED_FRAME ())->symbol;
+  return DISPLAY_TERMINAL_CODING (get_display (display, 1))->symbol;
 }
 
 DEFUN ("set-keyboard-coding-system-internal", Fset_keyboard_coding_system_internal,
-       Sset_keyboard_coding_system_internal, 1, 1, 0,
+       Sset_keyboard_coding_system_internal, 1, 2, 0,
        doc: /* Internal use only.  */)
-     (coding_system)
+     (coding_system, display)
      Lisp_Object coding_system;
+     Lisp_Object display;
 {
+  struct display *d = get_display (display, 1);
   CHECK_SYMBOL (coding_system);
+
   setup_coding_system (Fcheck_coding_system (coding_system),
-                       FRAME_KEYBOARD_CODING (SELECTED_FRAME ()));
+                       DISPLAY_KEYBOARD_CODING (d));
   /* Character composition should be disabled.  */
-  FRAME_KEYBOARD_CODING (SELECTED_FRAME ())->composing = COMPOSITION_DISABLED;
+  DISPLAY_KEYBOARD_CODING (d)->composing = COMPOSITION_DISABLED;
   return Qnil;
 }
 
 DEFUN ("keyboard-coding-system", Fkeyboard_coding_system,
-       Skeyboard_coding_system, 0, 0, 0,
+       Skeyboard_coding_system, 0, 1, 0,
        doc: /* Return coding system specified for decoding keyboard input.  */)
-     ()
+     (display)
+     Lisp_Object display;
 {
-  return FRAME_KEYBOARD_CODING (SELECTED_FRAME ())->symbol;
+  return DISPLAY_KEYBOARD_CODING (get_display (display, 1))->symbol;
 }
 
 
--- a/src/dispextern.h	Tue May 03 01:38:40 2005 +0000
+++ b/src/dispextern.h	Tue May 03 01:49:33 2005 +0000
@@ -2925,7 +2925,7 @@
 extern void calculate_costs P_ ((struct frame *));
 extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object));
 extern void tty_setup_colors P_ ((struct tty_display_info *, int));
-extern struct display *get_display P_ ((Lisp_Object display));
+extern struct display *get_display P_ ((Lisp_Object display, int));
 extern struct display *get_named_tty_display P_ ((char *));
 EXFUN (Fdisplay_tty_type, 1);
 extern struct display *init_initial_display P_ ((void));
--- a/src/frame.c	Tue May 03 01:38:40 2005 +0000
+++ b/src/frame.c	Tue May 03 01:49:33 2005 +0000
@@ -698,9 +698,7 @@
       {
         display_device = XCDR (display_device);
         CHECK_NUMBER (display_device);
-        d = get_display (XINT (display_device));
-        if (!d)
-          wrong_type_argument (Qdisplay_live_p, display_device);
+        d = get_display (XINT (display_device), 1);
       }
   }
   
@@ -1073,7 +1071,7 @@
 
   CHECK_LIVE_FRAME (frame);
 
-  d = get_display (frame);
+  d = get_display (frame, 0);
 
   if (!d)
     return Qnil;
--- a/src/term.c	Tue May 03 01:38:40 2005 +0000
+++ b/src/term.c	Tue May 03 01:49:33 2005 +0000
@@ -2105,17 +2105,17 @@
 
 /* Return the display object specified by DISPLAY.  DISPLAY may be a
    display id, a frame, or nil for the display device of the current
-   frame. */
+   frame.  If THROW is zero, return NULL for failure, otherwise throw
+   an error.  */
 
 struct display *
-get_display (Lisp_Object display)
+get_display (Lisp_Object display, int throw)
 {
+  Lisp_Object result = NULL;
+
   if (NILP (display))
     display = selected_frame;
 
-  if (! INTEGERP (display) && ! FRAMEP (display))
-    return NULL;
-
   if (INTEGERP (display))
     {
       struct display *d;
@@ -2123,15 +2123,21 @@
       for (d = display_list; d; d = d->next_display)
         {
           if (d->id == XINT (display))
-            return d;
+            {
+              result = d;
+              break;
+            }
         }
-      return NULL;
     }
   else if (FRAMEP (display))
     {
-      return FRAME_DISPLAY (XFRAME (display));
+      result = FRAME_DISPLAY (XFRAME (display));
     }
-  return NULL;
+
+  if (result == NULL && throw)
+    wrong_type_argument (Qdisplay_live_p, display);
+
+  return result;
 }
 
 /* Return the tty display object specified by DISPLAY. */
@@ -2139,7 +2145,7 @@
 static struct display *
 get_tty_display (Lisp_Object display)
 {
-  struct display *d = get_display (display);
+  struct display *d = get_display (display, 0);
   
   if (d && d->type == output_initial)
     d = NULL;
@@ -2194,10 +2200,7 @@
   (display)
      Lisp_Object display;
 {
-  struct display *d = get_display (display);
-
-  if (!d)
-    wrong_type_argument (Qdisplay_live_p, display);
+  struct display *d = get_display (display, 1);
 
   if (d->name)
     return build_string (d->name);
@@ -2210,10 +2213,8 @@
   (display)
      Lisp_Object display;
 {
-  struct display *d = get_display (display);
-
-  if (!d)
-    wrong_type_argument (Qdisplay_live_p, display);
+  struct display *d = get_display (display, 1);
+
   if (d->type != output_termcap)
     error ("Display %d is not a termcap display", d->id);
            
@@ -2228,10 +2229,7 @@
   (display)
      Lisp_Object display;
 {
-  struct display *d = get_display (display);
-
-  if (!d)
-    wrong_type_argument (Qdisplay_live_p, display);
+  struct display *d = get_display (display, 1);
 
   if (d->type != output_termcap || d->display_info.tty->name)
     return Qnil;
@@ -3157,7 +3155,7 @@
 {
   struct display *d, *p;
 
-  d = get_display (display);
+  d = get_display (display, 0);
 
   if (!d)
     return Qnil;
@@ -3193,7 +3191,7 @@
   if (!INTEGERP (object))
     return Qnil;
 
-  d = get_display (object);
+  d = get_display (object, 0);
 
   if (!d)
     return Qnil;
--- a/src/termhooks.h	Tue May 03 01:38:40 2005 +0000
+++ b/src/termhooks.h	Tue May 03 01:49:33 2005 +0000
@@ -550,6 +550,9 @@
 #define FRAME_TERMINAL_CODING(f) ((f)->display->terminal_coding)
 #define FRAME_KEYBOARD_CODING(f) ((f)->display->keyboard_coding)
 
+#define DISPLAY_TERMINAL_CODING(d) ((d)->terminal_coding)
+#define DISPLAY_KEYBOARD_CODING(d) ((d)->keyboard_coding)
+
 #define FRAME_RIF(f) ((f)->display->rif)
 
 #define FRAME_DISPLAY(f) ((f)->display)
--- a/src/xfns.c	Tue May 03 01:38:40 2005 +0000
+++ b/src/xfns.c	Tue May 03 01:49:33 2005 +0000
@@ -263,10 +263,8 @@
     }
   else if (INTEGERP (frame))
     {
-      struct display *d = get_display (XINT (frame));
-
-      if (!d)
-        wrong_type_argument (Qdisplay_live_p, frame);
+      struct display *d = get_display (XINT (frame), 1);
+
       if (d->type != output_x_window)
         error ("Display %d is not an X display", XINT (frame));