From:	CRDGW2::CRDGW2::MRGATE::"SMTP::PREP.AI.MIT.EDU::INFO-GNU-EMACS-REQUEST" 26-JUN-1989 17:48
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Performing functions in "the other window"

Received: by life.ai.mit.edu (4.0/AI-4.10) id AA01413; Mon, 26 Jun 89 14:52:17 EDT
Return-Path: <think!compass!worley@eddie.mit.edu>
Received: from AENEAS.MIT.EDU by life.ai.mit.edu (4.0/AI-4.10) id AA01376; Mon, 26 Jun 89 14:50:42 EDT
Received: from EDDIE.MIT.EDU by AENEAS.MIT.EDU (5.61/4.7) id AA27192; Mon, 26 Jun 89 14:50:29 -0400
Received: by EDDIE.MIT.EDU with UUCP with smail2.5 with sendmail-5.45/4.7 id <AA01369@EDDIE.MIT.EDU>; Mon, 26 Jun 89 14:50:18 EDT
Received: by think.com (smail2.5)
	id AA28250; 26 Jun 89 14:36:28 EDT (Mon)
Received: from galaxy.compass.com by compass.com (3.2/SMI-3.2)
	id AA19625; Mon, 26 Jun 89 14:25:15 EDT
Received: by galaxy.compass.com (3.2/SMI-3.2)
	id AA13559; Mon, 26 Jun 89 14:24:02 EDT
Date: Mon, 26 Jun 89 14:24:02 EDT
From: compass!worley@eddie.mit.edu (Dale Worley)
Message-Id: <8906261824.AA13559@galaxy.compass.com>
To: info-gnu-emacs@eddie.mit.edu
Subject: Performing functions in "the other window"

There is a whole series of operations that can be performed "in the
other window", all starting with "C-x 4".  It seemed that the support
code for the other-window-ness of these operations should be in one
function, so I wrote up the following function to do so.  As written,
it causes "C-x 6 anything" to do "C-x anything" in the other window,
and "ESC 6 anything" to do "ESC anything" in the other window, and if
you bind perform-operation-in-other-window to a two-character sequence
starting with any particular prefix key, it will extend the operations
of that prefix key to operate on the other window.

(defun perform-operation-in-other-window (prefix)
  "Performs an operation in the other window.
Prompts for the remainder of a multi-key command sequence, goes to the other
window, and executes the command.  The multi-key command sequence is assumed
to start with the first character that this command was invoked with.  Thus,
if it is invoked with C-x 6, then C-x 6 m invokes the command bound to C-x m
in the other window, and if it is invoked with ESC 6, then ESC 6 . invokes
the command bound to ESC . in the other window.  For this purpose, meta-ized
keys are treated as a two-key sequence starting with ESC.  Any prefix argument
is passed to the invoked command."
  (interactive "P")
  (let ((first-key (string-to-char (this-command-keys))))
    (if (>= first-key 128)
	(setq first-key ?\e))
    (setq unread-command-char first-key)
    (let ((key-sequence (read-key-sequence nil)))
      (other-window 1)
      (setq prefix-arg prefix)
      (call-interactively (key-binding key-sequence)))))

(global-set-key "\C-x6" 'perform-operation-in-other-window)
(global-set-key "\e6" 'perform-operation-in-other-window)

Dale
--
Dale Worley, Compass, Inc.                      worley@compass.com
The War on Drugs -- Prohibition for the '80s.
