dot-emacs/init.org
2024-07-15 18:31:10 +02:00

1202 lines
36 KiB
Org Mode
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; -*- lexical-binding: t -*-
#+TITLE:Emacs Configuration
#+AUTHOR: Janis Böhm
#+email: janis@nirgendwo.xyz
#+STARTUP: indent
#+BABEL: :session *R* :cache yes :results silent :exports code :tangle yes
#+PROPERTY: header-args :tangle "init.el"
* Preamble
** Inspiration
I started my own emacs config after becoming fed up with how slow Spacemacs, which is my go-to config of emacs, was for me, and how rigid the experience was to me.
I never felt like I could really change Spacemacs to fit my own needs beyond what the config offered itself.
After looking online for guides on how to do a "literate configuration" and stumbled upon Sophie Bosio's [[https://sophiebos.io/posts][emacs blogs]] and [[https://github.com/SophieBosio/.emacs.d][git repo]].
** Cool Packages to remember
These are some packages which I might want to use in the future, or maybe not, but I definitely want to remember that they exist.
- https://github.com/rnkn/olivetti
This might be really nice for creative writing.
Usually, I would probably have two buffers open to emulate this same behaviour and also have the benefit of having another section of the same file open for referencing/reading back.
- https://github.com/minad/vertico
Completion engine alternative to helm, super lightweight
- https://github.com/rougier/svg-tag-mode
create svg images to replace tokens based on regexes
- https://github.com/minad/org-modern
maybe for em dashes? does loads more too.
look at org-bullets to make a package which turns =--= and =---= into $\textemdash$ and $\textemdash$.
-> https://github.com/jorgenschaefer/typoel perchance?
** Links
https://emacs.stackexchange.com/questions/12383/how-to-unbind-a-key
https://github.com/noctuid/evil-guide?tab=readme-ov-file#keymap-precedence
* Start
** Lexical Scoping
#+begin_src emacs-lisp
;;; -*- lexical-binding: t -*-
#+end_src
** Tangling init.org
From Sophie's emacs.d:
#+begin_src emacs-lisp
(defun tangle-init ()
"If the current buffer is init.org the code-blocks are
tangled, and the tangled file is compiled."
(when (equal (buffer-file-name)
(expand-file-name (concat user-emacs-directory "init.org")))
;; Avoid running hooks when tangling.
(let ((prog-mode-hook nil))
(org-babel-tangle)
(byte-compile-file (concat user-emacs-directory "init.el")))))
(add-hook 'after-save-hook 'tangle-init)
#+end_src
** Startup performance
Usually, I like to run emacs as a daemon and only ever open new emacs clients, but that often doesn't work properly and definitely doesn't work when actively working on an emacs config, so this snippet might be useful.
#+begin_src emacs-lisp
(setq gc-cons-percentage 0.6)
(setq read-process-output-max (* 1024 1024)) ;; 1mb
#+end_src
Use GC magic hack.
#+begin_src emacs-lisp :tangle no
(use-package gcmh
:config
(setq gcmh-idle-delay 5
gcmh-high-cons-threshold (* 100 1024 1024)) ; 100mb
(gcmh-mode 1))
#+end_src
I have no idea what this does, but apparently it's an optimisation.
#+begin_src emacs-lisp
(setq idle-update-delay 1.0)
#+end_src
** Cleaning up elements
Remove visual elements:
#+begin_src emacs-lisp
(dolist (mode
'(tool-bar-mode
scroll-bar-mode
menu-bar-mode
blink-cursor-mode))
(funcall mode 0))
#+end_src
#+begin_src emacs-lisp
(setq ring-bell-function 'ignore
initial-scratch-message nil
inhibit-startup-message t
use-dialog-box nil)
#+end_src
Warnings crop up every so often and they are usually unimportant.
I disable this buffer when actively working on my config.
#+begin_src emacs-lisp :tangle no
(setq native-comp-async-report-warnings-errors 'silent) ;; native-comp warning
(setq byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local))
#+end_src
Backups / Auto-saves
#+begin_src emacs-lisp
(defvar emacs-autosave-directory
(concat user-emacs-directory "autosaves/")
"This variable dictates where to put auto saves. It is set to a
directory called autosaves located wherever your .emacs.d/ is
located.")
;; Sets all files to be backed up and auto saved in a single directory.
(setq backup-directory-alist
`((".*" . ,emacs-autosave-directory))
auto-save-file-name-transforms
`((".*" ,emacs-autosave-directory t)))
#+end_src
Auto-save files:
#+begin_src emacs-lisp :tangle no
(use-package auto-save-buffers-enhanced
:ensure t
:config
(auto-save-buffers-enhanced t)
(setq auto-save-buffers-enhanced-exclude-regexps '("init.org")))
#+end_src
** Package repositories
#+begin_src emacs-lisp
(require 'package)
(require 'use-package)
(require 'use-package-ensure)
(setq use-package-always-ensure t)
#+end_src
Add package repositories and rank them by priority
#+begin_src emacs-lisp
(setq package-archives
'(("GNU ELPA" . "https://elpa.gnu.org/packages/")
("MELPA" . "https://melpa.org/packages/")
("ORG" . "https://orgmode.org/elpa/")
("MELPA Stable" . "https://stable.melpa.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/"))
package-archive-priorities
'(("GNU ELPA" . 20)
("MELPA" . 15)
("ORG" . 10)
("MELPA Stable" . 5)
("nongnu" . 0)))
(package-initialize)
; (package-refresh-contents)
#+end_src
#+begin_src emacs-lisp
(defvar local-lisp (concat user-emacs-directory "local-lisp/"))
(add-to-list 'load-path local-lisp)
(let ((default-directory local-lisp))
(normal-top-level-add-subdirs-to-load-path))
#+end_src
** Global Variables
#+begin_src emacs-lisp
(set-language-environment "UTF-8")
(column-number-mode t) ;; Show current column number in mode line
(delete-selection-mode t) ;; Replace selected text when yanking
(dirtrack-mode t) ;; Directory tracking in shell
(global-so-long-mode t) ;; Mitigate performance for long lines
(global-visual-line-mode t) ;; Break lines instead of truncating them
(global-auto-revert-mode t) ;; Revert buffers automatically when they change
(recentf-mode t) ;; Remember recently opened files
(savehist-mode t) ;; Remember minibuffer prompt history
(save-place-mode t) ;; Remember last cursor location in file
(show-paren-mode t) ;; Highlight matching parentheses
#+end_src
#+begin_src emacs-lisp
(setq-default tab-width 4
fill-column 80
indent-tabs-mode nil)
(setq use-short-answers t)
(setq initial-major-mode 'org-mode)
#+end_src
#+begin_src emacs-lisp
(use-package exec-path-from-shell
:ensure t
:config
(when (daemonp)
(exec-path-from-shell-initialize)))
#+end_src
#+begin_src emacs-lisp
(use-package keychain-environment
:defer t
:config
(keychain-refresh-environment))
#+end_src
Keymap:
#+begin_src emacs-lisp
(defvar custom-bindings-map (make-keymap)
"A keymap for custom keybindings.")
(define-minor-mode custom-bindings-mode
"A mode that activates custom keybindings."
:init-value t
:keymap custom-bindings-map)
#+end_src
* Visuals
** Borders, Frames & Windows
#+begin_src emacs-lisp
(add-to-list 'default-frame-alist '(internal-border-width . 8 ))
(set-fringe-mode 4)
(setq-default fringes-outside-margins 0)
(setq-default indicate-buffer-boundaries nil)
(setq-default indicate-empty-lines nil)
(set-face-attribute 'header-line t :inherit 'default)
#+end_src
** Themes
Light theme for writing
#+begin_src emacs-lisp
(use-package gruvbox-theme
:ensure t)
#+end_src
[[https://github.com/doomemacs/themes][Doom Themes]] as default theme
#+begin_src emacs-lisp
;; doom needs this somehow
(use-package all-the-icons
:ensure t)
(use-package doom-themes
:ensure t
:config
(setq doom-themes-enable-bold t
doom-themes-enable-italic t)
(doom-themes-org-config))
#+end_src
Manage themes, use dark-theme by default:
#+begin_src emacs-lisp
(defvar nemo/dark-theme 'doom-one)
(defvar nemo/light-theme 'gruvbox-light-medium)
(load-theme nemo/dark-theme t)
#+end_src
Disable themes before loading a new one, from [[https://github.com/larstvei/dot-emacs?tab=readme-ov-file#advice][here]].
#+begin_src emacs-lisp
(defadvice load-theme
(before disable-before-load (theme &optional no-confirm no-enable) activate)
(mapc 'disable-theme custom-enabled-themes))
#+end_src
Helper function for switching themes.
#+begin_src emacs-lisp
(defun nemo/set-light-theme ()
(interactive)
(load-theme nemo/light-theme t))
(defun nemo/set-dark-theme ()
(interactive)
(load-theme nemo/dark-theme t))
#+end_src
** Fonts
Font size [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html][(height)]] in emacs works in $\frac{1}{10}$ths of points, so ~110~ is the same as ~11~ points.
#+begin_src emacs-lisp
(defvar nemo/font-height-mono 110)
(defvar nemo/font-height-sans 120)
#+end_src
#+begin_src emacs-lisp
(set-face-attribute 'default nil :font "monospace" :height nemo/font-height-mono)
(set-face-attribute 'fixed-pitch nil :font "monospace" :height nemo/font-height-mono)
(set-face-attribute 'variable-pitch nil :font "sans-serif" :height nemo/font-height-sans)
(when (member "SF Mono" (font-family-list))
(set-face-attribute 'default nil :font "SF Mono" :height nemo/font-height-mono)
(set-face-attribute 'fixed-pitch nil :family "SF Mono" :height nemo/font-height-mono))
(when (member "SF Pro Text" (font-family-list))
(set-face-attribute 'variable-pitch nil :family "SF Pro Text" :height nemo/font-height-sans))
#+end_src
Use nerd-icons and apple emojis
#+begin_src emacs-lisp
(use-package nerd-icons)
(use-package emojify
:config
(when (member "Apple Color Emoji" (font-family-list))
(set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji") nil 'prepend)))
#+end_src
Use both fixed and variable pitched fonts and faces.
#+begin_src emacs-lisp
(use-package mixed-pitch
:defer t
:hook ((org-mode . mixed-pitch-mode)
(LaTeX-mode . mixed-pitch-mode)))
#+end_src
** Mode Line
Honestly not very happy with this at the moment, but it's kind of hacked together based on Sophie's and Amit's modelines.
#+begin_src emacs-lisp
;; Mode line setup
(setq-default
mode-line-format
'(" "
(:propertize "λ" face font-lock-comment-face)
" "
mode-line-buffer-identification
" "
; read-only or modified status
(:eval
(cond (buffer-read-only
(propertize " RO " 'face 'mode-line-read-only-face))
((buffer-modified-p)
(propertize " ** " 'face 'mode-line-modified-face))
(t " ")))
; directory and buffer/file name
(:propertize (:eval (shorten-directory default-directory 30))
face mode-line-folder-face)
(:propertize "%b"
face mode-line-filename-face)
;; Version control info
(:eval (when-let (vc vc-mode)
;; Use a pretty branch symbol in front of the branch name
(list (propertize "" 'face 'font-lock-comment-face)
(propertize (substring vc 5)
'face 'font-lock-comment-face))))
" "
(:propertize mode-name)
; (global-mode-string global-mode-string)
(:eval (propertize
" " 'display
`((space :align-to
(- (+ right right-fringe right-margin)
,(+ 2 (string-width "%4l:%c")))))))
;; Line and column numbers
(:propertize "%4l:" face mode-line-position-face)
(:eval (propertize "%c" 'face
(if (>= (current-column) 80)
'mode-line-80col-face
'mode-line-position-face)))
))
;; Helper function
(defun shorten-directory (dir max-length)
"Show up to `max-length' characters of a directory name `dir'."
(let ((path (reverse (split-string (abbreviate-file-name dir) "/")))
(output ""))
(when (and path (equal "" (car path)))
(setq path (cdr path)))
(while (and path (< (length output) (- max-length 4)))
(setq output (concat (car path) "/" output))
(setq path (cdr path)))
(when path
(setq output (concat ".../" output)))
output))
;; Extra mode line faces
(make-face 'mode-line-read-only-face)
(make-face 'mode-line-modified-face)
(make-face 'mode-line-folder-face)
(make-face 'mode-line-filename-face)
(make-face 'mode-line-position-face)
(make-face 'mode-line-mode-face)
(make-face 'mode-line-80col-face)
(set-face-attribute 'mode-line-read-only-face nil
:inherit 'mode-line-face
:foreground "#4271ae"
:box '(:line-width 2 :color "#4271ae"))
(set-face-attribute 'mode-line-modified-face nil
:inherit 'mode-line-face
:foreground "#c82829"
:background "#ffffff"
:box '(:line-width 2 :color "#c82829"))
(set-face-attribute 'mode-line-folder-face nil
:inherit 'mode-line-face
:foreground "gray60")
(set-face-attribute 'mode-line-filename-face nil
:inherit 'mode-line-face
:foreground "#eab700"
:weight 'bold)
(set-face-attribute 'mode-line-position-face nil
:inherit 'mode-line-face)
(set-face-attribute 'mode-line-mode-face nil
:inherit 'mode-line-face
:foreground "gray80")
(set-face-attribute 'mode-line-80col-face nil
:inherit 'mode-line-position-face
:foreground "black" :background "#eab700")
#+end_src
* Packages
** Web Search
#+begin_src emacs-lisp
(use-package engine-mode
:defer t
:config
(defengine duckduckgo
"https://duckduckgo.com/?q=%s"
:keybinding "g")
(defengine twitter
"https://twitter.com/search?q=%s"
:keybinding "x")
(defengine wikipedia
"https://www.wikipedia.org/search-redirect.php?language=en&go=Go&search=%s"
:keybinding "w"
:docstring "Searchin' the wikis.")
(defengine wiktionary
"https://www.wikipedia.org/search-redirect.php?family=wiktionary&language=en&go=Go&search=%s"
:keybinding "d")
(defengine wolfram-alpha
"https://www.wolframalpha.com/input/?i=%s")
(defengine youtube
"https://www.youtube.com/results?aq=f&oq=&search_query=%s"
:keybinding "y")
(engine-mode t)
)
#+end_src
** =magit=
try out =diff-hl= for highlighting diffs in magit:
#+begin_src emacs-lisp
(use-package diff-hl
:config
(global-diff-hl-mode))
#+end_src
=magit= is awesome and the number one reason why I use Emacs!
#+begin_src emacs-lisp
(use-package magit
:defer t
:config
(setq magit-mode-quit-window 'magit-restore-window-configuration
;;magit-auto-revert-mode t
))
#+end_src
=magit-todos= sounds cool.
#+begin_src emacs-lisp
(use-package magit-todos
:after magit
:config
(magit-todos-mode t))
#+end_src
And forge sounds cool as well.
#+begin_src emacs-lisp
(use-package forge
:after magit)
#+end_src
** which-key
This is one of those features of Spacemacs that is super useful.
#+begin_src emacs-lisp
(use-package which-key
:config
(which-key-mode))
#+end_src
** rainbow-delimiters
raimbow delimiters colours matching delimiters with different colours.
Used by Spacemacs as well.
#+begin_src emacs-lisp
(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))
#+end_src
** evil
#+begin_src emacs-lisp
(use-package evil
:ensure t
:init
(setq evil-want-C-u-scroll t)
(setq evil-want-keybinding nil)
(setq evil-want-integration t)
:config
(evil-mode 1)
#+end_src
Evil key-binds:
#+begin_src emacs-lisp
(evil-global-set-key 'normal (kbd "<SPC>TAB") 'mode-line-other-buffer)
(evil-define-key 'normal 'global (kbd "<SPC>bb") 'consult-buffer)
(evil-define-key 'normal 'global (kbd "<SPC>bd") 'kill-current-buffer)
(evil-define-key 'normal 'global (kbd "<SPC>ff") 'find-file)
(evil-define-key 'normal 'global (kbd "<SPC>wj") 'evil-window-down)
(evil-define-key 'normal 'global (kbd "<SPC>wk") 'evil-window-up)
(evil-define-key 'normal 'global (kbd "<SPC>wh") 'evil-window-left)
(evil-define-key 'normal 'global (kbd "<SPC>wl") 'evil-window-right)
#+end_src
I want to bind =SPC g s= to magit status, just how it is in spacemacs.
#+begin_src emacs-lisp
(evil-define-key 'normal 'global (kbd "<SPC>gs") 'magit-status)
;; (evil-define-key 'normal 'global (kbd "<SPC>gd") 'magit-diff)
#+end_src
These bindings are somewhat different from spacemacs, which parents the insertion key binds under the major-mode prefix =m=.
With =TAB= I can cycle headings in org, and with =,,= I can exit the special source block editor.
#+begin_src emacs-lisp
(evil-define-key 'normal org-mode-map (kbd "TAB") 'org-cycle)
(evil-define-key 'normal 'org-mode-map (kbd ",,") 'org-edit-src-exit)
(evil-define-key 'normal 'org-mode-map (kbd "<SPC>ih") 'org-insert-heading)
(evil-define-key 'normal 'org-mode-map (kbd "<SPC>is") 'org-insert-subheading)
(evil-define-key 'normal 'org-mode-map (kbd "<SPC>ii") 'org-insert-item)
(evil-define-key 'normal 'org-mode-map (kbd "<SPC>ib") 'org-insert-structure-template)
(evil-define-key '(normal visual) 'org-mode-map (kbd "<SPC>il") 'org-insert-link)
#+end_src
Unassociated key-bindings:
#+begin_src emacs-lisp
;; for exiting out of magits commit editor with ,, instead of C-c C-c
(evil-define-key 'normal global (kbd ",,") 'with-editor-finish)
(evil-define-key 'normal 'global (kbd "<SPC>gb") 'xref-go-back)
#+end_src
Close =:config=.
#+begin_src emacs-lisp
)
#+end_src
#+begin_src emacs-lisp
(use-package evil-surround
:defer t
:config
(global-evil-surround-mode 1))
#+end_src
#+begin_src emacs-lisp
(use-package evil-collection
:after evil
:ensure t
:config
(evil-collection-init))
#+end_src
** =undo-fu=
Also use =undo-fu=, which evil can use.
#+begin_src emacs-lisp
(use-package undo-fu
:defer t)
#+end_src
** Projectile
#+begin_src emacs-lisp
(use-package projectile
:defer t
:config
(setq projectile-project-search-path '("~/code/"))
(projectile-mode))
#+end_src
** =ripgrep= & Co.
#+begin_src emacs-lisp
(use-package ripgrep
:defer t)
(use-package rg
:defer t)
#+end_src
** VTerm
#+begin_src emacs-lisp
(use-package vterm
:ensure t)
#+end_src
* Stuff
** Minibuffer escape
#+begin_src emacs-lisp :tangle no
(setq minibuffer-prompt-properties
'(read-only t
intangible t
cursor-intangible t
face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
#+end_src
#+begin_src emacs-lisp
(defun nemo/abort-minibuffer-if-active ()
"Abort the minibuffer if it is active."
(interactive)
(when (active-minibuffer-window)
(abort-recursive-edit)))
(global-set-key (kbd "<escape>") 'nemo/abort-minibuffer-if-active)
#+end_src
* Writing
** Olivetti
#+begin_src emacs-lisp
(use-package olivetti
:defer t
; :bind (:map custom-bindings-map ("C-c o" . olivetti-mode))
:config
(setq olivetti-style t))
(add-hook 'olivetti-mode-on-hook (lambda () (olivetti-set-width 88)))
#+end_src
** Spelling
#+begin_src emacs-lisp
(use-package jinx
:hook (emacs-startup . global-jinx-mode)
:bind (("M-$" . jinx-correct)
("C-M-$" . jinx-languages))
:config
(evil-define-key 'normal 'global (kbd "<SPC>Ss") 'jinx-correct)
(setq jinx-languages "en_GB dk_DK de_DE"))
#+end_src
** LaTeX
#+begin_src emacs-lisp
(use-package auctex
:hook
(LaTeX-mode . turn-on-prettify-symbols-mode)
(LaTeX-mode . reftex-mode)
; (LaTeX-mode . (lambda () (corfu-mode -1)))
; (LaTeX-mode . outline-minor-mode)
(LaTeX-mode . olivetti-mode)
)
#+end_src
PDF tools for latex previewing
#+begin_src emacs-lisp
(use-package pdf-tools
:defer t
:init (pdf-loader-install))
#+end_src
** Org
Taken from [[https://sophiebos.io/posts/prettifying-emacs-org-mode/][ here]].
#+begin_src emacs-lisp
(use-package org
:defer t
:hook (org-mode . olivetti-mode)
:hook (org-mode . variable-pitch-mode)
; I basically always want to be running =visual-line-mode= anyway, but certainly in org-mode.
:hook (org-mode . visual-line-mode)
:hook (org-mode . nemo/prettify-symbols-setup)
:config
#+end_src
Change heading font sizes:
#+begin_src emacs-lisp
(custom-set-faces
'(org-document-title ((t (:height 1.8))))
'(outline-1 ((t (:height 1.35))))
'(outline-2 ((t (:height 1.3))))
'(outline-3 ((t (:height 1.2))))
'(outline-4 ((t (:height 1.1))))
'(outline-5 ((t (:height 1.1))))
'(outline-6 ((t (:height 1.1))))
'(outline-8 ((t (:height 1.1))))
'(outline-9 ((t (:height 1.1)))))
#+end_src
Open Org files with the content folded away:
#+begin_src emacs-lisp
(setq org-startup-folded 'content)
#+end_src
Enable LaTeX previews.
#+begin_src emacs-lisp
(setq org-startup-with-latex-preview t)
#+end_src
Inline images as well.
#+begin_src emacs-lisp
(setq org-startup-with-inline-images t)
#+end_src
In case LaTeX previews are too small, use this to increase them.
#+begin_src emacs-lisp
(plist-put org-format-latex-options :scale 1.35)
#+end_src
==pretty-entities= allows for latex symbols to be embedded into org-mode.
=org-hide-leading-stars= hides all but one star on org headings.
#+begin_src emacs-lisp
(setq org-adapt-indentation t
org-hide-leading-stars t
org-pretty-entities-include-sub-superscripts t
org-pretty-entities t)
#+end_src
Let emacs act according to the language's rules inside of a source block.
#+begin_src emacs-lisp
(setq org-src-fontify-natively t
org-src-tab-acts-natively t
org-edit-src-content-indentation 0)
#+end_src
End =:config=
#+begin_src emacs-lisp
)
#+end_src
Use org-bullets for fancy headline markers
#+begin_src emacs-lisp :tangle no
(use-package org-bullets
:hook (org-mode . (lambda () (org-bullets-mode 1)))
:config)
#+end_src
Use typo-mode in org-mode for en and em dashes:
#+begin_src emacs-lisp
(require 'typo)
(typo-global-mode 1)
(add-hook 'org-mode-hook 'typo-mode)
#+end_src
Use =org-fragtog= to show embedded LaTeX fragments when in insert mode.
#+begin_src emacs-lisp
(use-package org-fragtog
:hook (org-mode . org-fragtog-mode))
#+end_src
Using =org-appear= we can hide emphasis markers for italic, bold, etc. and show when editing the surrounded word.
#+begin_src emacs-lisp
(use-package org-appear
:commands (org-appear-mode)
:hook (org-mode . org-appear-mode)
:config
(setq org-hide-emphasis-markers t)
(setq org-appear-autoemphasis t ;; show /../ *..* =..= ~..~ tokens
org-appear-autolinks t ;; show link hyperlinks when editing
org-appear-autosubmarkers t)) ;; show _.._ and superscript markers
#+end_src
#+begin_src emacs-lisp
(use-package org-modern
:defer t
:after org
:hook (org-mode . org-modern-mode))
#+end_src
Change org face fonts and font sizes for headers.
#+begin_src emacs-lisp :tangle no
(require 'org-faces)
;; size org levels differently
(dolist (face '((org-document-title . 1.8)
(org-level-1 . 1.35)
(org-level-2 . 1.3)
(org-level-3 . 1.2)
(org-level-4 . 1.1)
(org-level-5 . 1.1)
(org-level-6 . 1.1)
(org-level-7 . 1.1)
(org-level-8 . 1.1)))
;; set the font for each of them to sans-serif
(set-face-attribute
(car face)
nil
:font "SF Pro Text"
:weight 'bold
:height (cdr face)))
#+end_src
Fix org-indent to be fixed-pitch.
#+begin_src emacs-lisp :tangle no
(require 'org-indent)
(set-face-attribute 'org-indent nil :inherit '(org-hide fixed-pitch))
#+end_src
Make sure that faces like code blocks or verbatim text are still using a monospaced font:
#+begin_src emacs-lisp :tangle no
(set-face-attribute 'org-block nil :foreground nil :inherit 'fixed-pitch :height 0.85)
(set-face-attribute 'org-code nil :foreground nil :inherit '(shadow fixed-pitch) :height 0.85)
(set-face-attribute 'org-indent nil :foreground nil :inherit '(org-hide fixed-pitch) :height 0.85)
(set-face-attribute 'org-verbatim nil :foreground nil :inherit '(shadow fixed-pitch) :height 0.85)
(set-face-attribute 'org-special-keyword nil :foreground nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-meta-line nil :foreground nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-checkbox nil :foreground nil :inherit 'fixed-pitch)
#+end_src
prettify symbols for quotes and source blocks in org-mode.
#+begin_src emacs-lisp
(defun nemo/prettify-symbols-setup ()
;; org-babel
(push '("#+BEGIN_SRC" . ?≫) prettify-symbols-alist)
(push '("#+END_SRC" . ?≫) prettify-symbols-alist)
(push '("#+begin_src" . ?≫) prettify-symbols-alist)
(push '("#+end_src" . ?≫) prettify-symbols-alist)
(push '("#+BEGIN_QUOTE" . ?❝) prettify-symbols-alist)
(push '("#+END_QUOTE" . ?❞) prettify-symbols-alist)
(prettify-symbols-mode))
#+end_src
=svg-tags-mode= for fancy SVG images
#+begin_src emacs-lisp
(use-package svg-tag-mode
:config
(setq svg-tag-tags
'((":TODO:" . ((lambda (tag) (svg-tag-make "TODO"))))))
)
#+end_src
* Agenda
#+begin_src emacs-lisp
(require 'org)
(setq org-agenda-start-on-weekday nil
org-agenda-block-separator nil
org-agenda-remove-tags t)
(use-package org-super-agenda
:after org
:config
(org-super-agenda-mode))
(setq org-agenda-files (list "~/Shared/agenda.org"
"~/notes.org"
"~/projects.org"))
(add-hook 'emacs-startup-hook
(lambda () (progn (org-agenda nil "a")
(delete-other-windows)
(olivetti-mode))))
#+end_src
* Navigation / mini-buffer
Realistically, I will probably never use 90% of Helm's functionality, so =vertico= should be sufficient.
** Move Text
Use the =move-text= package to move the current line or selection up or down with =M-j= and =M-k=.
#+begin_src emacs-lisp
(use-package move-text
:defer t
:bind (("M-j" . move-text-down)
("M-k" . move-text-up)))
#+end_src
** Treemacs
#+begin_src emacs-lisp
(use-package treemacs
:defer t
;; hijack projectile prefix because they fit together
:bind (("C-x p t" . treemacs))
)
(use-package treemacs-evil
:after (treemacs evil)
:ensure t)
(use-package treemacs-projectile
:after (treemacs projectile)
:ensure t)
(use-package treemacs-icons-dired
:hook (dired-mode . treemacs-icons-dired-enable-once)
:ensure t)
(use-package treemacs-magit
:after (treemacs magit)
:ensure t)
#+end_src
** Vertico
#+begin_src emacs-lisp
(use-package vertico
:bind (:map minibuffer-local-map
("C-h" . backward-kill-sexp))
:config
(vertico-mode 1)
(setq vertico-count 25
completion-ignore-case t
read-buffer-completion-ignore-case t
read-file-name-completion-ignore-case t))
(vertico-multiform-mode)
#+end_src
Use =vertico-posframe= to make the =vertico= buffer floating in the centre of the frame.
#+begin_src emacs-lisp
(use-package vertico-posframe
:config
(vertico-posframe-mode 1)
(setq vertico-posframe-height vertico-count
vertico-multiform-commands
'((consult-line (:not posframe))
(consult-ripgrep (:not posframe))
(embark-act (:not posframe))
(t posframe))
))
(use-package savehist :init (savehist-mode))
#+end_src
Use =consult-xref= for =lsp-xref= and =xref-find-references=.
#+begin_src emacs-lisp
(use-package consult
:bind (:map custom-bindings-map
("C-x b" . consult-buffer)
("M-g g" . consult-goto-line))
:init
(setq xref-show-xrefs-function 'consult-xref
xref-show-definitions-function 'consult-xref)
:config
())
#+end_src
[[https://github.com/minad/marginalia][=marginalia=]] adds marginalia into the mini-buffer, for example key-binds in =M-x=
#+begin_src emacs-lisp
(use-package marginalia
:init
(marginalia-mode 1))
#+end_src
Auto-completion using =corfu=:
#+begin_src emacs-lisp
(use-package corfu
:custom
;; Enable auto completion
(corfu-auto t)
;; Enable cycling for `corfu-next/previous'
(corfu-cycle t)
;; No delay
(corfu-auto-delay 0)
;; Start when this many characters have been typed
(corfu-auto-prefix 1)
;; Short delay
(corfu-popupinfo-delay 0.5)
;; Preselect the first suggestion
(corfu-preselect 'first)
:init
(global-corfu-mode))
(use-package emacs
:custom
;; TODO
(enable-recursive-minibuffers t)
:init
;; TAB cycle if there are only few candidates
(setq completion-cycle-threshold 3)
;; Hide commands in M-x which do not apply to the current mode. Corfu
;; commands are hidden, since they are not supposed to be used via M-x.
(setq read-extended-command-predicate
#'command-completion-default-include-p)
(setq text-mode-ispell-word-completion nil)
;; Enable indentation+completion using the TAB key.
;; `completion-at-point' is often bound to M-TAB.
(setq tab-always-indent 'complete))
#+end_src
This package seems to slow down search quite a bit in common buffers like find-file and exectue-extended-comand:
#+begin_src emacs-lisp :tangle no
(use-package cape
;; Bind dedicated completion commands
;; Alternative prefix keys: C-c p, M-p, M-+, ...
:bind (("C-c p p" . completion-at-point) ;; capf
("C-c p t" . complete-tag) ;; etags
("C-c p d" . cape-dabbrev) ;; or dabbrev-completion
("C-c p h" . cape-history)
("C-c p f" . cape-file)
("C-c p k" . cape-keyword)
("C-c p s" . cape-symbol)
("C-c p a" . cape-abbrev)
("C-c p l" . cape-line)
("C-c p w" . cape-dict)
("C-c p \\" . cape-tex)
("C-c p _" . cape-tex)
("C-c p ^" . cape-tex)
("C-c p &" . cape-sgml)
("C-c p r" . cape-rfc1345))
:init
;; Add `completion-at-point-functions', used by `completion-at-point'.
;; NOTE: The order matters!
(add-to-list 'completion-at-point-functions #'cape-dabbrev)
(add-to-list 'completion-at-point-functions #'cape-file)
(add-to-list 'completion-at-point-functions #'cape-elisp-block)
(add-to-list 'completion-at-point-functions #'cape-history)
(add-to-list 'completion-at-point-functions #'cape-keyword)
(add-to-list 'completion-at-point-functions #'cape-tex)
(add-to-list 'completion-at-point-functions #'cape-dict)
;;(add-to-list 'completion-at-point-functions #'cape-sgml)
;;(add-to-list 'completion-at-point-functions #'cape-rfc1345)
;;(add-to-list 'completion-at-point-functions #'cape-abbrev)
;;(add-to-list 'completion-at-point-functions #'cape-symbol)
;;(add-to-list 'completion-at-point-functions #'cape-line)
)
#+end_src
Fuzzy and out-of-order completion matching using =orderless=:
#+begin_src emacs-lisp
(use-package orderless
:ensure t
:config
(setq completion-styles '(orderless basic partial-completion)
orderless-matching-styles '(orderless-flex)
completion-category-overrides '((file (styles basic partial-completion)))
orderless-component-separator "[ |]"))
#+end_src
Use =embark= for in-mini-buffer actions:
#+begin_src emacs-lisp
(use-package embark
:defer t
:bind (("C-." . embark-act))
:config
())
(use-package embark-consult
:defer t
:hook (embark-collect-mode . consult-preview-at-point-mode))
#+end_src
#+begin_src emacs-lisp
(defun my-consult-line-wrapper ()
(interactive)
(vertico-posframe-mode -1)
(consult-line)
(vertico-posframe-mode 1))
(defun my-consult-ripgrep-wrapper ()
(interactive)
(vertico-posframe-mode -1)
(consult-ripgrep)
(vertico-posframe-mode 1))
(bind-key "C-s" 'consult-line custom-bindings-map)
(bind-key "C-M-s" 'consult-ripgrep custom-bindings-map)
; Ensure posframe is always restored when exiting a minibuffer
(add-hook 'minibuffer-exit-hook
(lambda ()
(vertico-posframe-mode 1)))
#+end_src
* Programming
** smart-parens
#+begin_src emacs-lisp
(use-package smartparens
:defer t
:hook ((prog-mode text-mode markdown-mode) . smartparens-mode)
:config
(require 'smartparens-config))
#+end_src
** Company
#+begin_src emacs-lisp :tangle no
(use-package company
:defer t
:hook (after-init . company-mode)
:hook (prog-mode . company-mode)
:config
(setq
company-minimum-prefix-length 1
company-idle-delay 0.0))
#+end_src
Use =ispell= with company mode for completion in text-modes
#+begin_src emacs-lisp
(use-package ispell
:defer t
:config
(setq ispell-dictionary "en_GB"))
#+end_src
** Flycheck
#+begin_src emacs-lisp
(use-package flycheck
:defer t
:hook (after-init. global-flycheck-mode)
:config)
#+end_src
** Yasnippet
Auto-completion requires yasnippet for some competions, such as function arguments and parens.
#+begin_src emacs-lisp
(use-package yasnippet
:defer t
:hook ((prog-mode text-mode) . yas-minor-mode))
(use-package yasnippet-snippets
:ensure t)
#+end_src
** LSP
Use lsp-mode and lsp-ui for LSP functionality.
Emacs has its own internal LSP client called eglot, but I've never used it and I'm relatively happy with lsp-mode.
LSP sets it's prefix key to =s-l= by default, which uses the Super key which I use as my Mod key in sway, so I can't use it in emacs.
#+begin_src emacs-lisp
(use-package lsp-mode
:defer t
:hook (prog-mode . lsp)
:hook (lsp-mode . lsp-enable-which-key-integration)
:hook (lsp-mode . lsp-inlay-hints-mode)
:init
(setq lsp-keymap-prefix "C-l")
:commands lsp
:config
(setq
lsp-idle-delay 0.6
lsp-inlay-hint-enable t
lsp-modeline-code-actions-enable t
lsp-modeline-code-actions-segments '(name count)
lsp-modeline-diagnostics-enable t
lsp-rust-server 'rust-analyzer
lsp-rust-analyzer-server-display-inlay-hints t
lsp-rust-analyzer-proc-macro-enable t
lsp-rust-analyzer-binding-mode-hints t
lsp-rust-analyzer-display-closure-return-type-hints t
lsp-rust-analyzer-server-format-inlay-hints t)
)
(use-package lsp-treemacs
:commands lsp-treemacs-errors-list)
(use-package lsp-ui
:config
(setq
;;lsp-modeline-code-actions-enable nil
;;lsp-rust-analyzer-cargo-all-targets nil
;; lsp-rust-analyzer-server-command "xwin-env rust-analyzer"
lsp-ui-sideline-show-code-actions t
lsp-ui-doc-enable t
lsp-ui-doc-delay 0.5
lsp-ui-doc-show-with-cursor t
; lsp-ui-doc-use-childframe t
; lsp-ui-doc-use-webkit t
)
:commands lsp-ui-mode)
#+end_src
** Rust
[[https://github.com/rust-lang/rust-mode][rust-mode]]
#+begin_src emacs-lisp
(use-package rust-mode
:defer t
:hook (rust-mode . lsp)
:init
(setq rust-mode-treesitter-derive t)
:config
(setq rust-format-on-save t))
#+end_src
#+begin_src emacs-lisp
(use-package rust-playground
:defer t)
#+end_src
[[https://github.com/kwrooijen/cargo.el][cargo-mode]]
#+begin_src emacs-lisp
(use-package cargo-mode
:defer t
:hook (rust-mode . cargo-minor-mode))
#+end_src
** Web
#+begin_src emacs-lisp
(use-package web-mode
:defer t
:mode
(("\\.phtml\\'" . web-mode)
("\\.tpl\\.php\\'" . web-mode)
("\\.twig\\'" . web-mode)
("\\.xml\\'" . web-mode)
("\\.html\\'" . web-mode)
("\\.htm\\'" . web-mode)
("\\.[gj]sp\\'" . web-mode)
("\\.as[cp]x?\\'" . web-mode)
("\\.eex\\'" . web-mode)
("\\.erb\\'" . web-mode)
("\\.mustache\\'" . web-mode)
("\\.handlebars\\'" . web-mode)
("\\.hbs\\'" . web-mode)
("\\.eco\\'" . web-mode)
("\\.ejs\\'" . web-mode)
("\\.svelte\\'" . web-mode)
("\\.ctp\\'" . web-mode)
("\\.djhtml\\'" . web-mode))
:config
(setq
web-mode-css-indent-offset 2
web-mode-code-indent-offset 2
web-mode-attr-indent-offset 2
web-mode-markup-indent-offset 2))
#+end_src
** C/C++
clang-format
#+begin_src emacs-lisp
(use-package clang-format
:defer t)
#+end_src
* Keybinds
#+begin_src emacs-lisp
(define-key custom-bindings-map (kbd "C-c l") 'org-store-link)
(define-key custom-bindings-map (kbd "C-c a") 'org-agenda)
(define-key custom-bindings-map (kbd "C-c c") 'org-capture)
(define-key custom-bindings-map (kbd "C-c t") 'org-todo)
(define-key custom-bindings-map (kbd "M-h") 'org-todo)
#+end_src