Skip to content

nezia1/emacs-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

My literate Emacs config

Table of contents

Introduction

This is my personal Emacs config, using org mode to make it easier to structure things and comment what section is used for exactly.

Initialization

General settings

Set the author name

(setq user-full-name "Anthony Rodriguez")

Remove the startup message

(setq inhibit-startup-message t)

Disable some UI elements that I don’t need

(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(menu-bar-mode -1)

Add space on the sides

(set-fringe-mode 10)

Disable backup and auto save as I use git repositories a lot and I don’t like having to ignore Emacs specific files

(setq backup-inhibited t)
(setq auto-save-default nil)

Package management

I use straight.el for my package management, alongside use-package to make my configuration easier to maintain.

Environment variables

One issue I had using Emacs was the fact that my environment variables were not available inside of the GUI version. This is because on some systems, mainly OS X, where graphical apps inherit a minimal set of environment variables, or setups running Emacs as a daemon, graphical apps may not have all of the available environment variables (mainly $PATH and ssh related variables). This is why we use exec-path-from-shell, a handy library that will ensure we have access to the same stuff across Emacs and the terminal.

Here, we install the aforementioned package, and define a list of commonly needed variables to share with the Emacs instance.

(use-package exec-path-from-shell
  :config
  (dolist (var '("SSH_AUTH_SOCK" "SSH_AGENT_PID" "GPG_AGENT_INFO" "LANG" "LC_CTYPE" "NIX_SSL_CERT_FILE" "NIX_PATH"))
    (add-to-list 'exec-path-from-shell-variables var)))

Share the path on OS X

(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))

Share the path on daemonized setups

(when (daemonp)
  (exec-path-from-shell-initialize))

Completion

Minibuffer completion

I use vertico for my vertical/minibuffer completion. It’s light, stays out of my way and works great out of the box, which is what I expect from all of my Emacs packages.

(use-package vertico
:init
(vertico-mode))

Add flx to completion styles (fuzzy finding)

(add-to-list 'completion-styles 'flex t)

which-key

I use which-key, a small package that shows a window that describes available keybindings that follow the prefix I just hit. I just can’t live without it, it’s mandatory for me since I often don’t remember which exact keybind I need to press to do a certain thing.

(use-package which-key
:config
(which-key-mode))

expand-region

expand-region is a really useful package that allows for selection regions of text in semantic units. It works with text (words, sentences, paragraphs), code etc.

(use-package expand-region
  :bind
  ("C-=" . er/expand-region))

Appearance

Theme

I use catppuccin as my theme (the mocha flavor).

;; set theme
(use-package catppuccin-theme
  :custom
  (catppuccin-flavor 'mocha)
  :init
  (load-theme 'catppuccin t)
  (catppuccin-reload))

Font

I really like being able to use standard fonts, so I decided to set my Emacs font to my system monospace font.

(add-to-list 'default-frame-alist '(font . "Monospace 14"))
(add-hook 'text-mode-hook 'visual-line-mode)

Mode-line

I use doom-modeline as my mode-line, it’s really slick and shows me all that I need to know at all times.

(use-package doom-modeline
  :ensure t
  :init (doom-modeline-mode 1)
  :custom ((doom-modeline-height 15)))

doom-modeline requires nerd-icons to be able to display icons. Don’t forget to run nerd-icons-install-fonts to make it available on your system.

(use-package nerd-icons)

Icons for dired

nerd-icons-dired allows to have nerd-icons directly in dired (the same as doom-modeline icons)

(use-package nerd-icons-dired
  :hook
  (dired-mode . nerd-icons-dired-mode))

Org mode

This section contains all of my org mode configuration. Over the course of learning Emacs, I learned to appreciate org-mode more and more, and I use it for a lot of various tasks, from writing documents and exporting them to pdf, to writing this exact config, or just taking notes.

General settings

Export documents to A4 (I’m European, so US letter won’t work for me)

(with-eval-after-load 'ox-latex (add-to-list 'org-latex-classes
					       '("article" "\\documentclass[11pt,a4paper]{article}"
						 ("\\section{%s}" . "\\section*{%s}")
						 ("\\subsection{%s}" . "\\subsection*{%s}")
						 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
						 ("\\paragraph{%s}" . "\\paragraph*{%s}")
						 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))

Enable syntax highlighting in org source blocks

(setq org-src-fontify-natively t)

Automatically load the right language based on the language header

(add-to-list 'org-latex-packages-alist '("AUTO" "babel" t ("pdflatex")))

This allows to have a nicely formatted table of contents in org mode, like the one you’re seeing in this config

(use-package toc-org
  :init (add-to-list 'org-tag-alist '("TOC" . ?T))
  :hook ((org-mode markdown-mode) . toc-org-mode)
  :bind ("C-c C-o" . toc-org-markdown-follow-point-at-thing))

This adds

Publishing

I use org’s publishing feature to export all of my notes at once.

 (setq org-publish-project-alist
	(list 
	 '("notes"
	   :base-directory "~/org/notes"
	   :base-extension "org"
	   :publishing-directory "~/org/notes"
	   :publishing-function org-latex-publish-to-pdf
	   )))

org-roam

I use org-roam for my note taking purposes. The Zettelkasten method works for me, and allows for flexibility as I really dislike very strict note-taking systems.

(use-package org-roam
:custom
(org-roam-directory "~/org/notes")
(org-roam-completion-everywhere t)
:config
(org-roam-setup)
:bind (("C-c n f" . org-roam-node-find)
	 (:map org-mode-map
	       (("C-c n i" . org-roam-node-insert)
		("C-c n l" . org-roam-buffer-toggle)))))

Spellchecking

I use flyspell, Emac’s integated spellchecker.

Add different dictionaries for languages that I use

(let ((langs '("american" "francais")))
(setq lang-ring (make-ring (length langs)))
(dolist (elem langs) (ring-insert lang-ring elem)))

Enable flyspell for text modes

  (dolist (hook '(text-mode-hook))
  (add-hook hook (lambda () (flyspell-mode 1))))
(dolist (hook '(change-log-mode-hook log-edit-mode-hook))
  (add-hook hook (lambda () (flyspell-mode -1)))
  )

Cycle through languages with F6

  (defun cycle-ispell-languages ()
  (interactive)
  (let ((lang (ring-ref lang-ring -1)))
    (ring-insert lang-ring lang)
    (ispell-change-dictionary lang)))
(setq ispell-program-name "aspell")

(global-set-key [f6] 'cycle-ispell-languages)

Enable flyspell in comments for programming modes

(add-hook 'prog-mode-hook
	    (lambda ()
	      (flyspell-prog-mode)))

Install guess-language.el, which automatically detects the main language used and switches to that dictionary. It even works with documents written in multiple languages!

(use-package guess-language
  :custom
  (guess-language-languages '(en fr))
  (guess-language-min-paragraph-length 35)
:hook
(text-mode . guess-language-mode))

pdf-tools

pdf-tools allows us to have a pdf viewer embedded inside of Emacs, which also works with org exports.

(use-package pdf-tools
  :config
  (pdf-tools-install)
  (setq-default pdf-view-display-size 'fit-width))

Development

This section contains all of my development related configuration. As a compsci student, it’s absolutely mandatory for me to have a good editor experience and have it integrate well with all languages and frameworks I need to use in my day-to-day work.

git

I use magit as my git client. It’s incredible, it makes everything that you need to do in git available under a single prefix (C-x G), the diff interface is great and has genuinely made me more productive over the months of using it. Definitely prefer using it over the CLI.

(use-package magit)

LSP

The following section contains the configuration of lsp-mode, which aims to provide an IDE like experience by leveraging different available language server protocols.

Install lsp-mode

(use-package lsp-mode
  :custom
  (lsp-keymap-prefix "C-c l")
  :hook
  (lsp-mode . electric-pair-local-mode) ; enable electric pair for lsp buffers (pairs brackets, quotes etc. automatically)
  :commands lsp)

Install lsp-ui, which provides UI additions to lsp-mode such as code lenses, flycheck diagnostics etc.

(use-package lsp-ui
:after lsp-mode
:hook (lsp-mode . lsp-ui-mode))

Install company-mode, a text completion framework for Emacs that integrates with LSP to provide in-buffer code completion, similar to VS Code and other text editors / IDEs

(use-package company
:after lsp-mode)

Install company-box, which adds icons to company-mode

(use-package company-box
:hook (company-mode . company-box-mode))

Rust

Install rustic, an Emacs major mode for Rust

(use-package rustic
:custom
(rustic-format-trigger 'on-save)
(rustic-analyzer-command '("rustup" "run" "stable" "rust-analyzer"))
:hook
(rustic-mode . display-line-numbers-mode))

LSP

Use clippy as the watch command

(setq lsp-rust-analyzer-cargo-watch-command "clippy")
(setq lsp-eldoc-render-all t)
(setq lsp-idle-delay 0.6)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published