From:	CRDGW2::CRDGW2::MRGATE::"SMTP::PREP.AI.MIT.EDU::HELP-GNU-EMACS-REQUEST"  6-FEB-1992 14:57:07.69
To:	ARISIA::EVERHART
CC:	
Subj:	Re: *SUMMARY* Running EMACS on a Sun using X/Motif in No Window Mode

From:	help-gnu-emacs-request@prep.ai.mit.edu@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.122)
	 id AA11035; Thu, 6 Feb 92 14:29:21 EST
Received: by life.ai.mit.edu (4.1/AI-4.10) id AA29942; Wed, 5 Feb 92 04:37:17 EST
Return-Path: <help-gnu-emacs-request@prep.ai.mit.edu>
Received: from news.cis.ohio-state.edu by life.ai.mit.edu (4.1/AI-4.10) id AA29929; Wed, 5 Feb 92 04:34:28 EST
Received: by news.cis.ohio-state.edu (5.61-kk/5.911008)
	id AA26674; Wed, 5 Feb 92 04:28:16 -0500
Received: from USENET by news.cis.ohio-state.edu with netnews
	for help-gnu-emacs@prep.ai.mit.edu (help-gnu-emacs@prep.ai.mit.edu);
	contact usenet@news.cis.ohio-state.edu if you have questions.
To: help-gnu-emacs@prep.ai.mit.edu
Date: Wed, 5 Feb 92 09:11:06 GMT
Message-Id: <ruprecht.697277191@fidji>
Organization: Institut fuer Informatik der Universitaet Freiburg, Deutschland
From: ruprecht@informatik.uni-freiburg.de (Nick Ruprecht)
Sender: help-gnu-emacs-request@prep.ai.mit.edu
References: <9202042023.AA01884@porter>ps.oh
Subject: Re: *SUMMARY* Running EMACS on a Sun using X/Motif in No Window Mode

I believe there is a better way to run emacs within an xterm. Read on if you
want to know why and how ...

robinson@PORTER.GEO.BROWN.EDU (Darrin Robinson) writes:

>Here's how to get emacs to run on a Sun Sparc in no window mode inside an Xterm and
>maintain the same functionality it has under Sunview :
[...]
>;;F10
>(define-key dg-raw-map "-1z"  'replace-string)

This strange escape sequence is due to a bug in the function stringFuncVal()
in emacs/src/x11term.c, where whoever did it forgot to define the escape
sequence for F10 to ^[[233z. The effect is that F10 and Help both show up as
^[[-1z. I have complained about it to no avail.

>;;F11
>(define-key dg-raw-map "192z"  'query-replace)
>;;F12
>(define-key dg-raw-map "193z"  'abbrev-mode)

These escape sequences are due to a bug in X11, where F11 = L1 and F12 = L2,
so F11 and F12 send the same escape sequences as L1 and L2, respectively.
You can bind the keys to other KeySyms (e.g. KP_F1, KP_F2) with the program
xmodmap, but emacs does not know those keys :-( There is an alternative,
however. Read on ...

>(define-key dg-raw-map "A"      'previous-line)
>(define-key dg-raw-map "B"      'next-line)
>(define-key dg-raw-map "C"      'forward-char)
>(define-key dg-raw-map "D"      'backward-char)
>(define-key dg-raw-map "214z"    'beginning-of-buffer)
>(define-key dg-raw-map "220z"    'end-of-buffer)
>(define-key dg-raw-map "222z"    'scroll-up)
>(define-key dg-raw-map "216z"    'scroll-down)
>(define-key dg-raw-map "218z"    'recenter)

The rest of the keypad keys can't be bound this way, but here is how you can
do it, and much more:

xterm allows to define translations of keys in a resource file. Keys can be
mapped to arbitrary strings, and the mapping can be different for different
modifier combinations. You can also switch between keymaps. So I have done
the following:

1. Change xmodmap so more keys produce something useful.
Here is my file .xmodmaprc which I activate when I start X by putting
	xmodmap .xmodmaprc
in my file .xinitrc

-----8<----- snip snip -----8<-----
! .xmodmaprc - map keys to unique keysyms
!
! In /usr/include/X11/keysymdef.h, F11=L1 and F12=L2, so these must be moved
! to other keysyms, e.g. F11->KP_F1, F12->KP_F2
keycode 16	= KP_F1
keycode 18	= KP_F2

! Keycode 57 (Del/. on the right keypad) sends "Delete", as does the Delete
! key. To be able to distinguish them, I do
keycode 57	= KP_Decimal

! I want to use the Compose and AltGraph keys, so they must be bound to keysyms
keycode 20	= Alt_R
keycode 74	= Super_R
-----8<----- snip snip -----8<-----

2. Create a keymap for xterm.
This is merged into the resource database with this in my .xinitrc
	xrdb -merge .keymap
You might not want all of this. Cut away what you don't like.
I have removed my email address from the ftp keymap. Insert yours.

-----8<----- snip snip -----8<-----
! .keymap - An example for xterm keymaps.
!
! Default keymap: keypad is in NumLock state.
! ScrollLock switches to emacs-keymap, F10 to ftp-keymap.
! A few other keys also have special effects.
!
*VT100.Translations: #override \
	Mod1 Shift<Key>A:	string(0x43) \n\
	Mod1	<Key>A:		string(0x63) \n\
	Mod1	<Key>Delete:	string(0x17) \n\
	Shift	<Key>Delete:	string(0x7f) \n\
		<Key>Delete:	string(0x08) \n\
		<Key>L2:	string("!!") string(0x0d) \n\
		<Key>L4:	string(0x03) \n\
		<Key>Linefeed:	string(" | more") string(0x0d) \n\
		<Key>F10:	keymap(ftp) \n\
		<Key>R1:	string("(") \n\
		<Key>R2:	string(")") \n\
		<Key>R3:	keymap(emacspad) \n\
		<Key>Num_Lock:	ignore() \n\
		<Key>R4:	string("=") \n\
		<Key>R5:	string("/") \n\
		<Key>R6:	string("*") \n\
		<Key>KP_Subtract: string("-") \n\
		<Key>R7:	string("7") \n\
		<Key>Up:	string("8") \n\
		<Key>R9:	string("9") \n\
		<Key>KP_Add:	string("+") \n\
		<Key>Left:	string("4") \n\
		<Key>R11:	string("5") \n\
		<Key>Right:	string("6") \n\
		<Key>R13:	string("1") \n\
		<Key>Down:	string("2") \n\
		<Key>R15:	string("3") \n\
		<Key>Insert:	string("0") \n\
		<Key>KP_Decimal: string(".") \n\
		<Key>KP_Enter:	string(0x0d)

! Emacs keymap:
! L* and F* keys are bound to the default escape sequences. Modify to suit
! your taste ...
! The right keypad sends different strings for different modifier states:
! Unmodified keys generally do what you'd expect.
! <Control> send modified movement commands (like forward-word ...)
! <Shift> and <Lock> generally send the characters printed on the keys.
! <Meta> sends the associated number as numeric argument for a command.
! Numlock switches back to the default keymap.
! Some bindings refer to elisp functions I made up. I have listed these
! further below. See for yourself whether you find them useful.
!
*VT100.emacspadKeymap.translations: \
		<Key>Delete:	string(0x7f) \n\
		<Key>L1:	keymap(None) string(0x1b) string("[192z") \n\
		<Key>L2:	string(0x1b) string("[193z") \n\
		<Key>L3:	string(0x1b) string("[194z") \n\
		<Key>L4:	string(0x1b) string("[195z") \n\
		<Key>L5:	string(0x1b) string("[196z") \n\
		<Key>L6:	string(0x1b) string("[197z") \n\
		<Key>L7:	string(0x1b) string("[198z") \n\
		<Key>L8:	string(0x1b) string("[199z") \n\
		<Key>L9:	string(0x1b) string("[200z") \n\
		<Key>L10:	string(0x1b) string("[201z") \n\
		<Key>F1:	string(0x1b) string("[224z") \n\
		<Key>F2:	string(0x1b) string("[225z") \n\
		<Key>F3:	string(0x1b) string("[226z") \n\
		<Key>F4:	string(0x1b) string("[227z") \n\
		<Key>F5:	string(0x1b) string("[228z") \n\
		<Key>F6:	string(0x1b) string("[229z") \n\
		<Key>F7:	string(0x1b) string("[230z") \n\
		<Key>F8:	string(0x1b) string("[231z") \n\
		<Key>F9:	string(0x1b) string("[232z") \n\
		<Key>F10:	string(0x1b) string("[233z") \n\
		<Key>KP_F1: 	string(0x1b) string("[234z") \n\
		<Key>KP_F2: 	string(0x1b) string("[235z") \n\
		<Key>KP_F3:	string(0x1b) string("[236z") \n\
		<Key>KP_F4:	string(0x1b) string("[237z") \n\
		<Key>Break:	string(0x1b) string("[223z") \n\
		<Key>Help:	string(0x08) \n\
		<Key>R1:	string(0x18) string(0x02) \n\
		<Key>R2:	string(0x1b) \
				string("xelectric-command-history") \
				string(0x0d) \n\
		<Key>R3:	string(0x07) \n\
		<Key>Num_Lock:	keymap(None) \n\
	Ctrl	<Key>R4:	string(0x1b) string("xgoto-line") \
				string(0x0d) \n\
	Mod1	<Key>R4:	string(0x1b) string("xwhat-cursor-position") \
				string(0x0d) \n\
	Shift	<Key>R4:	string("=") \n\
	Lock	<Key>R4:	string("=") \n\
		<Key>R4:	string(0x1b) string("xwhat-line") \
				string(0x0d) \n\
	Ctrl	<Key>R5:	string(0x12) \n\
	Mod1	<Key>R5:	string(0x1b) string("xre-search-forward") \
				string(0x0d) \n\
	Shift	<Key>R5:	string("/") \n\
	Lock	<Key>R5:	string("/") \n\
		<Key>R5:	string(0x13) \n\
	Ctrl	<Key>R6:	string(0x1b) string("xtoggle-read-only") \
				string(0x0d) \n\
	Mod1	<Key>R6:	string(0x1b) string("xrevert-buffer")\n\
	Shift	<Key>R6:	string("*") \n\
	Lock	<Key>R6:	string("*") \n\
		<Key>R6:	string(0x1b) string("xauto-fill-mode") \
				string(0x0d) \n\
	Ctrl	<Key>KP_Subtract: string(0x1b) string("k") \n\
	Mod1	<Key>KP_Subtract: string(0x1b) string("-") \n\
	Shift	<Key>KP_Subtract: string("-") \n\
	Lock	<Key>KP_Subtract: string("-") \n\
		<Key>KP_Subtract: string(0x0b) \n\
	Ctrl	<Key>R7:	string(0x1b) string("xbackward-beg-of-line") \
				string(0x0d) \n\
	Mod1	<Key>R7:	string(0x1b) string("7") \n\
	Shift	<Key>R7:	string("7") \n\
	Lock	<Key>R7:	string("7") \n\
		<Key>R7:	string(0x1b) string("<") \n\
	Ctrl	<Key>Up:	string(0x1b) string("xbackward-paragraph") \
				string(0x0d) \n\
	Mod1	<Key>Up:	string(0x1b) string("8") \n\
	Shift	<Key>Up:	string("8") \n\
	Lock	<Key>Up:	string("8") \n\
		<Key>Up:	string(0x10) \n\
	Ctrl	<Key>R9:	string(0x1b) string("xbackward-end-of-line") \
				string(0x0d) \n\
	Mod1	<Key>R9:	string(0x1b) string("9") \n\
	Shift	<Key>R9:	string("9") \n\
	Lock	<Key>R9:	string("9") \n\
		<Key>R9:	string(0x1b) string("v") \n\
	Ctrl	<Key>KP_Add:	string(0x18) string("1") \n\
	Mod1	<Key>KP_Add:	string(0x18) string("2") \n\
	Shift	<Key>KP_Add:	string("+") \n\
	Lock	<Key>KP_Add:	string("+") \n\
		<Key>KP_Add:	string(0x18) string("o") \n\
	Ctrl	<Key>Left:	string(0x1b) string("b") \n\
	Mod1	<Key>Left:	string(0x1b) string("4") \n\
	Shift	<Key>Left:	string("4") \n\
	Lock	<Key>Left:	string("4") \n\
		<Key>Left:	string(0x02) \n\
	Ctrl	<Key>R11:	string(0x1b) string("xback-to-indentation") \
				string(0x0d) \n\
	Mod1	<Key>R11:	string(0x1b) string("5") \n\
	Shift	<Key>R11:	string("5") \n\
	Lock	<Key>R11:	string("5") \n\
		<Key>R11:	string(0x0c) \n\
	Ctrl	<Key>Right:	string(0x1b) string("f") \n\
	Mod1	<Key>Right:	string(0x1b) string("6") \n\
	Shift	<Key>Right:	string("6") \n\
	Lock	<Key>Right:	string("6") \n\
		<Key>Right:	string(0x06) \n\
	Ctrl	<Key>R13:	string(0x1b) string("xforward-beg-of-line") \
				string(0x0d) \n\
	Mod1	<Key>R13:	string(0x1b) string("1") \n\
	Shift	<Key>R13:	string("1") \n\
	Lock	<Key>R13:	string("1") \n\
		<Key>R13:	string(0x1b) string(">") \n\
	Ctrl	<Key>Down:	string(0x1b) string("xforward-paragraph") \
				string(0x0d) \n\
	Mod1	<Key>Down:	string(0x1b) string("2") \n\
	Shift	<Key>Down:	string("2") \n\
	Lock	<Key>Down:	string("2") \n\
		<Key>Down:	string(0x0e) \n\
	Ctrl	<Key>R15:	string(0x1b) string("xforward-end-of-line") \
				string(0x0d) \n\
	Mod1	<Key>R15:	string(0x1b) string("3") \n\
	Shift	<Key>R15:	string("3") \n\
	Lock	<Key>R15:	string("3") \n\
		<Key>R15:	string(0x16) \n\
	Ctrl	<Key>Insert:	string(0x1b) string("xforward-to-indentation")\
				string(0x0d) \n\
	Mod1	<Key>Insert:	string(0x1b) string("0") \n\
	Shift	<Key>Insert:	string("0") \n\
	Lock	<Key>Insert:	string("0") \n\
		<Key>Insert:	string(0x1b) string("xset-mark-command") \
				string(0x0d) \n\
	Ctrl	<Key>KP_Decimal: string(0x1b) string("d") \n\
	Mod1	<Key>KP_Decimal: string(0x1b) string(".") \n\
	Shift	<Key>KP_Decimal: string(".") \n\
	Lock	<Key>KP_Decimal: string(".") \n\
		<Key>KP_Decimal: string(0x04) \n\
		<Key>Alt_L:	string(0x18) \n\
		<Key>Alt_R:	string(0x18) string("4") \n\
		<Key>Super_R:	string(0x03)

! ftp keymap: avoid typos when I ftp ...
*VT100.ftpKeymap.translations: \
		<Key>R3:	keymap(emacspad) \n\
		<Key>Num_Lock:	keymap(None) \n\
		<Key>F10:	string("ftp ") \n\
		<Key>KP_F1:	string("anonymous") string(0x0d) \n\
		<Key>KP_F2:	string("* put your email address here *") \
				string(0x0d)
-----8<----- snip snip -----8<-----

These are a few functions that are referred to in the emacs keymap. Put them
in your .emacs file if you want to use them.
With the above emacs keymap and the below save-buffers-... function,
"AltGraph Compose" will save modified buffers and exit. Very convenient.

-----8<----- snip snip -----8<-----
;; advanced move commands
(defun forward-beg-of-line (arg)
  "Move forward to the beginning of the next line. With ARG, move ARG lines."
  (interactive "p")
  (if (< arg 0)
      (backward-beg-of-line (- 0 arg))
    (end-of-line arg)
    (forward-char)))

(defun backward-beg-of-line (arg)
  "Move backward to previous beginning of line. With ARG, move ARG lines."
  (interactive "p")
  (if (< arg 0)
      (forward-beg-of-line (- 0 arg))
    (backward-char)
    (beginning-of-line (- 2 arg))))

(defun forward-end-of-line (arg)
  "Move forward to the next end of line. With ARG, move ARG lines."
  (interactive "p")
  (forward-char)
  (end-of-line arg))

(defun backward-end-of-line (arg)
  "Move backward to the previous end of line. With ARG, move ARG lines."
  (interactive "p")
  (if (< arg 0)
      (forward-end-of-line (- 0 arg))
    (beginning-of-line (- 2 arg))
    (backward-char)))

;; save buffers silently, then kill emacs, put this on C-x 4 C-c
(defun save-buffers-silently-kill-emacs ()
  "Silently save all file-visiting buffers, then kill this Emacs fork."
  (interactive)
  (save-buffers-kill-emacs t))

(define-key ctl-x-4-map "\C-c" 'save-buffers-silently-kill-emacs)

-----8<----- snip snip -----8<-----

Ended up being a long posting ... Hope you can use it.

Regards,

--

Nick Ruprecht
Institut fuer Informatik der Universitaet Freiburg, Germany
(ruprecht@informatik.uni-freiburg.de)