30 days of Emacs – Day 1

TextMate is my editor of choice. Previously, I used vim for almost ten years. Now I've decided to try Emacs for 30 days.

Installation

I'm on macOS, so installing Emacs was painless using Homebrew (Sorry, nix users):

$ brew install --cask emacs
$ emacs --version
GNU Emacs 27.2
Copyright (C) 2021 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

First Steps

I decided to go through the Emacs tutorial. It was as easy as pressing C-h t. After finishing the tutorial, I decided to cleanup the UI a little bit.

Excerpt from my $HOME/.emacs.d/init.el file:

;; Configure font
(set-frame-font "DejaVu Sans Mono-14" nil t)

;; Inhibit the startup screen.
(setq inhibit-startup-screen t)

;; Disable tool-bar mode
(tool-bar-mode -1)

;; Disable menu-bar mode
(menu-bar-mode -1)

;; Disable scroll-bar mode
(scroll-bar-mode -1)

Much better! The only missing piece was replacing the default theme. A quick DuckDuckGo search led me to the Zenburn theme.

Package Management

To use the Zenburn theme I had to install the package. I knew for a fact that I would be installing more packages as I progress, so I decided to spend some time on a proper setup. The result? A use-package based setup:

Excerpt from my $HOME/.emacs.d/init.el file:

;; Configure packages
(setq package-file (expand-file-name "package.el" user-emacs-directory))
(when (file-exists-p package-file)
  (load package-file))

Excerpt from my $HOME/.emacs.d/package.el file:

(require 'package)

;; Do not automatically make installed packages available before
;; reading the init file.
(setq package-enable-at-startup nil)

;; Add the MELPA Stable repository to the list of package archives.
(add-to-list 'package-archives
             '("melpa-stable" . "https://stable.melpa.org/packages/") t)

;; Install the `use-package' package if not already installed.
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

;; Initialize `use-package'.
(eval-when-compile
  (require 'use-package))

;; Treat every package as though it had specified using ‘:ensure SEXP’.
(setq use-package-always-ensure t)

;; Enable the zenburn theme.
;; See https://github.com/bbatsov/zenburn-emacs
(use-package zenburn-theme
  :config
  (load-theme 'zenburn t))

This will automatically load the package.el file from $HOME/.emacs.d/package.el, should it exist. The package.el file is responsible for the heavily lifting. It automatically installs use-package if it's not already installed. The use-package macro allow me to install, load and configure packages in a declarative manner.

Voila! See you tomorrow.