changeset 83524:673d62ad74b5

Fix and/or simplify terminal initialization files. * lisp/faces.el (tty-create-frame-with-faces): Set up faces and background mode only after the terminal has been initialized. (frame-set-background-mode): Handle the 'background-mode terminal parameter. (tty-run-terminal-initialization): Add type option. * lisp/term/README: Update. * lisp/term/rxvt.el: Simplify. * lisp/term/xterm.el: Simplify and fix. * lisp/term/*.el: Simplify and fix. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-564
author Karoly Lorentey <lorentey@elte.hu>
date Sat, 20 May 2006 17:02:47 +0000
parents 6ce7108f7eef
children b2e7507b55c6
files README.multi-tty lisp/faces.el lisp/term/AT386.el lisp/term/README lisp/term/apollo.el lisp/term/bobcat.el lisp/term/cygwin.el lisp/term/iris-ansi.el lisp/term/lk201.el lisp/term/news.el lisp/term/rxvt.el lisp/term/vt100.el lisp/term/vt102.el lisp/term/vt125.el lisp/term/vt200.el lisp/term/vt201.el lisp/term/vt220.el lisp/term/vt240.el lisp/term/vt300.el lisp/term/vt320.el lisp/term/vt400.el lisp/term/vt420.el lisp/term/xterm.el
diffstat 23 files changed, 661 insertions(+), 666 deletions(-) [+]
line wrap: on
line diff
--- a/README.multi-tty	Sat May 20 15:28:05 2006 +0000
+++ b/README.multi-tty	Sat May 20 17:02:47 2006 +0000
@@ -404,6 +404,8 @@
 THINGS TO DO
 ------------
 
+** See if `tty-defined-color-alist' needs to be terminal-local.
+
 ** emacsclient -t on the console does not work after su.  You have to
    use non-root accounts or start as root to see this.
 
--- a/lisp/faces.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/faces.el	Sat May 20 17:02:47 2006 +0000
@@ -1598,11 +1598,13 @@
 	  (and (window-system frame)
 	       (x-get-resource "backgroundMode" "BackgroundMode")))
 	 (bg-color (frame-parameter frame 'background-color))
-	 (tty-type (frame-parameter frame 'tty-type))
+	 (terminal-bg-mode (terminal-parameter frame 'background-mode))
+	 (tty-type (tty-type frame))
 	 (bg-mode
 	  (cond (frame-background-mode)
 		(bg-resource
 		 (intern (downcase bg-resource)))
+		(terminal-bg-mode)
 		((and (null (window-system frame))
 		      ;; Unspecified frame background color can only
 		      ;; happen on tty's.
@@ -1826,8 +1828,6 @@
     (unwind-protect
 	(with-selected-frame frame
 	  (tty-handle-reverse-video frame (frame-parameters frame))
-	  (frame-set-background-mode frame)
-	  (face-set-after-frame-default frame)
 
 	  ;; Make sure the kill and yank functions do not touch the X clipboard.
 	  (modify-frame-parameters frame '((interprogram-cut-function . nil)))
@@ -1835,6 +1835,8 @@
 
 	  (set-locale-environment nil frame)
 	  (tty-run-terminal-initialization frame)
+	  (frame-set-background-mode frame)
+	  (face-set-after-frame-default frame)
 	  (setq success t))
       (unless success
 	(delete-frame frame)))
@@ -1857,8 +1859,11 @@
 	      nil))))
   type)
 
-(defun tty-run-terminal-initialization (frame)
-  "Run the special initialization code for the terminal type of FRAME."
+(defun tty-run-terminal-initialization (frame &optional type)
+  "Run the special initialization code for the terminal type of FRAME.
+The optional TYPE parameter may be used to override the autodetected
+terminal type to a different value."
+  (setq type (or type (tty-type frame)))
   ;; Load library for our terminal type.
   ;; User init file can set term-file-prefix to nil to prevent this.
   (with-selected-frame frame
@@ -1874,12 +1879,12 @@
 			     (and file
 				  (or (assoc file load-history)
 				      (load file t t)))))
-		       (tty-type frame))
+		       type)
 	;; Next, try to find a matching initialization function, and call it.
 	(tty-find-type #'(lambda (type)
 			   (fboundp (setq term-init-func
 					  (intern (concat "terminal-init-" type)))))
-		       (tty-type frame))
+		       type)
 	(when (fboundp term-init-func)
 	  (funcall term-init-func))
 	(set-terminal-parameter frame 'terminal-initted term-init-func)))))
--- a/lisp/term/AT386.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/AT386.el	Sat May 20 17:02:47 2006 +0000
@@ -31,10 +31,8 @@
 
 (defun terminal-init-AT386 ()
   "Terminal initialization function for AT386."
-  (if (boundp 'AT386-keypad-map)
-      nil
+  (let ((AT386-keypad-map (lookup-key local-function-key-map "\e[")))
     ;; The terminal initialization should already have set up some keys
-    (setq AT386-keypad-map (lookup-key local-function-key-map "\e["))
     (if (not (keymapp AT386-keypad-map))
 	(error "What?  Your AT386 termcap/terminfo has no keycaps in it"))
 
--- a/lisp/term/README	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/README	Sat May 20 17:02:47 2006 +0000
@@ -1,19 +1,43 @@
    This directory contains files of elisp that customize Emacs for certain
 terminal types.
 
-   When Emacs starts, it checks the TERM environment variable to see what type
-of terminal the user is running on, checks for an elisp file named
-"term/${TERM}.el", and if one exists, loads it.  If that doesn't yield a file
-that exists, the last hyphen and what follows it is stripped.  If that doesn't
-yield a file that exists, the previous hyphen is stripped, and so on until all
-hyphens are gone.  For example, if the terminal type is `aaa-48-foo', Emacs
-will try first `term/aaa-48-foo.el', then `term/aaa-48.el' and finally
-`term/aaa.el'.  Each terminal specific file should contain a function
-named terminal-init-TERMINALNAME (eg terminal-init-aaa-48 for
-term/aaa-48.el) that Emacs will call in order to initialize the
-terminal. The terminal files should not contain any top level forms
-that are executed when the file is loaded, all the initialization
-actions are performed by the terminal-init-TERMINALNAME functions.
+   When Emacs opens a new terminal, it checks the TERM environment variable to
+see what type of terminal the user is running on, searches for an elisp file
+named "term/${TERM}.el", and if one exists, loads it.  If Emacs finds no
+suitable file, then it strips the last hyphen and what follows it from TERM,
+and tries again.  If that still doesn't yield a file, then the previous hyphen
+is stripped, and so on until all hyphens are gone.  For example, if the
+terminal type is `aaa-48-foo', Emacs will try first `term/aaa-48-foo.el', then
+`term/aaa-48.el' and finally `term/aaa.el'.  Emacs stops searching at the
+first file found, and will not load more than one file for any terminal.  Note
+that it is not an error if Emacs is unable to find a terminal initialization
+file; in that case, it will simply proceed with the next step without loading
+any files.
+
+   Once the file has been loaded (or the search failed), Emacs tries to call a
+function named `terminal-init-TERMINALNAME' (eg `terminal-init-aaa-48' for the
+`aaa-48' terminal) in order to initialize the terminal.  Once again, if the
+function is not found, Emacs strips the last component of the name and tries
+again using the shorter name.  This search is independent of the previous file
+search, so that you can have terminal initialization functions for a family of
+terminals collected in a single file named after the family name, and users
+may put terminal initialization functions directly in their .emacs files.
+
+   Note that an individual terminal file is loaded only once in an Emacs
+session; if the same terminal type is opened again, Emacs will simply call the
+initialization function without reloading the file.  Therefore, all the actual
+initialization actions should be collected in terminal-init-* functions; the
+file should not contain any top-level form that is not a function or variable
+declaration.  Simply loading the file should not have any side effect.
+
+   Similarly, the terminal initialization function is called only once on any
+given terminal, when the first frame is created on it.  The function is not
+called for subsequent frames on the same terminal.  Therefore, terminal-init-*
+functions should only modify terminal-local variables (such as
+`local-function-key-map') and terminal parameters.  For example, it is not
+correct to modify frame parameters, since the modifications will only be
+applied for the first frame opened on the terminal.
+
 
    When writing terminal packages, there are some things it is good to keep in
 mind.
--- a/lisp/term/apollo.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/apollo.el	Sat May 20 17:02:47 2006 +0000
@@ -1,7 +1,7 @@
 ;; -*- no-byte-compile: t -*-
 (defun terminal-init-apollo ()
   "Terminal initialization function for apollo."
-  (terminal-init-vt100))
+  (tty-run-terminal-initialization (selected-frame) "vt100"))
 
 ;;; arch-tag: c72f446f-e6b7-4749-90a4-bd68632adacf
 ;;; apollo.el ends here
--- a/lisp/term/bobcat.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/bobcat.el	Sat May 20 17:02:47 2006 +0000
@@ -1,7 +1,7 @@
 ;; -*- no-byte-compile: t -*-
 
 (defun terminal-init-bobcat ()
-  "Terminal initialization function for bobcat."  
+  "Terminal initialization function for bobcat."
   ;; HP terminals usually encourage using ^H as the rubout character
   (keyboard-translate ?\177 ?\^h)
   (keyboard-translate ?\^h ?\177))
--- a/lisp/term/cygwin.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/cygwin.el	Sat May 20 17:02:47 2006 +0000
@@ -3,7 +3,7 @@
 ;;; The Cygwin terminal can't really display underlines.
 
 (defun terminal-init-cygwin ()
-  "Terminal initialization function for cygwin."  
+  "Terminal initialization function for cygwin."
   (tty-no-underline))
 
 ;; arch-tag: ca81ce67-3c41-4883-a29b-4c3d64a21191
--- a/lisp/term/iris-ansi.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/iris-ansi.el	Sat May 20 17:02:47 2006 +0000
@@ -26,321 +26,314 @@
 
 ;;; Code:
 
-(defvar iris-function-map nil
+(defvar iris-function-map (make-sparse-keymap)
   "Function key definitions for SGI xwsh and winterm apps.")
 
-;; Make reloads faster.
-(unless iris-function-map
-  (setq iris-function-map (make-sparse-keymap))
+(define-key iris-function-map "\e[120q" [S-escape])
+(define-key iris-function-map "\e[121q" [C-escape])
 
-  (define-key iris-function-map "\e[120q" [S-escape])
-  (define-key iris-function-map "\e[121q" [C-escape])
-
-  (define-key iris-function-map "\e[001q" [f1])
-  (define-key iris-function-map "\e[013q" [S-f1])
-  (define-key iris-function-map "\e[025q" [C-f1])
+(define-key iris-function-map "\e[001q" [f1])
+(define-key iris-function-map "\e[013q" [S-f1])
+(define-key iris-function-map "\e[025q" [C-f1])
 
 
-  (define-key iris-function-map "\e[002q" [f2])
-  (define-key iris-function-map "\e[014q" [S-f2])
-  (define-key iris-function-map "\e[026q" [C-f2])
-  (define-key iris-function-map "\e[038q" [M-f2])
+(define-key iris-function-map "\e[002q" [f2])
+(define-key iris-function-map "\e[014q" [S-f2])
+(define-key iris-function-map "\e[026q" [C-f2])
+(define-key iris-function-map "\e[038q" [M-f2])
 
-  (define-key iris-function-map "\e[003q" [f3])
-  (define-key iris-function-map "\e[015q" [S-f3])
-  (define-key iris-function-map "\e[027q" [C-f3])
+(define-key iris-function-map "\e[003q" [f3])
+(define-key iris-function-map "\e[015q" [S-f3])
+(define-key iris-function-map "\e[027q" [C-f3])
 
 
-  (define-key iris-function-map "\e[004q" [f4])
-  (define-key iris-function-map "\e[016q" [S-f4])
-  (define-key iris-function-map "\e[028q" [C-f4])
+(define-key iris-function-map "\e[004q" [f4])
+(define-key iris-function-map "\e[016q" [S-f4])
+(define-key iris-function-map "\e[028q" [C-f4])
 
 
-  (define-key iris-function-map "\e[005q" [f5])
-  (define-key iris-function-map "\e[017q" [S-f5])
-  (define-key iris-function-map "\e[029q" [C-f5])
+(define-key iris-function-map "\e[005q" [f5])
+(define-key iris-function-map "\e[017q" [S-f5])
+(define-key iris-function-map "\e[029q" [C-f5])
+
+
+(define-key iris-function-map "\e[006q" [f6])
+(define-key iris-function-map "\e[018q" [S-f6])
+(define-key iris-function-map "\e[030q" [C-f6])
 
 
-  (define-key iris-function-map "\e[006q" [f6])
-  (define-key iris-function-map "\e[018q" [S-f6])
-  (define-key iris-function-map "\e[030q" [C-f6])
+(define-key iris-function-map "\e[007q" [f7])
+(define-key iris-function-map "\e[019q" [S-f7])
+(define-key iris-function-map "\e[031q" [C-f7])
 
 
-  (define-key iris-function-map "\e[007q" [f7])
-  (define-key iris-function-map "\e[019q" [S-f7])
-  (define-key iris-function-map "\e[031q" [C-f7])
+(define-key iris-function-map "\e[008q" [f8])
+(define-key iris-function-map "\e[020q" [S-f8])
+(define-key iris-function-map "\e[032q" [C-f8])
 
 
-  (define-key iris-function-map "\e[008q" [f8])
-  (define-key iris-function-map "\e[020q" [S-f8])
-  (define-key iris-function-map "\e[032q" [C-f8])
-
-
-  (define-key iris-function-map "\e[009q" [f9])
-  (define-key iris-function-map "\e[021q" [S-f9])
-  (define-key iris-function-map "\e[033q" [C-f9])
+(define-key iris-function-map "\e[009q" [f9])
+(define-key iris-function-map "\e[021q" [S-f9])
+(define-key iris-function-map "\e[033q" [C-f9])
 
 
-  (define-key iris-function-map "\e[010q" [f10])
-  (define-key iris-function-map "\e[022q" [S-f10])
-  (define-key iris-function-map "\e[034q" [C-f10])
+(define-key iris-function-map "\e[010q" [f10])
+(define-key iris-function-map "\e[022q" [S-f10])
+(define-key iris-function-map "\e[034q" [C-f10])
 
 
-  (define-key iris-function-map "\e[011q" [f11])
-  (define-key iris-function-map "\e[023q" [S-f11])
-  (define-key iris-function-map "\e[035q" [C-f11])
-  (define-key iris-function-map "\e[047q" [M-f11])
+(define-key iris-function-map "\e[011q" [f11])
+(define-key iris-function-map "\e[023q" [S-f11])
+(define-key iris-function-map "\e[035q" [C-f11])
+(define-key iris-function-map "\e[047q" [M-f11])
 
-  (define-key iris-function-map "\e[012q" [f12])
-  (define-key iris-function-map "\e[024q" [S-f12])
-  (define-key iris-function-map "\e[036q" [C-f12])
-  (define-key iris-function-map "\e[048q" [M-f12])
+(define-key iris-function-map "\e[012q" [f12])
+(define-key iris-function-map "\e[024q" [S-f12])
+(define-key iris-function-map "\e[036q" [C-f12])
+(define-key iris-function-map "\e[048q" [M-f12])
 
 
-  (define-key iris-function-map "\e[057q" [C-`])
-  (define-key iris-function-map "\e[115q" [M-`])
+(define-key iris-function-map "\e[057q" [C-`])
+(define-key iris-function-map "\e[115q" [M-`])
 
-  (define-key iris-function-map "\e[049q" [?\C-1])
-  (define-key iris-function-map "\e[058q" [?\M-1])
+(define-key iris-function-map "\e[049q" [?\C-1])
+(define-key iris-function-map "\e[058q" [?\M-1])
 
 
-  (define-key iris-function-map "\e[059q" [?\M-2])
+(define-key iris-function-map "\e[059q" [?\M-2])
 
-  (define-key iris-function-map "\e[050q" [?\C-3])
-  (define-key iris-function-map "\e[060q" [?\M-3])
+(define-key iris-function-map "\e[050q" [?\C-3])
+(define-key iris-function-map "\e[060q" [?\M-3])
 
-  (define-key iris-function-map "\e[051q" [?\C-4])
-  (define-key iris-function-map "\e[061q" [?\M-4])
+(define-key iris-function-map "\e[051q" [?\C-4])
+(define-key iris-function-map "\e[061q" [?\M-4])
 
-  (define-key iris-function-map "\e[052q" [?\C-5])
-  (define-key iris-function-map "\e[062q" [?\M-5])
+(define-key iris-function-map "\e[052q" [?\C-5])
+(define-key iris-function-map "\e[062q" [?\M-5])
 
 
-  (define-key iris-function-map "\e[063q" [?\M-6])
+(define-key iris-function-map "\e[063q" [?\M-6])
 
-  (define-key iris-function-map "\e[053q" [?\C-7])
-  (define-key iris-function-map "\e[064q" [?\M-7])
+(define-key iris-function-map "\e[053q" [?\C-7])
+(define-key iris-function-map "\e[064q" [?\M-7])
 
-  (define-key iris-function-map "\e[054q" [?\C-8])
-  (define-key iris-function-map "\e[065q" [?\M-8])
+(define-key iris-function-map "\e[054q" [?\C-8])
+(define-key iris-function-map "\e[065q" [?\M-8])
 
-  (define-key iris-function-map "\e[055q" [?\C-9])
-  (define-key iris-function-map "\e[066q" [?\M-9])
+(define-key iris-function-map "\e[055q" [?\C-9])
+(define-key iris-function-map "\e[066q" [?\M-9])
 
-  (define-key iris-function-map "\e[056q" [?\C-0])
-  (define-key iris-function-map "\e[067q" [?\M-0])
+(define-key iris-function-map "\e[056q" [?\C-0])
+(define-key iris-function-map "\e[067q" [?\M-0])
 
-  (define-key iris-function-map "\e[068q" [?\M--])
+(define-key iris-function-map "\e[068q" [?\M--])
 
-  (define-key iris-function-map "\e[069q" [?\C-=])
-  (define-key iris-function-map "\e[070q" [?\M-=])
+(define-key iris-function-map "\e[069q" [?\C-=])
+(define-key iris-function-map "\e[070q" [?\M-=])
 
-  ;; I don't know what to do with those.
-  ;;(define-key iris-function-map "^H" [<del>])
-  ;;(define-key iris-function-map "^H" [S-<del>])
-  ;;(define-key iris-function-map "\177" [C-<del>])
-  ;;(define-key iris-function-map "\e[071q" [M-<del>])
+;; I don't know what to do with those.
+;;(define-key iris-function-map "^H" [<del>])
+;;(define-key iris-function-map "^H" [S-<del>])
+;;(define-key iris-function-map "\177" [C-<del>])
+;;(define-key iris-function-map "\e[071q" [M-<del>])
 
-  (define-key iris-function-map "\e[Z" [?\S-\t])
-  (define-key iris-function-map "\e[072q" [?\C-\t])
-  ;; This only works if you remove the M-TAB keybing from the system.4Dwmrc
-  ;; our your ~/.4Dwmrc, if you use the 4Dwm window manager.
-  (define-key iris-function-map "\e[073q" [?\M-\t])
+(define-key iris-function-map "\e[Z" [?\S-\t])
+(define-key iris-function-map "\e[072q" [?\C-\t])
+;; This only works if you remove the M-TAB keybing from the system.4Dwmrc
+;; our your ~/.4Dwmrc, if you use the 4Dwm window manager.
+(define-key iris-function-map "\e[073q" [?\M-\t])
 
-  (define-key iris-function-map "\e[074q" [?\M-q])
+(define-key iris-function-map "\e[074q" [?\M-q])
 
-  (define-key iris-function-map "\e[075q" [?\M-w])
+(define-key iris-function-map "\e[075q" [?\M-w])
 
-  (define-key iris-function-map "\e[076q" [?\M-e])
+(define-key iris-function-map "\e[076q" [?\M-e])
 
-  (define-key iris-function-map "\e[077q" [?\M-r])
+(define-key iris-function-map "\e[077q" [?\M-r])
 
-  (define-key iris-function-map "\e[078q" [?\M-t])
+(define-key iris-function-map "\e[078q" [?\M-t])
 
-  (define-key iris-function-map "\e[079q" [?\M-y])
+(define-key iris-function-map "\e[079q" [?\M-y])
 
-  (define-key iris-function-map "\e[080q" [?\M-u])
+(define-key iris-function-map "\e[080q" [?\M-u])
 
-  (define-key iris-function-map "\e[081q" [?\M-i])
+(define-key iris-function-map "\e[081q" [?\M-i])
 
-  (define-key iris-function-map "\e[082q" [?\M-o])
+(define-key iris-function-map "\e[082q" [?\M-o])
 
-  (define-key iris-function-map "\e[083q" [?\M-p])
+(define-key iris-function-map "\e[083q" [?\M-p])
 
-  (define-key iris-function-map "\e[084q" [?\M-\[])
+(define-key iris-function-map "\e[084q" [?\M-\[])
 
-  (define-key iris-function-map "\e[085q" [?\M-\]])
+(define-key iris-function-map "\e[085q" [?\M-\]])
 
-  (define-key iris-function-map "\e[086q" [?\M-\\])
+(define-key iris-function-map "\e[086q" [?\M-\\])
 
-  (define-key iris-function-map "\e[087q" [?\M-a])
+(define-key iris-function-map "\e[087q" [?\M-a])
 
-  (define-key iris-function-map "\e[088q" [?\M-s])
+(define-key iris-function-map "\e[088q" [?\M-s])
 
-  (define-key iris-function-map "\e[089q" [?\M-d])
+(define-key iris-function-map "\e[089q" [?\M-d])
 
-  (define-key iris-function-map "\e[090q" [?\M-f])
+(define-key iris-function-map "\e[090q" [?\M-f])
 
-  (define-key iris-function-map "\e[091q" [?\M-g])
+(define-key iris-function-map "\e[091q" [?\M-g])
 
-  (define-key iris-function-map "\e[092q" [?\M-h])
+(define-key iris-function-map "\e[092q" [?\M-h])
 
-  (define-key iris-function-map "\e[093q" [?\M-j])
+(define-key iris-function-map "\e[093q" [?\M-j])
 
-  (define-key iris-function-map "\e[094q" [?\M-k])
+(define-key iris-function-map "\e[094q" [?\M-k])
 
-  (define-key iris-function-map "\e[095q" [?\M-l])
+(define-key iris-function-map "\e[095q" [?\M-l])
 
-  (define-key iris-function-map "\e[096q" [?\C-\;])
-  (define-key iris-function-map "\e[097q" [?\M-:]) ;; we are cheating
+(define-key iris-function-map "\e[096q" [?\C-\;])
+(define-key iris-function-map "\e[097q" [?\M-:]) ;; we are cheating
 					          ;; here, this is realy
 						  ;; M-;, but M-:
 						  ;; generates the same
 						  ;; string and is more
 						  ;; usefull.
 
-  (define-key iris-function-map "\e[098q" [?\C-'])
-  (define-key iris-function-map "\e[099q" [?\M-'])
+(define-key iris-function-map "\e[098q" [?\C-'])
+(define-key iris-function-map "\e[099q" [?\M-'])
 
-  (define-key iris-function-map "\e[100q" [?\M-\n])
+(define-key iris-function-map "\e[100q" [?\M-\n])
 
-  (define-key iris-function-map "\e[101q" [?\M-z])
+(define-key iris-function-map "\e[101q" [?\M-z])
 
-  (define-key iris-function-map "\e[102q" [?\M-x])
+(define-key iris-function-map "\e[102q" [?\M-x])
 
-  (define-key iris-function-map "\e[103q" [?\M-c])
+(define-key iris-function-map "\e[103q" [?\M-c])
 
-  (define-key iris-function-map "\e[104q" [?\M-v])
+(define-key iris-function-map "\e[104q" [?\M-v])
 
-  (define-key iris-function-map "\e[105q" [?\M-b])
+(define-key iris-function-map "\e[105q" [?\M-b])
 
-  (define-key iris-function-map "\e[106q" [M-n])
+(define-key iris-function-map "\e[106q" [M-n])
 
-  (define-key iris-function-map "\e[107q" [M-m])
+(define-key iris-function-map "\e[107q" [M-m])
 
-  (define-key iris-function-map "\e[108q" [?\C-,])
-  (define-key iris-function-map "\e[109q" [?\M-,])
+(define-key iris-function-map "\e[108q" [?\C-,])
+(define-key iris-function-map "\e[109q" [?\M-,])
 
-  (define-key iris-function-map "\e[110q" [?\C-.])
-  (define-key iris-function-map "\e[111q" [?\M-.])
+(define-key iris-function-map "\e[110q" [?\C-.])
+(define-key iris-function-map "\e[111q" [?\M-.])
 
-  (define-key iris-function-map "\e[112q" [?\C-/])
-  (define-key iris-function-map "\e[113q" [?\M-/])
+(define-key iris-function-map "\e[112q" [?\C-/])
+(define-key iris-function-map "\e[113q" [?\M-/])
 
-  (define-key iris-function-map "\e[139q" [insert])
-  (define-key iris-function-map "\e[139q" [S-insert])
-  (define-key iris-function-map "\e[140q" [C-insert])
-  (define-key iris-function-map "\e[141q" [M-insert])
+(define-key iris-function-map "\e[139q" [insert])
+(define-key iris-function-map "\e[139q" [S-insert])
+(define-key iris-function-map "\e[140q" [C-insert])
+(define-key iris-function-map "\e[141q" [M-insert])
 
-  (define-key iris-function-map "\e[H" [home])
-  (define-key iris-function-map "\e[143q" [S-home])
-  (define-key iris-function-map "\e[144q" [C-home])
+(define-key iris-function-map "\e[H" [home])
+(define-key iris-function-map "\e[143q" [S-home])
+(define-key iris-function-map "\e[144q" [C-home])
 
 
-  (define-key iris-function-map "\e[150q" [prior])
-  (define-key iris-function-map "\e[151q" [S-prior]) ;; those don't seem
+(define-key iris-function-map "\e[150q" [prior])
+(define-key iris-function-map "\e[151q" [S-prior]) ;; those don't seem
 						    ;; to generate
 						    ;; anything
-  (define-key iris-function-map "\e[152q" [C-prior])
+(define-key iris-function-map "\e[152q" [C-prior])
 
 
-  ;; (define-key iris-function-map "^?" [delete]) ?? something else seems to take care of this.
-  (define-key iris-function-map "\e[P" [S-delete])
-  (define-key iris-function-map "\e[142q" [C-delete])
-  (define-key iris-function-map "\e[M" [M-delete])
+;; (define-key iris-function-map "^?" [delete]) ?? something else seems to take care of this.
+(define-key iris-function-map "\e[P" [S-delete])
+(define-key iris-function-map "\e[142q" [C-delete])
+(define-key iris-function-map "\e[M" [M-delete])
 
-  (define-key iris-function-map "\e[146q" [end])
-  (define-key iris-function-map "\e[147q" [S-end]) ;; those don't seem to
+(define-key iris-function-map "\e[146q" [end])
+(define-key iris-function-map "\e[147q" [S-end]) ;; those don't seem to
 						  ;; generate anything
-  (define-key iris-function-map "\e[148q" [C-end])
+(define-key iris-function-map "\e[148q" [C-end])
 
-  (define-key iris-function-map "\e[154q" [next])
-  (define-key iris-function-map "\e[155q" [S-next])
-  (define-key iris-function-map "\e[156q" [C-next])
+(define-key iris-function-map "\e[154q" [next])
+(define-key iris-function-map "\e[155q" [S-next])
+(define-key iris-function-map "\e[156q" [C-next])
 
 
-  (define-key iris-function-map "\e[161q" [S-up])
-  (define-key iris-function-map "\e[162q" [C-up])
-  (define-key iris-function-map "\e[163q" [M-up])
+(define-key iris-function-map "\e[161q" [S-up])
+(define-key iris-function-map "\e[162q" [C-up])
+(define-key iris-function-map "\e[163q" [M-up])
 
-  (define-key iris-function-map "\e[158q" [S-left])
-  (define-key iris-function-map "\e[159q" [C-left])
-  (define-key iris-function-map "\e[160q" [M-left])
+(define-key iris-function-map "\e[158q" [S-left])
+(define-key iris-function-map "\e[159q" [C-left])
+(define-key iris-function-map "\e[160q" [M-left])
 
-  (define-key iris-function-map "\e[164q" [S-down])
-  (define-key iris-function-map "\e[165q" [C-down])
-  (define-key iris-function-map "\e[166q" [M-down])
+(define-key iris-function-map "\e[164q" [S-down])
+(define-key iris-function-map "\e[165q" [C-down])
+(define-key iris-function-map "\e[166q" [M-down])
 
-  (define-key iris-function-map "\e[167q" [S-right])
-  (define-key iris-function-map "\e[168q" [C-right])
-  (define-key iris-function-map "\e[169q" [M-right])
+(define-key iris-function-map "\e[167q" [S-right])
+(define-key iris-function-map "\e[168q" [C-right])
+(define-key iris-function-map "\e[169q" [M-right])
 
-  ;; Keypad functions, most of those are untested.
-  (define-key iris-function-map "\e[179q" [?\C-/])
-  (define-key iris-function-map "\e[180q" [?\M-/])
+;; Keypad functions, most of those are untested.
+(define-key iris-function-map "\e[179q" [?\C-/])
+(define-key iris-function-map "\e[180q" [?\M-/])
 
-  (define-key iris-function-map "\e[187q" [?\C-*])
-  (define-key iris-function-map "\e[188q" [?\M-*])
+(define-key iris-function-map "\e[187q" [?\C-*])
+(define-key iris-function-map "\e[188q" [?\M-*])
 
-  (define-key iris-function-map "\e[198q" [?\C--])
-  (define-key iris-function-map "\e[199q" [?\M--])
+(define-key iris-function-map "\e[198q" [?\C--])
+(define-key iris-function-map "\e[199q" [?\M--])
 
-  ;; Something else takes care of home, up, prior, down, left, right, next
-  ;(define-key iris-function-map "\e[H" [home])
-  (define-key iris-function-map "\e[172q" [C-home])
+;; Something else takes care of home, up, prior, down, left, right, next
+;(define-key iris-function-map "\e[H" [home])
+(define-key iris-function-map "\e[172q" [C-home])
 
-  ;(define-key iris-function-map "\e[A" [up])
-  (define-key iris-function-map "\e[182q" [C-up])
+;(define-key iris-function-map "\e[A" [up])
+(define-key iris-function-map "\e[182q" [C-up])
 
 
-  ;(define-key iris-function-map "\e[150q" [prior])
-  (define-key iris-function-map "\e[190q" [C-prior])
+;(define-key iris-function-map "\e[150q" [prior])
+(define-key iris-function-map "\e[190q" [C-prior])
 
 
-  (define-key iris-function-map "\e[200q" [?\C-+])
-  (define-key iris-function-map "\e[201q" [?\M-+])
+(define-key iris-function-map "\e[200q" [?\C-+])
+(define-key iris-function-map "\e[201q" [?\M-+])
 
-  ;(define-key iris-function-map "\e[D" [left])
-  (define-key iris-function-map "\e[174q" [C-left])
+;(define-key iris-function-map "\e[D" [left])
+(define-key iris-function-map "\e[174q" [C-left])
 
 
-  (define-key iris-function-map "\e[000q" [begin])
-  (define-key iris-function-map "\e[184q" [C-begin])
+(define-key iris-function-map "\e[000q" [begin])
+(define-key iris-function-map "\e[184q" [C-begin])
 
 
-  ;(define-key iris-function-map "\e[C" [right])
-  (define-key iris-function-map "\e[192q" [C-right])
+;(define-key iris-function-map "\e[C" [right])
+(define-key iris-function-map "\e[192q" [C-right])
 
-  ;(define-key iris-function-map "\e[146q" [end])
-  (define-key iris-function-map "\e[176q" [C-end])
+;(define-key iris-function-map "\e[146q" [end])
+(define-key iris-function-map "\e[176q" [C-end])
 
-  ;(define-key iris-function-map "\e[B" [down])
-  (define-key iris-function-map "\e[186q" [C-down])
+;(define-key iris-function-map "\e[B" [down])
+(define-key iris-function-map "\e[186q" [C-down])
 
-  ;(define-key iris-function-map "\e[154q" [next])
-  (define-key iris-function-map "\e[194q" [C-next])
+;(define-key iris-function-map "\e[154q" [next])
+(define-key iris-function-map "\e[194q" [C-next])
 
 
-  (define-key iris-function-map "\e[100q" [M-enter])
+(define-key iris-function-map "\e[100q" [M-enter])
 
-  (define-key iris-function-map "\e[139q" [insert])
-  (define-key iris-function-map "\e[178q" [C-inset])
+(define-key iris-function-map "\e[139q" [insert])
+(define-key iris-function-map "\e[178q" [C-inset])
 
-  (define-key iris-function-map "\e[P" [delete])
-  (define-key iris-function-map "\e[196q" [C-delete])
-  (define-key iris-function-map "\e[197q" [M-delete]))
+(define-key iris-function-map "\e[P" [delete])
+(define-key iris-function-map "\e[196q" [C-delete])
+(define-key iris-function-map "\e[197q" [M-delete])
 
 (defun terminal-init-iris-ansi ()
   "Terminal initialization function for iris-ansi."
-  ;; The terminal-local stuff only need to be set up on the first
-  ;; frame on that device.
-  (when (eq 1 (length (frames-on-display-list)))
-    ;; Use inheritance to let the main keymap override these defaults.
-    ;; This way we don't override terminfo-derived settings or settings
-    ;; made in the .emacs file.
-    (let ((m (copy-keymap iris-function-map)))
-      (set-keymap-parent m (keymap-parent local-function-key-map))
-      (set-keymap-parent local-function-key-map m))))
+  ;; Use inheritance to let the main keymap override these defaults.
+  ;; This way we don't override terminfo-derived settings or settings
+  ;; made in the .emacs file.
+  (let ((m (copy-keymap iris-function-map)))
+    (set-keymap-parent m (keymap-parent local-function-key-map))
+    (set-keymap-parent local-function-key-map m)))
 
 ;;; arch-tag: b1d0e73a-bb7d-47be-9fb2-6fb126469a1b
 ;;; iris-ansi.el ends here
--- a/lisp/term/lk201.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/lk201.el	Sat May 20 17:02:47 2006 +0000
@@ -1,91 +1,83 @@
 ;; -*- no-byte-compile: t -*-
 ;; Define function key sequences for DEC terminals.
 
-(defvar lk201-function-map nil
+(defvar lk201-function-map (make-sparse-keymap)
   "Function key definitions for DEC terminals.")
 
-;; Make reloads faster.
-(unless lk201-function-map
-  (setq lk201-function-map (make-sparse-keymap))
-
-  ;; Termcap or terminfo should set these.
-  ;; (define-key lk201-function-map "\e[A" [up])
-  ;; (define-key lk201-function-map "\e[B" [down])
-  ;; (define-key lk201-function-map "\e[C" [right])
-  ;; (define-key lk201-function-map "\e[D" [left])
+;; Termcap or terminfo should set these.
+;; (define-key lk201-function-map "\e[A" [up])
+;; (define-key lk201-function-map "\e[B" [down])
+;; (define-key lk201-function-map "\e[C" [right])
+;; (define-key lk201-function-map "\e[D" [left])
 
-  (define-key lk201-function-map "\e[1~" [find])
-  (define-key lk201-function-map "\e[2~" [insert])
-  (define-key lk201-function-map "\e[3~" [delete])
-  (define-key lk201-function-map "\e[4~" [select])
-  (define-key lk201-function-map "\e[5~" [prior])
-  (define-key lk201-function-map "\e[6~" [next])
-  (define-key lk201-function-map "\e[11~" [f1])
-  (define-key lk201-function-map "\e[12~" [f2])
-  (define-key lk201-function-map "\e[13~" [f3])
-  (define-key lk201-function-map "\e[14~" [f4])
-  (define-key lk201-function-map "\e[15~" [f5])
-  (define-key lk201-function-map "\e[17~" [f6])
-  (define-key lk201-function-map "\e[18~" [f7])
-  (define-key lk201-function-map "\e[19~" [f8])
-  (define-key lk201-function-map "\e[20~" [f9])
-  (define-key lk201-function-map "\e[21~" [f10])
-  ;; Customarily F11 is used as the ESC key.
-  ;; The file that includes this one, takes care of that.
-  (define-key lk201-function-map "\e[23~" [f11])
-  (define-key lk201-function-map "\e[24~" [f12])
-  (define-key lk201-function-map "\e[25~" [f13])
-  (define-key lk201-function-map "\e[26~" [f14])
-  (define-key lk201-function-map "\e[28~" [help])
-  (define-key lk201-function-map "\e[29~" [menu])
-  (define-key lk201-function-map "\e[31~" [f17])
-  (define-key lk201-function-map "\e[32~" [f18])
-  (define-key lk201-function-map "\e[33~" [f19])
-  (define-key lk201-function-map "\e[34~" [f20])
+(define-key lk201-function-map "\e[1~" [find])
+(define-key lk201-function-map "\e[2~" [insert])
+(define-key lk201-function-map "\e[3~" [delete])
+(define-key lk201-function-map "\e[4~" [select])
+(define-key lk201-function-map "\e[5~" [prior])
+(define-key lk201-function-map "\e[6~" [next])
+(define-key lk201-function-map "\e[11~" [f1])
+(define-key lk201-function-map "\e[12~" [f2])
+(define-key lk201-function-map "\e[13~" [f3])
+(define-key lk201-function-map "\e[14~" [f4])
+(define-key lk201-function-map "\e[15~" [f5])
+(define-key lk201-function-map "\e[17~" [f6])
+(define-key lk201-function-map "\e[18~" [f7])
+(define-key lk201-function-map "\e[19~" [f8])
+(define-key lk201-function-map "\e[20~" [f9])
+(define-key lk201-function-map "\e[21~" [f10])
+;; Customarily F11 is used as the ESC key.
+;; The file that includes this one, takes care of that.
+(define-key lk201-function-map "\e[23~" [f11])
+(define-key lk201-function-map "\e[24~" [f12])
+(define-key lk201-function-map "\e[25~" [f13])
+(define-key lk201-function-map "\e[26~" [f14])
+(define-key lk201-function-map "\e[28~" [help])
+(define-key lk201-function-map "\e[29~" [menu])
+(define-key lk201-function-map "\e[31~" [f17])
+(define-key lk201-function-map "\e[32~" [f18])
+(define-key lk201-function-map "\e[33~" [f19])
+(define-key lk201-function-map "\e[34~" [f20])
 
-  ;; Termcap or terminfo should set these.
-  ;; (define-key lk201-function-map "\eOA" [up])
-  ;; (define-key lk201-function-map "\eOB" [down])
-  ;; (define-key lk201-function-map "\eOC" [right])
-  ;; (define-key lk201-function-map "\eOD" [left])
+;; Termcap or terminfo should set these.
+;; (define-key lk201-function-map "\eOA" [up])
+;; (define-key lk201-function-map "\eOB" [down])
+;; (define-key lk201-function-map "\eOC" [right])
+;; (define-key lk201-function-map "\eOD" [left])
 
-  ;; Termcap or terminfo should set these, but doesn't properly.
-  ;; Termcap sets these to k1-k4, which get mapped to f1-f4 in term.c
-  (define-key lk201-function-map "\eOP" [kp-f1])
-  (define-key lk201-function-map "\eOQ" [kp-f2])
-  (define-key lk201-function-map "\eOR" [kp-f3])
-  (define-key lk201-function-map "\eOS" [kp-f4])
+;; Termcap or terminfo should set these, but doesn't properly.
+;; Termcap sets these to k1-k4, which get mapped to f1-f4 in term.c
+(define-key lk201-function-map "\eOP" [kp-f1])
+(define-key lk201-function-map "\eOQ" [kp-f2])
+(define-key lk201-function-map "\eOR" [kp-f3])
+(define-key lk201-function-map "\eOS" [kp-f4])
 
-  (define-key lk201-function-map "\eOI" [kp-tab])
-  (define-key lk201-function-map "\eOj" [kp-multiply])
-  (define-key lk201-function-map "\eOk" [kp-add])
-  (define-key lk201-function-map "\eOl" [kp-separator])
-  (define-key lk201-function-map "\eOM" [kp-enter])
-  (define-key lk201-function-map "\eOm" [kp-subtract])
-  (define-key lk201-function-map "\eOn" [kp-decimal])
-  (define-key lk201-function-map "\eOo" [kp-divide])
-  (define-key lk201-function-map "\eOp" [kp-0])
-  (define-key lk201-function-map "\eOq" [kp-1])
-  (define-key lk201-function-map "\eOr" [kp-2])
-  (define-key lk201-function-map "\eOs" [kp-3])
-  (define-key lk201-function-map "\eOt" [kp-4])
-  (define-key lk201-function-map "\eOu" [kp-5])
-  (define-key lk201-function-map "\eOv" [kp-6])
-  (define-key lk201-function-map "\eOw" [kp-7])
-  (define-key lk201-function-map "\eOx" [kp-8])
-  (define-key lk201-function-map "\eOy" [kp-9]))
+(define-key lk201-function-map "\eOI" [kp-tab])
+(define-key lk201-function-map "\eOj" [kp-multiply])
+(define-key lk201-function-map "\eOk" [kp-add])
+(define-key lk201-function-map "\eOl" [kp-separator])
+(define-key lk201-function-map "\eOM" [kp-enter])
+(define-key lk201-function-map "\eOm" [kp-subtract])
+(define-key lk201-function-map "\eOn" [kp-decimal])
+(define-key lk201-function-map "\eOo" [kp-divide])
+(define-key lk201-function-map "\eOp" [kp-0])
+(define-key lk201-function-map "\eOq" [kp-1])
+(define-key lk201-function-map "\eOr" [kp-2])
+(define-key lk201-function-map "\eOs" [kp-3])
+(define-key lk201-function-map "\eOt" [kp-4])
+(define-key lk201-function-map "\eOu" [kp-5])
+(define-key lk201-function-map "\eOv" [kp-6])
+(define-key lk201-function-map "\eOw" [kp-7])
+(define-key lk201-function-map "\eOx" [kp-8])
+(define-key lk201-function-map "\eOy" [kp-9]))
 
 (defun terminal-init-lk201 ()
-  ;; The terminal-local stuff only need to be set up on the first
-  ;; frame on that device.
-  (when (eq 1 (length (frames-on-display-list)))
-
-    ;; Use inheritance to let the main keymap override these defaults.
-    ;; This way we don't override terminfo-derived settings or settings
-    ;; made in the .emacs file.
-    (let ((m (copy-keymap lk201-function-map)))
-      (set-keymap-parent m (keymap-parent local-function-key-map))
-      (set-keymap-parent local-function-key-map m))))
+  ;; Use inheritance to let the main keymap override these defaults.
+  ;; This way we don't override terminfo-derived settings or settings
+  ;; made in the .emacs file.
+  (let ((m (copy-keymap lk201-function-map)))
+    (set-keymap-parent m (keymap-parent local-function-key-map))
+    (set-keymap-parent local-function-key-map m)))
 
 ;;; arch-tag: 7ffb4444-6a23-43e1-b457-43cf4f673c0d
 ;;; lk201.el ends here
--- a/lisp/term/news.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/news.el	Sat May 20 17:02:47 2006 +0000
@@ -31,10 +31,8 @@
 
 (defun terminal-init-news ()
   "Terminal initialization function for news."
-  (if (boundp 'news-fkey-prefix)
-      nil
-    ;; The terminal initialization should already have set up some keys
-    (setq news-fkey-prefix (lookup-key local-function-key-map "\eO"))
+  ;; The terminal initialization should already have set up some keys
+  (let ((news-fkey-prefix (lookup-key local-function-key-map "\eO")))
     (if (not (keymapp news-fkey-prefix))
 	(error "What?  Your news termcap/terminfo has no keycaps in it"))
 
--- a/lisp/term/rxvt.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/rxvt.el	Sat May 20 17:02:47 2006 +0000
@@ -26,149 +26,142 @@
 
 ;;; Code:
 
-(defvar rxvt-function-map nil
+(defvar rxvt-function-map (make-sparse-keymap)
   "Function key overrides for rxvt.")
 
-;; Protect against reloads.
-(unless rxvt-function-map
-  (setq rxvt-function-map (make-sparse-keymap))
+;; Set up function-key-map entries that termcap and terminfo don't know.
+(define-key rxvt-function-map "\e[A" [up])
+(define-key rxvt-function-map "\e[B" [down])
+(define-key rxvt-function-map "\e[C" [right])
+(define-key rxvt-function-map "\e[D" [left])
+(define-key rxvt-function-map "\e[2~" [insert])
+(define-key rxvt-function-map "\e[3~" [delete])
+(define-key rxvt-function-map "\e[4~" [select])
+(define-key rxvt-function-map "\e[5~" [prior])
+(define-key rxvt-function-map "\e[6~" [next])
+(define-key rxvt-function-map "\e[7~" [home])
+(define-key rxvt-function-map "\e[8~" [end])
+(define-key rxvt-function-map "\e[11~" [f1])
+(define-key rxvt-function-map "\e[12~" [f2])
+(define-key rxvt-function-map "\e[13~" [f3])
+(define-key rxvt-function-map "\e[14~" [f4])
+(define-key rxvt-function-map "\e[15~" [f5])
+(define-key rxvt-function-map "\e[17~" [f6])
+(define-key rxvt-function-map "\e[18~" [f7])
+(define-key rxvt-function-map "\e[19~" [f8])
+(define-key rxvt-function-map "\e[20~" [f9])
+(define-key rxvt-function-map "\e[21~" [f10])
+;; The strings emitted by f11 and f12 are the same as the strings
+;; emitted by S-f1 and S-f2, so don't define f11 and f12.
+;; (define-key rxvt-function-map "\e[23~" [f11])
+;; (define-key rxvt-function-map "\e[24~" [f12])
+(define-key rxvt-function-map "\e[29~" [print])
 
-  ;; Set up function-key-map entries that termcap and terminfo don't know.
-  (define-key rxvt-function-map "\e[A" [up])
-  (define-key rxvt-function-map "\e[B" [down])
-  (define-key rxvt-function-map "\e[C" [right])
-  (define-key rxvt-function-map "\e[D" [left])
-  (define-key rxvt-function-map "\e[2~" [insert])
-  (define-key rxvt-function-map "\e[3~" [delete])
-  (define-key rxvt-function-map "\e[4~" [select])
-  (define-key rxvt-function-map "\e[5~" [prior])
-  (define-key rxvt-function-map "\e[6~" [next])
-  (define-key rxvt-function-map "\e[7~" [home])
-  (define-key rxvt-function-map "\e[8~" [end])
-  (define-key rxvt-function-map "\e[11~" [f1])
-  (define-key rxvt-function-map "\e[12~" [f2])
-  (define-key rxvt-function-map "\e[13~" [f3])
-  (define-key rxvt-function-map "\e[14~" [f4])
-  (define-key rxvt-function-map "\e[15~" [f5])
-  (define-key rxvt-function-map "\e[17~" [f6])
-  (define-key rxvt-function-map "\e[18~" [f7])
-  (define-key rxvt-function-map "\e[19~" [f8])
-  (define-key rxvt-function-map "\e[20~" [f9])
-  (define-key rxvt-function-map "\e[21~" [f10])
-  ;; The strings emitted by f11 and f12 are the same as the strings
-  ;; emitted by S-f1 and S-f2, so don't define f11 and f12.
-  ;; (define-key rxvt-function-map "\e[23~" [f11])
-  ;; (define-key rxvt-function-map "\e[24~" [f12])
-  (define-key rxvt-function-map "\e[29~" [print])
-
-  (define-key rxvt-function-map "\e[11^" [C-f1])
-  (define-key rxvt-function-map "\e[12^" [C-f2])
-  (define-key rxvt-function-map "\e[13^" [C-f3])
-  (define-key rxvt-function-map "\e[14^" [C-f4])
-  (define-key rxvt-function-map "\e[15^" [C-f5])
-  (define-key rxvt-function-map "\e[17^" [C-f6])
-  (define-key rxvt-function-map "\e[18^" [C-f7])
-  (define-key rxvt-function-map "\e[19^" [C-f8])
-  (define-key rxvt-function-map "\e[20^" [C-f9])
-  (define-key rxvt-function-map "\e[21^" [C-f10])
+(define-key rxvt-function-map "\e[11^" [C-f1])
+(define-key rxvt-function-map "\e[12^" [C-f2])
+(define-key rxvt-function-map "\e[13^" [C-f3])
+(define-key rxvt-function-map "\e[14^" [C-f4])
+(define-key rxvt-function-map "\e[15^" [C-f5])
+(define-key rxvt-function-map "\e[17^" [C-f6])
+(define-key rxvt-function-map "\e[18^" [C-f7])
+(define-key rxvt-function-map "\e[19^" [C-f8])
+(define-key rxvt-function-map "\e[20^" [C-f9])
+(define-key rxvt-function-map "\e[21^" [C-f10])
 
-  (define-key rxvt-function-map "\e[23~" [S-f1])
-  (define-key rxvt-function-map "\e[24~" [S-f2])
-  (define-key rxvt-function-map "\e[25~" [S-f3])
-  (define-key rxvt-function-map "\e[26~" [S-f4])
-  (define-key rxvt-function-map "\e[28~" [S-f5])
-  (define-key rxvt-function-map "\e[29~" [S-f6])
-  (define-key rxvt-function-map "\e[31~" [S-f7])
-  (define-key rxvt-function-map "\e[32~" [S-f8])
-  (define-key rxvt-function-map "\e[33~" [S-f9])
-  (define-key rxvt-function-map "\e[34~" [S-f10])
+(define-key rxvt-function-map "\e[23~" [S-f1])
+(define-key rxvt-function-map "\e[24~" [S-f2])
+(define-key rxvt-function-map "\e[25~" [S-f3])
+(define-key rxvt-function-map "\e[26~" [S-f4])
+(define-key rxvt-function-map "\e[28~" [S-f5])
+(define-key rxvt-function-map "\e[29~" [S-f6])
+(define-key rxvt-function-map "\e[31~" [S-f7])
+(define-key rxvt-function-map "\e[32~" [S-f8])
+(define-key rxvt-function-map "\e[33~" [S-f9])
+(define-key rxvt-function-map "\e[34~" [S-f10])
 
-  (define-key rxvt-function-map "\e[23^" [C-S-f1])
-  (define-key rxvt-function-map "\e[24^" [C-S-f2])
-  (define-key rxvt-function-map "\e[25^" [C-S-f3])
-  (define-key rxvt-function-map "\e[26^" [C-S-f4])
-  (define-key rxvt-function-map "\e[28^" [C-S-f5])
-  (define-key rxvt-function-map "\e[29^" [C-S-f6])
-  (define-key rxvt-function-map "\e[31^" [C-S-f7])
-  (define-key rxvt-function-map "\e[32^" [C-S-f8])
-  (define-key rxvt-function-map "\e[33^" [C-S-f9])
-  (define-key rxvt-function-map "\e[34^" [C-S-f10])
+(define-key rxvt-function-map "\e[23^" [C-S-f1])
+(define-key rxvt-function-map "\e[24^" [C-S-f2])
+(define-key rxvt-function-map "\e[25^" [C-S-f3])
+(define-key rxvt-function-map "\e[26^" [C-S-f4])
+(define-key rxvt-function-map "\e[28^" [C-S-f5])
+(define-key rxvt-function-map "\e[29^" [C-S-f6])
+(define-key rxvt-function-map "\e[31^" [C-S-f7])
+(define-key rxvt-function-map "\e[32^" [C-S-f8])
+(define-key rxvt-function-map "\e[33^" [C-S-f9])
+(define-key rxvt-function-map "\e[34^" [C-S-f10])
 
-  (define-key rxvt-function-map "\e[2^" [C-insert])
-  (define-key rxvt-function-map "\e[3^" [C-delete])
-  (define-key rxvt-function-map "\e[5^" [C-prior])
-  (define-key rxvt-function-map "\e[6^" [C-next])
-  (define-key rxvt-function-map "\e[7^" [C-home])
-  (define-key rxvt-function-map "\e[8^" [C-end])
-  (define-key rxvt-function-map "\eOd" [C-left])
-  (define-key rxvt-function-map "\eOc" [C-right])
-  (define-key rxvt-function-map "\eOa" [C-up])
-  (define-key rxvt-function-map "\eOb" [C-down])
+(define-key rxvt-function-map "\e[2^" [C-insert])
+(define-key rxvt-function-map "\e[3^" [C-delete])
+(define-key rxvt-function-map "\e[5^" [C-prior])
+(define-key rxvt-function-map "\e[6^" [C-next])
+(define-key rxvt-function-map "\e[7^" [C-home])
+(define-key rxvt-function-map "\e[8^" [C-end])
+(define-key rxvt-function-map "\eOd" [C-left])
+(define-key rxvt-function-map "\eOc" [C-right])
+(define-key rxvt-function-map "\eOa" [C-up])
+(define-key rxvt-function-map "\eOb" [C-down])
 
-  (define-key rxvt-function-map "\e[2;2~" [S-insert])
-  (define-key rxvt-function-map "\e[3$" [S-delete])
-  (define-key rxvt-function-map "\e[5$" [S-prior])
-  (define-key rxvt-function-map "\e[6$" [S-next])
-  (define-key rxvt-function-map "\e[7$" [S-home])
-  (define-key rxvt-function-map "\e[8$" [S-end])
-  (define-key rxvt-function-map "\e[d" [S-left])
-  (define-key rxvt-function-map "\e[c" [S-right])
-  (define-key rxvt-function-map "\e[a" [S-up])
-  (define-key rxvt-function-map "\e[b" [S-down]))
+(define-key rxvt-function-map "\e[2;2~" [S-insert])
+(define-key rxvt-function-map "\e[3$" [S-delete])
+(define-key rxvt-function-map "\e[5$" [S-prior])
+(define-key rxvt-function-map "\e[6$" [S-next])
+(define-key rxvt-function-map "\e[7$" [S-home])
+(define-key rxvt-function-map "\e[8$" [S-end])
+(define-key rxvt-function-map "\e[d" [S-left])
+(define-key rxvt-function-map "\e[c" [S-right])
+(define-key rxvt-function-map "\e[a" [S-up])
+(define-key rxvt-function-map "\e[b" [S-down])
 
 (defun terminal-init-rxvt ()
   "Terminal initialization function for rxvt."
 
-  ;; The terminal-local stuff only need to be set up on the first
-  ;; frame on that device.
-  (when (eq 1 (length (frames-on-display-list)))
-    ;; The terminal intialization C code file might have initialized
-    ;; function keys F11->F42 from the termcap/terminfo information.  On
-    ;; a PC-style keyboard these keys correspond to
-    ;; MODIFIER-FUNCTION_KEY, where modifier is S-, C-, C-S-.  The
-    ;; code here subsitutes the corresponding defintions in
-    ;; function-key-map.  This substitution is needed because if a key
-    ;; definition if found in function-key-map, there are no further
-    ;; lookups in other keymaps.
-    (substitute-key-definition [f11] [S-f1] local-function-key-map)
-    (substitute-key-definition [f12] [S-f2] local-function-key-map)
-    (substitute-key-definition [f13] [S-f3] local-function-key-map)
-    (substitute-key-definition [f14] [S-f4] local-function-key-map)
-    (substitute-key-definition [f15] [S-f5] local-function-key-map)
-    (substitute-key-definition [f16] [S-f6] local-function-key-map)
-    (substitute-key-definition [f17] [S-f7] local-function-key-map)
-    (substitute-key-definition [f18] [S-f8] local-function-key-map)
-    (substitute-key-definition [f19] [S-f9] local-function-key-map)
-    (substitute-key-definition [f20] [S-f10] local-function-key-map)
+  ;; The terminal intialization C code file might have initialized
+  ;; function keys F11->F42 from the termcap/terminfo information.  On
+  ;; a PC-style keyboard these keys correspond to
+  ;; MODIFIER-FUNCTION_KEY, where modifier is S-, C-, C-S-.  The
+  ;; code here subsitutes the corresponding defintions in
+  ;; function-key-map.  This substitution is needed because if a key
+  ;; definition if found in function-key-map, there are no further
+  ;; lookups in other keymaps.
+  (substitute-key-definition [f11] [S-f1] local-function-key-map)
+  (substitute-key-definition [f12] [S-f2] local-function-key-map)
+  (substitute-key-definition [f13] [S-f3] local-function-key-map)
+  (substitute-key-definition [f14] [S-f4] local-function-key-map)
+  (substitute-key-definition [f15] [S-f5] local-function-key-map)
+  (substitute-key-definition [f16] [S-f6] local-function-key-map)
+  (substitute-key-definition [f17] [S-f7] local-function-key-map)
+  (substitute-key-definition [f18] [S-f8] local-function-key-map)
+  (substitute-key-definition [f19] [S-f9] local-function-key-map)
+  (substitute-key-definition [f20] [S-f10] local-function-key-map)
 
-    (substitute-key-definition [f23] [C-f1] local-function-key-map)
-    (substitute-key-definition [f24] [C-f2] local-function-key-map)
-    (substitute-key-definition [f25] [C-f3] local-function-key-map)
-    (substitute-key-definition [f26] [C-f4] local-function-key-map)
-    (substitute-key-definition [f27] [C-f5] local-function-key-map)
-    (substitute-key-definition [f28] [C-f6] local-function-key-map)
-    (substitute-key-definition [f29] [C-f7] local-function-key-map)
-    (substitute-key-definition [f30] [C-f8] local-function-key-map)
-    (substitute-key-definition [f31] [C-f9] local-function-key-map)
-    (substitute-key-definition [f32] [C-f10] local-function-key-map)
+  (substitute-key-definition [f23] [C-f1] local-function-key-map)
+  (substitute-key-definition [f24] [C-f2] local-function-key-map)
+  (substitute-key-definition [f25] [C-f3] local-function-key-map)
+  (substitute-key-definition [f26] [C-f4] local-function-key-map)
+  (substitute-key-definition [f27] [C-f5] local-function-key-map)
+  (substitute-key-definition [f28] [C-f6] local-function-key-map)
+  (substitute-key-definition [f29] [C-f7] local-function-key-map)
+  (substitute-key-definition [f30] [C-f8] local-function-key-map)
+  (substitute-key-definition [f31] [C-f9] local-function-key-map)
+  (substitute-key-definition [f32] [C-f10] local-function-key-map)
 
-    (substitute-key-definition [f33] [C-S-f1] local-function-key-map)
-    (substitute-key-definition [f34] [C-S-f2] local-function-key-map)
-    (substitute-key-definition [f35] [C-S-f3] local-function-key-map)
-    (substitute-key-definition [f36] [C-S-f4] local-function-key-map)
-    (substitute-key-definition [f37] [C-S-f5] local-function-key-map)
-    (substitute-key-definition [f38] [C-S-f6] local-function-key-map)
-    (substitute-key-definition [f39] [C-S-f7] local-function-key-map)
-    (substitute-key-definition [f40] [C-S-f8] local-function-key-map)
-    (substitute-key-definition [f41] [C-S-f9] local-function-key-map)
-    (substitute-key-definition [f42] [C-S-f10] local-function-key-map)
+  (substitute-key-definition [f33] [C-S-f1] local-function-key-map)
+  (substitute-key-definition [f34] [C-S-f2] local-function-key-map)
+  (substitute-key-definition [f35] [C-S-f3] local-function-key-map)
+  (substitute-key-definition [f36] [C-S-f4] local-function-key-map)
+  (substitute-key-definition [f37] [C-S-f5] local-function-key-map)
+  (substitute-key-definition [f38] [C-S-f6] local-function-key-map)
+  (substitute-key-definition [f39] [C-S-f7] local-function-key-map)
+  (substitute-key-definition [f40] [C-S-f8] local-function-key-map)
+  (substitute-key-definition [f41] [C-S-f9] local-function-key-map)
+  (substitute-key-definition [f42] [C-S-f10] local-function-key-map)
 
-    ;; Use inheritance to let the main keymap override those defaults.
-    ;; This way we don't override terminfo-derived settings or settings
-    ;; made in the .emacs file.
-    (let ((m (copy-keymap rxvt-function-map)))
-      (set-keymap-parent m (keymap-parent local-function-key-map))
-      (set-keymap-parent local-function-key-map m)))
+  ;; Use inheritance to let the main keymap override those defaults.
+  ;; This way we don't override terminfo-derived settings or settings
+  ;; made in the .emacs file.
+  (let ((m (copy-keymap rxvt-function-map)))
+    (set-keymap-parent m (keymap-parent local-function-key-map))
+    (set-keymap-parent local-function-key-map m))
 
   ;; Initialize colors and background mode.
   (rxvt-register-default-colors)
@@ -250,7 +243,7 @@
 			    (- 256 ncolors)
 			    (list color color color))
 	  (setq ncolors (1- ncolors))))
-       
+
        ((= ncolors 72) ; rxvt-unicode
 	;; 64 non-gray colors
 	(let ((levels '(0 139 205 255))
@@ -293,7 +286,7 @@
   "Set background mode as appropriate for the default rxvt colors."
   (let ((fgbg (getenv "COLORFGBG" (terminal-id)))
 	bg rgb)
-    (setq default-frame-background-mode 'light)
+    (set-terminal-parameter nil 'background-mode 'light)
     (when (and fgbg
 	       (string-match ".*;\\([0-9][0-9]?\\)\\'" fgbg))
       (setq bg (string-to-number (substring fgbg (match-beginning 1))))
@@ -306,8 +299,7 @@
 	     ;; The following line assumes that white is the 15th
 	     ;; color in rxvt-standard-colors.
 	     (* (apply '+ (car (cddr (nth 15 rxvt-standard-colors)))) 0.6))
-	  (setq default-frame-background-mode 'dark)))
-    (frame-set-background-mode (selected-frame))))
+	  (set-terminal-parameter nil 'background-mode 'dark)))))
 
 ;; arch-tag: 20cf2fb6-6318-4bab-9dbf-1d15048f2257
 ;;; rxvt.el ends here
--- a/lisp/term/vt100.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt100.el	Sat May 20 17:02:47 2006 +0000
@@ -40,7 +40,7 @@
 
 (defun terminal-init-vt100 ()
   "Terminal initialization function for vt100."
-  (terminal-init-lk201))
+  (tty-run-terminal-initialization (selected-frame) "lk201"))
 
 ;;; Controlling the screen width.
 (defvar vt100-wide-mode (= (frame-width) 132)
--- a/lisp/term/vt102.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt102.el	Sat May 20 17:02:47 2006 +0000
@@ -1,8 +1,8 @@
 ;; -*- no-byte-compile: t -*-
 
 (defun terminal-init-vt102 ()
-  "Terminal initialization function for vt102."  
-  (terminal-init-vt100))
+  "Terminal initialization function for vt102."
+  (tty-run-terminal-initialization (selected-frame) "vt100"))
 
 ;;; arch-tag: 6e839cfc-125a-4574-82f1-c23a51f7c50f
 ;;; vt102.el ends here
--- a/lisp/term/vt125.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt125.el	Sat May 20 17:02:47 2006 +0000
@@ -1,8 +1,8 @@
 ;; -*- no-byte-compile: t -*-
 
 (defun terminal-init-vt125 ()
-  "Terminal initialization function for vt125."  
-  (terminal-init-vt100))
+  "Terminal initialization function for vt125."
+  (tty-run-terminal-initialization (selected-frame) "vt100"))
 
 ;;; arch-tag: 1d92d70f-dd55-4a1d-9088-e215a4883801
 ;;; vt125.el ends here
--- a/lisp/term/vt200.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt200.el	Sat May 20 17:02:47 2006 +0000
@@ -3,7 +3,7 @@
 ;; Most differences are handled by the termcap entry.
 (defun terminal-init-vt200 ()
   "Terminal initialization function for vt200."
-  (terminal-init-vt100)
+  (tty-run-terminal-initialization (selected-frame) "vt100")
   ;; Make F11 an escape key.
   (define-key local-function-key-map "\e[23~" [?\e]))
 
--- a/lisp/term/vt201.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt201.el	Sat May 20 17:02:47 2006 +0000
@@ -3,7 +3,7 @@
 ;; Most differences are handled by the termcap entry.
 (defun terminal-init-vt201 ()
   "Terminal initialization function for vt201."
-  (terminal-init-vt100)
+  (tty-run-terminal-initialization (selected-frame) "vt100")
   ;; Make F11 an escape key.
   (define-key local-function-key-map "\e[23~" [?\e]))
 
--- a/lisp/term/vt220.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt220.el	Sat May 20 17:02:47 2006 +0000
@@ -3,7 +3,7 @@
 ;; Most differences are handled by the termcap entry.
 (defun terminal-init-vt220 ()
   "Terminal initialization function for vt220."
-  (terminal-init-vt100)
+  (tty-run-terminal-initialization (selected-frame) "vt100")
   ;; Make F11 an escape key.
   (define-key local-function-key-map "\e[23~" [?\e]))
 
--- a/lisp/term/vt240.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt240.el	Sat May 20 17:02:47 2006 +0000
@@ -3,7 +3,7 @@
 ;; Most differences are handled by the termcap entry.
 (defun terminal-init-vt240 ()
   "Terminal initialization function for vt240."
-  (terminal-init-vt100)
+  (tty-run-terminal-initialization (selected-frame) "vt100")
   ;; Make F11 an escape key.
   (define-key local-function-key-map "\e[23~" [?\e]))
 
--- a/lisp/term/vt300.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt300.el	Sat May 20 17:02:47 2006 +0000
@@ -1,7 +1,7 @@
 ;; -*- no-byte-compile: t -*-
 (defun terminal-init-vt300 ()
   "Terminal initialization function for vt300."
-  (terminal-init-vt100)
+  (tty-run-terminal-initialization (selected-frame) "vt100")
   ;; Make F11 an escape key.
   (define-key local-function-key-map "\e[23~" [?\e]))
 
--- a/lisp/term/vt320.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt320.el	Sat May 20 17:02:47 2006 +0000
@@ -1,7 +1,7 @@
 ;; -*- no-byte-compile: t -*-
 (defun terminal-init-vt320 ()
   "Terminal initialization function for vt320."
-  (terminal-init-vt100)
+  (tty-run-terminal-initialization (selected-frame) "vt100")
   ;; Make F11 an escape key.
   (define-key local-function-key-map "\e[23~" [?\e]))
 
--- a/lisp/term/vt400.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt400.el	Sat May 20 17:02:47 2006 +0000
@@ -1,7 +1,7 @@
 ;; -*- no-byte-compile: t -*-
 (defun terminal-init-vt400 ()
   "Terminal initialization function for vt400."
-  (terminal-init-vt100)
+  (tty-run-terminal-initialization (selected-frame) "vt100")
   ;; Make F11 an escape key.
   (define-key local-function-key-map "\e[23~" [?\e]))
 
--- a/lisp/term/vt420.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/vt420.el	Sat May 20 17:02:47 2006 +0000
@@ -1,7 +1,7 @@
 ;; -*- no-byte-compile: t -*-
 (defun terminal-init-vt420
   "Terminal initialization function for vt420."
-  (terminal-init-vt100)
+  (tty-run-terminal-initialization (selected-frame) "vt100")
   ;; Make F11 an escape key.
   (define-key local-function-key-map "\e[23~" [?\e]))
 
--- a/lisp/term/xterm.el	Sat May 20 15:28:05 2006 +0000
+++ b/lisp/term/xterm.el	Sat May 20 17:02:47 2006 +0000
@@ -27,257 +27,248 @@
 
 ;;; Code:
 
-(defvar xterm-function-map nil
+(defvar xterm-function-map (make-sparse-keymap)
   "Function key map overrides for xterm.")
 
-;; Make reloads faster.
-(unless xterm-function-map
-  (setq xterm-function-map (make-sparse-keymap))
-  ;; xterm from X.org 6.8.2 uses these key definitions.
-  (define-key xterm-function-map "\eOP" [f1])
-  (define-key xterm-function-map "\eOQ" [f2])
-  (define-key xterm-function-map "\eOR" [f3])
-  (define-key xterm-function-map "\eOS" [f4])
-  (define-key xterm-function-map "\e[15~" [f5])
-  (define-key xterm-function-map "\e[17~" [f6])
-  (define-key xterm-function-map "\e[18~" [f7])
-  (define-key xterm-function-map "\e[19~" [f8])
-  (define-key xterm-function-map "\e[20~" [f9])
-  (define-key xterm-function-map "\e[21~" [f10])
-  (define-key xterm-function-map "\e[23~" [f11])
-  (define-key xterm-function-map "\e[24~" [f12])
+;; xterm from X.org 6.8.2 uses these key definitions.
+(define-key xterm-function-map "\eOP" [f1])
+(define-key xterm-function-map "\eOQ" [f2])
+(define-key xterm-function-map "\eOR" [f3])
+(define-key xterm-function-map "\eOS" [f4])
+(define-key xterm-function-map "\e[15~" [f5])
+(define-key xterm-function-map "\e[17~" [f6])
+(define-key xterm-function-map "\e[18~" [f7])
+(define-key xterm-function-map "\e[19~" [f8])
+(define-key xterm-function-map "\e[20~" [f9])
+(define-key xterm-function-map "\e[21~" [f10])
+(define-key xterm-function-map "\e[23~" [f11])
+(define-key xterm-function-map "\e[24~" [f12])
 
-  (define-key xterm-function-map "\eO2P" [S-f1])
-  (define-key xterm-function-map "\eO2Q" [S-f2])
-  (define-key xterm-function-map "\eO2R" [S-f3])
-  (define-key xterm-function-map "\eO2S" [S-f4])
-  (define-key xterm-function-map "\e[15;2~" [S-f5])
-  (define-key xterm-function-map "\e[17;2~" [S-f6])
-  (define-key xterm-function-map "\e[18;2~" [S-f7])
-  (define-key xterm-function-map "\e[19;2~" [S-f8])
-  (define-key xterm-function-map "\e[20;2~" [S-f9])
-  (define-key xterm-function-map "\e[21;2~" [S-f10])
-  (define-key xterm-function-map "\e[23;2~" [S-f11])
-  (define-key xterm-function-map "\e[24;2~" [S-f12])
+(define-key xterm-function-map "\eO2P" [S-f1])
+(define-key xterm-function-map "\eO2Q" [S-f2])
+(define-key xterm-function-map "\eO2R" [S-f3])
+(define-key xterm-function-map "\eO2S" [S-f4])
+(define-key xterm-function-map "\e[15;2~" [S-f5])
+(define-key xterm-function-map "\e[17;2~" [S-f6])
+(define-key xterm-function-map "\e[18;2~" [S-f7])
+(define-key xterm-function-map "\e[19;2~" [S-f8])
+(define-key xterm-function-map "\e[20;2~" [S-f9])
+(define-key xterm-function-map "\e[21;2~" [S-f10])
+(define-key xterm-function-map "\e[23;2~" [S-f11])
+(define-key xterm-function-map "\e[24;2~" [S-f12])
+
+(define-key xterm-function-map "\eO5P" [C-f1])
+(define-key xterm-function-map "\eO5Q" [C-f2])
+(define-key xterm-function-map "\eO5R" [C-f3])
+(define-key xterm-function-map "\eO5S" [C-f4])
+(define-key xterm-function-map "\e[15;5~" [C-f5])
+(define-key xterm-function-map "\e[17;5~" [C-f6])
+(define-key xterm-function-map "\e[18;5~" [C-f7])
+(define-key xterm-function-map "\e[19;5~" [C-f8])
+(define-key xterm-function-map "\e[20;5~" [C-f9])
+(define-key xterm-function-map "\e[21;5~" [C-f10])
+(define-key xterm-function-map "\e[23;5~" [C-f11])
+(define-key xterm-function-map "\e[24;5~" [C-f12])
 
-  (define-key xterm-function-map "\eO5P" [C-f1])
-  (define-key xterm-function-map "\eO5Q" [C-f2])
-  (define-key xterm-function-map "\eO5R" [C-f3])
-  (define-key xterm-function-map "\eO5S" [C-f4])
-  (define-key xterm-function-map "\e[15;5~" [C-f5])
-  (define-key xterm-function-map "\e[17;5~" [C-f6])
-  (define-key xterm-function-map "\e[18;5~" [C-f7])
-  (define-key xterm-function-map "\e[19;5~" [C-f8])
-  (define-key xterm-function-map "\e[20;5~" [C-f9])
-  (define-key xterm-function-map "\e[21;5~" [C-f10])
-  (define-key xterm-function-map "\e[23;5~" [C-f11])
-  (define-key xterm-function-map "\e[24;5~" [C-f12])
-
-  (define-key xterm-function-map "\eO6P" [C-S-f1])
-  (define-key xterm-function-map "\eO6Q" [C-S-f2])
-  (define-key xterm-function-map "\eO6R" [C-S-f3])
-  (define-key xterm-function-map "\eO6S" [C-S-f4])
-  (define-key xterm-function-map "\e[15;6~" [C-S-f5])
-  (define-key xterm-function-map "\e[17;6~" [C-S-f6])
-  (define-key xterm-function-map "\e[18;6~" [C-S-f7])
-  (define-key xterm-function-map "\e[19;6~" [C-S-f8])
-  (define-key xterm-function-map "\e[20;6~" [C-S-f9])
-  (define-key xterm-function-map "\e[21;6~" [C-S-f10])
-  (define-key xterm-function-map "\e[23;6~" [C-S-f11])
-  (define-key xterm-function-map "\e[24;6~" [C-S-f12])
+(define-key xterm-function-map "\eO6P" [C-S-f1])
+(define-key xterm-function-map "\eO6Q" [C-S-f2])
+(define-key xterm-function-map "\eO6R" [C-S-f3])
+(define-key xterm-function-map "\eO6S" [C-S-f4])
+(define-key xterm-function-map "\e[15;6~" [C-S-f5])
+(define-key xterm-function-map "\e[17;6~" [C-S-f6])
+(define-key xterm-function-map "\e[18;6~" [C-S-f7])
+(define-key xterm-function-map "\e[19;6~" [C-S-f8])
+(define-key xterm-function-map "\e[20;6~" [C-S-f9])
+(define-key xterm-function-map "\e[21;6~" [C-S-f10])
+(define-key xterm-function-map "\e[23;6~" [C-S-f11])
+(define-key xterm-function-map "\e[24;6~" [C-S-f12])
 
-  (define-key xterm-function-map "\eO3P" [A-f1])
-  (define-key xterm-function-map "\eO3Q" [A-f2])
-  (define-key xterm-function-map "\eO3R" [A-f3])
-  (define-key xterm-function-map "\eO3S" [A-f4])
-  (define-key xterm-function-map "\e[15;3~" [A-f5])
-  (define-key xterm-function-map "\e[17;3~" [A-f6])
-  (define-key xterm-function-map "\e[18;3~" [A-f7])
-  (define-key xterm-function-map "\e[19;3~" [A-f8])
-  (define-key xterm-function-map "\e[20;3~" [A-f9])
-  (define-key xterm-function-map "\e[21;3~" [A-f10])
-  (define-key xterm-function-map "\e[23;3~" [A-f11])
-  (define-key xterm-function-map "\e[24;3~" [A-f12])
+(define-key xterm-function-map "\eO3P" [A-f1])
+(define-key xterm-function-map "\eO3Q" [A-f2])
+(define-key xterm-function-map "\eO3R" [A-f3])
+(define-key xterm-function-map "\eO3S" [A-f4])
+(define-key xterm-function-map "\e[15;3~" [A-f5])
+(define-key xterm-function-map "\e[17;3~" [A-f6])
+(define-key xterm-function-map "\e[18;3~" [A-f7])
+(define-key xterm-function-map "\e[19;3~" [A-f8])
+(define-key xterm-function-map "\e[20;3~" [A-f9])
+(define-key xterm-function-map "\e[21;3~" [A-f10])
+(define-key xterm-function-map "\e[23;3~" [A-f11])
+(define-key xterm-function-map "\e[24;3~" [A-f12])
 
-  (define-key xterm-function-map "\eOA" [up])
-  (define-key xterm-function-map "\eOB" [down])
-  (define-key xterm-function-map "\eOC" [right])
-  (define-key xterm-function-map "\eOD" [left])
-  (define-key xterm-function-map "\eOF" [end])
-  (define-key xterm-function-map "\eOH" [home])
+(define-key xterm-function-map "\eOA" [up])
+(define-key xterm-function-map "\eOB" [down])
+(define-key xterm-function-map "\eOC" [right])
+(define-key xterm-function-map "\eOD" [left])
+(define-key xterm-function-map "\eOF" [end])
+(define-key xterm-function-map "\eOH" [home])
 
-  (define-key xterm-function-map "\e[1;2A" [S-up])
-  (define-key xterm-function-map "\e[1;2B" [S-down])
-  (define-key xterm-function-map "\e[1;2C" [S-right])
-  (define-key xterm-function-map "\e[1;2D" [S-left])
-  (define-key xterm-function-map "\e[1;2F" [S-end])
-  (define-key xterm-function-map "\e[1;2H" [S-home])
+(define-key xterm-function-map "\e[1;2A" [S-up])
+(define-key xterm-function-map "\e[1;2B" [S-down])
+(define-key xterm-function-map "\e[1;2C" [S-right])
+(define-key xterm-function-map "\e[1;2D" [S-left])
+(define-key xterm-function-map "\e[1;2F" [S-end])
+(define-key xterm-function-map "\e[1;2H" [S-home])
 
-  (define-key xterm-function-map "\e[1;5A" [C-up])
-  (define-key xterm-function-map "\e[1;5B" [C-down])
-  (define-key xterm-function-map "\e[1;5C" [C-right])
-  (define-key xterm-function-map "\e[1;5D" [C-left])
-  (define-key xterm-function-map "\e[1;5F" [C-end])
-  (define-key xterm-function-map "\e[1;5H" [C-home])
+(define-key xterm-function-map "\e[1;5A" [C-up])
+(define-key xterm-function-map "\e[1;5B" [C-down])
+(define-key xterm-function-map "\e[1;5C" [C-right])
+(define-key xterm-function-map "\e[1;5D" [C-left])
+(define-key xterm-function-map "\e[1;5F" [C-end])
+(define-key xterm-function-map "\e[1;5H" [C-home])
 
-  (define-key xterm-function-map "\e[1;6A" [C-S-up])
-  (define-key xterm-function-map "\e[1;6B" [C-S-down])
-  (define-key xterm-function-map "\e[1;6C" [C-S-right])
-  (define-key xterm-function-map "\e[1;6D" [C-S-left])
-  (define-key xterm-function-map "\e[1;6F" [C-S-end])
-  (define-key xterm-function-map "\e[1;6H" [C-S-home])
+(define-key xterm-function-map "\e[1;6A" [C-S-up])
+(define-key xterm-function-map "\e[1;6B" [C-S-down])
+(define-key xterm-function-map "\e[1;6C" [C-S-right])
+(define-key xterm-function-map "\e[1;6D" [C-S-left])
+(define-key xterm-function-map "\e[1;6F" [C-S-end])
+(define-key xterm-function-map "\e[1;6H" [C-S-home])
 
-  (define-key xterm-function-map "\e[1;3A" [A-up])
-  (define-key xterm-function-map "\e[1;3B" [A-down])
-  (define-key xterm-function-map "\e[1;3C" [A-right])
-  (define-key xterm-function-map "\e[1;3D" [A-left])
-  (define-key xterm-function-map "\e[1;3F" [A-end])
-  (define-key xterm-function-map "\e[1;3H" [A-home])
+(define-key xterm-function-map "\e[1;3A" [A-up])
+(define-key xterm-function-map "\e[1;3B" [A-down])
+(define-key xterm-function-map "\e[1;3C" [A-right])
+(define-key xterm-function-map "\e[1;3D" [A-left])
+(define-key xterm-function-map "\e[1;3F" [A-end])
+(define-key xterm-function-map "\e[1;3H" [A-home])
 
-  (define-key xterm-function-map "\e[2~" [insert])
-  (define-key xterm-function-map "\e[3~" [delete])
-  (define-key xterm-function-map "\e[5~" [prior])
-  (define-key xterm-function-map "\e[6~" [next])
+(define-key xterm-function-map "\e[2~" [insert])
+(define-key xterm-function-map "\e[3~" [delete])
+(define-key xterm-function-map "\e[5~" [prior])
+(define-key xterm-function-map "\e[6~" [next])
 
-  (define-key xterm-function-map "\e[2;2~" [S-insert])
-  (define-key xterm-function-map "\e[3;2~" [S-delete])
-  (define-key xterm-function-map "\e[5;2~" [S-prior])
-  (define-key xterm-function-map "\e[6;2~" [S-next])
+(define-key xterm-function-map "\e[2;2~" [S-insert])
+(define-key xterm-function-map "\e[3;2~" [S-delete])
+(define-key xterm-function-map "\e[5;2~" [S-prior])
+(define-key xterm-function-map "\e[6;2~" [S-next])
 
-  (define-key xterm-function-map "\e[2;5~" [C-insert])
-  (define-key xterm-function-map "\e[3;5~" [C-delete])
-  (define-key xterm-function-map "\e[5;5~" [C-prior])
-  (define-key xterm-function-map "\e[6;5~" [C-next])
+(define-key xterm-function-map "\e[2;5~" [C-insert])
+(define-key xterm-function-map "\e[3;5~" [C-delete])
+(define-key xterm-function-map "\e[5;5~" [C-prior])
+(define-key xterm-function-map "\e[6;5~" [C-next])
 
-  (define-key xterm-function-map "\e[2;6~" [C-S-insert])
-  (define-key xterm-function-map "\e[3;6~" [C-S-delete])
-  (define-key xterm-function-map "\e[5;6~" [C-S-prior])
-  (define-key xterm-function-map "\e[6;6~" [C-S-next])
+(define-key xterm-function-map "\e[2;6~" [C-S-insert])
+(define-key xterm-function-map "\e[3;6~" [C-S-delete])
+(define-key xterm-function-map "\e[5;6~" [C-S-prior])
+(define-key xterm-function-map "\e[6;6~" [C-S-next])
 
-  (define-key xterm-function-map "\e[2;3~" [A-insert])
-  (define-key xterm-function-map "\e[3;3~" [A-delete])
-  (define-key xterm-function-map "\e[5;3~" [A-prior])
-  (define-key xterm-function-map "\e[6;3~" [A-next])
+(define-key xterm-function-map "\e[2;3~" [A-insert])
+(define-key xterm-function-map "\e[3;3~" [A-delete])
+(define-key xterm-function-map "\e[5;3~" [A-prior])
+(define-key xterm-function-map "\e[6;3~" [A-next])
 
-  (define-key xterm-function-map "\e[4~" [select])
-  (define-key xterm-function-map "\e[29~" [print])
+(define-key xterm-function-map "\e[4~" [select])
+(define-key xterm-function-map "\e[29~" [print])
 
-  ;; These keys will be available xterm starting probably from
-  ;; version 214.
-  (define-key xterm-function-map "\e[27;5;9~"  [(control ?\t)])
-  (define-key xterm-function-map "\e[27;5;44~" [(control ?\,)])
-  (define-key xterm-function-map "\e[27;5;46~" [(control ?\.)])
-  (define-key xterm-function-map "\e[27;5;47~" [(control ?\/)])
-  (define-key xterm-function-map "\e[27;5;92~" [(control ?\\)])
+;; These keys will be available xterm starting probably from
+;; version 214.
+(define-key xterm-function-map "\e[27;5;9~"  [(control ?\t)])
+(define-key xterm-function-map "\e[27;5;44~" [(control ?\,)])
+(define-key xterm-function-map "\e[27;5;46~" [(control ?\.)])
+(define-key xterm-function-map "\e[27;5;47~" [(control ?\/)])
+(define-key xterm-function-map "\e[27;5;92~" [(control ?\\)])
 
-  ;; Other versions of xterm might emit these.
-  (define-key xterm-function-map "\e[A" [up])
-  (define-key xterm-function-map "\e[B" [down])
-  (define-key xterm-function-map "\e[C" [right])
-  (define-key xterm-function-map "\e[D" [left])
-  (define-key xterm-function-map "\e[1~" [home])
+;; Other versions of xterm might emit these.
+(define-key xterm-function-map "\e[A" [up])
+(define-key xterm-function-map "\e[B" [down])
+(define-key xterm-function-map "\e[C" [right])
+(define-key xterm-function-map "\e[D" [left])
+(define-key xterm-function-map "\e[1~" [home])
 
-  (define-key xterm-function-map "\e[1;2A" [S-up])
-  (define-key xterm-function-map "\e[1;2B" [S-down])
-  (define-key xterm-function-map "\e[1;2C" [S-right])
-  (define-key xterm-function-map "\e[1;2D" [S-left])
-  (define-key xterm-function-map "\e[1;2F" [S-end])
-  (define-key xterm-function-map "\e[1;2H" [S-home])
+(define-key xterm-function-map "\e[1;2A" [S-up])
+(define-key xterm-function-map "\e[1;2B" [S-down])
+(define-key xterm-function-map "\e[1;2C" [S-right])
+(define-key xterm-function-map "\e[1;2D" [S-left])
+(define-key xterm-function-map "\e[1;2F" [S-end])
+(define-key xterm-function-map "\e[1;2H" [S-home])
 
-  (define-key xterm-function-map "\e[1;5A" [C-up])
-  (define-key xterm-function-map "\e[1;5B" [C-down])
-  (define-key xterm-function-map "\e[1;5C" [C-right])
-  (define-key xterm-function-map "\e[1;5D" [C-left])
-  (define-key xterm-function-map "\e[1;5F" [C-end])
-  (define-key xterm-function-map "\e[1;5H" [C-home])
+(define-key xterm-function-map "\e[1;5A" [C-up])
+(define-key xterm-function-map "\e[1;5B" [C-down])
+(define-key xterm-function-map "\e[1;5C" [C-right])
+(define-key xterm-function-map "\e[1;5D" [C-left])
+(define-key xterm-function-map "\e[1;5F" [C-end])
+(define-key xterm-function-map "\e[1;5H" [C-home])
 
-  (define-key xterm-function-map "\e[11~" [f1])
-  (define-key xterm-function-map "\e[12~" [f2])
-  (define-key xterm-function-map "\e[13~" [f3])
-  (define-key xterm-function-map "\e[14~" [f4]))
+(define-key xterm-function-map "\e[11~" [f1])
+(define-key xterm-function-map "\e[12~" [f2])
+(define-key xterm-function-map "\e[13~" [f3])
+(define-key xterm-function-map "\e[14~" [f4])
 
 (defun terminal-init-xterm ()
   "Terminal initialization function for xterm."
   ;; rxvt terminals sometimes set the TERM variable to "xterm", but
-  ;; rxvt's keybindings that are incompatible with xterm's. It is
+  ;; rxvt's keybindings are incompatible with xterm's. It is
   ;; better in that case to use rxvt's initializion function.
   (if (and (getenv "COLORTERM" (terminal-id))
 	   (string-match "\\`rxvt" (getenv "COLORTERM" (terminal-id))))
-      (progn
-	(eval-and-compile (load "term/rxvt"))
-	(terminal-init-rxvt))
+      (tty-run-terminal-initialization (selected-frame) "rxvt")
 
-    ;; The terminal-local stuff only need to be set up on the first
-    ;; frame on that device.
-    (when (eq 1 (length (frames-on-display-list)))
-      ;; The terminal intialization C code file might have initialized
-      ;; function keys F13->F60 from the termcap/terminfo information.  On
-      ;; a PC-style keyboard these keys correspond to
-      ;; MODIFIER-FUNCTION_KEY, where modifier is S-, C, A-, C-S-.  The
-      ;; code here subsitutes the corresponding defintions in
-      ;; function-key-map. This substitution is needed because if a key
-      ;; definition if found in function-key-map, there are no further
-      ;; lookups in other keymaps.
-      (substitute-key-definition [f13] [S-f1] local-function-key-map)
-      (substitute-key-definition [f14] [S-f2] local-function-key-map)
-      (substitute-key-definition [f15] [S-f3] local-function-key-map)
-      (substitute-key-definition [f16] [S-f4] local-function-key-map)
-      (substitute-key-definition [f17] [S-f5] local-function-key-map)
-      (substitute-key-definition [f18] [S-f6] local-function-key-map)
-      (substitute-key-definition [f19] [S-f7] local-function-key-map)
-      (substitute-key-definition [f20] [S-f8] local-function-key-map)
-      (substitute-key-definition [f21] [S-f9] local-function-key-map)
-      (substitute-key-definition [f22] [S-f10] local-function-key-map)
-      (substitute-key-definition [f23] [S-f11] local-function-key-map)
-      (substitute-key-definition [f24] [S-f12] local-function-key-map)
+    ;; The terminal intialization C code file might have initialized
+    ;; function keys F13->F60 from the termcap/terminfo information.  On
+    ;; a PC-style keyboard these keys correspond to
+    ;; MODIFIER-FUNCTION_KEY, where modifier is S-, C, A-, C-S-.  The
+    ;; code here subsitutes the corresponding defintions in
+    ;; function-key-map. This substitution is needed because if a key
+    ;; definition if found in function-key-map, there are no further
+    ;; lookups in other keymaps.
+    (substitute-key-definition [f13] [S-f1] local-function-key-map)
+    (substitute-key-definition [f14] [S-f2] local-function-key-map)
+    (substitute-key-definition [f15] [S-f3] local-function-key-map)
+    (substitute-key-definition [f16] [S-f4] local-function-key-map)
+    (substitute-key-definition [f17] [S-f5] local-function-key-map)
+    (substitute-key-definition [f18] [S-f6] local-function-key-map)
+    (substitute-key-definition [f19] [S-f7] local-function-key-map)
+    (substitute-key-definition [f20] [S-f8] local-function-key-map)
+    (substitute-key-definition [f21] [S-f9] local-function-key-map)
+    (substitute-key-definition [f22] [S-f10] local-function-key-map)
+    (substitute-key-definition [f23] [S-f11] local-function-key-map)
+    (substitute-key-definition [f24] [S-f12] local-function-key-map)
 
-      (substitute-key-definition [f25] [C-f1] local-function-key-map)
-      (substitute-key-definition [f26] [C-f2] local-function-key-map)
-      (substitute-key-definition [f27] [C-f3] local-function-key-map)
-      (substitute-key-definition [f28] [C-f4] local-function-key-map)
-      (substitute-key-definition [f29] [C-f5] local-function-key-map)
-      (substitute-key-definition [f30] [C-f6] local-function-key-map)
-      (substitute-key-definition [f31] [C-f7] local-function-key-map)
-      (substitute-key-definition [f32] [C-f8] local-function-key-map)
-      (substitute-key-definition [f33] [C-f9] local-function-key-map)
-      (substitute-key-definition [f34] [C-f10] local-function-key-map)
-      (substitute-key-definition [f35] [C-f11] local-function-key-map)
-      (substitute-key-definition [f36] [C-f12] local-function-key-map)
+    (substitute-key-definition [f25] [C-f1] local-function-key-map)
+    (substitute-key-definition [f26] [C-f2] local-function-key-map)
+    (substitute-key-definition [f27] [C-f3] local-function-key-map)
+    (substitute-key-definition [f28] [C-f4] local-function-key-map)
+    (substitute-key-definition [f29] [C-f5] local-function-key-map)
+    (substitute-key-definition [f30] [C-f6] local-function-key-map)
+    (substitute-key-definition [f31] [C-f7] local-function-key-map)
+    (substitute-key-definition [f32] [C-f8] local-function-key-map)
+    (substitute-key-definition [f33] [C-f9] local-function-key-map)
+    (substitute-key-definition [f34] [C-f10] local-function-key-map)
+    (substitute-key-definition [f35] [C-f11] local-function-key-map)
+    (substitute-key-definition [f36] [C-f12] local-function-key-map)
 
-      (substitute-key-definition [f37] [C-S-f1] local-function-key-map)
-      (substitute-key-definition [f38] [C-S-f2] local-function-key-map)
-      (substitute-key-definition [f39] [C-S-f3] local-function-key-map)
-      (substitute-key-definition [f40] [C-S-f4] local-function-key-map)
-      (substitute-key-definition [f41] [C-S-f5] local-function-key-map)
-      (substitute-key-definition [f42] [C-S-f6] local-function-key-map)
-      (substitute-key-definition [f43] [C-S-f7] local-function-key-map)
-      (substitute-key-definition [f44] [C-S-f8] local-function-key-map)
-      (substitute-key-definition [f45] [C-S-f9] local-function-key-map)
-      (substitute-key-definition [f46] [C-S-f10] local-function-key-map)
-      (substitute-key-definition [f47] [C-S-f11] local-function-key-map)
-      (substitute-key-definition [f48] [C-S-f12] local-function-key-map)
+    (substitute-key-definition [f37] [C-S-f1] local-function-key-map)
+    (substitute-key-definition [f38] [C-S-f2] local-function-key-map)
+    (substitute-key-definition [f39] [C-S-f3] local-function-key-map)
+    (substitute-key-definition [f40] [C-S-f4] local-function-key-map)
+    (substitute-key-definition [f41] [C-S-f5] local-function-key-map)
+    (substitute-key-definition [f42] [C-S-f6] local-function-key-map)
+    (substitute-key-definition [f43] [C-S-f7] local-function-key-map)
+    (substitute-key-definition [f44] [C-S-f8] local-function-key-map)
+    (substitute-key-definition [f45] [C-S-f9] local-function-key-map)
+    (substitute-key-definition [f46] [C-S-f10] local-function-key-map)
+    (substitute-key-definition [f47] [C-S-f11] local-function-key-map)
+    (substitute-key-definition [f48] [C-S-f12] local-function-key-map)
 
-      (substitute-key-definition [f49] [A-f1] local-function-key-map)
-      (substitute-key-definition [f50] [A-f2] local-function-key-map)
-      (substitute-key-definition [f51] [A-f3] local-function-key-map)
-      (substitute-key-definition [f52] [A-f4] local-function-key-map)
-      (substitute-key-definition [f53] [A-f5] local-function-key-map)
-      (substitute-key-definition [f54] [A-f6] local-function-key-map)
-      (substitute-key-definition [f55] [A-f7] local-function-key-map)
-      (substitute-key-definition [f56] [A-f8] local-function-key-map)
-      (substitute-key-definition [f57] [A-f9] local-function-key-map)
-      (substitute-key-definition [f58] [A-f10] local-function-key-map)
-      (substitute-key-definition [f59] [A-f11] local-function-key-map)
-      (substitute-key-definition [f60] [A-f12] local-function-key-map))
+    (substitute-key-definition [f49] [A-f1] local-function-key-map)
+    (substitute-key-definition [f50] [A-f2] local-function-key-map)
+    (substitute-key-definition [f51] [A-f3] local-function-key-map)
+    (substitute-key-definition [f52] [A-f4] local-function-key-map)
+    (substitute-key-definition [f53] [A-f5] local-function-key-map)
+    (substitute-key-definition [f54] [A-f6] local-function-key-map)
+    (substitute-key-definition [f55] [A-f7] local-function-key-map)
+    (substitute-key-definition [f56] [A-f8] local-function-key-map)
+    (substitute-key-definition [f57] [A-f9] local-function-key-map)
+    (substitute-key-definition [f58] [A-f10] local-function-key-map)
+    (substitute-key-definition [f59] [A-f11] local-function-key-map)
+    (substitute-key-definition [f60] [A-f12] local-function-key-map)
 
-      ;; Use inheritance to let the main keymap override those defaults.
-      ;; This way we don't override terminfo-derived settings or settings
-      ;; made in the .emacs file.
-      (let ((m (copy-keymap xterm-function-map)))
-	(set-keymap-parent m (keymap-parent local-function-key-map))
-	(set-keymap-parent local-function-key-map m)))
+    ;; Use inheritance to let the main keymap override those defaults.
+    ;; This way we don't override terminfo-derived settings or settings
+    ;; made in the .emacs file.
+    (let ((m (copy-keymap xterm-function-map)))
+      (set-keymap-parent m (keymap-parent local-function-key-map))
+      (set-keymap-parent local-function-key-map m)))
 
-    ;; Do it!
     (xterm-register-default-colors)
     ;; This recomputes all the default faces given the colors we've just set up.
     (tty-set-up-initial-frame-faces))