Skip to content

Latest commit

 

History

History
358 lines (247 loc) · 8.69 KB

init.org

File metadata and controls

358 lines (247 loc) · 8.69 KB

Paweł Bartkiewicz’s Emacs configuration

About this file

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.

Header

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 -*-

Basic settings

Remove visual clutter

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)

Security

Never use unsafe file local variables, especially eval.

(setq enable-local-variables :safe
      enable-local-eval nil)

Appearance

Always start maximised [0/1]

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.

Customisations

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)

Save last visited place

Automatically save last place visited in each file.

(require 'saveplace)
(save-place-mode t)

Scrolling

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)

Show buffer boundaries

Display some symbols in windows’ left fringes indicating where buffers start and end.

(setq-default indicate-buffer-boundaries 'left
              indicate-empty-lines +1)

Show whitespace

(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)))

Package

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)

Use-package

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)

IDO

(use-package ido)
(ido-mode)
(ido-everywhere)

Projectile

(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)

Perspective

(use-package perspective)
(persp-mode)

Selected perspective face

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)

Integration with Projectile

(use-package persp-projectile)

CRUX

“A Collection of Ridiculously Useful eXtensions”.

(use-package crux)

Transpose windows

(global-set-key (kbd "C-x 4 t") 'crux-transpose-windows)

Avy

(use-package avy)
(global-set-key (kbd "C-;") 'avy-goto-char-2)

Git

(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.

Org

(use-package org)

org-store-link

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)

org-capture

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)

org-reveal

(use-package ox-reveal)

Emojis

Emojify

(use-package emojify)

(global-set-key (kbd "C-c e") 'emojify-insert-emoji)

Htmlize

(use-package htmlize)

Communication helpers

Copy as format

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)

Git link

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))))

Scala

Scala-mode

(use-package scala-mode)

Disable double indentation

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 "\\)"))

Scaladoc indentation style

Use javadoc indentation style instead (all asterisks aligned to the first one).

(custom-set-variables
 '(scala-indent:use-javadoc-style t))

Ensime

(use-package ensime)

Load legacy.el

(load "~/.emacs.d/legacy.el")