;;; init.el --- Emacs configuration -*- lexical-binding: t -*- ;;; Commentary: ;; Save the contents of this file to ~/.config/emacs/init.el and ;; you're ready to boot up Emacs. ;; Hack this file! One of the best ways to get started with Emacs is ;; to look at other peoples' configurations and extract the pieces ;; that work for you. That's where this configuration started. I ;; encourage you to read through the code in this file and explore the ;; functions and variables using the built-in help system (details ;; below). Happy hacking! ;; "C- means hold the CONTROL key while typing the character . ;; Thus, C-f would be: hold the CONTROL key and type f." (Emacs tutorial) ;; ;; - C-h t: Start the Emacs tutorial ;; - C-h o some-symbol: Describe symbol ;; - C-h C-q: Pull up the quick-help cheatsheet ;;; Code: ;; Performance tweaks for modern machines (setq gc-cons-threshold 100000000) ; 100 mb (setq read-process-output-max (* 1024 1024)) ; 1mb ;; Remove extra UI clutter by hiding the scrollbar, menubar, and toolbar. (menu-bar-mode -1) (tool-bar-mode -1) (scroll-bar-mode -1) ;; Set the font. Note: height = px * 100 (set-face-attribute 'default nil :font "Menlo" :height 120) ;; Add unique buffer names in the minibuffer where there are many ;; identical files. This is super useful if you rely on folders for ;; organization and have lots of files with the same name, ;; e.g. foo/index.ts and bar/index.ts. (require 'uniquify) ;; Automatically insert closing parens (electric-pair-mode t) ;; Visualize matching parens (show-paren-mode 1) ;; Prefer spaces to tabs (setq-default indent-tabs-mode nil) ;; Automatically save your place in files (save-place-mode t) ;; Save history in minibuffer to keep recent commands easily accessible (savehist-mode t) ;; Keep track of open files (recentf-mode t) ;; Keep files up-to-date when they change outside Emacs (global-auto-revert-mode t) ;; Display line numbers only when in programming modes (add-hook 'prog-mode-hook 'display-line-numbers-mode) ;; The `setq' special form is used for setting variables. Remember ;; that you can look up these variables with "C-h v variable-name". (setq uniquify-buffer-name-style 'forward window-resize-pixelwise t frame-resize-pixelwise t load-prefer-newer t backup-by-copying t ;; Backups are placed into your Emacs directory, e.g. ~/.config/emacs/backups backup-directory-alist `(("." . ,(concat user-emacs-directory "backups"))) ;; I'll add an extra note here since user customizations are important. ;; Emacs actually offers a UI-based customization menu, "M-x customize". ;; You can use this menu to change variable values across Emacs. By default, ;; changing a variable will write to your init.el automatically, mixing ;; your hand-written Emacs Lisp with automatically-generated Lisp from the ;; customize menu. The following setting instead writes customizations to a ;; separate file, custom.el, to keep your init.el clean. custom-file (expand-file-name "custom.el" user-emacs-directory)) ;; Bring in package utilities so we can install packages from the web. (require 'package) ;; Add MELPA, an unofficial (but well-curated) package registry to the ;; list of accepted package registries. By default Emacs only uses GNU ;; ELPA and NonGNU ELPA, https://elpa.gnu.org/ and ;; https://elpa.nongnu.org/ respectively. (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) ;; Unless we've already fetched (and cached) the package archives, ;; refresh them. (unless package-archive-contents (package-refresh-contents)) ;; Add the :vc keyword to use-package, making it easy to install ;; packages directly from git repositories. (unless (package-installed-p 'vc-use-package) (package-vc-install "https://github.com/slotThe/vc-use-package")) (require 'vc-use-package) ;; A quick primer on the `use-package' function (refer to ;; "C-h f use-package" for the full details). ;; ;; (use-package my-package-name ;; :ensure t ; Ensure my-package is installed ;; :after foo ; Load my-package after foo is loaded (seldom used) ;; :init ; Run this code before my-package is loaded ;; :bind ; Bind these keys to these functions ;; :custom ; Set these variables ;; :config ; Run this code after my-package is loaded ;; A package with a great selection of themes: ;; https://protesilaos.com/emacs/ef-themes (use-package ef-themes :ensure t :config (ef-themes-select 'ef-autumn)) ;; Minibuffer completion is essential to your Emacs workflow and ;; Vertico is currently one of the best out there. There's a lot to ;; dive in here so I recommend checking out the documentation for more ;; details: https://elpa.gnu.org/packages/vertico.html. The short and ;; sweet of it is that you search for commands with "M-x do-thing" and ;; the minibuffer will show you a filterable list of matches. (use-package vertico :ensure t :custom (vertico-cycle t) (read-buffer-completion-ignore-case t) (read-file-name-completion-ignore-case t) (completion-styles '(basic substring partial-completion flex)) :init (vertico-mode)) ;; Improve the accessibility of Emacs documentation by placing ;; descriptions directly in your minibuffer. Give it a try: ;; "M-x find-file". (use-package marginalia :after vertico :ensure t :init (marginalia-mode)) ;; Adds intellisense-style code completion at point that works great ;; with LSP via Eglot. You'll likely want to configure this one to ;; match your editing preferences, there's no one-size-fits-all ;; solution. (use-package corfu :ensure t :init (global-corfu-mode) :custom (corfu-auto t) ;; You may want to play with delay/prefix/styles to suit your preferences. (corfu-auto-delay 0) (corfu-auto-prefix 0) (completion-styles '(basic))) ;; Adds LSP support. Note that you must have the respective LSP ;; server installed on your machine to use it with Eglot. e.g. ;; rust-analyzer to use Eglot with `rust-mode'. (use-package eglot :ensure t :bind (("s-" . eglot-find-implementation) ("C-c ." . eglot-code-action-quickfix))) ;; Add extra context to Emacs documentation to help make it easier to ;; search and understand. This configuration uses the keybindings ;; recommended by the package author. (use-package helpful :ensure t :bind (("C-h f" . #'helpful-callable) ("C-h v" . #'helpful-variable) ("C-h k" . #'helpful-key) ("C-c C-d" . #'helpful-at-point) ("C-h F" . #'helpful-function) ("C-h C" . #'helpful-command))) ;; Adds vim emulation. Activate `evil-mode' to swap your default Emacs ;; keybindings with the modal editor of great infamy. There's a ton of ;; keybindings that Evil needs to modify, so this configuration also ;; includes `evil-collection' to fill in the gaps. (use-package evil :ensure t :init (setq evil-want-integration t) (setq evil-want-keybinding nil) :config (evil-mode 1)) (use-package evil-collection :after evil :ensure t :config (evil-collection-init)) ;; `org-mode' is great but Denote makes it even better by adding ;; features that you'd find in something like Obsidian (like ;; backlinks!). You can write your notes in org, markdown, or plain ;; text, though I recommend giving `org-mode' a try if you've never ;; used it before. The Denote manual is also excellent: ;; https://protesilaos.com/emacs/denote (use-package denote :ensure t :custom (denote-known-keywords '("emacs" "journal")) ;; This is the directory where your notes live. (denote-directory (expand-file-name "~/denote/")) :bind (("C-c n n" . denote) ("C-c n f" . denote-open-or-create) ("C-c n i" . denote-link))) ;; An extremely feature-rich git client. Activate it with "C-c g". (use-package magit :ensure t :bind (("C-c g" . magit-status))) ;; In addition to installing packages from the configured package ;; registries, you can also install straight from version control ;; with the :vc keyword argument. For the full list of supported ;; fetchers, view the documentation for the variable ;; `vc-use-package-fetchers'. ;; ;; Breadcrumb adds, well, breadcrumbs to the top of your open buffers ;; and works great with project.el, the Emacs project manager. ;; ;; Read more about projects here: ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Projects.html (use-package breadcrumb :vc (:fetcher github :repo joaotavora/breadcrumb) :init (breadcrumb-mode)) ;; As you've probably noticed, Lisp has a lot of parentheses. ;; Maintaining the syntactical correctness of these parentheses ;; can be a pain when you're first getting started with Lisp, ;; especially when you're fighting the urge to break up groups ;; of closing parens into separate lines. Luckily we have ;; Paredit, a package that maintains the structure of your ;; parentheses for you. At first, Paredit might feel a little ;; odd; you'll probably need to look at a tutorial (linked ;; below) or read the docs before you can use it effectively. ;; But once you pass that initial barrier you'll write Lisp ;; code like it's second nature. ;; http://danmidwood.com/content/2014/11/21/animated-paredit.html ;; https://stackoverflow.com/a/5243421/3606440 (use-package paredit :ensure t :hook ((emacs-lisp-mode . enable-paredit-mode) (lisp-mode . enable-paredit-mode) (ielm-mode . enable-paredit-mode) (lisp-interaction-mode . enable-paredit-mode) (scheme-mode . enable-paredit-mode)))