Introduction
After I set up a basic development environment on my Samsung XE303C12 Chromebook (details in this previous post), I wanted to customize my Emacs installation to better fit my workflow (Ruby on Rails web development, in particular). Here’s the list of things I did:
- Set up MELPA
- Installed a theme (flatland-black)
- Added a mode (web-mode)
MELPA Setup
I use MELPA (in addition to ELPA) to manage my Emacs packages. I really don’t have an opinion on the MELPA vs. Marmalade debate: once upon a time I used MELPA and it’s worked for me, so I haven’t put any more thought into it. For the base installation of Emacs installed via apt-get, I couldn’t find any of the common initialization files: no .emacs, no .emacs.d/init.el, and no site-start.el. I made a .emacs file in my home directory and added the following, cribbed from [1], to enable MELPA packages:
(require 'package) ;; You might already have this line (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) (when (< emacs-major-version 24) ;; For important compatibility libraries like cl-lib (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))) (package-initialize) ;; You might already have this line
A New Theme
After getting MELPA working, I wanted to install a new Emacs theme. I like light-on-dark themes and syntax highlighting for editing code and text, so I wanted a theme that offered those things. I’ve used flatland-black in the past, so I decided to go with that again this time. I suppose if I ever switch to Sublime Text I’ll be in good shape, as this is a port of one of its themes for Emacs. I installed the theme from within Emacs via:
M-x package-install RET flatland-theme
Where M indicates the meta-key (alt, typically) and RET indicates you press enter/return and it’ll prompt you for input; in this case, it wants the package name you’d like to install.
I then edited my .emacs file to have the theme load on startup by adding the following to the end (after the MELPA block we added earlier):
(load-theme 'flatland-black t)
Additional Modes
Emacs is installed with a bunch of modes, but editing embedded ruby files (.erb) is pretty painful without an additional mode. I use web-mode [2], which supports a bunch of other types of embedded parts/blocks, like CSS and JavaScript. I tried to install it from within Emacs via M-x package-install RET flatland-theme, but it failed. I had to install it via:
M-x package-list-packages
package-list-package opens a mini-buffer with a list of all the packages available in the repositories told Emacs it can look in. Then, I paged down to web-mode, selected it, switched to the newly opened mini-buffer that shows some details about it, and chose install. I opened a .erb file and used M-x web-mode RET to ensure that the mode loaded correctly.
After I was sure that the mode worked, I edited my .emacs file so that web-mode would automatically be started when I opened embedded Ruby (and some additional) files; The following is cribbed from [2]:
(require 'web-mode) (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
Summary
If you’ve followed along, you’ve got easy access to a lot more Emacs packages from its package manager (thanks to MELPA), you’ve installed a nice theme, and you’ve added a new mode to handle embedded Ruby files (or embedded CSS, JavaScript, etc.). Even if you don’t like flatland-black or don’t want to use web-mode, you can modify the instructions in the latter two sections to install a theme or mode of your choice that better fits your workflow; in particular, you can use reference [3] to browse for a theme that fits your preferences and find out if it’s available from MELPA.
References
- [MELPA: ] Getting Started. https://melpa.org/#/getting-started. Retrieved 2016-04-30.
- web-mode.el. http://web-mode.org. Retrieved 2016-05-01.
- Emacs Themes. https://emacsthemes.com. Retrieved 2016-05-01.