This chapter describes some simple ways of customising Emacs without knowing much about MLisp programming. If you find that the information given in this chapter does not allow you to customise Emacs satisfactorily, then you should read the Barry's Emacs Programmer's Guide.
Emacs is designed to be customisable; you can rearrange many Emacs attributes to suit your own taste. Simple customisations are primarily of the following types:
Most Emacs users find that they want to customise some features when they first start using Emacs. Later, as they become more familiar with Emacs features, new customisations become apparent.
You will decide which bindings, options and libraries you want to access regularly, and then expect them to be automatically available each time you use Emacs. You can achieve this by making your customisations, then saving them in an Emacs environment file. Emacs starts very quickly when using environment files.
Emacs saves the following information in environment files:
Subprocesses stored in an environment file are re-started when the Emacs environment is restored. The subprocess input, output and termination procedures and buffers are also restored. Note, however, that re-created subprocesses execute with the default directory of the new Emacs process. Symbols and logical names set up in the saved process are not restored.
Scheduled procedures are procedures delivered at a specified time. If that time has already expired, they are delivered immediately.
You use the ESC-x save-environment command to save the current environment in an Emacs environment file. save-environment asks for the name of the file you want to create. Press Return to get the default filename.
You use the /restore command qualifier on the Emacs command to make Emacs restore an environment. This qualifier is implicitly applied when it is not present on the command line. By default, Emacs restores the environment file from emacs_user:
Each operating system uses a different name for the default Emacs environment file. This allows you use share your emacs_user directory between different operating systems.
Operating System | Default Emacs Environment Filename |
---|---|
Windows NT | emacs_user:emacs7_nt.env |
Windows 95 | emacs_user:emacs7_95.env |
FreeBSD | emacs_user:emacs7_FreeBSD_i386.emacs_environment |
HP-UX | emacs_user:emacs7_hpux_pa_risc.emacs_environment |
AIX | emacs_user:emacs7_aix_ppc.emacs_environment |
You cannot restore an environment file that was saved by a previous version of Emacs or on a different operating system.
If Emacs detects an attempt to restore an incompatible environment, an error message is displayed and the editing session is aborted. If this happens to you, you must rebuild your environment file.
Since it is possible that an environment file can become out-of-date, it is best to build your environment file in such a way that it can be easily rebuilt.
Some customisations in Emacs can be achieved by setting system variables . Some examples of system variables are:
ask-about-buffer-names split-height-threshold quick-redisplay
To change a variable while Emacs is running, use the command ESC-x set. set will ask you for the name of the variable you want to change. You can use name completion to enter the variable name. set will then ask for the value to be inserted into the variable. All the usual Mini-buffer editing commands are available while entering the value. You can abort the whole command using ^G.
If the variable is a boolean, you can type the string 1, on, yes or true to set the value of a variable to logical true, or 0, off, no or false to set the value to logical false. Otherwise, just type the value required.
If the variable is a string, then the value you type is inserted into the variable exactly as you type it. If the variable is numeric, the value is first converted to an integer.
To set a variable in your emacsinit.ml file, you must use the setq function rather than set. The format is as follows:
(setq variable-name value)
where variable-name is the name of the variable to be set, and value is the value required. If the value is a string, then the text of the string should be enclosed in double quotes.
Some variables have a different value in each buffer. These are called buffer-specific variables . Each buffer-specific variable has a default value which is used to initialise each buffer's local copy of the variable. To set the default value of a buffer-specific variable in your EmacsINIT.ML file, enter a line with the following format:
(setq-default variable-name value)
where variable-name is the name of the variable to be set, and value is the value required.
Some examples of setting variables are:
(setq journal-frequency 30) (setq global-mode-string "Emacs") (setq-default highlight-region 1)
Emacs allows you to associate arbitrary sequences of keystrokes with any Emacs function. This association is called a key binding -- the key sequence is said to be bound to the function. More than one key sequence can be bound to each function.
For each buffer, Emacs keeps two possible sets of associations: the global bindings and the local bindings. Global bindings apply to all of Emacs' buffers, while local bindings apply only to a specific buffer. Each type of binding has its own command that makes the function-to-keystroke association.
To create a global binding while Emacs is running, use the ESC-x bind-to-key command. This command prompts you for the command name and the key sequence. To make the binding in your EmacsINIT.ML file, enter a line of the form:
(bind-to-key "function-name" "key-sequence")
where function-name is the name of the function to be bound to the sequence key-sequence.
To make local bindings, use the same syntax as above, but replace bind-to-key with local-bind-to-key.
Here are some examples of key bindings:
(bind-to-key "new-undo" "\^Z") (bind-to-key "execute-extended-command" "\[f12]") (local-bind-to-key "execute-mlisp-file" "\^X\^X")
Emacs has two sets of key names. For older code there is a set of key names based on the DEC LK201 keyboard used on the VT220 video terminal.
The second set of key names if based on the names of key from the PC keyboard.
describe-binding, describe-key, etc use the name of keys on the PC key board, not the LK201 as before.
Use \[pc-key-name] to bind to a key using the name of keys as they appear on a PC keyboard. Use \(lk201-key-name) for LK201 key names.
You can bind to seperately to a KEY and to ctrl-KEY. For example \[f5] and \[ctrl-f5]
The full list of PC key names is:
\[f1] | \[ctrl-f1] |
\[f2] | \[ctrl-f2] |
\[f3] | \[ctrl-f3] |
\[f4] | \[ctrl-f4] |
\[f5] | \[ctrl-f5] |
\[f6] | \[ctrl-f6] |
\[f7] | \[ctrl-f7] |
\[f8] | \[ctrl-f8] |
\[f9] | \[ctrl-f9] |
\[f10] | \[ctrl-f10] |
\[f11] | \[ctrl-f11] |
\[f12] | \[ctrl-f12] |
\[delete] | \[ctrl-delete] |
\[insert] | \[ctrl-insert] |
\[shift-delete] | \[shift-insert] |
\[end] | \[ctrl-end] |
\[home] | \[ctrl-home] |
\[page-down] | \[ctrl-page-down] |
\[page-up] | \[ctrl-page-up] |
\[pause] | \[ctrl-pause] |
\[scroll-lock] | \[ctrl-scroll-lock] |
\[left] | \[ctrl-left] |
\[right] | \[ctrl-right] |
\[up] | \[ctrl-up] |
\[down] | \[ctrl-down] |
\[mouse-wheel-neg] | \[ctrl-mouse-wheel-neg] |
\[mouse-wheel-pos] | \[ctrl-mouse-wheel-pos] |
\[kp-divide] | \[kp-dot] |
\[kp-enter] | \[kp-minus] |
\[kp-multiple] | \[kp-plus] |
\[kp0] | \[kp1] |
\[kp2] | \[kp3] |
\[kp4] | \[kp5] |
\[kp6] | \[kp7] |
\[kp8] | \[kp9] |
\[csi] | \[ss3] |
\[menu] | \[mouse] |
\[mouse-1-down] | \[mouse-1-up] |
\[mouse-2-down] | \[mouse-2-up] |
\[mouse-3-down] | \[mouse-3-up] |
\[mouse-4-down] | \[mouse-4-up] |
\[mouse-wheel] |
A considerable number of the functions in Emacs reside in libraries. A function is not accessible unless the library that defines the function is loaded. A number of libraries are provided with Emacs, and can be loaded automatically or on request to make their functions available.
To load a library while Emacs is running, use ESC-x execute-mlisp-file. Emacs looks for the library either in your default directory or the directory you specify, or in the Emacs directory, or in the MLisp-library database search-list. Once Emacs has located the library, it is loaded. All the functions defined in the library are then available for use.
For example, if you load the AREA library, you can then use ESC-x delete-area to delete an area of the screen. The delete-area function is defined in the AREA library.
In addition to making functions accessible to ESC-x, the library may bind some functions to key sequences. This is done by the library loading another file called libraryname.key, where libraryname is the name of the library being loaded.
This separation of functions from key bindings allows you to define your own bindings for functions in the library that will override the default bindings. To do this, make a private copy of the .key file, edit it to make your own bindings, then put the modified in your emacs_user directory or in your personal emacslib database file.
Some libraries are loaded automatically in the course of executing certain functions. You will not normally notice this. For example, the process library is automatically loaded when you use the shell function for the first time. This facility is known as autoloading. Autoloading is used to make library functions available without you having to know how to load the library; autoloading also saves space in Emacs by loading libraries only when you need them.
Autoloading works as if you had used execute-mlisp-file on the required library. Autoloading is set up using the function autoload.
To make an autoload association, enter a line with the format shown below in your emacsinit.ml file:
(autoload "function-name" "file-name")
where function-name is the name of the function to be autoloaded and file-name is the library which must be loaded to define the specified function. Both are text strings and should be enclosed in double quotes.
Some examples of autoloads are:
(autoload "dabbrev" "dabbrev") (autoload "shell" "process")
You can create your own libraries which you can share with other Emacs users if you know how to write MLisp code. See the Barry's Emacs Programmer's Guide for details on MLisp programming.