[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
#### Write me.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
Add the following (Thanks to Richard Mlynarik and Wayne Newberry) to ‘.emacs’:
(defun scroll-up-one-line () (interactive) (scroll-up 1)) (defun scroll-down-one-line () (interactive) (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] | [ ? ] |
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 () (interactive) (message "You hit DELETE")) (define-key key-translation-map 'delete 'redirected-delete) (global-set-key 'redirected-delete 'foo) |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
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 , => çetc.
Also, recent versions of XFree86 define various AltGr-<key> combinations as dead keys, i.e.
AltGr [ => dead_diaeresis AltGr ] => dead_tilde AltGr ; => dead_acuteetc.
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] | [ ? ] |
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] | [ ? ] |
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)or
; Emacs only (define-key global-map [C-right] 'forward-word)or
; ver > 20, both (define-key global-map (kbd "C-<right>") 'forward-word)
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
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’:
(tpu-edt) |
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] | [ ? ] |
Our recommended VI emulator is viper. To make viper-mode the default, add this to your ‘init.el’:
(viper-mode) |
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] | [ ? ] |
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] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
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] | [ ? ] |
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] | [ ? ] |
The following code will replace the default popup on button3:
(global-set-key [button3] 'popup-buffer-menu) |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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\", \"___________`_`_`___b_b_b_b_________`____\", \"_________`_`_`___b_c_c_c_b_b____________\", \"_____`_`_`_e___b_b_c_c_c___b___b_______`\", \"___`_`_e_a___b_b_d___b___b___b___b______\", \"_`_`_e_a_e___b_b_d_b___b___b___b___b____\", \"_`_`_a_e_a___b_b_d___b___b___b___b___b__\", \"_`_`_e_a_e___b_b_d_b___b___b___b___b_b__\", \"___`_`_e_a___b_b_b_d_c___b___b___d_b____\", \"_____`_`_e_e___b_b_b_d_c___b_b_d_b______\", \"_`_____`_`_`_`___b_b_b_d_d_d_d_b________\", \"___`_____`_`_`_`___b_b_b_b_b_b__________\", } ;"] [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] | [ ? ] |
Like this:
(insert (current-time-string)) |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Vin Shelton writes:
(setq initial-frame-plist '(minibuffer nil)) (setq default-frame-plist '(minibuffer nil)) (setq default-minibuffer-frame (make-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))) (frame-notice-user-settings) |
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] | [ ? ] |
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-hook
s yourself.
Please note that the fa-extras
package is no longer useful.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 () (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).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
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] | [ ? ] |
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’:
(cond ((fboundp 'turn-on-pending-delete) (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] | [ ? ] |
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] | [ ? ] |
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:
a transient selection that gets replaced every time a new selection is made
for "exchanging" with the primary selection
a clipboard internal to the X server (deprecated)
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] | [ ? ] |
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] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
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.