3 Editing Functions

This is part 3 of the XEmacs Frequently Asked Questions list. This
section is devoted to the editing-related capabilities of XEmacs (the
keyboard, mouse, buffers, text selections, etc.) and how to customize
them.

3.0: The Keyboard

Q3.0.1: How can I customize the keyboard?

Q3.0.2: How can I bind complex functions (or macros) to keys?

As an example, say you want the paste key on a Sun keyboard to
insert the current Primary X selection at point. You can accomplish this
with:

(define-key global-map [f18] 'x-insert-selection)

However, this only works if there is a current X selection (the
selection will be highlighted). The functionality I like is for the
paste key to insert the current X selection if there is one,
otherwise insert the contents of the clipboard. To do this you need to
pass arguments to x-insert-selection. This is done by wrapping
the call in a ’lambda form:

Q3.0.5: How to map Help key alone on Sun type4 keyboard?

But it doesn’t work alone. This is in the file ‘PROBLEMS’ which
should have come with your XEmacs installation: Emacs ignores the
help key when running OLWM.

OLWM grabs the help key, and retransmits it to the appropriate
client using
XSendEvent. Allowing Emacs to react to synthetic
events is a security hole, so this is turned off by default. You can
enable it by setting the variable x-allow-sendevents to t. You
can also cause fix this by telling OLWM to not grab the help key, with
the null binding OpenWindows.KeyboardCommand.Help:.

Q3.0.7: Can I turn on sticky modifier keys?

Yes, with (setq modifier-keys-are-sticky t). This will give the
effect of being able to press and release Shift and have the next
character typed come out in upper case. This will affect all the other
modifier keys like Control and Meta as well.

3.1: The Mouse

Q3.1.1: How can I turn off Mouse pasting?

I keep hitting the middle mouse button by accident and getting stuff
pasted into my buffer so how can I turn this off?

Here is an alternative binding, whereby the middle mouse button selects
(but does not cut) the expression under the mouse. Clicking middle on a
left or right paren will select to the matching one. Note that you can
use define-key or global-set-key.

Q3.1.2: How do I set control/meta/etc modifiers on mouse buttons?

Use, for instance, [(meta button1)]. For example, here is a common
setting for Common Lisp programmers who use the bundled ilisp
package, whereby meta-button1 on a function name will find the file where
the function name was defined, and put you at that location in the source
file.

[Inside a function that gets called by the lisp-mode-hook and
ilisp-mode-hook]

This will enable Filladapt for all modes except C mode, where it doesn’t
work well. To turn Filladapt on only in particular major modes, remove
the (setq-default ...) line and use
turn-on-filladapt-mode, like this:

(add-hook 'text-mode-hook 'turn-on-filladapt-mode)

You can customize filling and adaptive filling with Customize.
Select from the Options menu
Advanced (Customize)->Emacs->Editing->Fill->Fill...
or type M-x customize <RET> fill <RET>.

Note that well-behaving text-lookalike modes will run
text-mode-hook by default (e.g. that’s what Message does). For
the nasty ones, you’ll have to provide the add-hooks yourself.

Q3.2.5: How can I get XEmacs to come up in text/auto-fill mode by default?

WARNING: note that changing the value of
default-major-mode from fundamental-mode can break a large
amount of built-in code that expects newly created buffers to be in
fundamental-mode. (Changing from fundamental-mode to
text-mode might not wreak too much havoc, but changing to
something more exotic like a lisp-mode would break many Emacs packages).

Note that Emacs by default starts up in buffer *scratch* in
initial-major-mode, which defaults to
lisp-interaction-mode. Thus adding the following form to your
Emacs init file will cause the initial *scratch* buffer to be put
into auto-fill’ed text-mode:

(setq initial-major-mode
(lambda ()
(text-mode)
(turn-on-auto-fill)))

Note that after your init file is loaded, if
inhibit-startup-message is nil (the default) and the
startup buffer is *scratch* then the startup message will be
inserted into *scratch*; it will be removed after a timeout by
erasing the entire *scratch* buffer. Keep in mind this default
usage of *scratch* if you desire any prior manipulation of
*scratch* from within your Emacs init file. In particular,
anything you insert into *scratch* from your init file will be
later erased. Also, if you change the mode of the *scratch*
buffer, be sure that this will not interfere with possible later
insertion of the startup message (e.g. if you put *scratch* into
a nonstandard mode that has automatic font lock rules, then the startup
message might get fontified in a strange foreign manner, e.g. as code in
some programming language).

Q3.3.2: How can I turn off or change highlighted selections?

The zmacs mode allows for what some might call gratuitous
highlighting for selected regions (either by setting mark or by using
the mouse). This is the default behavior. To turn off, add the
following line to your ‘init.el’ file:

(setq zmacs-regions nil)

You can also change this with Customize. Select from the
Options menu
Advanced (Customize)->Emacs->Editing->Basics->Zmacs Regions
or type M-x customize <RET> editing-basics <RET>.

To change the face for selection, look at Options->Advanced (Customize)
on the menubar.

Q3.3.3: How do I cause typing on an active region to remove it?

I want to change things so that if I select some text and start typing,
the typed text replaces the selected text, similar to Motif.

You want to use something called pending delete. Pending delete
is what happens when you select a region (with the mouse or keyboard)
and you press a key to replace the selected region by the key you typed.
Usually backspace kills the selected region.

To get this behavior, ensure that you have the ‘pc’ package
installed, and add the following lines to your
‘init.el’:

Q3.3.5: Why is killing so slow?

This actually is an X Windows question, although you’ll notice it with
keyboard operations as well as while using the GUI. Basically, there
are four ways to communicate interprogram via the X server:

Primary selection

a transient selection that gets replaced every time a new selection is made

Secondary selection

for "exchanging" with the primary selection

Cut buffers

a clipboard internal to the X server (deprecated)

Clipboard selection

a selection with a notification protocol that allows a separate app to
manage the clipboard

The cut buffers are deprecated because managing them is even more
inefficient than the clipboard notification protocol. The primary
selection works fine for many users and applications, but is not very
robust under intensive or sophisticated use.

In Motif and MS Windows, a clipboard has become the primary means for
managing cut and paste. These means that "modern" applications tend to
be oriented toward a true clipboard, rather than the primary selection.
(On Windows, there is nothing equivalent to the primary selection.)
It’s not that XEmacs doesn’t support the simple primary selection
method, it’s that more and more other applications don’t.

So the slowdown occurs because XEmacs now engages in the clipboard
notification protocol on every kill. This is especially slow on
Motif.

With most people running most clients and server on the same host, and
many of the rest working over very fast communication, you may expect
that the situation is not going to improve.

There are a number of workarounds. The most effective is to use a
special command to do selection ownership only when you intend to paste
to another application. Useful commands are kill-primary-selection
and copy-primary-selection. These work only on text selected
with the mouse (probably; experiment), and are bound by default to the
Cut and Copy, respectively, buttons on the toolbar.
copy-primary-selection is also bound to C-Insert. You can
yank the clipboard contents with yank-primary-selection, bound to
the Paste toolbar button and Sh-Insert.

If you are communicating by cut and paste with applications that use the
primary selection, then you can customize
interprogram-cut-function to nil, restoring the XEmacs
version 20 behavior. How can you tell if a program will support this?
Motifly-correct programs require the clipboard; you lose. For others,
only by trying it. You also need to customize the complementary
interprogram-paste-function to nil. (Otherwise
XEmacs-to-XEmacs pastes will not work correctly.)

You may get some relief on Motif by setting
x-selection-strict-motif-ownership to nil, but this means you will
only intermittently be able to paste XEmacs kills to Motif applications.

Q3.3.6: Why does M-w take so long?

It actually doesn’t. It leaves the region visible for a second so that
you can see what area is being yanked. If you start working, though, it
will immediately complete its operation. In other words, it will only
delay for a second if you let it.

3.4: Editing Source Code

Q3.4.1: I do not like cc-mode. How do I use the old c-mode?

Well, first off, consider if you really want to do this. cc-mode is
much more powerful than the old c-mode. If you’re having trouble
getting your old offsets to work, try using c-set-offset instead.
You might also consider using the package cc-compat.