After many years of creating new init.el
files from scratch on each machine I used (because old
ones somehow weren’t portable and were so degenerate I didn’t want to fix them) I finally decided
to organise my Emacs configuration properly. This is the result. It is heavily influenced by
Sacha Chua’s Org mode-based .emacs.d. This is also my first foray into literate programming using
Org mode. Even if not useful to anyone else, I do hope it will help me remember the purpose of each
elisp snippet I add here.
I’m starting by creating an almost empty Org file and keeping my old config as legacy.el
.
I will slowly move code here over time.
Make sure we’re using UTF-8. Also set Org’s :padline
to no
here to avoid generating an empty
line at the beginning of the file (who would ever want to begin a file with an empty line?!).
;; -*- coding: utf-8 -*-
I don’t want all this clutter. Disable tool bars, menu bars and scroll bars.
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
The startup screen is nice, but I don’t need it.
(setq inhibit-startup-screen t)
Never use unsafe file local variables, especially eval
.
(setq enable-local-variables :safe
enable-local-eval nil)
Emacs is the most important thing I run on my computer. Of course I want it to occupy my whole screen (at least one)!
(toggle-frame-maximized)
- [ ] Do this only for X. Doesn’t make sense in console.
I don’t want Emacs to automatically save customised variables in my init.el
, because they will
be overriden by org-babel-tangle
. Let’s use a separate file (custom.el
) instead.
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file)
Automatically save last place visited in each file.
(require 'saveplace)
(save-place-mode t)
Stop that annoying error when scrolling would result in cursor moving beyond buffer’s boundaries. Scroll to the top or bottom of the buffer instead.
(setq scroll-error-top-bottom t)
When scrolling with M-v
and C-v
keep 5 lines of context visible (default is 2).
(setq next-screen-context-lines 5)
Display some symbols in windows’ left fringes indicating where buffers start and end.
(setq-default indicate-buffer-boundaries 'left
indicate-empty-lines +1)
(require 'whitespace)
(global-whitespace-mode t)
Too much noise by default, we only want to see whitespace which shouldn’t be there (like tabs and lines which contain only spaces).
(setq whitespace-style (quote (face tabs trailing space-before-tab empty space-after-tab tab-mark)))
Load and activate package.el
. Add some repositories (only gnu
is available by default).
(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("org" . "http://orgmode.org/elpa/")
("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")))
(package-initialize)
Install use-package
if needed and load it. It makes installing dependencies easier.
(when (not package-archive-contents)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
Always install packages if they are not installed yet.
(setq use-package-always-ensure t)
(use-package ido)
(ido-mode)
(ido-everywhere)
(use-package projectile)
(projectile-global-mode)
Since version 1.1, Projectile no longer sets C-c p
as the default prefix, so we need to do
this manually:
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(use-package perspective)
(persp-mode)
By default, persp-selected-face
uses an ugly blue colour and no themes seem to override it,
so let’s forcefully set foreground colour to nil
, but make the face bold.
(set-face-attribute 'persp-selected-face nil
:foreground nil
:weight 'bold)
(use-package persp-projectile)
“A Collection of Ridiculously Useful eXtensions”.
(use-package crux)
(global-set-key (kbd "C-x 4 t") 'crux-transpose-windows)
(use-package avy)
(global-set-key (kbd "C-;") 'avy-goto-char-2)
(use-package magit
:commands magit-status magit-diff-buffer-file magit-log magit-blame
:init (setq magit-revert-buffers nil)
:bind (("C-c C-g s" . magit-status)
("C-c C-g d" . magit-diff-buffer-file)
("C-c C-g l" . magit-log)
("C-c C-g b" . magit-blame)))
[ ] magit-revert-buffers
is deprecated. Check alternatives and set something safe but more
convenient than nil
.
(use-package org)
Handy when creating notes about some part of a program in an organised way.
C-c l
to store current location, switch to an Org buffer, C-c C-l
to paste the link.
(require 'org)
(global-set-key (kbd "C-c l") 'org-store-link)
This, on the other hand, is useful for taking notes at any time without interrupting your normal
workflow: C-c c
, choose a template, note something down, C-c C-c
to save the note to
~/org/notes.org
and go back to where you left. You can later go to your notes.org
file and
hit C-c C-w
to refile your notes, i.e. move them to different sections/files.
(setq org-default-notes-file (concat org-directory "/notes.org"))
(global-set-key (kbd "C-c c") 'org-capture)
(use-package ox-reveal)
(use-package emojify)
(global-set-key (kbd "C-c e") 'emojify-insert-emoji)
(use-package htmlize)
Format selected code region as a snippet ready for pasting.
(use-package copy-as-format)
(global-set-key (kbd "C-c w s") 'copy-as-format-slack)
(global-set-key (kbd "C-c w g") 'copy-as-format-gitlab)
(global-set-key (kbd "C-c w j") 'copy-as-format-jira)
Copy link to current file/line from a Git repository. For private servers we need to configure
git-link-remote-alist
and git-link-commit-remote-alist
(see example below).
(use-package git-link)
(global-set-key (kbd "C-c C-g C-l") 'git-link)
;; (eval-after-load 'git-link
;; '(progn
;; (add-to-list 'git-link-remote-alist
;; '("git\\.example\\.com" git-link-gitlab))
;; (add-to-list 'git-link-commit-remote-alist
;; '("git\\.example\\.com" git-link-commit-gitlab))))
(use-package scala-mode)
scala-mode
indents extends
, with
and forSome
with an additional step. I don’t want this.
(setq scala-indent:double-indent-re
(concat (regexp-opt '() 'words)
"\\|:\\(" scala-syntax:after-reserved-symbol-re "\\)"))
Use javadoc indentation style instead (all asterisks aligned to the first one).
(custom-set-variables
'(scala-indent:use-javadoc-style t))
(use-package ensime)
(load "~/.emacs.d/legacy.el")