flocon/emacs/.emacs.d
2023-06-08 10:20:14 +02:00
..
.gitignore initial commit 2023-06-01 11:26:29 +02:00
init.el move everything to README.org 2023-06-08 09:42:38 +02:00
README.org comment general settings and appearance 2023-06-08 10:20:14 +02:00

My literate Emacs config

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.

Initialize straight.el

  (defvar bootstrap-version)
  (let ((bootstrap-file
	 (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
	(bootstrap-version 6))
    (unless (file-exists-p bootstrap-file)
      (with-current-buffer
	  (url-retrieve-synchronously
	   "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
	   'silent 'inhibit-cookies)
	(goto-char (point-max))
	(eval-print-last-sexp)))
    (load bootstrap-file nil 'nomessage))

Install use-package with straight.el

  (straight-use-package 'use-package)

Set use-package to always ensure (makes sure all of our packages download automatically)

  (setq use-package-always-ensure t)

Makes use-package use straight.el by default

  (use-package straight
    :custom
    (straight-use-package-by-default t))

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

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 15"))
  (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)
  
  (use-package vertico
    :init
    (vertico-mode))


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

  ;; org setup
  ;; export to a4
  (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}"))))

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

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

  ;; spell checking 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))))

  (add-hook 'prog-mode-hook
	    (lambda ()
	      (flyspell-prog-mode)))
  ;; avoid spell checking code regions in org mode
  (add-to-list 'ispell-skip-region-alist '("^#+BEGIN_SRC" . "^#+END_SRC"))

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

  ;; cycle through languages
  (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)

  ;; automatic language detection
  (use-package guess-language
    :config
    (setq guess-language-languages '(en fr))
    (setq guess-language-min-paragraph-length 35)
    :hook
    (text-mode . guess-language-mode))

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

  ;; enable syntax highlighting in org source blocks
  (setq org-src-fontify-natively t)

  ;; disable latex subscript in org-mode
  (setq org-export-with-sub-superscripts nil)

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

  (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 integration
  (use-package lsp-mode
    :ensure
    :commands lsp
    :custom
    ;; what to use when checking on-save. "check" is default, I prefer clippy
    (lsp-rust-analyzer-cargo-watch-command "clippy")
    (lsp-eldoc-render-all t)
    (lsp-idle-delay 0.6))

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

  ;; code completion
  (use-package company
    :after lsp-mode)

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