changeset 83333:40c0ee282254

Implement rudimentary Lisp-level terminal parameters. * lisp/frame.el (terminal-id, terminal-parameters, terminal-parameter) (set-terminal-parameter, terminal-handle-delete-frame): New functions. (delete-frame-functions): Add to `delete-frame-functions' hook. (terminal-parameter-alist): New variable. * lisp/international/encoded-kb.el (saved-input-mode): Delete variable. (encoded-kbd-setup-display): Store the saved input method as a terminal parameter. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-373
author Karoly Lorentey <lorentey@elte.hu>
date Wed, 06 Jul 2005 00:41:41 +0000
parents 6c13700d1c13
children 6afa124501e6
files README.multi-tty lisp/frame.el lisp/international/encoded-kb.el
diffstat 3 files changed, 98 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/README.multi-tty	Tue Jul 05 22:22:24 2005 +0000
+++ b/README.multi-tty	Wed Jul 06 00:41:41 2005 +0000
@@ -355,6 +355,9 @@
 *** New functions: frame-tty-name, frame-tty-type, delete-tty,
     terminal-local-value, set-terminal-local-value
 
+    terminal-id, terminal-parameters, terminal-parameter,
+    set-terminal-parameter
+
 *** New variables: global-key-translation-map
 
 *** The keymaps key-translation-map and function-key-map are now
@@ -382,6 +385,23 @@
 THINGS TO DO
 ------------
 
+** The handling of lisp/term/*.el, and frame creation in general, is a
+   big, big mess.  How come the terminal-specific file is loaded by
+   tty-create-frame-with-faces?  I don't think it is necessary to load
+   these files for each frame; once per terminal should be enough.
+
+** Fix frame-set-background-mode in this branch.  It was recently
+   changed in CVS, and frame.el in multi-tty has not yet been adapted
+   for the changes.  (It needs to look at
+   default-frame-background-mode.)
+
+** I think `(set-)terminal-local-value' and the terminal parameter
+   mechanism should be integrated into a single framework.
+
+** Add the following hooks: after-delete-frame-hook (for server.el,
+   instead of delete-frame-functions),
+   after-delete-terminal-functions, after-create-terminal-functions.
+
 ** Having {reset,init}_all_sys_modes in set-input-mode breaks arrow
    keys on non-selected terminals under screen, and sometimes on other
    terminal types as well.  The other function keys continue to work
--- a/lisp/frame.el	Tue Jul 05 22:22:24 2005 +0000
+++ b/lisp/frame.el	Wed Jul 06 00:41:41 2005 +0000
@@ -1427,6 +1427,69 @@
 
 (substitute-key-definition 'suspend-emacs 'suspend-frame global-map)
 
+
+(defun terminal-id (terminal)
+  "Return the numerical id of terminal TERMINAL.
+
+TERMINAL can be a terminal id, a frame, or nil (meaning the
+selected frame's terminal)."
+  (cond
+   ((integerp terminal)
+    terminal)
+   ((or (null terminal) (framep terminal))
+    (frame-display terminal))
+   (t
+    (error "Invalid argument %s in `terminal-id'" terminal))))
+
+(defvar terminal-parameter-alist nil
+  "An alist of terminal parameter alists.")
+
+(defun terminal-parameters (&optional terminal)
+  "Return the paramater-alist of terminal TERMINAL.
+It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
+
+TERMINAL can be a terminal id, a frame, or nil (meaning the
+selected frame's terminal)."
+  (cdr (assq (terminal-id terminal) terminal-parameter-alist)))
+
+(defun terminal-parameter (terminal parameter)
+  "Return TERMINAL's value for parameter PARAMETER.
+
+TERMINAL can be a terminal id, a frame, or nil (meaning the
+selected frame's terminal)."
+  (cdr (assq parameter (cdr (assq (terminal-id terminal) terminal-parameter-alist)))))
+
+(defun set-terminal-parameter (terminal parameter value)
+  "Set TERMINAL's value for parameter PARAMETER to VALUE.
+Returns the previous value of PARAMETER.
+
+TERMINAL can be a terminal id, a frame, or nil (meaning the
+selected frame's terminal)."
+  (setq terminal (terminal-id terminal))
+  (let* ((alist (assq terminal terminal-parameter-alist))
+	 (pair (assq parameter (cdr alist)))
+	 (result (cdr pair)))
+    (cond
+     (pair (setcdr pair value))
+     (alist (setcdr alist (cons (cons parameter value) (cdr alist))))
+     (t (setq terminal-parameter-alist
+	      (cons (cons terminal
+			  (cons (cons parameter value)
+				nil))
+		    terminal-parameter-alist))))
+    result))
+
+(defun terminal-handle-delete-frame (frame)
+  "Clean up terminal parameters of FRAME, if it's the last frame on its terminal."
+  ;; XXX We assume that the display is closed immediately after the
+  ;; last frame is deleted on it.  It would be better to create a hook
+  ;; called `delete-display-functions', and use it instead.
+  (when (= 1 (length (frames-on-display-list (frame-display frame))))
+    (setq terminal-parameter-alist
+	  (assq-delete-all (frame-display frame) terminal-parameter-alist))))
+
+(add-hook 'delete-frame-functions 'terminal-handle-delete-frame)
+
 (provide 'frame)
 
 ;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56
--- a/lisp/international/encoded-kb.el	Tue Jul 05 22:22:24 2005 +0000
+++ b/lisp/international/encoded-kb.el	Wed Jul 06 00:41:41 2005 +0000
@@ -251,10 +251,6 @@
    (t
     nil)))
 
-;; Input mode at the time Encoded-kbd mode is turned on is saved here.
-;; XXX This should be made display-local somehow.
-(defvar saved-input-mode nil)
-
 ;;;###autoload
 (defun encoded-kbd-setup-display (display)
   "Set up a `key-translation-map' for `keyboard-coding-system' on DISPLAY.
@@ -276,26 +272,29 @@
 	    ;; We are turning on Encoded-kbd mode.
 	    (let ((coding (keyboard-coding-system))
 		  (keymap (make-sparse-keymap "encoded-kb"))
+		  (cim (current-input-mode))
 		  result)
 	      (set-keymap-parent keymap (terminal-local-value 'key-translation-map frame))
 	      (set-terminal-local-value 'key-translation-map frame keymap)
-	      (or saved-input-mode
-		  (setq saved-input-mode (current-input-mode)))
+	      (or (terminal-parameter nil 'encoded-kbd-saved-input-mode)
+		  (set-terminal-parameter nil 'encoded-kbd-saved-input-mode cim))
 	      (setq result (and coding (encoded-kbd-setup-keymap keymap coding)))
 	      (if result
-		  (if (eq result 8)
-		      (set-input-mode
-		       (nth 0 saved-input-mode)
-		       (nth 1 saved-input-mode)
-		       'use-8th-bit
-		       (nth 3 saved-input-mode)))
-		(setq saved-input-mode nil)
+		  (when (and (eq result 8)
+			     (not (memq (nth 2 cim) '(t nil))))
+		    (set-input-mode
+		     (nth 0 cim)
+		     (nth 1 cim)
+		     'use-8th-bit
+		     (nth 3 cim)))
+		(set-terminal-local-value nil 'encoded-kbd-saved-input-mode nil)
 		(error "Unsupported coding system in Encoded-kbd mode: %S"
 		       coding)))
 	  ;; We are turning off Encoded-kbd mode.
-	  (and saved-input-mode
-	       (apply 'set-input-mode saved-input-mode))
-	  (setq saved-input-mode nil))))))
+	  (unless (equal (current-input-mode)
+			 (terminal-parameter nil 'encoded-kbd-saved-input-mode))
+	       (apply 'set-input-mode (terminal-parameter nil 'encoded-kbd-saved-input-mode)))
+	  (set-terminal-parameter nil 'saved-input-mode nil))))))
 
 (provide 'encoded-kb)