In this post I want to write about probably the most powerful text editor there is: Emacs and how to set it up so you can begin programming and live coding with Overtone in no time. Many users would disagree and argue that vi/Vim is the king of editors, and I’m not going to get into that bickering, which has lasted for several decades, as can be seen on this wiki page. Even Google joined in on this joke, as can be seen in the following screenshot:
I’m just going to say that Emacs has been my primary text editor/programming environment for several years now, and I found that it is very pleasant to use once I got past the fact that it has different keybindings than most modern programs.
Why should you consider Emacs?
It is one of the oldest editors still in use. It is very stable, powerful, extensible, and has great learning resources. On top of that, there is a mature development environment built for Clojure called CIDER that most Clojurians use. In fact, for every programming language there is a mode which enhances your experience while working in Emacs. Modes also exist for other software programmers typically use, such as Magit for git or Ansi-term if you want to run a terminal process inside Emacs.
Since Emacs is keyboard oriented (although you can use it with context menus if you want) in this article everything I do and describe will be done using keybindings. Although harder at first, it ultimately enables us to be more proficient and have better workflow, rarely taking our hands off our keyboards. There are many other benefits to using Emacs, but in favor of keeping this article short(ish) we will leave that for some other time. Now, let’s move on to the installation and setup!
Install Emacs
Linux
There are many ways to install Emacs on Linux, but the easiest is probably through your distribution package manager. Since I’m using Arch Linux with default package manager Pacman, I can just type in my terminal sudo pacman -S emacs
and voilà, it is on my system and ready to run. If you are on Ubuntu, the command for you would be sudo apt install emacs
. Best way to find out is to search the web for installation instructions on your particular distribution. But most of them probably have very similar and easy process as Arch or Ubuntu.
Mac OSX
I seldom use Apple computers and their OSX, but I came across this page which shows us several ways how to install Emacs. I know that Homebrew is pretty popular, so you can use it for installation. I noticed that you should first uninstall outdated version of Emacs that comes with the system and then you can install current version. Execute the following lines in your terminal:
1 2 3 4 |
sudo rm /usr/bin/emacs sudo rm -rf /usr/share/emacs brew tap railwaycat/emacsmacport brew install emacs-mac |
and that should do it. If you want to do it another way visit the first link I gave in the Mac OSX section.
Windows
This operating system doesn’t have an integrated package manager, so it’s best to go to GNU Emacs for Windows repository, open the latest directory (at the time of writing of this article that is emacs-28 and download the emacs-xx.x-installer.exe (xx.x representing the version number here). Run the downloaded executable and install the program. The same process can be repeated for updates in the future.
Next, you should set the HOME
variable because we are going to need it when configuring Emacs. Open Powershell as administrator and execute the following: setx HOME %USERPROFILE%
. This will set your HOME
variable location to C:usersyourusername
. You can specify some other location if you wish so.
Configure Emacs
Plain Emacs installation looks like this:
It looks much like any software: It has context menus at the top, then some useful graphical shortcuts below, and the rest is a welcome screen that you get when you first open Emacs. It contains some info on the program and further links where you can learn to use the editor.
Prelude
Since Emacs has been actively developed for several decades, many people configured it to suit their particular needs. But most of us are lazy and want to change as little as we need to have the best experience possible. Fortunately, there is a project called Prelude that enhances Emacs experience and makes it so that you get fully functioning development environment for many programming languages. It also contains CIDER which means we don’t have to install it separately. You can go to Prelude’s GitHub Page to find out more about the changes it brings to the default Emacs installation.
Prelude replaces your .emacs.d directory which is a place where emacs stores all preferences. You can easily install it by executing curl -L https://git.io/epre | sh
in your terminal. Another way to do it is to visit aforementioned Prelude GitHub page, click on the green Code button and then Download ZIP. Or you can just use this link to download that same ZIP. Then extract the contents in your $HOME/.emacs.d/
directory and the effect should have the same results as if you used the terminal method, except the terminal method backs up your .emacs.d directory automatically, and manually downloading and extracting the repo from the ZIP doesn’t do that.
Tweaking Prelude
If you open up Emacs now you’ll see bunch of changes happening really fast. This is because Emacs applies new settings which we got with Prelude. After that fairly short process you’ll get the message similar to “Prelude is ready to do thy bidding, Master username!”. Now, we need to do some minor tweaking to enable various prelude modules which will enhance our Experience.
First, copy the file prelude-modules.el
from your-.emacs.d-directory/sample/
to your-.emacs.d-directory/personal/
and open the freshly copied file in your favorite text editor (yes, I do mean Emacs!). There you can uncomment (remove semicolons before starting parenthesis) for modes that you want to be loaded. Here’s how my preload-modules.el file looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
;;; Uncomment the modules you'd like to use and restart Prelude afterwards ;;; General productivity tools (require 'prelude-ido) ;; Supercharges Emacs completion for C-x C-f and more ;; (require 'prelude-ivy) ;; A mighty modern alternative to ido ;; (require 'prelude-selectrum) ;; A powerful, yet simple, alternative to ivy (require 'prelude-helm) ;; Interface for narrowing and search ;; (require 'prelude-helm-everywhere) ;; Enable Helm everywhere (require 'prelude-company) (require 'prelude-key-chord) ;; Binds useful features to key combinations ;;; Vim emulation ;; ;; Enable this module if you're fond of vim's keybindings. ;; (require 'prelude-evil) ;;; Org-mode (a legendary productivity tool that deserves its own category) ;; ;; Org-mode helps you keep TODO lists, notes and more. (require 'prelude-org) ;;; Programming languages support ;; ;; Modules for a few very common programming languages ;; are enabled by default. (require 'prelude-c) (require 'prelude-clojure) (require 'prelude-coffee) (require 'prelude-common-lisp) (require 'prelude-css) (require 'prelude-dart) (require 'prelude-emacs-lisp) (require 'prelude-erlang) (require 'prelude-elixir) (require 'prelude-fsharp) (require 'prelude-go) (require 'prelude-haskell) (require 'prelude-js) (require 'prelude-latex) (require 'prelude-lisp) ;; |