Starting Up Emacs

This chapter describes the events involved in starting up Emacs, and the various facilities that you can use to change the way Emacs starts.

The Emacs Start-Up Procedure describes the Emacs start-up procedure. Emacs Initialisation Files describes how to use initialisation files to customise EMACS. Emacs Environment Files describes how to save customisations in environment files.

The Emacs Start-Up Procedure

This section describes in detail what happens when Emacs is initially started and re-started after an ESC-x pause-emacs command. The steps that are executed when returning to a paused Emacs are specifically noted.

This section describes in detail what happens when Emacs is initially started.

The following steps are executed in order:

  1. If the /restore qualifier has been specified, Emacs restores the specified environment file and initialisation continues from step 4.
  2. If /norestore qualifier is specified, Emacs executes the file emacs_library:emacs_profile.ml as a series of Mock Lisp (MLisp) expressions.
  3. emacs_library:emacs_profile.ml causes the file sys$login:emacsinit.ml to be executed as a series of MLisp expressions. If this file does not exist emacs searches the directories named in emacs_path for emacsinit.ml and executes the first one found instead.
  4. If the variable user-interface-hook contains the name of an MLisp function, then this function is executed. Normally you will leave this variable alone and let Emacs set it up for you.
  5. If Emacs is starting and the variable enter-emacs-hook contains the name of an MLisp function, then this function is executed.
  6. This is the hook you may used to execute code each time emacs starts up.
  7. If the /package=package-name qualifier is specified on the Emacs command line then the designated package is loaded and run otherwise the emacs package is loaded and run. This is achieved by taking the name specified and adding .mlp to it.

    The resulting name is then used as the name of a file to execute as a series of MLisp expressions. When the file has been completely executed, the function package-name-com is called.

    For example, a package called dired will have a file called dired.mlp that contains an MLisp function called dired-com.

  8. If the Emacs functions argc and argv have not been used since the Emacs command was issued, all the files specified on the command line are automatically visited.
  9. If no arguments were specified on the command line, Emacs attempts to restore the files that were displayed on the screen when Emacs last exited completely. This information is maintained in the emacs memory file. The contents of this file are private to Emacs, and should never be altered or edited. If the file does not exist, no files will be automatically visited. Under Unix the Emacs memory file is named emacs_memory:.emacs_mem. Under Windows the Emacs memory file is named emacs_memory:__emacs_.mem.
  10. Emacs now calls its display processor to display the screen, and then calls its keyboard processor to process keyboard commands.

Emacs Initialisation Files

An initialisation file is an MLisp program which is executed whenever you start Emacs. Emacs looks for an initialisation file using the file name emacs_path:emacsinit.ml or the MLisp program EMACSINIT.

An initialisation file can ask you questions and do things, as well as just setting up commands for later use.

The example shows a sample initialisation file.

Example: Sample EMACSINIT.ML

;
; Setup EMACS in the windows UI style
;
(default-emacs-init "windows,windows-extended,ere-searching")

;
; Set up some variables
;
(setq scroll-step 1)
(setq visible-bell 1)
(setq silently-kill-processes 1)
(setq checkpoint-frequency 500)
(setq unlink-checkpoint-files 1)
(setq default-case-fold-search 1)
(setq default-comment-column 41)

;
; Make some functions automatically load a library or package
;
(autoload "add-tag" "tags")
(autoload "goto-tag" "tags")
(autoload "email" "email")

;
; Associate some commands with file specifications
;
(auto-execute "lisp-mode" "*.ml")
(auto-execute "text-mode" "*.tex")
(auto-execute "c-mode" "*.c")

;
; Some re-wired key bindings
;
(bind-to-key "goto-percent" "\^Xg")
(bind-to-key "add-tag" "\[F2]")
(bind-to-key "goto-tag" "\^XL")
(bind-to-key "visit-function" "\^XP")

Emacs Environment Files

On current computer hardware it is not usually worth bothering with the Emacs Environment feature.

Consider using the Emacs Environment feature if:

It may be more efficient to save your customisations, extensions and small amounts of data in an Emacs environment file. Emacs can be started up using an environment file faster than it can when reading in initialisation files.

However, environment files tend to be much larger than initialisation files because they contain all the volatile information needed to re-start an Emacs editing session.

Emacs saves the following information in environment files:

Subprocesses stored in an environment file are re-started when the Emacs environment is restored. The input, output and termination procedures and buffers are also restored. Note, however, that recreated subprocesses execute with the default directory of the new Emacs process. Symbols and logical names defined in the saved process are not restored.

Scheduled procedures saved in an environment file are delivered at the 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 and will supply a default file type of ".EMACS_ENVIRONMENT" if no file type is specified.

Use the /RESTORE qualifier on the Emacs command line to cause Emacs to restore an environment file.

You cannot restore an environment file that was saved by a previous version of Emacs. Emacs will not be able to restore an environment file if the VMS shared libraries that Emacs uses have changed significantly since the environment was saved (this often happens when VMS is upgraded).

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.