GNU Emacs

See also

GNU Emacs
The official webpage for GNU Emacs.

GNU Emacs for Mac OS X

A tour of Emacs
A brief history and introduction to Emacs.

Installation

The following sections briefly describe where and how to install Emacs on the most common systems. One should install Emacs version 2x, where x > 3. If one’s system is not listed here, one might find help on installing Emacs in the official Emacs documentation or that of one’s host system.

Windows

Windows users can use the official Windows binary. One should download the zip-file and unpack it to one’s desired install location. No further installation should be necessary. More information on installation and setup can be found in the README file.

To try it out, one should run bin/emacs.exe from the Emacs installation folder. Emacs should start and a window should open. To stop Emacs and close this window,

  1. while pressing the control key, one should type x,
  2. while pressing the control key, one should type c, and then
  3. answer y.

To install Emacs shortcuts in one’s menu, one should run bin/addpm.exe.

Mac OS X

OS X users can find a “vanilla” Emacs for OS X which is recommended here. Alternatively Carbon Emacs and Aquamacs are variants of Emacs customized specifically for OS X.

Linux etc.

*nix users should use the package manager of their host system.

  • Ubuntu and Debian based systems: sudo apt install emacs
  • RedHat and Suse based systems: sudo yum install emacs
  • etc.

Setup

After installing Emacs, one should configure it by adding the following to one’s .emacs file which is the user configuration file for Emacs. To this end,

  1. press the control key and type x (i.e., C-x),
  2. press the control key and type f (i.e., C-f),
  3. type exactly ~/.emacs, and
  4. press the return key (the one written “enter” on the keyboard).

This maneuver will open up the .emacs file, which is most likely empty. Paste the following code into the buffer by pressing C-y:

(setq inhibit-startup-message t)  ; dont show the GNU splash screen
(transient-mark-mode t)           ; show selection from mark
(setq visible-bell 1)             ; turn off bip warnings
(show-paren-mode t)               ; turn on highlight paren mode
(fset 'yes-or-no-p 'y-or-n-p)     ; use y and n for questions
(global-font-lock-mode t)         ; enable syntax highlighting
(icomplete-mode 99)               ; better buffer switching

Now save the .emacs file by

  1. pressing the control key and typing x (i.e., C-x), and
  2. pressing the control key and typing s (i.e., C-s).

From now on, we will refer to the above sequence as C-x C-s (“control x control s”).

Mac OS X

In case M-x run-ocaml RET does not start OCaml inside Emacs, and assuming one’s user name on one’s Mac is one-s-user-name:

  • create the subdirectory /Users/one-s-user-name/.emacs.d/lisp,

  • put Steve Purcell’s file exec-path-from-shell.el as found on GitHub in the subdirectory /Users/one-s-user-name/.emacs.d/lisp, and

  • add the lines:

    (setq load-path (cons "/Users/one-s-user-name/.emacs.d/lisp" load-path))
    
    (require 'exec-path-from-shell)
    (exec-path-from-shell-initialize)
    

    in the .emacs file.

Doing this will enable OCaml to be started inside Emacs.

OCaml mode for Emacs

See the Tuareg repository on github.

Usage

To start OCaml inside Emacs one should run: M-x run-ocaml RET [1]. This should open a new window with an OCaml read-eval-print loop, e.g.,:

        OCaml version 4.04.0

#

If an OCaml banner and the prompt above do not appear, there is an error in one’s installation and one should seek assistance from a colleague student with the same operating system, from a peer tutor, or from the lecturer.

If one sees the banner and the prompt above, then one can type C-x 2 to split one’s screen horizontally into two windows, and then C-x b RET to get back to where one was. One types C-x o to switch windows, C-x 2 to split the current window horizontally into two, C-x 3 to split the current window vertically into two, and C-x 0 to close the current window.

The OCaml mode defines a number of useful features for programming in OCaml, as can be found through the help system with C-h m and of course through the Emacs tutorial (C-h t).

Footnote

[1]M refers the Alt-key and is pronounced meta. RET refers to the return key (a.k.a. the enter key).

Version

Created [11 Aug 2022]

Table Of Contents

Previous topic

Tools

Next topic

Objective Caml