+++
title = "Emacs config"
author = ["Pavel"]
draft = false
+++
\#+begin\_quote
One day we won't hate one another, no young boy will march to war and I will clean up my Emacs config. But that day isn'.
Table of Contents
- [Primary setup](#primary-setup)
- [Measure startup speed](#measure-startup-speed)
- [straight.el](#straight-dot-el)
- [use-package](#use-package)
- [Config variants & environment](#config-variants-and-environment)
- [Performance](#performance)
- [Garbage collection](#garbage-collection)
- [Run garbage collection when Emacs is unfocused](#run-garbage-collection-when-emacs-is-unfocused)
- [Native compilation](#native-compilation)
- [Anaconda](#anaconda)
- [Custom file location](#custom-file-location)
- [Private config](#private-config)
- [No littering](#no-littering)
- [Prevent Emacs from closing](#prevent-emacs-from-closing)
- [Global editing configuration](#global-editing-configuration)
- [General keybindings stuff](#general-keybindings-stuff)
- [general.el](#general-dot-el)
- [which-key](#which-key)
- [dump keybindings](#dump-keybindings)
- [Evil mode](#evil-mode)
- [evil](#evil)
- [Addons](#addons)
- [evil-collection](#evil-collection)
- [More keybindings](#more-keybindings)
- [Escape key](#escape-key)
- [Home & end](#home-and-end)
- [My leader](#my-leader)
- [Universal argument](#universal-argument)
- [Profiler](#profiler)
- [Buffer switching](#buffer-switching)
- [Buffer management](#buffer-management)
- [xref](#xref)
- [Folding](#folding)
- [Zoom](#zoom)
- [i3 integration](#i3-integration)
- [Editing helpers](#editing-helpers)
- [Visual fill column mode](#visual-fill-column-mode)
- [smartparens](#smartparens)
- [Aggressive Indent](#aggressive-indent)
- [Delete trailing whitespace](#delete-trailing-whitespace)
- [Expand region](#expand-region)
- [Various settings](#various-settings)
- [Tabs](#tabs)
- [Scrolling config](#scrolling-config)
- [Clipboard](#clipboard)
- [Backups](#backups)
- [Undo Tree](#undo-tree)
- [Help](#help)
- [Ivy, counsel, swiper](#ivy-counsel-swiper)
- [ivy-rich](#ivy-rich)
- [prescient](#prescient)
- [Keybindings](#keybindings)
- [Treemacs](#treemacs)
- [Helper functions](#helper-functions)
- [Custom icons](#custom-icons)
- [Projectile](#projectile)
- [Company](#company)
- [Git & Magit](#git-and-magit)
- [Editorconfig](#editorconfig)
- [Snippets](#snippets)
- [Time trackers](#time-trackers)
- [WakaTime](#wakatime)
- [ActivityWatch](#activitywatch)
- [UI](#ui)
- [General UI & GUI Settings](#general-ui-and-gui-settings)
- [Theme & global stuff](#theme-and-global-stuff)
- [Custom theme](#custom-theme)
- [Font](#font)
- [Custom frame title](#custom-frame-title)
- [perspective.el](#perspective-dot-el)
- [Some functions](#some-functions)
- [
OFF (OFF) Tab bar](#off--tab-bar)
- [Setup](#setup)
- [My title](#my-title)
- [Doom Modeline](#doom-modeline)
- [
OFF (OFF) Spaceline](#off--spaceline)
- [Perspectives](#perspectives)
- [EXWM workspace](#exwm-workspace)
- [Debug](#debug)
- [My theme](#my-theme)
- [Font stuff](#font-stuff)
- [Ligatures](#ligatures)
- [Icons](#icons)
- [Highlight todo](#highlight-todo)
- [Text highlight improvements](#text-highlight-improvements)
- [Dired](#dired)
- [Basic config & keybindings](#basic-config-and-keybindings)
- [Addons](#addons)
- [Subdirectories](#subdirectories)
- [TRAMP](#tramp)
- [Bookmarks](#bookmarks)
- [Shells](#shells)
- [vterm](#vterm)
- [Configuration](#configuration)
- [Subterminal](#subterminal)
- [Dired integration](#dired-integration)
- [With-editor integration](#with-editor-integration)
- [Eshell](#eshell)
- [Org Mode](#org-mode)
- [Installation & basic settings](#installation-and-basic-settings)
- [Encryption](#encryption)
- [org-contrib](#org-contrib)
- [Integration with evil](#integration-with-evil)
- [Literate programing](#literate-programing)
- [Python & Jupyter](#python-and-jupyter)
- [Hy](#hy)
- [View HTML in browser](#view-html-in-browser)
- [PlantUML](#plantuml)
- [Setup](#setup)
- [Managing Jupyter kernels](#managing-jupyter-kernels)
- [Do not wrap the output in emacs-jupyter](#do-not-wrap-the-output-in-emacs-jupyter)
- [Wrap source code output](#wrap-source-code-output)
- [Managing a literate programming project](#managing-a-literate-programming-project)
- [Productivity & Knowledge management](#productivity-and-knowledge-management)
- [Capture templates & various settings](#capture-templates-and-various-settings)
- [Trello sync](#trello-sync)
- [org-ql](#org-ql)
- [Custom agendas](#custom-agendas)
- [Review workflow](#review-workflow)
- [Data from git & org-roam](#data-from-git-and-org-roam)
- [Data from org-journal](#data-from-org-journal)
- [Data from org-agenda via org-ql](#data-from-org-agenda-via-org-ql)
- [Capture template](#capture-template)
- [Org Journal](#org-journal)
- [Org Roam](#org-roam)
- [org-roam-ui](#org-roam-ui)
- [org-roam-protocol](#org-roam-protocol)
- [org-ref](#org-ref)
- [org-roam-bibtex](#org-roam-bibtex)
- [Managing tables](#managing-tables)
- [UI](#ui)
- [
OFF (OFF) Instant equations preview](#off--instant-equations-preview)
- [LaTeX fragments](#latex-fragments)
- [Better headers](#better-headers)
- [Org Agenda Icons](#org-agenda-icons)
- [Export](#export)
- [General settings](#general-settings)
- [Hugo](#hugo)
- [Jupyter Notebook](#jupyter-notebook)
- [Html export](#html-export)
- [LaTeX](#latex)
- [Keybindings & stuff](#keybindings-and-stuff)
- [Copy a link](#copy-a-link)
- [Open a file from `org-directory`](#open-a-file-from-org-directory)
- [Presentations](#presentations)
- [Tools](#tools)
- [TOC](#toc)
- [Screenshots](#screenshots)
- [System configuration](#system-configuration)
- [Tables for Guix Dependencies](#tables-for-guix-dependencies)
- [Noweb evaluations](#noweb-evaluations)
- [yadm hook](#yadm-hook)
- [Programming](#programming)
- [General setup](#general-setup)
- [LSP](#lsp)
- [Setup](#setup)
- [Integrations](#integrations)
- [Keybindings](#keybindings)
- [Flycheck](#flycheck)
- [Tree Sitter](#tree-sitter)
- [DAP](#dap)
- [Controls](#controls)
- [UI Fixes](#ui-fixes)
- [Helper functions](#helper-functions)
- [Improved stack frame switching](#improved-stack-frame-switching)
- [Debug templates](#debug-templates)
- [
OFF (OFF) TabNine](#off--tabnine)
- [
OFF (OFF) Code Compass](#off--code-compass)
- [Dependencies](#dependencies)
- [Plugin](#plugin)
- [Reformatter](#reformatter)
- [General additional config](#general-additional-config)
- [Web development](#web-development)
- [Emmet](#emmet)
- [Prettier](#prettier)
- [TypeScript](#typescript)
- [JavaScript](#javascript)
- [Jest](#jest)
- [web-mode](#web-mode)
- [
OFF (OFF) Vue.js](#off--vue-dot-js)
- [mmm-mode fix](#mmm-mode-fix)
- [
OFF (OFF) Svelte](#off--svelte)
- [SCSS](#scss)
- [PHP](#php)
- [LaTeX](#latex)
- [AUCTeX](#auctex)
- [BibTeX](#bibtex)
- [Import \*.sty](#import-dot-sty)
- [Snippets](#snippets)
- [Greek letters](#greek-letters)
- [English letters](#english-letters)
- [Math symbols](#math-symbols)
- [Section snippets](#section-snippets)
- [Other markup languages](#other-markup-languages)
- [Markdown](#markdown)
- [PlantUML](#plantuml)
- [LanguageTool](#languagetool)
- [Lisp](#lisp)
- [Meta Lisp](#meta-lisp)
- [Emacs Lisp](#emacs-lisp)
- [Package Lint](#package-lint)
- [General settings](#general-settings)
- [Common lisp](#common-lisp)
- [SLIME](#slime)
- [General settings](#general-settings)
- [Clojure](#clojure)
- [Hy](#hy)
- [Scheme](#scheme)
- [CLIPS](#clips)
- [Python](#python)
- [pipenv](#pipenv)
- [yapf](#yapf)
- [isort](#isort)
- [sphinx-doc](#sphinx-doc)
- [pytest](#pytest)
- [Fix comint buffer width](#fix-comint-buffer-width)
- [code-cells](#code-cells)
- [tensorboard](#tensorboard)
- [Java](#java)
- [Go](#go)
- [.NET](#dot-net)
- [C#](#c)
- [MSBuild](#msbuild)
- [fish](#fish)
- [sh](#sh)
- [Haskell](#haskell)
- [Lua](#lua)
- [JSON](#json)
- [SQL](#sql)
- [YAML](#yaml)
- [.env](#dot-env)
- [CSV](#csv)
- [
OFF (OFF) PDF](#off--pdf)
- [Docker](#docker)
- [crontab](#crontab)
- [Apps & Misc](#apps-and-misc)
- [Managing dotfiles](#managing-dotfiles)
- [Open Emacs config](#open-emacs-config)
- [Open Magit for yadm](#open-magit-for-yadm)
- [Open a dotfile](#open-a-dotfile)
- [Internet & Multimedia](#internet-and-multimedia)
- [Notmuch](#notmuch)
- [Elfeed](#elfeed)
- [Some additions](#some-additions)
- [Custom faces](#custom-faces)
- [elfeed-score](#elfeed-score)
- [YouTube & EMMS](#youtube-and-emms)
- [EMMS](#emms)
- [MPD](#mpd)
- [MPV](#mpv)
- [Cache cleanup](#cache-cleanup)
- [Fetching lyrics](#fetching-lyrics)
- [Some keybindings](#some-keybindings)
- [EMMS & mpd Fixes](#emms-and-mpd-fixes)
- [ytel](#ytel)
- [EWW](#eww)
- [ERC](#erc)
- [Google Translate](#google-translate)
- [Reading documentation](#reading-documentation)
- [tldr](#tldr)
- [man & info](#man-and-info)
- [devdocs.io](#devdocs-dot-io)
- [Utilities](#utilities)
- [pass](#pass)
- [Docker](#docker)
- [Progidy](#progidy)
- [screenshot.el](#screenshot-dot-el)
- [proced](#proced)
- [Guix](#guix)
- [Productivity](#productivity)
- [pomm](#pomm)
- [
OFF (OFF) Pomidor](#off--pomidor)
- [Calendar](#calendar)
- [Fun](#fun)
- [Discord integration](#discord-integration)
- [Snow](#snow)
- [Zone](#zone)
- [Guix settings](#guix-settings)
## Primary setup {#primary-setup}
### Measure startup speed {#measure-startup-speed}
A small function to print out the loading time and number of GCs during the loading. Can be useful as a point of data for optimizing Emacs startup time.
```emacs-lisp
(add-hook 'emacs-startup-hook
(lambda ()
(message "*** Emacs loaded in %s with %d garbage collections."
(format "%.2f seconds"
(float-time
(time-subtract after-init-time before-init-time)))
gcs-done)))
```
Set the following to `t` to print debug information during the startup. This will include the order in which the packages are loaded and the loading time of individual packages.
```emacs-lisp
;; (setq use-package-verbose t)
```
### straight.el {#straight-dot-el}
Straight.el is my Emacs package manager of choice. Its advantages & disadvantages over other options are listed pretty thoroughly in the README file in the repo.
The following is a straight.el bootstrap script.
References:
- [straight.el repo](https://github.com/raxod502/straight.el)
```emacs-lisp
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
```
### use-package {#use-package}
A macro to simplify package specification & configuration. Integrates with straight.el.
Set `use-package-verbose` to `t` to print out individual package loading time.
References:
- [use-package repo](https://github.com/jwiegley/use-package)
```emacs-lisp
(straight-use-package 'use-package)
(eval-when-compile (require 'use-package))
```
### Config variants & environment {#config-variants-and-environment}
This section is about optionating the Emacs config.
The following variable is true when my machine is not powerful enough for some resource-heavy packages.
```emacs-lisp
(setq my/lowpower (string= (system-name) "azure"))
```
The following is true if Emacs is meant to be used with TRAMP over slow ssh. Take a look at the [TRAMP](#tramp) section for more details.
```emacs-lisp
(setq my/slow-ssh
(or
(string= (getenv "IS_TRAMP") "true")
(string= (system-name) "dev-digital")
(string= (system-name) "violet")))
```
The following is true is Emacs is ran on a remote server where I don't need stuff like my org workflow
```emacs-lisp
(setq my/remote-server
(or (string= (getenv "IS_REMOTE") "true")
(string= (system-name) "dev-digital")
(string= (system-name) "violet")))
```
And the following is true if Emacs is run from termux on Android.
```emacs-lisp
(setq my/is-termux (string-match-p (rx (* nonl) "com.termux" (* nonl)) (getenv "HOME")))
```
Also, I sometimes need to know if a program is running inside Emacs (say, inside a terminal emulator). To do that, I set the following environment variable:
```emacs-lisp
(setenv "IS_EMACS" "true")
```
Finally, I want to have a minimal Emacs config for debugging purposes. This has just straight.el, use-packages and evil.
```emacs-lisp
<