Snippets from this configuration can be either tangled using org-babel-tangle
or copied individually.
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
Multiple package managers exist for Emacs.
As of Emacs 29, use-package
has been built in so I’ll use this one.
(package-initialize)
(require 'use-package)
(setq use-package-always-ensure t) ; auto enable packages from config file
If some packages cannot be found, try running package-refresh-contents
again.
Also, it is recommended to run package-update-all
from time to time. Especially strange warnings are encountered.
Straight is another great package manager that one might want to look into.
Remove some unneeded UI elements. Tangle this to ./early-init.el
for better optimization.
(push '(menu-bar-lines . 0) default-frame-alist)
(push '(tool-bar-lines . 0) default-frame-alist)
(push '(vertical-scroll-bars) default-frame-alist)
Then set this in ./init.el
for consistency.
(setq menu-bar-mode nil
tool-bar-mode nil
scroll-bar-mode nil)
doom-themes is the collection of themes from Doom Emacs. It integrates well with multiple packages.
(use-package doom-themes
:config
;; Global settings (defaults)
(setq doom-themes-enable-bold t ; if nil, bold is universally disabled
doom-themes-enable-italic t) ; if nil, italics is universally disabled
(load-theme 'doom-snazzy t)
;; Corrects (and improves) org-mode's native fontification.
(doom-themes-org-config)
)
Setting the font. Those need to be installed on your system.
On NixOS, those can be installed with:
$ nix profile install nixpkgs#source-code-pro
$ nix profile install nixpkgs#victor-mono
$ nix profile install nixpkgs#ubuntu_font_family
(set-face-attribute 'default nil
:font "Source Code Pro" :height 130 :weight 'medium)
(set-face-attribute 'italic nil
:family "Victor Mono" :weight 'regular :slant 'italic)
(set-face-attribute 'variable-pitch nil
:font "Ubuntu Nerd Font" :height 150 :weight 'light)
(set-face-attribute 'fixed-pitch nil :inherit 'default)
Emacs defaults bindings can be weird at times. Here are simple enhancements.
;; Revert Dired and other buffers
(setq global-auto-revert-non-file-buffers t)
;; Revert buffers when the underlying file has changed
(global-auto-revert-mode 1)
;; Typed text replaces the selection if the selection is active,
;; pressing delete or backspace deletes the selection.
(delete-selection-mode)
;; Use "y" and "n" to confirm/negate prompt instead of "yes" and "no"
;; Using `advice' here to make it easy to reverse in custom
;; configurations with `(advice-remove 'yes-or-no-p #'y-or-n-p)'
;;
;; N.B. Emacs 28 has a variable for using short answers, which should
;; be preferred if using that version or higher.
(if (boundp 'use-short-answers)
(setq use-short-answers t)
(advice-add 'yes-or-no-p :override #'y-or-n-p))
;; Turn on recentf mode
(add-hook 'after-init-hook #'recentf-mode)
;; Do not save duplicates in kill-ring
(setq kill-do-not-save-duplicates t)
;; Enable savehist-mode for command history
(savehist-mode 1)
Those variables can be used by various packages for various options.
For instance, org-export-dispatch
sets the name of output files with theme.
(setq user-full-name "Tristan Floch"
user-mailaddress "[email protected]")
If your name is not Tristan Floch, you might want to change this.
evil-mode is the Vim emulation for Emacs.
(use-package evil
:init
(setq evil-want-integration t
evil-want-keybinding nil
evil-vsplit-window-right t
evil-split-window-below t
evil-want-C-u-scroll t
evil-want-Y-yank-to-eol t
evil-undo-system 'undo-redo)
:config
(evil-mode 1)
)
evil-collection helps evil-mode
applying the emulation to every emacs mode.
(use-package evil-collection
:after evil
:config
(evil-collection-init))
Which Key is a plugin that pops up a window showing available key chords for each shortcut. It helps a lot with shortcut and command discoverability.
(use-package which-key
:config
(which-key-mode))
Corfu is a better front-end than the default completion UI.
(use-package corfu
:custom
(corfu-cycle t)
(corfu-auto t)
(corfu-auto-prefix 2) ; number of characters to type before triggering corfu
(corfu-auto-delay 0.0) ; no delay for completion
(corfu-echo-documentation 0.25)
(corfu-preview-current nil)
(corfu-max-width 70)
(tab-always-indent nil)
:bind
(:map corfu-map
("TAB" . corfu-next)
([tab] . corfu-next)
("S-TAB" . corfu-previous)
([backtab] . corfu-previous))
:init
(global-corfu-mode)
:config
;; Silence the pcomplete capf, no errors or messages!
;; Important for corfu
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-silent)
;; Ensure that pcomplete does not write to the buffer
;; and behaves as a pure `completion-at-point-function'.
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-purify))
Then we can setup cape which is a completion back-end. It enhances emacs basic completion with many features such as filename, buffer local words, and more.
(use-package cape
:init
(add-to-list 'completion-at-point-functions #'cape-file)
(add-to-list 'completion-at-point-functions #'cape-keyword)
(add-to-list 'completion-at-point-functions #'cape-dabbrev))
Vertico provides a performant and minimalistic vertical completion UI (e.g. the mini-buffer) based on Emacs default completion system.
(use-package vertico
:init
(vertico-mode))
Orderless enhances Vertico by providing better fuzzy matching over query results. It is recommended to use both packages together.
(use-package orderless
:custom
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles basic partial-completion)))))
This configuration can be tested straight away by running M-x
or the find-file (C-x C-f)
command for instance.
Finally, Marginalia can be used to annotate query results from Vertico with information.
(use-package marginalia
:init
(marginalia-mode))
LSP (Language Server Protocol) is a tool that analyses code on the fly. It is implemented in multiple editors, namely Emacs (with lsp-mode).
LSP provides multiple features, such as:
- Code completion
- Definition/implementation finding
- Symbol renaming
- Syntax checking
NOTE: LSP can make your editor slow. If so, feel free to disable this module. You can also look into the performance section of Emacs LSP mode documentation.
(use-package lsp-mode
:init
;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
(setq lsp-keymap-prefix "C-c l"
lsp-idle-delay 0
lsp-enable-on-type-formatting nil
lsp-headerline-breadcrumb-segments '(project file symbols)
lsp-enable-suggest-server-download nil)
:custom (lsp-completion-provider :none) ;; use corfu instead
:init
:hook (;; replace XXX-mode with concrete major-mode(e. g. python-mode)
(cc-mode . lsp-deferred)
(c-mode . lsp-deferred)
(lsp-mode . lsp-enable-which-key-integration)) ;; see the following section
:commands (lsp lsp-deferred)) ;; starts lsp when one of these command is called
In order for LSP to work, some language dependant back-end need to be installed on the system. For instance, c-mode can use clangd as a back-end. On NixOS, it can be installed with:
$ nix profile install clang-tools
Those are handy coding style compliant defaults.
;; Use spaces instead of tabs
(setq indent-tabs-mode nil)
;; Highlight trailing whitespaces
(global-whitespace-mode 1)
(setq whitespace-style '(face tab-mark lines-tail trailing))
(setq whitespace-action '(cleanup auto-cleanup))
;; Ensure file ends with a newline
(setq require-final-newline t)
Enhance parens behavior.
(electric-pair-mode 1) ; auto-insert matching bracket
(show-paren-mode 1) ; turn on paren match highlighting
Enable line numbers of course :)
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
stroustrup
is a style that comes close to EPITA coding style.
Parenthesis are well align and it sets c-basic-offset
to 4.
(add-hook 'c-mode #'(c-set-style "stroustrup"))
Magit has to be the best git front-end out there, and one of the best Emacs plugin. It speeds up one’s git usage by allowing to run commands in simple keystrokes.
(use-package magit
:commands (magit-status magit-init)
:config
(setq magit-save-repository-buffers nil))