Skip to main content

TIL: Editor Series - Configuring Emacs To Fit The Needs Part 1

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

Hi guys in this blog post, I’ll let you take a peek into my daily driver in terms of software development. Before I was an avid Vim1 user and configured Vim to its full potential, creating plugins and custom configuration but there are things which Vim couldn’t handle still. Things like handling long lines, on which when I transferred to Emacs2 didn’t occur. Been waiting for it to get implemented in Vim and Neovim3, but still none.


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.

Configuring the beast

As a software developer, I’ve spent on average an entire day to configure my text editor. Because its the life and blood of software development, without text editors we can’t create superfluous and wonderful things.

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 garbage collector threshold so it could boot up fast.

(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 where in the age of internalization where there are font face with emojis and cryptic languages.

;; 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. As sometimes Ctrl + z could be problematic in-case your running Emacs in terminal mode, which will background the current process.

;; 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 uncanny Emacs toolbar and menus. The menus for me is not necessary, as I could always call M + x to launch certain commands. I’m not fan of point and click when using text editor.

;; 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 Emacs startup screen, as I like to have empty screen when opening my editor. The setup will also disable screen flashing alerts and sounds when there is an error.

(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 run helpers to install packages easily during runtime.

(require 'package)
(setq package-enable-at-startup nil)
(setq package-archives
      '(("gnu" . "")
        ("melpa" . "")
        ("melpa-stable" . "")
        ("org" . "")
        ("marmalade" . "")))

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

  (require 'use-package))

The next configuration, as I like vim quick buffer switch. The C-6 or in vim C-^, either way it would work out in Emacs.

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

Also we will be configuration the infamous yes-or-no dialog in Emacs. The configuration will accept shorten yes or no, y or n.

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

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

  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. Wikipedia ↩︎

  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”. Wikipedia ↩︎

  3. Neovim is Vim-fork focused on extensibility and usability. ↩︎

Popular posts from this blog

TIL: Disable mDNS and SSDP Discovery in Google Chrome

We're born alone, we live alone, we die alone. Only through our love and friendship can we create the illusion for the moment that we're not alone. — Orson Welles.

TIL: Flutter Series - Custom Icons

Everyone thinks of changing the world, but no one thinks of changing himself. — Leo Tolstoy.

TIL: Gimp Automating Image Processing with Python Fu

What a large volume of adventures may be grasped within the span of his little life by him who interests his heart in everything. — Laurence Sterne.

TOP: Three DNS Providers That Provides Good Service in SEA (Southeast Asia)

If you give a hacker a new toy, the first thing he'll do is take it apart to figure out how it works. — Jamie Zawinski.