When I’m editing code I like as little going on as possible. Editors like VSCode won’t do it for me due to the miriad of icons and options surrounding the editing area. Emacs on the other hand offers that experience after just a couple of tweaks.
In this article I’ll walk through the visual tweaks that I’ve applied to my Emacs.
Rather than try and cram everything into my .emacs
file I keep my emacs config in a ~/.emacs.d
directory. Starting with version 22 Emacs will look for a ~/.emacs.d/init.el
file it it can’t find a .emacs
file.
To get started create a .emacs.d
directory with an init.el
file inside. Inside of our Emacs directory we’ll keep all of our code in a lisp
directory so we’ll make that as well.
cd ~
mkdir .emacs.d
cd .emacs.d
touch init.el
mkdir lisp
In order to load files inside our lisp
directory, we’ll need to tell emacs about it. To do that, add the following line to the top of your init.el
file:
;; Load files from the lisp directory.
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))
Now, lets create our first elisp file. We’ll call it init-elpa
and we’ll use it to initialize our emacs package manager and add a function for loading packages. First, create it and load it in init.el
.
touch lisp/init-elpa.el
;; init.el
(require 'init-elpa)
Then, create the file and add the following:
(require 'package)
(defun require-package (package)
"Install given PACKAGE if it was not installed before."
(if (package-installed-p package)
t
(progn
(unless (assoc package package-archive-contents)
(package-refresh-contents))
(package-install package))))
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives
'("gnu" . "https://elpa.gnu.org/packages/"))
;; Use Melpa and GNU packages
(package-initialize)
(provide 'init-elpa)
This gives us a function called require-package
which will make sure that a package is installed and install it if not and it hooks us up to the emacs package managers.
With that done we can now make our Emacs beautiful! Create a file called lisp/init-ui.el
and add (require 'init-ui)
to your init.el
file then add the following to it:
(require 'init-elpa)
(require-package 'rebecca-theme)
(require-package 'golden-ratio)
(require 'golden-ratio)
(setq inhibit-startup-message t)
(menu-bar-mode -1)
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
(when (fboundp 'scroll-bar-mode)
(scroll-bar-mode -1))
(global-set-key [mouse-4] 'scroll-down-line)
(global-set-key [mouse-5] 'scroll-up-line)
(xterm-mouse-mode 1)
(load-theme 'rebecca t)
(blink-cursor-mode 0)
(setq-default cursor-type 'bar)
(set-cursor-color "#cccccc")
(setq ring-bell-function 'ignore)
(golden-ratio-mode 1)
(setq golden-ratio-auto-scale t)
(provide 'init-ui)
This removes the top bar, scroll bar, and startup message. Then, it sets up mouse mode so you use your mouse with emacs and use it to scroll. Finally it makes some modifications to the cursor and turns on golden-ratio-mode
. With golden-ratio-mode
your emacs windows will resize to highlight the active window using the golden ratio.
And with that, you’re done! Happy Emacs-ing!