Previous: Programmatic Rebinding, Up: Rebinding


27.4.2.3 Using Strings for Changing Key Bindings

For backward compatibility, you can still use strings to represent key sequences. Thus you can use commands like the following:

     ;;; Bind end-of-line to C-f
     (global-set-key "\C-f" 'end-of-line)

Note, however, that in some cases you may be binding more than one key sequence by using a single command. This situation can arise because in ASCII, C-i and <TAB> have the same representation. Therefore, when Emacs sees:

     (global-set-key "\C-i" 'end-of-line)

it is unclear whether the user intended to bind C-i or <TAB>. The solution SXEmacs adopts is to bind both of these key sequences.

After binding a command to two key sequences with a form like:

             (define-key global-map "\^X\^I" 'command-1)

it is possible to redefine only one of those sequences like so:

             (define-key global-map [(control x) (control i)] 'command-2)
             (define-key global-map [(control x) tab] 'command-3)

This applies only when running under a window system. If you are talking to Emacs through an ASCII-only channel, you do not get any of these features.

Here is a table of pairs of key sequences that behave in a similar fashion:

             control h      backspace
             control l      clear
             control i      tab
             control m      return
             control j      linefeed
             control [      escape
             control @      control space