Last active
August 5, 2025 23:17
-
-
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 | |
;;; 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)) | |
(straight-use-package '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 | |
;;;; 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 | |
:ensure t | |
:hook (after-init . doom-modeline-mode) | |
:defines doom-modeline-custom-segment-point | |
:functions (list 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 | |
:ensure t | |
: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 | |
:ensure t | |
:functions (list 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 | |
:ensure t | |
: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)))) | |
;;;; 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) | |
(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 (list 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 | |
:ensure t | |
: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 | |
(use-package lsp-java | |
:config | |
(add-hook 'java-mode-hook #'lsp)) | |
;;;;; Json | |
(use-package json-mode) | |
;;;;; Markdown | |
(use-package markdown-mode | |
:hook (markdown-mode . lsp) | |
:config | |
(require 'lsp-marksman)) | |
;;;;; Org-mode | |
(with-eval-after-load 'org | |
(setq-default org-preview-latex-default-process 'dvisvgm) | |
(setq-default org-format-latex-options | |
(plist-put org-format-latex-options :scale 1.3))) | |
;;;;; 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 | |
:ensure t | |
: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