>>FIRST MISSION//LOGS//bash//editor-series-configuring-emacs-to-fit-the-needs-part-1.MD
[ + ] TARGET_LOCKED200 OK
NOV 30, 2018timer 3 MIN READSYS_TAG: bash STATUS: VERIFIED_WORKING

Editor Series - Configuring Emacs To Fit The Needs Part 1

ENGINE: KERNEL // STABLE
BASE_ARCH: x86_64
HOST: VASTORIGINS.COM
GPG: OKSIG_ID: 0x4EB27DB0

Doing what needs to be done may not make you happy, but it will make you great.

~ George Bernard Shaw.

In this blog post, I’ll let you take a peek into my daily driver in terms of software development. Before this, I was an avid Vim1 user and configured Vim to its full potential, creating plugins and custom configurations, but there are things which Vim couldn’t handle still. Long lines, for example: wrapping and navigating very long lines in Vim always fought me, while on Emacs2, the problem simply didn’t occur. I kept waiting for it to get implemented in Vim and Neovim3, but it never quite landed the way I hoped.

So I made the switch, and this series is the map of everything I learned while making Emacs fit my needs exactly.

✅ Prerequisites

First of all, you need Emacs 26 and up, as this is the main topic of this article that we need to configure. There are many ways to install it on your system, kindly check your GNU/Linux distribution for specific ways to install it. On Arch, for example, pacman -S emacs is all it takes, and on Debian the package is emacs-gtk if you want the GUI flavor.

🐉 Configuring the beast

As a software developer, I’ve spent on average an entire day to configure my text editor. Because it’s the life and blood of software development; without text editors we can’t create superfluous and wonderful things. The goal is simple: an editor that boots fast, behaves predictably, and comes alive exactly when I need it.

The first thing I’ll always do is open ~/.emacs.d/init.el and set its required version and garbage collection threshold. I put versioning first, as most of the time I clone the config in a remote working environment, and the garbage collector threshold comes right after, so the editor could boot up fast instead of stuttering through the startup phase.

(unless (>= emacs-major-version 24)
  (error "Emacs version 24 or higher is required"))

;;; Code: Emacs 24 or higher only

;; Hasten up startup
(setq gc-cons-threshold (* 24 1024 1024))
(add-hook 'after-init-hook (lambda ()
                             (setq gc-cons-threshold (* 8 1024))))

Then set to accept Unicode and UTF-8. Come on guys, we’re in the age of internationalization, with font faces, emojis, and cryptic languages everywhere. A text editor that chokes on a byte sequence instead of a character is not a text editor, it is a museum piece.

;; Default to UTF-8
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq-default buffer-file-coding-system 'utf-8)

Set external changes to load up in Emacs and unset Ctrl + z. Sometimes Ctrl + z could be problematic in case you’re running Emacs in terminal mode, which will background the current process. One accidental keypress, and your editor silently disappears into the background, leaving you staring at a shell prompt wondering where your buffers went.

;; Unset C-z that freezes emacs gui
(global-unset-key (kbd "C-z"))

;; Buffers reflect external file chanes
(global-auto-revert-mode t)

Then we disable the uncanny Emacs toolbar and menus. The menus for me are not necessary, as I could always call M + x to launch certain commands. I’m not a fan of point and click when using a text editor. The same goes for the tool bar and scroll bar: every pixel of chrome is a pixel of editing space wasted.

;; Turn off interface early
(if (fboundp 'menu-bar-mode)
    (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode)
    (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode)
    (scroll-bar-mode -1))

After that we will disable the Emacs startup screen, as I like to have an empty screen when opening my editor. The setup will also disable screen flashing alerts and sounds when there is an error. There is nothing more jarring than a full screen welcome page with a GNU unicorn when all you want is to start typing.

(setq inhibit-startup-screen t                  ; Disable startup screen with graphics
      inhibit-startup-echo-area-message t       ; Disable startup echo messages
      visible-bell nil                          ; Disable visual bell graphics
      load-prefer-newer t                       ; Load newer files
      ring-bell-function 'ignore)               ; Disable audio bell

Here on we start getting our favorite packages, but before that we must configure our package repository as well as run helpers to install packages easily during runtime. The default GNU ELPA archive is a good start, but the real ecosystem lives across MELPA and the rest, so pointing Emacs at all of them upfront saves you the “package not found” dance later.

(require 'package)
(setq package-enable-at-startup nil)
(setq package-archives
      '(("gnu" . "http://elpa.gnu.org/packages/")
        ("melpa" . "http://melpa.org/packages/")
        ("melpa-stable" . "http://stable.melpa.org/packages/")
        ("org" . "https://orgmode.org/elpa/")
        ("marmalade" . "http://marmalade-repo.org/packages/")))
(package-initialize)

;; Bootstrap packages
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(eval-when-compile
  (require 'use-package))

The next configuration is for the Vim quick buffer switch that I liked so much. The C-6 or in Vim C-^, either way it would work out in Emacs. Old habits die hard, and this one binding keeps the muscle memory alive.

(global-set-key (kbd "C-6") 'mode-line-other-buffer)

Also we will be configuring the infamous yes-or-no dialog in Emacs. The configuration will accept shortened yes or no, y or n. Emacs asking “yes or no” when you are mid-flow is a small cruelty; answering y alone is the fix.

;; Disable yes-or-no
(fset 'yes-or-no-p 'y-or-n-p)

These configurations are partially the basics in configuring Emacs. Stay tuned in the next chapter as we’ll configure the necessary packages to run.

🧠 Final Thoughts

That is the foundation: a fast booting, UTF-8 friendly, chrome free Emacs with a sane package manager. None of it is glamorous, but every line here saves seconds on every single launch, and those seconds add up over a career of editing.

If this is your first time poking at Emacs configuration, copy the snippets one at a time and restart Emacs between each one, so you know exactly which change did what. In the next part we will fill this clean machine with the packages that make it a real development environment. See you there.


  1. Vim is a clone, with additions, of Bill Joy’s vi text editor program for Unix. Vim’s author, Bram Moolenaar, based it upon the source code for a port of the Stevie editor to the Amiga and released a version to the public in 1991. ↩︎
  2. Emacs or EMACS is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as “the extensible, customizable, self-documenting, real-time display editor”. ↩︎
  3. Neovim is Vim-fork focused on extensibility and usability. ↩︎
[ SIGNATURE VERIFIED // GPG 0x4EB27DB0 // PROVENANCE SECURE ]
➔ RETURN TO LOGS