Emacs Describe Key

Find That Function

Sometimes using Emacs you have a key combination and your not sure which function its using. To find the name of the function, use:

Alt-x 'describe-key'

This will display the function name and bindings.

For example:

Alt-x 'describe-key' M->
M-> runs the command end-of-buffer

Try it.

Emacs ASCII Extended Character

Insert Extended Character

Its not so difficult to insert an ASCII Extended Character into a file using Emacs.

Do this:

Ctrl-q 0 Octal-Value

To get the Pi symbol:

Ctrl-q 0 227

To get Infinity symbol:

Ctrl-q 0 236

Thats it.

Emacs Select All

Grab The Whole File

Sometimes working in Emacs you want to grab the whole file contents.

Its easy. Do this:

Ctrl-x h

Thats it.

Emacs File Code

Change Saved File Code

Sometimes you import a DOS file into Linux. To change the file coding in Emacs, do:

M-x set-buffer-file-coding-system [Return] unix

Its that simple.

You can also save Unix files in a DOS/Windows format:

M-x set-buffer-file-coding-system [Return] dos

X-Windows Ctrl & Caps-Lock Keys

Swap Ctrl Caps-Lock

Go to /etc/X11/xorg.conf and make a back up copy. Open xorg.conf file and find section marked as "InputDevice". Add the following:

Option "XkbOptions" "ctrl:swapcaps"

To keep your original Ctrl key as a second Ctrl and lose Caps-Lock, add the following:

Option "XkbOptions" "ctrl;nocaps"

Thats it.

Emacs Tuning

Go Faster Tweaks

Emacs is a great writing tool, but the stock install needs some tuning to make it more usable.

Here are some tweaks I use to get Emacs purring like a tuned V8.

To see what it looks like click the image to view larger size:

Here's the dot.emacs config file:

; Disable scroll jump
(setq scroll-step 1)

; Enable line number in mode line
(line-number-mode 1)

; Enable column number in mode line
(column-number-mode 1)

; Set cursor color to blue
(set-cursor-color "blue")

; Disable blinking cursor
(blink-cursor-mode nil)

; Disable beep. Flash on error
(setq-default visible-bell t)

; Highlight selected text - Ctrl-Space
(transient-mark-mode t)

; Spaces instead tabs
(setq-default indent-tabs-mode nil)

; Delete selected/highlighted text
(delete-selection-mode t)

; Re-Map M-<
(global-set-key (kbd "C-x t") 'beginning-of-buffer)

; Re-Map M-> to Ctrl-x e
(global-set-key (kbd "C-x e") 'end-of-buffer)

; Disable startup message
(setq inhibit-startup-message t)

; Disable file backup
(setq make-backup-files nil)

; Disable file saves
(setq auto-save-list-file-name nil)

; Disable auto-save
(setq auto-save-default nil)

; Enable search highlight

(setq search-highlight t)

; Enable replace highlight
(setq query-replace-highlight t)

; Enable mouse highlight
(setq mouse-sel-retain-highlight t)

; Set region background color
(set-face-background 'region "orangered")

; Set region foreground color
(set-face-foreground 'region "white")

; Set background color
(set-background-color "white")

; Define Ctrl-h to backward delete
(keyboard-translate ?\C-h ?\C-?)

; Define M-h to help - Don't add extra ' after help
(global-set-key "\M-h" 'help)

The following is from Steve Yegge's Effective Emacs. Essential reading to improve your Emacs skills.

; Item 7: Lose the UI
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))

; Item 3: Prefer backward-kill-word over Backspace
(global-set-key "\C-w" 'backward-kill-word)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-c\C-k" 'kill-region)

; Item 2: Invoke M-x without the Alt key

; To enable Ctrl-x Ctrl-m sequence add following to .emacs
(global-set-key "\C-x\C-m" 'execute-extended-command)
(global-set-key "\C-c\C-m" 'execute-extended-command)

; Item 1: Swap Caps-Lock and Control

That's about it.

XTerm TrueType Fonts

Getting XTerm To Use Your Fonts

To get XTerm to use a TrueType Font, do:

xterm -fa lucidatypewriter-10

I happen to use Lucida typewriter font. Select your own if you wish.

Enter the same command to a launcher to get an XTerm with the same fonts.

That's about it.

Emacs Fonts

Setting The Default Font

Changing fonts (faces as they are called) is not exactly intuitive in Emacs. I set the font using the menu, but it kept reverting back to a different default font each time Emacs started.

I dont use the Toolbar, Menubar or Scrollbar in Emacs, so to access the fonts menu, hold down the Ctrl key and click the right mouse button.

Select Options > Set Font/Fontset > Misc > 9x15

In order to set the default font permanently in Emacs Initialization file, you need to know the full font name. I knew it was Misc 9x15, but Emacs complained if I put that in the .emacs file.

To find the font name, open an XTerm or Terminal and do:

xfd -fn '9x15'

An X Font Display window pops up with the font details at the top. In my case it was:


I copied the file named and added it to my .emacs file.

;; Set default font to Misc 9x15
(set-default-font "-Misc-Fixed-Medium-R-Normal--15-140-75-75-C-90-ISO8859-1")

Notice the font name is "quoted".

If there's a delay before Emacs loads file, add the following to the start of you .emacs file:

(modify-frame-parameters nil '((wait-for-wm . nil)))

That's it.