customising emacs

There are many different ways you can customise Emacs. You can do the following:

Emacs menus

Many of the options on the Emacs menus are similar to those found in other text editors. This section does not describe such options; instead, it describes those options that are less common.

The File menu

Option Description
Open... Open a file
Save Save the current buffer
Save As... Save the current buffer with a new name
Save All Modified files Save any file buffers contents.

The Edit menu

Many of the options on the Edit menu are similar to those found in other text editors. The less common options are:

Option Description
Mark Sets a hard mark so that you can select text. Unlike a normal Windows mark, this mark is not cleared when you move the cursor.
Case Blind Search Makes Emacs ignore the case of letters when searching.
Advanced, Delete White Space Removes all spaces and tabs that are next to the cursoron the current line. This removes white space to the left and to the right of the cursor.
Advanced, Tabify Region Replaces spaces with tabs, where possible, throughout the selected region.
Advanced, Untabify Region Replaces tabs with spaces throughout the selected region.
Advanced, Indent Region Indents the selected text, moving it to the right by one tab stop.
Advanced, Undent Region Moves the selected text to the left by one tab stop.
Preferences, Font This option enables you to select a screen font for Emacs to use. The list shows just monospaced fonts.
Preferences, Colours This option enables you to select the colours to use for
Preferences, Directories This enables you to specify various locations that Emacs uses:
Sys$Login This is your personal directory. Under Windows NT this defaults to the login in directory as defined by the system administrator.
Sys$Scratch This is the directory that Emacs functions can use for temporary files. You can use it when writing your own functions. On a Windows system you would normally set this to point to your temporary directory, often c:\temp
Emacs_User This is your personal Emacs directory. Under Windows NT it defaults to sys$login:\bemacs
Emacs_Local_Library This optional logical name may be used to point to a local library of Emacs programs and library files.
Emacs_Journal Emacs writes all journal files to the directory specified by this logical name.

When journalling is enabled, Emacs saves all the insertions and deletions made to your buffers in a journal file. The changes are saved to the journal file at the same time as you make them to the proper file.
See Barry's Emacs User Guide for more information about journalling.
Emacs_Checkpoint Emacs writes all checkpoint files to the directory specified by this logical name.

When checkpointing is enabled, Emacs saves buffers from time-to-time when a certain number of keystrokes have been made. The buffers are written automatically, but you can also force Emacs to checkpoint at any time you wish. Checkpointing prevents you from losing more than a limited amount of work if a disaster occurs.

See Barry's Emacs User Guide for more information about checkpointing.
Emacs_Memory Points to the location of the Emacs memory file. By default, this is the current directory. Define emacs_memory to be the null device to disable memory files. NUL is the name of the null device on Windows.
Emacs_Path This name is used when Emacs attempts to load an MLisp library from a file. Emacs automatically sets the value of this logical name. Its value is typically .;emacs_user:;emacs_library:
Preferences, User Logical Names A user logical name points to a directory. You can use the logical name as shorthand way of referring to that directory. For example, if you define a user logical name of tmp to point to c:\windows\temp you could then refer to a file, myfile.tmp within that directory as:
tmp:myfile.tmp


You can also use logical names when changing Emacs' default directory. You must use a colon (:) at the end of the name to force Emacs to translate the logical name. For example, to make Emacs change to the directory pointed to by the tmp logical name, you could use the following command:

change-directory tmp:
Preferences, Printing The strings you can enter to set up the print page are:
%p page number
%P total number of pages
%b buffer name
%fn file name and type
%fp path to file
%ft time stamp of the file
Preferences, File Parsing rules Use this option if you need to force Emacs to use long filenames or to use short filenames when accessing a particular disk. Normally, Emacs can determine the correct setting automatically, so you are unlikely to need to use this option.

The View menu

Option Description
View White Space Displays tabs and returns.
Wrap Long Lines When this is set, Emacs wraps lines that are too long to fit in the window. The behaviour is not the same as you get with Windows programs such as Notepad: movement commands still regard the line as a single line. Thus, next-line moves the cursor to the next proper line, which may mean moving past several wrapped lines.

Using the Emacs command line

There are a number of different command line options that you can use when starting Emacs:

To make Emacs open a file and go to a specific line number you can use any of the following:

$ bemacs +line-num file
$ bemacs /line=line-num file
$ bemacs /line:line-num file
$ bemacs -line=line-num file
$ bemacs -line:line-num file
$ bemacs file:line-num:column-num

To make Emacs open a file and make the buffer read-only you can use either of the following:

$ bemacs /readonly file
$ bemacs -readonly file

To make Emacs open a file and make the buffer writeable you can use either of the following:

$ bemacs /noreadonly file
$ bemacs -noreadonly file
$ bemacs /cd
$ bemacs -cd

Changing the Emacs startup files

When Emacs starts up, it does the following:

  1. Looks in the directory pointed to by the environemt variable emacs_user for the file emacsinit.ml. If the file is there, Emacs executes the commands in it.
  2. If Emacs cannot find emacsinit.ml in emacs_user:, it looks for the default emacsinit.m, which is in emacs_Library.

If you do not already have a copy of emacs_user:emacsinit.ml, the best way to start is to copy emacs_Library:emacsinit.ml to Emacs_User:Emacsinit.ml. You can then add your own customisations to the bottom of the file.

Setting a variable

The simplest thing you can do when editing Emacsinit.ml is to make changes to Emacs variables. For example, there is an Emacs global variable called replace-case. If you set this variable to 1 then, when doing string replacements, Emacs alters the case of the new string to match that of the string that is being replaced.

By default, Emacs starts with replace-case set to 0, but you could easily add the following line to your Emacsinit.ml file so that Emacs starts up with replace-case turned on:

(setq replace-case 1)

The standard variables are listed in the Mlisp Reference.

Customising Emacs for different filetypes

You can make Emacs behave differently depending on the type of file that you are editing. For example, when editing a text file you may want to make Emacs automatically set up margins, or to change which characters are word characters, or set up some key definitions.

Whatever it is you want Emacs to do, you must define a suitable function, or use an existing function. For example, to make Emacs execute a function called c-mode for all *.c files that it opens, you can add the following line to emacsinit.ml:

(auto-execute "c-mode" "*.c")