Next: , Previous: , Up: Customization Basics   [Contents][Index]


4.1 Customize key bindings

Most of SXEmacs commands use key sequences. See Keystrokes in SXEmacs User’s Manual, for more information about Keys and Commands. In SXEmacs, the keys themselves carry no meaning unless they are bound to a function. For example, C-n moves the cursor to the next line because its bound to the function next-line. Similarly, C-p moves to the previous line because its bound to the function previous-line. The functions themselves define a particular behavior. You can customize the key C-n to move to the previous line by binding it to previous-line and C-p to move to the next line by binding it to next-line. To bind keys to globally run commands you need to use the following syntax in your init.el file:

(global-set-key keys cmd)

Here, global-set-key is a function which will bind the keys to the specified cmd. For example, if you type the following in your init.el file:

(global-set-key "\C-p" 'next-line)
(global-set-key "\C-n" 'previous-line)

then C-p will move to the next line and C-n to the previous line.

You can also disable a key binding, by using ‘nil’ as the cmd in the syntax stated above. Here, ‘nil’ stands for ‘false’ which means disable a command or turn off a feature. If you want to enable a command or turn on a particular feature use ‘t’ which stands for ‘true’. For example, if you do not wish C-x C-c to ‘Exit SXEmacs’ you can type the following expression in your init.el file:

(global-set-key "\C-x\C-c" nil)

You might want to have this statement in your init.el file because its easy to hit this command by mistake and it could be annoying to exit Emacs unintentionally. There is an Exit SXEmacs option in the File menu which you might want to use instead. To make a particular key undefined you can also use:

(global-unset-key "\C-x\C-c")

Now if you use the command C-x C-c, you will get an error saying that the command is undefined.

Some other customizations you could try are:

Another syntax for customizing key bindings is: (define-key keymap keys def) It defines keys to run def in the keymap keymap.

keymap is a keymap object which records the bindings of keys to the commands that they run.

keys is the sequence of keystrokes to bind.

def is anything that can be a key’s definition:

Look at the following two examples:

(define-key global-map "\C-xl" 'make-symbolic-link)
(define-key c-mode-map "\C-xl" 'make-symbolic-link)

Both the examples bind the key C-xl to run the function make-symbolic-link (see Misc File Ops in SXEmacs User’s Manual). However, the second example will bind the key only for C mode. See Major Modes in SXEmacs User’s Manual, for more information on Major Modes in SXEmacs.


Next: , Previous: , Up: Customization Basics   [Contents][Index]