[net.emacs] Assigning key bindings.

karl@ernie.Berkeley.EDU (Karl Berry.) (07/07/86)

The basic advantage of Emacs over, say, vi is that the key
bindings can be rebound. The default bindings of Emacs make
it just as incomprehensible as vi. (Well, almost -- still no
insert mode.) Abut two days after I first learned about
Emacs, I realized I would never be able to understand the
default key bindings, and started writing my own. Of course,
the documentation for every Emacs system I've ever seen
(Gosling, Gnumacs, Unipress) is TERRIBLE. (Especially if
you're either a novice or a programmer.)

Anyway, the problem of assigning new key bindings is rather
difficult, because of the tradeoff between rational
assignments and usability. One of the ways to assign keys is
to come up with a list of functions; say, kill, move
forward, move backward, move up, move down. Then assign
prefix keys for each function: ^K, ^F, ^B, ^U, ^D. Now add
second keys for each object. So, kill a character would be
^K^C. Moving up a line would be ^U^L.

It is obviously possible to reverse this -- make the objects
the prefix keys, and the functions the second key.

Both methods suffer from the same problem: it takes at least
two keys to get anything done. For a novice, that is
probably acceptable -- until the second week of use. Past
that, it is not.

So. The solution I came up with is to have hierarchies. For
example, ^T transposes two characters. ESC t transposes two
words.  ^Xt transposes two lines. Thus, as we go from
control to ESC to ^X, the object operated on gets larger.
ESC and ^X were chosen arbitrarily, because they were prefix
keys already.

Unfortunately, the key-binding designer has to work under
rather severe constraints. Many control keys have already
been usurped by manufacturers and/or networks. In order to
make my bindings work on every system I've come in contact
with, I've had to refrain from using ^S and ^Q. Furthermore,
all keyboards use ^I for tab, ^J and ^M are sent when
return is hit, and ^H is backspace. Rather a bleak
situation. (It is all very well for Stallman to say ``buy a
new terminal'' if it uses ^S/^Q flow control, but that's not
very practical if I already have one...)

Furthermore, the second character should not, I think,
distinguish between control and non-control. I spent a
frustrating few days before I simply decided to make all
key pairs (prefix,control ?) also be (prefix,?). So I also
have ^X^T bound to transposing lines.

Well. The scheme I outlined above works reasonably well for
me. It does not take care of all the cases: I have function
prefixes too, for things like killing
and inserting larger blocks of text. Since I was only
designing for myself, I was free to put in only the
functions that I personally used, which made it easier. The
problem of deciding what operations should be bound to keys
in the first place is more difficult (in general), I think, than
deciding what the bindings should be!

If anyone has any better ideas about how to assign bindings,
I'd love to hear about them. 

Please do not quote this message in its entirety or in large
part!

ucbvax!ernie!karl
karl@ernie.berkeley.edu

rajendra@bcsaic.UUCP (07/10/86)

Another problem that I have faced is that different EMACS' use different
key bindings for the same function. Maybe there should be a standard
set so that you dont have to relearn the keystrokes when the system
administer at your site decides to change from one emacs to another! 

Some of the standardization may come from ZMACS, maybe, which is pretty
much the standard on lisp machines (huh! Xerox?). Of course, ^S/^Q etc
problems will have to be sorted out. (I know in some emacs you can bind
a key to have "gobble-char" (or something similar) which basically boils
down to a no-op.) I don't know if any effort on standardization has
taken place before; its about time one did. If any particular
implementation does not use the standardized key bindings, then we
should boycott it. 

This will enable us to use the same .emacs_pro, i.e. the init files for
whatever extra stuff we write to build our environment (the feature of 
emacs that makes it the BEST!).

				- rajendra
 
arpa: uw-june!rajendra@bcsaic

Usual disclaimers apply.

jw@astgb1.UUCP (John Woodruff) (07/11/86)

In article <14754@ucbvax.BERKELEY.EDU>, karl@ernie.Berkeley.EDU (Karl Berry.) writes:
>               Abut two days after I first learned about
> Emacs, I realized I would never be able to understand the
> default key bindings, and started writing my own.

The problem is that then everyone has their own bindings, and
you are lost if you sit down at another user's login.  It's
worse if they're all coming to you for help!

I recomend that site administrators consider establishing "better"
bindings that are already developed, such as those that emulate
other editors, and make incremental changes if the need is real.
That way emacs'es are at least partially transportable.

We use Unipress emacs with slightly modified DEC EDT bindings.

crm@duke.UUCP (Charlie Martin) (07/15/86)

If we can figure out and establish a standard key-binding, then all the 
reconfigurable EMACSes (at least) can have a standard bindings set-up
which can then be fiddled with...  but can we find a single binding to
set as the standard with so many EMACSes around?
-- 
The Force be with us (of course... the Force *is* us!)

			Charlie Martin
			(...mcnc!duke!crm)

dick@tjalk.UUCP (07/20/86)

In article <7934@duke.duke.UUCP> crm@duke.UUCP (Charlie Martin) writes:
>
>If we can figure out and establish a standard key-binding, then all the 
>reconfigurable EMACSes (at least) can have a standard bindings set-up
>which can then be fiddled with...  but can we find a single binding to
>set as the standard with so many EMACSes around?
>-- 
>The Force be with us (of course... the Force *is* us!)
>
>			Charlie Martin
>			(...mcnc!duke!crm)

As a small contribution, Sjoerd Mullender and I can again bring forward
our proposal for key bindings, as already aired earlier this year.
This version has minimal modifications, the main being that
inverse-add-X-abbreviation has been removed.


1. INTRODUCTION

At this moment we, the authors, have at our disposal 7 emacses, all
slightly or more than slightly different in their key bindings, enough
to confuse novice and expert alike.  Emacs's great strength, its
programmability, turns into a weakness and chaos rages.  In an
attempt to bring some order into this chaos we have drawn up the
complete lists of initial key bindings of each emacs (i.e. the
bindings the unsuspecting user gets when he just calls the specific
emacs) and printed them side by side, on a virtual piece of paper,
210 columns wide.  Upon examination, patterns began to emerge, and
we have observed the following.

1.	Almost all elementary functions, functions "that every emacs
should have," are always bound to the same keys, ^H and ^Z being the
only problems.  These key bindings are brought together in Class A in
the proposal.

2.	Most of the non-essential functions have a "home", a binding
about which a majority of the emacses agree.  Those for which a home
could be identified are grouped in Class B.

3.	All emacses agree that ^X- or ESC- followed by a capital
letter is either bound to nothing or to the same function as ^X- or
ESC- followed by the corresponding small letter.

4.	None of the emacses directly solves the problems caused by
the fact that on some systems ^S and ^Q are preempted by the
terminal communication, as X-OFF and X-ON.  Any emacs should supply
reasonable alternatives.

This has led us to submit the attached proposal, which is
accompanied by a rationale.  The version presented here is version
2, into which we have incorporated reactions to version 1; these
reactions have helped to clear up many details.

We welcome further comments and suggestions, which will serve for
version 3, to be issued perhaps a year from now.  In the meantime we
shall endeavour to give the present proposal as wide a dissemination
as possible.  We thank all those who have given us their support.

			Dick Grune		dick@vu44.UUCP
			Sjoerd Mullender	sjoerd@vu44.UUCP
			Vrije Universiteit
			de Boelelaan 1081
			1081 HV  Amsterdam
			the Netherlands


2. PROPOSAL

	Proposal for recommended key bindings in emacs-like editors.
		Version 2.			July 1986.

SCOPE
The recommendations in this proposal apply to the key bindings as
they appear initially --upon calling the editor-- to the user who has
given no customization or initialization information.

This proposal is NOT to be construed as a recommendation against
differing local or personal key bindings, and is intended solely to
reduce confusion in the unsuspecting user and as matter for
consideration to future emacs authors.  It concerns itself primarily
with the use as a document text editor rather than a program text
editor.

The editor functions are grouped into 3 classes, according to their
relative importance:

	Class A: functions the user can expect to be present.
	Class B: optional functions, which the user can nevertheless
		expect to be present in a wordprocessor/development
		environment.
	Class C: specialized optional features, which are common
		enough for a recommendation to be in order.

In addition to these classes, two general recommendations are given.

Class A:

	Character commands:
	^B	go backward character
	^D	delete next character
	^F	go forward character
	^T	transpose characters
	^?	delete previous character

	Line commands:
	^A	go to beginning of line
	^E	go to end of line
	^K	delete to end of line

	Intra-line commands:
	^N	go to next line
	^P	go to previous line

	Word commands:
	ESC-b	go backward word
	ESC-d	delete next word
	ESC-f	go forward word
	ESC-^?	delete previous word

	Window commands:
	^V	page this window
	^Z	scroll forward
	^X-1	delete other windows
	^X-2	split window
	^X-d	delete window
	^X-o	go to other window
	ESC-^V	page other window
	ESC-<	go to beginning of file
	ESC->	go to end of file
	ESC-v	page backward
	ESC-z	scroll backward

	Buffer commands:
	^X-^B	list buffers
	^X-b	switch to named buffer
	^X-k	delete named buffer

	File commands:
	^X-^F	find named file
	^X-^I	insert named file
	^X-^M	save modified files
	^X-^R	read named file
	^X-^S	save file
	^X-^W	write named file

	Region commands:
	^@	set mark
	ESC-SPACE set mark
	^W	delete region to internal buffer
	^Y	insert from internal buffer
	^X-^X	exchange cursor and mark

	White space commands:
	^I	insert tab
	^J	insert newline and indent
	^M	insert newline
	^O	insert newline and backup

	Search commands:
	^R	search reverse
	^S	search forward
	ESC-q	query replace string
	ESC-r	replace string

	Miscellaneous commands:
	^C	exit
	^X-^C	exit
	^G	abort				(directly mapped)
	^L	redraw screen
	^Q	quote next character
	^U	argument prefix
	^^	replacement for ^Q		(directly mapped)
	^\	replacement for ^S		(directly mapped)
	^]	alternate prefix

Class B:

	Word commands:
	ESC-t	transpose words

	Sentence commands:
	^X-^?	delete to beginning of sentence
	ESC-a	go backward sentence
	ESC-e	go forward sentence
	ESC-k	delete to end of sentence

	Paragraph commands:
	ESC-[	go backward paragraph
	ESC-]	go forward paragraph
	ESC-j	justify paragraph

	Window commands:
	^X-^	enlarge window

	Region commands:
	ESC-w	copy region to internal buffer
	ESC-^W	delete region to end of internal buffer

	Case commands:
	ESC-c	capitalize word
	ESC-l	lower case word
	ESC-u	upper case word

	White space commands:
	^X-^O	delete blank lines
	ESC-\	delete horizontal space

	Macro commands:
	^X-(	start keyboard macro
	^X-)	stop keyboard macro
	^X-e	execute keyboard macro

	Information commands:
	^X-=	display cursor position
	ESC-?	help

	System commands:
	^X-^E	compile
	^X-^N	display next error
	^X-!	give command to command interpreter
	^_	call command interpreter

Class C:

	Line commands:
	^X-^T	transpose lines
	ESC-m	go to first non-blank

	Window commands:
	^X-n	go to next window
	^X-p	go to previous window
	ESC-,	go to beginning of window
	ESC-.	go to end of window

	Buffer commands:
	ESC-~	set buffer not modified

	Case commands:
	^X-^L	lower case region
	^X-^U	upper case region

	Internal editor commands:
	ESC-ESC	evaluate internal expression
	ESC-x	execute internal command
	^X-*	display version number

	Abbreviations:
	^X-^A	add local abbreviation
	^X-+	add global abbreviation

	Layout control:
	^X-.	set indent column
	^X-;	set comment column
	^X-f	set fill column
	ESC-;	indent to comment column

	Scroll sideways:
	^X-<	scroll left
	^X->	scroll right

	Parentheses:
	ESC-^B	go backward parenthesis
	ESC-^F	go forward parenthesis



CAPITAL LETTERS IN A PREFIXED COMMAND
Key strokes consisting of a prefix (^X- or ESC-) followed by a
capital letter should be bound to the same command as the prefix
followed by the corresponding small letter.

DIRECT MAPPING OF ^S, ^Q AND ^G
All key bindings that include a ^S or ^Q should have a corresponding
binding with ^\ substituted for ^S and ^^ for ^Q; all key bindings
that include ^G should result in abort.  If the editor supports
direct mapping (low-level interpretation), this should be used, so
that new bindings will automatically inherit the substitution.  If
not, appropriate explicit bindings should be supplied.

END OF PROPOSAL


3. RATIONALE

3.1 The concept
The reason for this proposal at all is the same as that for any
standard: some design decisions are to a large extend arbitrary, and
to reduce the ensuing complexity, additional artificial order has to
be imposed.  We feel that the subject has at present reached a
certain maturity and has not yet petrified.

For an editor to be used efficiently, the user must be able to
operate it by reflexes only. Having to learn a slightly different
set of reflexes leads to much aggravation, more so than having to
learn, e.g., a variant of a programming language.

3.2 The approach
We have considered the initial key bindings of
	emacs2.10 (Unipress/Gosling),
	jove (Jonathan Payne/Unison World),
	PerfectWriter (Perfect Software),
	MicroEmacs (Curt Jutzi, jutz@pogo),
	GNU (Richard M. Stallman),
	scame (Leif Samuelsson, leif@erisun),
	MicroEMACS (Dave Conroy, conroy@dec-rex).
For Class A and B we only considered those key bindings that were
defined in at least four of the above.  The key bindings for which
no rationale is given below were either unanimous or defined by some
and not contradicted by any of the others.

We have not concerned ourselves with small semantic differences:
"next-paragraph" will go to the beginning of the next paragraph on
some editors and to the end of this paragraph on others;
"transpose-characters" may transpose cursor[-2..-1] or
cursor[-1..0], etc.  These are considered equivalent, since the user
has direct optical feedback.

3.3 Specific key bindings
^H is left unbound.  It is usually bound to go-backward-character or
to delete-previous-character, without clear preference for either.
Both of these are available under other keys (^B and ^?).  Users
working on low-grade telephone lines may need to avoid ^? since it
is often generated by noise; they may bind delete-previous-character
to ^H and unbind ^?.

^Z
Some systems have the possibility to suspend a running process; this
action is traditionally coupled to the ^Z key.  It is, however, not
at all universal and requires considerable OS support.  We feel
therefore that we can still use ^Z (and its companion ESC-z) for
scrolling  --with suspending, calling the command interpreter, etc.,
bound to ^_ .

^]
Most editors do not use a third prefix besides ^X and ESC; among
those that do, there is no consensus, with ^H, ^Z, ^\, ^^ and ^X-4
being used.  ^] is not used by any editor for anything.

ESC-SPACE
Not all terminals or OSs can transmit a NUL character (^@).
ESC-SPACE can serve to bind set-mark to.  Since no more single
characters are available, a direct mapping cannot be found, nor is
one needed, in the absence of compound key sequences with ^@.

^X-^F, ^X-^R
Generally there exist two commands, "read file into new buffer" and
"read file into existing buffer", called "find named file" and "read
named file" respectively here.  They are bound to various
permutations of ^X-^F, ^X-^R and ^X-^V, the latter being called
"visit file", but being identical to "find named file".  The
proposed assignment seems more mnemonic and seems to have a slight
majority.


3.4 Capital letters in a prefixed command
The beginning user would have difficulty in telling apart ^X-^S,
^X-s, ^X-S, ESC-^S, ESC-s and ESC-S, with assorted meanings like
save-file, forward-search, call-spelling-checker, center-line or
scratch-buffer.  Some tutorials print ^X-S when they mean ^X-s.
Some users may want to use their terminals with CAPS LOCK on.

Some terminals with function keys send ESC-@ to ESC-O for them; if,
however, function keys are to play a role, local customization will
be necessary anyway, which is outside the scope of this proposal.

3.5 ^S and ^Q
^S and ^Q are used by some communication protocols and will then
cause a great deal of confusion, both to the user and to the
computer.  It seems preferable to lift this problem out of the user
realm and into the editor.

The mapping
	^S -> ^\		^Q -> ^^
is preferable to
	^S -> ^^		^Q -> ^\
since ^^ is difficult to produce on some terminals and ^Q is the
rarer of the two.  It is the binding in much of the material that
comes with GNU, Unipress and jove.

3.6 Fancy search facilities
Many emacses provide two levels of search facilities, one searching
for a simple string match, and a fancier one, e.g., incremental
search or search for a regular expression.  We do not provide
recommendations for the latter, since we feel that those who use
them will want to choose their own key bindings (like binding them
in the place of the simple ones).  Some editors govern the choice
with a mode variable.

END OF RATIONALE