[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.0: The Keyboard

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.0.1: How can I customize the keyboard?

#### Write me.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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:

(global-set-key [f18]
  (lambda () (interactive) (x-insert-selection t nil)))

This binds the f18 key to a generic functional object. The interactive spec is required because only interactive functions can be bound to keys.

For the FAQ example you could use:

(global-set-key [(control ?.)]
  (lambda () (interactive) (scroll-up 1)))
(global-set-key [(control ?;)]
  (lambda () (interactive) (scroll-up -1)))

This is fine if you only need a few functions within the lambda body. If you’re doing more it’s cleaner to define a separate function. See section How do I bind C-. and C-; to scroll one line up and down?.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.0.3: How do I bind C-. and C-; to scroll one line up and down?

Add the following (Thanks to Richard Mlynarik and Wayne Newberry) to ‘.emacs’:

(defun scroll-up-one-line ()
  (scroll-up 1))

(defun scroll-down-one-line ()
  (scroll-down 1))

(global-set-key [(control ?.)] 'scroll-up-one-line) ; C-.
(global-set-key [(control ?;)] 'scroll-down-one-line) ; C-;

The key point is that you can only bind simple functions to keys; you can not bind a key to a function that you’re also passing arguments to. (see section How can I bind complex functions (or macros) to keys? for a better answer).

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.0.4: Globally binding Delete?

I cannot manage to globally bind my Delete key to something other than the default. How does one do this?

Answer: The problem is that many modes explicitly bind Delete. To get around this, try the following:

(defun foo ()
  (message "You hit DELETE"))

(define-key key-translation-map 'delete 'redirected-delete)
(global-set-key 'redirected-delete 'foo)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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

The following works in GNU Emacs 19:

(global-set-key [help] 'help-command);; Help

The following works in XEmacs with the addition of shift:

(global-set-key [(shift help)] 'help-command);; Help

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:.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.0.6: How can you type in special characters in XEmacs?

One way is to use the package x-compose. Then you can use sequences like Compose " a to get , etc.

Another way is to use the iso-insert package. Then you can use sequences like C-x 8 " a to get , etc.

Glynn Clements writes:

It depends upon your X server.

Generally, the simplest way is to define a key as Multi_key with xmodmap, e.g.

        xmodmap -e 'keycode 0xff20 = Multi_key'

You will need to pick an appropriate keycode. Use xev to find out the keycodes for each key.

[NB: On a ‘Windows’ keyboard, recent versions of XFree86 automatically define the right ‘Windows’ key as Multi_key’.]

Once you have Multi_key defined, you can use e.g.

        Multi a '       => 
        Multi e "       => 
        Multi c ,       => 


Also, recent versions of XFree86 define various AltGr-<key> combinations as dead keys, i.e.

        AltGr [         => dead_diaeresis
        AltGr ]         => dead_tilde
        AltGr ;         => dead_acute


Running ‘xmodmap -pk’ will list all of the defined keysyms.

For the related problem of displaying non-ASCII characters in a non-Mule XEmacs, See section How do I display non-ASCII characters?.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

Ben Wing writes:

One thing about the sticky modifiers is that if you move the mouse out of the frame and back in, it cancels all currently “stuck” modifiers.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.0.8: How do I map the arrow keys?

Say you want to map C-<right> to forward-word:

Sam Steingold writes:

; both XEmacs and Emacs
(define-key global-map [(control right)] 'forward-word)


; Emacs only
(define-key global-map [C-right] 'forward-word)


; ver > 20, both
(define-key global-map (kbd "C-<right>") 'forward-word)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.0.9: HP Alt key as Meta.

How can I make XEmacs recognize the Alt key of my HP workstation as a Meta key?

Put the following line into a file and load it with xmodmap(1) before starting XEmacs:

remove Mod1 = Mode_switch

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.0.10: Why does edt emulation not work?

We don’t know, but you can use tpu-edt emulation instead, which works fine and is a little fancier than the standard edt emulation. To do this, add the following line to your ‘init.el’:


If you don’t want it to replace C-h with an edt-style help menu add this as well:

(global-set-key [(control h)] 'help-for-help)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.0.11: How can I emulate VI and use it as my default mode?

Our recommended VI emulator is viper. To make viper-mode the default, add this to your ‘init.el’:


Michael Kifer writes:

This should be added as close to the top of ‘init.el’ as you can get it, otherwise some minor modes may not get viper-ized.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.0.12: Mac Alt/Option key as Meta.

Due to the Apple Command key being Meta, I can’t use XEmacs on OS X.

Didier Verna suggests:

I use an X version of XEmacs on a Mac every day. You have to tweak the keyboard configuration a bit but that’s all.

Here’s my Xmodmap file on Darwin:

clear mod1
clear mod2
keycode 66 = Meta_L
keycode 63 = Mode_switch
add mod1 = Meta_L

This leaves the command key alone and uses alt/option for Meta.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1: The Mouse

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

(defun mouse-set-point-and-select (event)
  "Sets the point at the mouse location, then marks following form"
  (interactive "@e")
  (mouse-set-point event)
  (mark-sexp 1))
(define-key global-map [button2] 'mouse-set-point-and-select)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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]

(local-set-key [(meta button1)] 'edit-definitions-lisp)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.1.3: Clicking the left button does not do anything in buffer list.

I do C-x C-b to get a list of buffers and the entries get highlighted when I move the mouse over them but clicking the left mouse does not do anything.

Use the middle mouse button.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.1.4: How can I get a list of buffers when I hit mouse button 3?

The following code will replace the default popup on button3:

(global-set-key [button3] 'popup-buffer-menu)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.1.5: How can I set XEmacs up so that it pastes where the text cursor is?

By default XEmacs pastes X selections where the mouse pointer is. How do I disable this?

Examine the function mouse-yank, by typing C-h f mouse-yank <RET>.

To get XEmacs to paste at the text cursor, add this your ‘init.el’:

(setq mouse-yank-at-point t)

You can also change this with Customize. Select from the Options menu Advanced (Customize)->Emacs->Editing->Mouse->Yank At Point... or type M-x customize <RET> mouse <RET>.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2: Buffers, Text Editing

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.2.1: Can I have the end of the buffer delimited in some way?

Say, with: ‘[END]’?

Try this:

(let ((ext (make-extent (point-min) (point-max))))
  (set-extent-property ext 'start-closed t)
  (set-extent-property ext 'end-closed t)
  (set-extent-property ext 'detachable nil)
  (set-extent-end-glyph ext (make-glyph [string :data "[END]"])))

Since this is XEmacs, you can specify an icon to be shown on window-system devices. To do so, change the make-glyph call to something like this:

(make-glyph '([xpm :file "~/something.xpm"]
              [string :data "[END]"]))

You can inline the XPM definition yourself by specifying :data instead of :file. Here is such a full-featured version that works on both X and TTY devices:

(let ((ext (make-extent (point-min) (point-max))))
  (set-extent-property ext 'start-closed t)
  (set-extent-property ext 'end-closed t)
  (set-extent-property ext 'detachable nil)
  (set-extent-end-glyph ext (make-glyph '([xpm :data "\
/* XPM */
static char* eye = {
\"20 11 7 2\",
\"__ c None\"
\"_` c #7f7f7f\",
\"_a c #fefefe\",
\"_b c #7f0000\",
\"_c c #fefe00\",
\"_d c #fe0000\",
\"_e c #bfbfbf\",
} ;"]
                                          [string :data "[END]"]))))

Note that you might want to make this a function, and put it to a hook. We leave that as an exercise for the reader.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.2.2: How do I insert today’s date into a buffer?

Like this:

(insert (current-time-string))

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.2.3: How do I get a single minibuffer frame?

Vin Shelton writes:

(setq initial-frame-plist '(minibuffer nil))
(setq default-frame-plist '(minibuffer nil))
(setq default-minibuffer-frame
       '(minibuffer only
                    width 86
                    height 1
                    menubar-visible-p nil
                    default-toolbar-visible-p nil
                    name "minibuffer"
                    top -2
                    left -2
                    has-modeline-p nil)))

Please note: The single minibuffer frame may not be to everyone’s taste, and there any number of other XEmacs options settings that may make it difficult or inconvenient to use.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.2.4: How can I enable auto-indent and/or Filladapt?

Put the following line in your ‘init.el’:

(setq indent-line-function 'indent-relative-maybe)

If you want to get fancy, try the filladapt package available standard with XEmacs. Put this into your ‘init.el’:

(require 'filladapt)
(setq-default filladapt-mode t)
(add-hook 'c-mode-hook 'turn-off-filladapt-mode)

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.

Please note that the fa-extras package is no longer useful.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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

Try the following lisp in your ‘init.el’:

(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill)

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 ()

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).

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3: Text Selections

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.3.1: How do I select a rectangular region?

Just select the region normally, then use the rectangle commands (e.g. kill-rectangle on it. The region does not highlight as a rectangle, but the commands work just fine.

To actually sweep out rectangular regions with the mouse you can use mouse-track-do-rectangle which is assigned to M-button1. Then use rectangle commands.

You can also do the following to change default behavior to sweep out rectangular regions:

(setq mouse-track-rectangle-p t)

You can also change this with Customize. Select from the Options menu Advanced (Customize)->Emacs->Editing->Mouse->Track Rectangle... or type M-x customize <RET> mouse <RET>.

 mouse-track-do-rectangle: (event)
   -- an interactive compiled Lisp function.
 Like `mouse-track' but selects rectangles instead of regions.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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’:

 ((fboundp 'turn-on-pending-delete)
 ((fboundp 'pending-delete-on)
  (pending-delete-on t)))

Note that this will work with both Backspace and Delete. This code is a tad more complicated than it has to be for XEmacs in order to make it more portable.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.3.4: Can I turn off the highlight during isearch?

I do not like my text highlighted while I am doing isearch as I am not able to see what’s underneath. How do I turn it off?

Put the following in your ‘init.el’:

(setq isearch-highlight nil)

You can also change this with Customize. Type M-x customize-variable <RET> isearch-highlight <RET>.

Note also that isearch-highlight affects query-replace and ispell. Instead of disabling isearch-highlight you may find that a better solution consists of customizing the isearch face.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

Thanks to Jeff Mincy and Glynn Clements for corrections.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4: Editing Source Code

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

But, if you still insist, add the following lines to your ‘init.el’:

(fmakunbound 'c-mode)
(makunbound 'c-mode-map)
(fmakunbound 'c++-mode)
(makunbound 'c++-mode-map)
(makunbound 'c-style-alist)
(load-library "old-c-mode")
(load-library "old-c++-mode")

This must be done before any other reference is made to either c-mode or c++-mode.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Q3.4.2: How do you make XEmacs indent CL if-clauses correctly?

I’d like XEmacs to indent all the clauses of a Common Lisp if the same amount instead of indenting the 3rd clause differently from the first two.

The package cl-indent that comes with XEmacs sets up this kind of indentation by default. cl-indent also knows about many other CL-specific forms. To use cl-indent, one can do this:

(setq lisp-indent-function 'common-lisp-indent-function)

One can also customize ‘cl-indent.el’ so it mimics the default if indentation then indented more than the else. Here’s how:

(put 'if 'common-lisp-indent-function '(nil nil &body))

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Aidan Kehoe on December 27, 2016 using texi2html 1.82.