Emacs 29 Quick Start
Posted: ; Updated: Apr 13, 2024 emacs
Update: I created Start Emacs as an easier way to get up and running with Emacs. It follows many of the same principles in this guide and throws in some extras. Check it out here
The no-nonsense guide to getting started with Emacs.
By the end of this guide you'll have Emacs 29 configured with better default settings, IDE features like code-completion and LSP support, and much improved minibuffer completion. Everything listed here is available out of the box or downloaded from the default Emacs package server, GNU Elpa.
Installation
Begin by installing Emacs 29 for your OS:
- Mac OS: emacs-plus via Homebrew
- Linux: Build from source (see INSTALL)
- Windows: Download an alpha.gnu.org snapshot
It's important to use Emacs 29+ and not a prior version. Emacs 29 ships with two important libraries (eglot and use-package) that are used extensively in this guide.
Run through the tutorial
Go ahead and launch Emacs. You're greeted with the startup screen which presents a bunch of useful information and a dated logo. Of particular note is the Emacs tutorial, which you should click on before continuing with the rest of this guide.
You can also launch the tutorial via C-h t
. (What is C-h
?)
Settings
You've installed Emacs and you know some basic commands. It's time to edit your emacs configuration file:
C-x C-f ~/.emacs.d/init.el
Drop in the following Emacs Lisp code:
;; Hide UI
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; Better default modes
(electric-pair-mode t)
(show-paren-mode 1)
(setq-default indent-tabs-mode nil)
(save-place-mode t)
(savehist-mode t)
(recentf-mode t)
(global-auto-revert-mode t)
;; Better default settings
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward
window-resize-pixelwise t
frame-resize-pixelwise t
load-prefer-newer t
backup-by-copying t
custom-file (expand-file-name "custom.el" user-emacs-directory))
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
;; Refresh package archives (GNU Elpa)
(require 'package)
(unless package-archive-contents
(package-refresh-contents))
I'm not going to walk through each line of code here, you can do that yourself with the built-in Emacs help system. Use M-x describe-function
or M-x describe-variable
:
M-x describe-function menu-bar-mode
M-x describe-variable window-resize-pixelwise
Or equivalently,
C-h f menu-bar-mode
C-h v window-resize-pixelwise
It's best to get acquainted with the Emacs help system and learn how to find help within Emacs itself. Later on you'll install vertico and marginalia, two packages that make navigating the minibuffer for commands (like M-x
) much more enjoyable.
Packages
With those settings out of the way, we're going to install some packages. All of these packages are available on the default Emacs package server, GNU Elpa. If you'd like to configure alternatives, like MELPA, consult the docs.
;; Great looking theme
(use-package modus-themes
:ensure t
:init
(modus-themes-load-themes)
:config
(modus-themes-load-vivendi))
;; Code completion at point
(use-package company
:ensure t
:hook (after-init . global-company-mode)
:custom
(company-idle-delay 0))
;; Better minibuffer completion
(use-package vertico
:ensure t
:custom
(vertico-cycle t)
(read-buffer-completion-ignore-case t)
(read-file-name-completion-ignore-case t)
(completion-styles '(basic substring partial-completion flex))
:init
(vertico-mode))
;; Save minibuffer results
(use-package savehist
:init
(savehist-mode))
;; Show lots of useful stuff in the minibuffer
(use-package marginalia
:after vertico
:ensure t
:init
(marginalia-mode))
Next steps
Save your configuration file, close and re-open Emacs. Time to experiment!
If you have an LSP server already installed, e.g. solargraph for Ruby, browse to a source file and activate eglot with M-x eglot
. You can ensure this happens automatically by adding an eglot-ensure
hook to your Emacs configuration:
(use-package eglot
:ensure t
:hook (ruby-mode . eglot-ensure))
From here, it's really up to you to explore and learn on your own. Here are some suggestions to help you along:
- Read about Basic Editing Commands
- Read about Working with Projects
- Read about Dired, the Directory Editor
- Browse my other Emacs posts
- Check out Mickey Peterson's Mastering Emacs