Last active
March 19, 2026 15:49
-
-
Save mateusfccp/63bfd981ae801d981b678fbfd8f60849 to your computer and use it in GitHub Desktop.
My Emacs Configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; early-init.el --- My personal, self-containted early-init.el | |
| ;;; Commentary: | |
| ;; This is my personal early-init.el, to be used with my init.el. | |
| ;;; Code: | |
| ;;;; Language Server Protocol | |
| (setenv "LSP_USE_PLISTS" "true") | |
| ;;; early-init.el ends here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; init.el --- My personal, self-containted init.el -*- lexical-binding: t; -*- | |
| ;;; Commentary: | |
| ;; This is my personal init.el file. It is self-contained and does not depend | |
| ;; on any external configuration files. It uses straight.el as a package | |
| ;; manager and use-package to configure packages. | |
| ;; | |
| ;; This should work out of the box. Tested with Emacs 29 to 31. If any other | |
| ;; external dependencies are needed, they will be mentioned in the respective | |
| ;; package configuration. | |
| ;; | |
| ;; You should also use the early-init.el, also available in the gist. | |
| ;;; Code: | |
| ;;;; Package management (straight.el) | |
| ;; This must be the first piece of code to run, as it sets up the package | |
| ;; manager for the rest of the configuration. | |
| (defvar bootstrap-version) | |
| (defvar straight-use-package-by-default t) | |
| (let ((bootstrap-file | |
| (expand-file-name | |
| "straight/repos/straight.el/bootstrap.el" | |
| (or (bound-and-true-p straight-base-dir) | |
| user-emacs-directory))) | |
| (bootstrap-version 7)) | |
| (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)) | |
| (require 'use-package) | |
| ;;;; General Emacs behavior | |
| (setq ring-bell-function 'ignore) ; Prevent annoying sound when something happens | |
| (setq-default truncate-lines t) ; Truncate lines by default | |
| (setq-default fill-column 80) ; Set default fill column to 80 | |
| (setq-default native-comp-async-report-warnings-errors nil) | |
| ;;;;; General hooks for programming modes | |
| (add-hook 'prog-mode-hook 'display-line-numbers-mode) ; Enable line numbers on prog mode | |
| (add-hook 'prog-mode-hook 'display-fill-column-indicator-mode) ; Enable fill column indicator on prog mode | |
| (add-hook 'prog-mode-hook 'column-number-mode) ; Show line and column in on prog mode | |
| ;;;;; Backup files | |
| (setq backup-directory-alist `(("." . "~/.emacs.d/backup")) ; Set backup directory | |
| backup-by-copying t ; Copy files instead of renaming them | |
| delete-old-versions t ; Delete old versions silently | |
| kept-new-versions 6 ; Keep 6 newest versions | |
| kept-old-versions 2 ; Keep 2 oldest versions | |
| version-control t) ; Use version numbers on backup files | |
| ;;;;; PATH configuration | |
| (use-package exec-path-from-shell | |
| :config | |
| ;; Tell the package to use fish shell | |
| (setq exec-path-from-shell-shell-name "fish") | |
| ;; This is the critical part for fish to load its config | |
| (setq exec-path-from-shell-shell-args '("-i" "-l")) | |
| ;; Run the initialization only in GUI sessions | |
| (when (memq window-system '(mac ns x)) | |
| (exec-path-from-shell-initialize))) | |
| ;;;; UI & Aesthetics | |
| ;;;;; Vanilla configuration | |
| (set-frame-font "Fira Code 12" nil t) | |
| (tool-bar-mode -1) ; Hide toolbar | |
| (menu-bar-mode -1) ; Hide menu bar | |
| (scroll-bar-mode -1) ; Hide scrol bar | |
| ;;;;; Theme | |
| (use-package catppuccin-theme | |
| :config (load-theme 'catppuccin t) | |
| :init (setq-default catppuccin-flavor 'macchiato)) | |
| ;;;;; Icons | |
| ;; Remember to install the fonts with the `all-the-icons-install-fonts` command. | |
| (use-package all-the-icons | |
| :if (display-graphic-p)) | |
| ;; Needed for Doom Modeline | |
| ;; | |
| ;; Remember to install the fonts with the `nerd-icons-install-fonts` command. | |
| (use-package nerd-icons) | |
| ;;;;; Modeline | |
| (use-package doom-modeline | |
| :hook (after-init . doom-modeline-mode) | |
| :defines doom-modeline-custom-segment-point | |
| :functions (doom-modeline-def-segment | |
| doom-modeline-def-modeline | |
| doom-modeline-set-modeline) | |
| ;; Show point value in the modeline | |
| :config | |
| (doom-modeline-def-segment doom-modeline-custom-segment-point | |
| "Shows the point value." | |
| (format "(%d)" (1- (point)))) | |
| (doom-modeline-def-modeline 'custom-modeline | |
| '(bar matches buffer-info remote-host buffer-position | |
| doom-modeline-custom-segment-point parrot selection-info) | |
| '(misc-info minor-modes input-method buffer-encoding major-mode process vcs | |
| check)) | |
| ;; Set default mode-line | |
| (add-hook 'doom-modeline-mode-hook | |
| (lambda () | |
| (doom-modeline-set-modeline 'custom-modeline 'default)))) | |
| ;; Dependency of Doom Modeline | |
| (use-package shrink-path | |
| :demand t) | |
| ;;;; Indentation guides | |
| (use-package highlight-indent-guides | |
| :hook (prog-mode . highlight-indent-guides-mode) | |
| :config | |
| (setq-default highlight-indent-guides-method 'column) | |
| (setq-default highlight-indent-guides-responsive 'top)) | |
| ;;;;; diff-hl | |
| (use-package diff-hl | |
| :functions global-diff-hl-mode | |
| :config (global-diff-hl-mode)) | |
| ;;;;; ligatures.el | |
| (use-package ligature | |
| :functions (ligature-set-ligatures | |
| global-ligature-mode) | |
| :config | |
| ;; Enable all Iosevka ligatures in programming modes | |
| (ligature-set-ligatures 'prog-mode | |
| '("<---" "<--" "<<-" "<-" "->" "-->" "--->" "<->" | |
| "<-->" "<--->" "<---->" "<!--" "<==" "<===" "<=" | |
| "=>" "=>>" "==>" "===>" ">=" "<=>" "<==>" "<===>" | |
| "<====>" "<!---" "<~~" "<~" "~>" "~~>" "::" ":::" | |
| "==" "!=" "===" "!==" ":=" ":-" ":+" "<*" "<*>" "*>" | |
| "<|" "<|>" "|>" "+:" "-:" "=:" "<******>" "++" | |
| "+++")) | |
| ;; Enables ligature checks globally in all buffers. You can also do it | |
| ;; per mode with `ligature-mode'. | |
| (global-ligature-mode t)) | |
| ;;;;; Dashboard | |
| (use-package dashboard | |
| :functions dashboard-setup-startup-hook | |
| :config | |
| (dashboard-setup-startup-hook) | |
| (setq-default dashboard-banner-logo-title "Welcome to Emacs!") | |
| (setq-default dashboard-startup-banner 'logo) | |
| (setq-default dashboard-icon-type 'all-the-icons) | |
| (setq-default dashboard-projects-backend 'projectile) | |
| (setq-default dashboard-items '((recents . 5) | |
| (projects . 5) | |
| (agenda . 5)))) | |
| ;;;;; PDF handling | |
| (use-package pdf-tools | |
| :config | |
| (pdf-tools-install) | |
| (add-hook 'pdf-view-mode-hook 'auto-revert-mode)) | |
| ;;;; Core editing enhancements | |
| ;;;;; Avy | |
| (use-package avy | |
| :bind (("C-c C-j" . avy-goto-char-2))) | |
| ;;;;; Which key | |
| (use-package which-key | |
| :config (which-key-mode)) | |
| ;;;;; Multiple cursors | |
| (use-package multiple-cursors | |
| :config | |
| (global-set-key (kbd "C-s-n") 'mc/mark-next-like-this) | |
| (global-set-key (kbd "C-s-p") 'mc/mark-previous-like-this) | |
| (global-set-key (kbd "C-s-a") 'mc/mark-all-like-this) | |
| (global-set-key (kbd "C-s-r") 'mc/edit-lines)) | |
| ;;;;; Smartparens | |
| (use-package smartparens | |
| :hook (prog-mode text-mode markdown-mode) | |
| :config | |
| ;; Default configuration | |
| (require 'smartparens-config)) | |
| ;;;;; Guru mode | |
| (use-package guru-mode | |
| :functions guru-global-mode | |
| :config (guru-global-mode +1)) | |
| ;;;;; visual-regexp-search | |
| ;; You have to have the `python` executable in your PATH. If you are using | |
| ;; macOS, you may have to make an alias to the `python3` executable. | |
| (use-package visual-regexp-steroids | |
| :bind (("C-c r" . vr/replace) | |
| ("C-c q" . vr/query-replace) | |
| ("C-c m" . vr/mc-mark) | |
| ("C-r" . vr/isearch-backward) | |
| ("C-s" . vr/isearch-forward))) | |
| ;;;;; ag | |
| ;; Better search | |
| (use-package ag) | |
| ;;;; Projectile | |
| (use-package projectile | |
| :functions projectile-mode | |
| :init (projectile-mode +1) | |
| :bind (("s-p" . projectile-command-map) | |
| :map projectile-mode-map)) | |
| ;;;;; Magit | |
| (use-package magit) | |
| ;;;; Programming support | |
| ;;;;; General programming support | |
| ;;;;;; Company | |
| ;; Code completion | |
| (use-package company | |
| :config | |
| (setq-default company-minimum-prefix-length 1) | |
| (setq-default company-idle-delay 0.4)) | |
| ;;;;;; Flycheck | |
| ;; Error analysis | |
| (use-package flycheck | |
| :functions global-flycheck-mode | |
| :config | |
| (global-flycheck-mode) | |
| (setq-default flycheck-checker-error-threshold nil)) | |
| ;;;; Language Server Protocol | |
| ;; To use plists, the environment variable LSP_USE_PLISTS should be set to | |
| ;; "true". This can be done by including `(setenv "LSP_USE_PLISTS" "true")` in | |
| ;; the early-init.el file. | |
| ;; | |
| ;; It is recommended to use emacs-lsp-booster for improved performance. To | |
| ;; install it, check their documentation at | |
| ;; https://github.com/blahgeek/emacs-lsp-booster. | |
| ;; | |
| ;; Don't forget to install `libjansson'. | |
| (use-package lsp-mode | |
| :hook ((lsp-mode . lsp-enable-which-key-integration)) | |
| :defines lsp-use-plists | |
| :commands lsp | |
| :config | |
| (setq-default gc-cons-threshold (* 100 1024 1024)) | |
| (setq-default lsp-ui-doc-show-with-mouse nil) | |
| (setq-default lsp-ui-sideline-show-code-actions nil) | |
| (setq-default read-process-output-max (* 1024 1024))) | |
| (use-package lsp-ui :commands lsp-ui-mode) | |
| (use-package lsp-dart) | |
| (use-package lsp-treemacs :commands lsp-treemacs-errors-list) | |
| ;;;; DAP Mode | |
| (use-package dap-mode) | |
| ;; Configure emacs-lsp-booster | |
| ;; (defun lsp-booster--advice-json-parse (old-fn &rest args) | |
| ;; "Try to parse bytecode instead of JSON or fallback to OLD-FN with ARGS." | |
| ;; (or | |
| ;; (when (equal (following-char) ?#) | |
| ;; (let ((bytecode (read (current-buffer)))) | |
| ;; (when (byte-code-function-p bytecode) | |
| ;; (funcall bytecode)))) | |
| ;; (apply old-fn args))) | |
| ;; (advice-add (if (progn (require 'json) | |
| ;; (fboundp 'json-parse-buffer)) | |
| ;; 'json-parse-buffer | |
| ;; 'json-read) | |
| ;; :around | |
| ;; #'lsp-booster--advice-json-parse) | |
| ;; (defun lsp-booster--advice-final-command (old-fn cmd &optional test?) | |
| ;; "Prepend emacs-lsp-booster CMD to OLD-FN." | |
| ;; (let ((orig-result (funcall old-fn cmd test?))) | |
| ;; (if (and (not test?) ;; for check lsp-server-present? | |
| ;; (not (file-remote-p default-directory)) ;; see lsp-resolve-final-command, it would add extra shell wrapper | |
| ;; lsp-use-plists | |
| ;; (not (functionp 'json-rpc-connection)) ;; native json-rpc | |
| ;; (executable-find "emacs-lsp-booster")) | |
| ;; (progn | |
| ;; (when-let* ((command-from-exec-path | |
| ;; (executable-find (car orig-result)))) ;; resolve command from exec-path (in case not found in $PATH) | |
| ;; (setcar orig-result command-from-exec-path)) | |
| ;; (message "Using emacs-lsp-booster for %s!" orig-result) | |
| ;; (cons "emacs-lsp-booster" orig-result)) | |
| ;; orig-result))) | |
| ;; (advice-add 'lsp-resolve-final-command | |
| ;; :around #'lsp-booster--advice-final-command) | |
| ;;;;; Yasnippet | |
| ;; Snippets support | |
| (use-package yasnippet | |
| :functions yas-global-mode | |
| :config (yas-global-mode)) | |
| ;;;;; Languages support | |
| ;; Keep alphabetical sorting for language modes | |
| ;;;;;; BNF | |
| (use-package bnf-mode) | |
| ;;;;;; Common Lisp | |
| (use-package slime | |
| ;; I'm using a tagged version because loading it from git master was resulting | |
| ;; in conflicts with the Swank version loaded by Clack. | |
| :straight (:branch "v2.31") | |
| :defines inferior-lisp-program | |
| :config | |
| (setq inferior-lisp-program "sbcl") | |
| (slime-setup '(slime-fancy ;; slime-company | |
| )) | |
| :hook | |
| (slime-mode . (lambda () | |
| (add-to-list 'slime-contribs 'slime-fancy) | |
| (add-to-list 'slime-contribs 'inferior-slime)))) | |
| (use-package slime-company | |
| :defines (slime-company-completion | |
| slime-company-after-completion) | |
| :after (slime company) | |
| :config | |
| (setq slime-company-completion 'fuzzy | |
| slime-company-after-completion 'slime-company-just-one-space)) | |
| ;;;;;; Dart | |
| (use-package dart-mode | |
| :hook (dart-mode . lsp)) | |
| ;;;;;; Dhall | |
| (use-package dhall-mode | |
| :mode "\\.dhall\\'" | |
| ;; You have to have the `dhall-lsp-server' binary in your PATH. | |
| ;; See: https://github.com/dhall-lang/dhall-haskell/tree/main/dhall-lsp-server#dhall-language-support-in-vscodeium | |
| :hook (dhall-mode . lsp)) | |
| ;;;;; Groovy | |
| (use-package groovy-mode) | |
| ;;;;; Java | |
| ;; I gave up of using Java with Emacs. Java is the kind of technology that works | |
| ;; only with a dedicated IDE, and all my tentatives of configuring a reasonable | |
| ;; Java environment on Emacs failed miserably. Maybe it is possible, but too | |
| ;; much of a hassle. | |
| ;;;;; Json | |
| (use-package json-mode) | |
| ;;;;; Markdown | |
| (use-package markdown-mode | |
| :hook (markdown-mode . lsp) | |
| :config | |
| (require 'lsp-marksman)) | |
| ;;;;; Org-mode | |
| (use-package htmlize) | |
| (use-package org-tree-slide) | |
| ;; For PlantUML, it is necessary to have `plantuml' in the PATH. It is also | |
| ;; recommended to have GraphViz installed. | |
| (defcustom org-confirm-babel-evaluate-list nil | |
| "A list of ignored languages for `org-mode' source block prompt." | |
| :type 'list | |
| :group 'init-el) | |
| (defun org-confirm-babel-evaluate-list (language _block) | |
| "Checks whether given LANGUAGE is in the evaluation prompt ignore list." | |
| (member language org-confirm-babel-evaluate-list)) | |
| (require 'org) | |
| (with-eval-after-load 'org | |
| ;; Use LuaLaTeX to process SVG | |
| (add-to-list 'org-preview-latex-process-alist | |
| '(luasvgm | |
| :programs ("dvilualatex" "dvisvgm") | |
| :description "dvi > svg" | |
| :message "you need to install the programs: dvilualatex and dvisvgm." | |
| :image-input-type "dvi" | |
| :image-output-type "svg" | |
| :image-size-adjust (1.0 . 1.0) | |
| :latex-compiler ("dvilualatex -interaction nonstopmode -output-directory %o %f") | |
| :image-converter ("dvisvgm %f -n -b min -c %S -o %O"))) | |
| (setq-default org-preview-latex-default-process 'luasvgm) | |
| ;; Default scale | |
| (setq-default org-format-latex-options | |
| (plist-put org-format-latex-options :scale 1.5)) | |
| ;; Allow setting inline image width | |
| (setq-default org-image-actual-width nil) | |
| ;; Smart quotes export | |
| (setq org-export-with-smart-quotes t) | |
| ;; Enable shell-scape for SVG exporting. | |
| (setq org-latex-pdf-process | |
| '("lualatex -shell-escape -interaction nonstopmode -output-directory %o %f" | |
| "lualatex -shell-escape -interaction nonstopmode -output-directory %o %f" | |
| "lualatex -shell-escape -interaction nonstopmode -output-directory %o %f")) | |
| ;; Tell Org-mode to open PDFs inside Emacs instead of an external viewer | |
| (setq org-file-apps | |
| (append '(("\\.pdf\\'" . emacs)) org-file-apps)) | |
| ;; Use custom function to ignore prompt if language is in | |
| ;; org-confirm-babel-evaluate-list. | |
| (setq-default org-confirm-babel-evaluate #'org-confirm-babel-evaluate-list) | |
| (setq org-src-fontify-natively t) | |
| ;; Enable fill modes for org-mode | |
| (add-hook 'org-mode-hook 'turn-on-auto-fill) | |
| (add-hook 'org-mode-hook #'display-fill-column-indicator-mode) | |
| ;; Automatically display images in Org mode after generating them | |
| (add-hook 'org-babel-after-execute-hook #'org-display-inline-images) | |
| ;;;;;; PlantUML support | |
| (setq-default org-plantuml-exec-mode 'plantuml) | |
| (org-babel-do-load-languages | |
| 'org-babel-load-languages | |
| '((latex . t) | |
| (lisp . t) | |
| (plantuml . t)))) | |
| ;;;;; PlantUML | |
| ;; For PlantUML, it is necessary to have `plantuml' in the PATH. It is also | |
| ;; recommended to have GraphViz installed. | |
| (use-package plantuml-mode | |
| :defines plantuml-preview-buffer | |
| :functions plantuml-preview-style | |
| :config | |
| (add-to-list 'auto-mode-alist '("\\.plantuml\\'" . plantuml-mode)) | |
| (setq-default plantuml-default-exec-mode 'executable) | |
| (defun plantuml-preview-style () | |
| "Set a custom background for the PlantUML preview buffer." | |
| (when (string-equal (buffer-name) plantuml-preview-buffer) | |
| (setq-local face-remapping-alist | |
| '((default :background "#EFF1F5"))))) | |
| ;; Add our custom function to the image-mode-hook. | |
| (add-hook 'image-mode-hook #'plantuml-preview-style)) | |
| (use-package flycheck-plantuml | |
| :functions flycheck-plantuml-setup | |
| :config | |
| (flycheck-plantuml-setup) | |
| (setq-default flycheck-plantuml-executable "plantuml")) | |
| ;;;;; pint° | |
| (define-abbrev-table 'pinto-mode-abbrev-table | |
| '(("\\top" "⊤" ) | |
| ("\\bot" "⊥" )) | |
| "Abbrev table for `pinto'") | |
| (define-derived-mode pinto-mode prog-mode "pint°" | |
| "The pint° mode is a basic mode for editing ° scripts." | |
| (setq-local comment-start "//") | |
| (setq-local comment-end "") | |
| (abbrev-mode 1)) | |
| (add-to-list 'auto-mode-alist '("\\.pinto\\'" . pinto-mode)) | |
| ;;;;; Python | |
| (use-package python-mode | |
| :hook (python-mode . lsp-mode)) | |
| (use-package lsp-pyright | |
| :custom (lsp-pyright-langserver-command "pyright") | |
| :hook (python-mode . (lambda () | |
| (require 'lsp-pyright) | |
| (lsp)))) ; or lsp-deferred | |
| ;;;;; Toml | |
| (use-package toml-mode | |
| :hook (toml-mode . lsp-mode)) | |
| ;;;;; Typescript | |
| (add-hook 'typescript-mode #'lsp) | |
| ;;;;; Web (base) | |
| ;; HTML, Javascript and CSS | |
| (use-package web-mode | |
| :mode ("\\.phtml\\'" | |
| "\\.tpl\\.php\\'" | |
| "\\.[agj]sp\\'" | |
| "\\.as[cp]x\\'" | |
| "\\.erb\\'" | |
| "\\.mustache\\'" | |
| "\\.djhtml\\'" | |
| "\\.html?\\'") | |
| :hook | |
| (css-mode . lsp) | |
| (js-mode . lsp)) | |
| ;;;;; Yaml | |
| (use-package yaml-mode) | |
| (provide 'init) | |
| ;;; init.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment