Installing emacs
Emacs is installed by default on most linux machines and on Macs, but it may not be the most recent version. To get the most out of emacs, you should be running an up-to-date version, certainly at least version 24.4.
If you use a Mac, you should install the latest emacs from Emacs for OSX
To install your own version of emacs on linux, use your package manager, which should provide a new version. Failing that, you can build from source to get the bleeding-edge version using
git clone git://git.savannah.gnu.org/emacs.git
cd emacs
./autogen.sh
./configure --prefix=/my/install/path
make
make check
make install
If you use Windows, I’m afraid I don’t have any good recommendations. It is perfectly possible to get a nice emacs setup in Windows, but I don’t know how!
Setting up emacs
Emacs is fully useable and powerful out of the box, but is infinitely configurable and several comprehensive packaged configurations exist to get you off to a flying start. My recommendation is prelude which you install using the following steps in a terminal wondow:
- Back up any previous emacs configuration
mv ~/.emacs ~/.emacs_backup mv ~/.emacs.d ~/.emacs.d_backup rm ~/.emacs.desktop
- Now we can use curl to install prelude:
curl -L http://git.io/epre | sh
- This step is optional, and adjusts some of the modules installed by prelude to match my tastes – you can change this later. In a text editor (not emacs – we don’t want to start emacs yet) edit the file
~/.emacs.d/prelude-modules.el
– I will usenano
nano ~/.emacs.d/prelude-modules.el
and comment out the line containing
prelude-company
and uncomment the lines containingprelude-helm
andprelude-latex
- Now start
emacs
and wait a minute or two as it sets itself up for the first time. Once it has completed, quit emacs. - Next we’ll create a personal emacs configuration file where you can add your own options as you become more familiar with emacs. use
nano
or any other text editor to create a file called~/.emacs.d/personal/emacs_config.el
and paste in the following and then save
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; basic emacs configuration to be used in conjunction with prelude ;; ;; pragmaticemacs.com/installing-and-setting-up-emacs/ ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;Add MELPA repository for packages (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; prelude options ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; install additional packages - add anyto this list that you want to ;; be installed automatically (prelude-require-packages '(multiple-cursors ess)) ;;enable arrow keys (setq prelude-guru nil) ;;smooth scrolling (setq prelude-use-smooth-scrolling t) ;;uncomment this to use default theme ;;(disable-theme 'zenburn) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; display options ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;enable tool and menu bars - good for beginners (tool-bar-mode 1) (menu-bar-mode 1)
These are my personal preferences and you can ignore these if you like. You can edit this file as you get more familiar with emacs to make further config changes.
- Now start
emacs
again and wait as it finishes setting itself up.
Optional Prelude Tweaks
For the following changes you will need to edit your ~/.emacs.d/personal/emacs_config.el
, save the changes and restart emacs
- Prelude uses the dark zenburn colour scheme. You can choose lots of others, but if you just want to use the light, default colour scheme, edit your
~/.emacs.d/personal/emacs_config.el
file and uncomment the line mentioning zenburn, so it reads;;uncomment this to use default theme (disable-theme 'zenburn)
and then save the file and restart emacs
- I find that the default highlight colour in the dark zenburn theme can be hard to see, so add the following to your config file to change the colour
;;change highlight colour (set-face-attribute 'region t :background "#164040")
- Prelude highlights the ends of lines longer than 80 characters to encourage good code formatting. To prevent this, add the following to your
emacs_config.el
;;don't highlight the end of long lines (setq whitespace-line-column 99999)
- Prelude automatically saves your file frequently while you are editing. Instead, you can make emacs keep backups of your files frequently, but not overwrite the file. In this code, we tell it to make the backups in
/tmp/emacs-backup
, so look there if you ever loose or mess up a file!;;turn off aggressive auto save (setq prelude-auto-save nil) (setq backup-by-copying t ;; don't clobber symlinks backup-directory-alist '(("." . "/tmp/emacs-backups")) ;; don't litter my fs tree delete-old-versions t kept-new-versions 6 kept-old-versions 2 version-control t)
N.B. I copied this code from somewhere, but don’t remember where, so can’t give credit – sorry!
Starting to use emacs
The best thing to do is to just start using emacs for any text editing needs you have. Make use of the menus at first using the mouse, but as you do, note the keyboard shortcuts for common tasks and try to start using them. You will get the most out of emacs by using the keyboard shortcuts.
There are also lots of good emacs tutorials, including the built-in one (found under the help menu), this tutorial, and the new book at Mastering Emacs.
You can also start digging into my tips. The beginner category is a good place to start!