dots

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 2fdcef93f077cdbc1bb1aeefd025de6c44231708
parent 3fd22a2a37a8f54e868fe1edd1032cee97e0ec0e
Author: Gabriel G. de Brito <me@gboncoffee.dev.br>
Date:   Mon, 23 Mar 2026 12:04:43 -0300

Rewritten Emacs config

Diffstat:
Memacs/config.org | 739++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 487 insertions(+), 252 deletions(-)

diff --git a/emacs/config.org b/emacs/config.org @@ -1,264 +1,499 @@ #+PROPERTY: header-args:emacs-lisp :tangle config.el +* Gabriel's Emacs configuration + +This is my Emacs configuration. Enjoy. + +** Package management configuration + +Nowadays, Emacs already comes with ~use-package~. But we still bootstrap it +here as it costs us nothing and we need to setup it anyways. + #+BEGIN_SRC emacs-lisp - (require 'package) +(require 'package) + +(add-to-list 'package-archives + '("melpa" . "https://melpa.org/packages/") t) + +(package-initialize) - (add-to-list 'package-archives - '("melpa" . "https://melpa.org/packages/") t) +(unless (package-installed-p 'use-package) + (package-refresh-contents) + (package-install 'use-package)) - (package-initialize) +(require 'use-package) - (unless (package-installed-p 'use-package) - (package-refresh-contents) - (package-install 'use-package)) +(setq use-package-always-ensure t) +#+END_SRC + +** Appearance +*** Basics + +Unclutter the UI, stop the blinking cursor, don't jump text when the width +changes, no startup screen. - (require 'use-package) +#+BEGIN_SRC emacs-lisp +(menu-bar-mode 0) +(tool-bar-mode 0) +(scroll-bar-mode 0) +(blink-cursor-mode 0) + +(setq-default display-line-numbers-width 3) +(setq inhibit-startup-screen t) +#+END_SRC - (setq use-package-always-ensure t) +*** Theme and modeline - ;; - ;; Appearance. - ;; +The theme I like is tomorrow. The ~doom-themes~ version is a little better +and more supported than ~sanityinc~. I have little to no affection to the +modeline, just use it because it's a little more organized by default. I +make it show the current column number and clock. - (menu-bar-mode 0) - (tool-bar-mode 0) - (scroll-bar-mode 0) - (blink-cursor-mode 0) +#+BEGIN_SRC emacs-lisp +(use-package doom-themes + :custom + (doom-themes-enable-bold t) + (doom-themes-enable-italic t) + :config + (load-theme 'doom-tomorrow-night t) + (doom-themes-org-config)) + +(use-package doom-modeline + :init + (setq display-time-default-load-average nil) + (setq display-time-interval 10) + (display-time-mode 1) (column-number-mode 1) - (setq-default display-line-numbers-width 3) - (setq-default show-trailing-whitespace t) - (setq inhibit-startup-screen t) - (savehist-mode 1) - (recentf-mode 1) - (add-hook 'minibuffer-mode-hook (lambda () (setq show-trailing-whitespace nil))) - - (defun prog-and-text-mode-setup () - (display-line-numbers-mode t) - (display-fill-column-indicator-mode t)) - (add-hook 'prog-mode-hook #'prog-and-text-mode-setup) - (add-hook 'text-mode-hook #'prog-and-text-mode-setup) - - (set-face-attribute 'default nil :font "Hack-11") - (set-face-attribute 'fixed-pitch nil :font "Hack-11") - (set-face-attribute 'variable-pitch nil :font "Noto Sans-14") - - (setq scroll-step 1) - (setq scroll-conservatively 100000) - - (use-package all-the-icons) - (use-package doom-modeline - :init - (display-time-mode 1) - (doom-modeline-mode 1) - :custom - (display-time-format "%a %b %e, %H:%M")) - - (use-package doom-themes - :custom - (doom-themes-enable-bold t) - (doom-themes-enable-italic t) - :config - (load-theme 'doom-tomorrow-night t) - (doom-themes-org-config)) - - (use-package ido-vertical-mode - :config - (setq ido-vertical-show-count t) - (ido-vertical-mode t)) - - ;; - ;; Interface. - ;; - - (defun open-dir (dir) - (interactive (list (read-directory-name "Open directory: " nil nil t))) - (let ((dir (file-name-as-directory - (expand-file-name dir)))) - (setq-default default-directory dir) - (setq default-directory dir) - (setenv "PWD" dir) - (let ((file-name (concat default-directory ".emacs.el"))) - (unless (not (file-exists-p file-name)) - (load-file file-name) - (message "Loaded custom directory configuration."))) - (dired dir))) - - (global-set-key (kbd "C-c o") #'open-dir) - - (defalias 'yes-or-no-p 'y-or-n-p) - (setopt use-short-answers t) - (windmove-default-keybindings 'meta) - (setq-default fill-column 80) - - (use-package ido-completing-read+ - :config - (ido-mode t) - (ido-everywhere t) - (ido-ubiquitous-mode t)) - - (use-package amx - :config - (amx-mode t)) - - (setq make-backup-files nil) - - (setq-default compile-command "") - - (defun window-half-height () - (max 1 (/ (1- (window-height (selected-window))) 2))) - - (defun scroll-up-half () - (interactive) - (scroll-up (window-half-height))) - - (defun scroll-down-half () - (interactive) - (scroll-down (window-half-height))) - - (global-set-key (kbd "C-v") #'scroll-up-half) - (global-set-key (kbd "M-v") #'scroll-down-half) - - (global-set-key (kbd "C-c c") #'compile) - - ;; Stolen from (http://endlessparentheses.com/ansi-colors-in-the-compilation-buffer-output.html) - (require 'ansi-color) - (defun colorize-compilation () - "Colorize from `compilation-filter-start' to `point'." - (let ((inhibit-read-only t)) - (ansi-color-apply-on-region - compilation-filter-start (point)))) - - (add-hook 'compilation-filter-hook - #'colorize-compilation) - - (use-package lice) - (use-package magit) - (use-package magit-gh - :after magit) - - (setq dired-kill-when-opening-new-dired-buffer t) - (setq dired-delete-by-moving-to-trash t) - (setq dired-listing-switches "-D --group-directories-first") - - (use-package copilot-chat) - - ;; - ;; Editing. - ;; - - (electric-indent-mode t) - (electric-pair-mode t) - (add-hook 'text-mode-hook - (lambda () - (auto-fill-mode t))) - (delete-selection-mode t) - - (use-package multiple-cursors - :bind ( - ("C-S-c" . mc/edit-lines) - ("C->" . #'mc/mark-next-like-this) - ("C-<" . #'mc/mark-previous-like-this))) - - (use-package editorconfig - :config - (editorconfig-mode t)) - - (with-eval-after-load 'etags - (add-hook 'prog-mode-hook - (lambda () - (etags-regen-mode t) - (xref-etags-mode t)))) - - - ;; - ;; Langs. - ;; - - (add-hook 'emacs-lisp-mode-hook - (lambda () - (prettify-symbols-mode t))) - - (use-package go-mode - :config - (add-hook 'go-mode-hook - (lambda () - (setq tab-width 4) - (setq indent-tabs-mode t) - (add-hook 'before-save-hook #'gofmt-before-save nil t)))) - - (use-package clang-format) - (setq-default c-basic-offset 4) - (setq-default c-default-style "linux") - (defun c-configs () - (setq tab-width 4) - (setq indent-tabs-mode nil) - (add-hook 'before-save-hook #'clang-format nil t) - ;; I hate c-mode for using C-c. - (local-set-key (kbd "C-c C-c") #'compile)) - (add-hook 'c-mode-hook #'c-configs) - (add-hook 'c++-mode-hook #'c-configs) - - (setq-default pascal-indent-level 4) - (add-hook 'pascal-mode-hook - (lambda () - (setq tab-width 4) - (setq pascal-indent-level 4) - (setq pascal-auto-lineup '()) - (setq indent-tabs-mode nil) - (local-set-key (kbd "C-c C-c") #'compile))) - - (use-package web-mode - :config - (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))) - - (use-package markdown-mode) - - (use-package nasm-mode - :config - (add-to-list 'auto-mode-alist '("\\.asm\\'" . nasm-mode)) - (add-to-list 'auto-mode-alist '("\\.s\\'" . nasm-mode))) - - (use-package zig-mode) - - (use-package odin-mode - :commands odin-mode - :vc (:url "https://github.com/mattt-b/odin-mode.git" - :rev :last-release)) - - (use-package elixir-mode - :config - (add-hook 'elixir-mode-hook - (lambda () (add-hook 'before-save-hook 'elixir-format nil t)))) - - (use-package haskell-mode - :config - (setq haskell-stylish-on-save t)) - - (use-package rust-mode - :config - (setq rust-format-on-save t)) - - ;; - ;; Tasks system. - ;; - (setq-default tasks '()) - (defvar tasks/history nil) - (defun run-task () - (interactive) - (let* ((choices (mapcar #'car tasks)) - (last (car tasks/history)) - (choice (completing-read - "Task: " - choices - nil t - nil 'tasks/history - last))) - (compile - (cadr (assoc choice tasks))))) - (global-set-key (kbd "C-c C-t") #'run-task) - (global-set-key (kbd "C-c t") #'run-task) - - ;; Move custom elsewhere. - (setq custom-file (expand-file-name "custom.el" user-emacs-directory)) - (load custom-file 'noerror) + + (setq doom-modeline-icon t) + (setq doom-modeline-height 32) + (doom-modeline-mode 1)) +#+END_SRC + +*** Fonts + +Hack and Noto Sans. + +#+BEGIN_SRC emacs-lisp +(set-face-attribute 'default nil :family "Hack" :height 110) +(set-face-attribute 'fixed-pitch nil :family "Hack" :height 110) +(set-face-attribute 'variable-pitch nil :family "Noto Sans" :height 130) +#+END_SRC + +All the icons. I like icons. Don't you like icons? + +#+BEGIN_SRC emacs-lisp +(use-package all-the-icons) +#+END_SRC + +*** Rainbow + +Rainbow delimiters and rainbow mode. + +#+BEGIN_SRC emacs-lisp +(use-package rainbow-delimiters + :config + (rainbow-delimiters-mode t)) + +(use-package rainbow-mode + :config + (rainbow-mode t)) +#+END_SRC + +** Behaviour +*** Basics + +Short answers, fill column, don't make backups. + +#+BEGIN_SRC emacs-lisp +(defalias 'yes-or-no-p 'y-or-n-p) +(setopt use-short-answers t) + +(setq-default fill-column 80) + +(setq make-backup-files nil) +#+END_SRC + +Move custom elsewhere. + +#+BEGIN_SRC emacs-lisp +(setq custom-file (expand-file-name "custom.el" user-emacs-directory)) +(load custom-file 'noerror) +#+END_SRC + +*** Compile mode + +No default command a keybind, colorize the buffer. + +#+BEGIN_SRC emacs-lisp +(setq-default compile-command "") +(global-set-key (kbd "C-c c") #'compile) + +(require 'ansi-color) +(defun colorize-compilation () + "Colorize from `compilation-filter-start' to `point'." + (let ((inhibit-read-only t)) + (ansi-color-apply-on-region + compilation-filter-start (point)))) + +(add-hook 'compilation-filter-hook + #'colorize-compilation) +#+END_SRC + +*** IDO + +Makes the minibuffer much nicer. IDO vertically, amx, etc. + +#+BEGIN_SRC emacs-lisp +(use-package ido-vertical-mode + :config + (setq ido-vertical-show-count t) + (ido-vertical-mode t)) + +(use-package ido-completing-read+ + :config + (ido-mode t) + (ido-everywhere t) + (ido-ubiquitous-mode t)) + +(use-package amx + :config + (amx-mode t)) +#+END_SRC + +*** Windows + +Move windows with meta. Makes C-v and M-v to move by half pages instead of +full ones. + +#+BEGIN_SRC emacs-lisp +(windmove-default-keybindings 'meta) + +(defun window-half-height () + (max 1 (/ (1- (window-height (selected-window))) 2))) + +(defun scroll-up-half () + (interactive) + (scroll-up (window-half-height))) + +(defun scroll-down-half () + (interactive) + (scroll-down (window-half-height))) + +(global-set-key (kbd "C-v") #'scroll-up-half) +(global-set-key (kbd "M-v") #'scroll-down-half) +#+END_SRC + +** Editor configuration +*** Basics + +Show trailing whitespaces, but not on the minibuffer of course. Display +line numbers and fill column in all actual editing modes. Scroll nicely. +Save history and recent files. + +#+BEGIN_SRC emacs-lisp +(setq-default show-trailing-whitespace t) +(add-hook + 'minibuffer-mode-hook (lambda () (setq show-trailing-whitespace nil))) + +(defun prog-and-text-mode-setup () + (display-line-numbers-mode t) + (display-fill-column-indicator-mode t)) +(add-hook 'prog-mode-hook #'prog-and-text-mode-setup) +(add-hook 'text-mode-hook #'prog-and-text-mode-setup) + +(setq scroll-step 1) +(setq scroll-conservatively 100000) + +(savehist-mode 1) +(recentf-mode 1) +#+END_SRC + +*** Respect ~.editorconfig~ files. + +#+BEGIN_SRC emacs-lisp +(use-package editorconfig + :config + (editorconfig-mode t)) +#+END_SRC + +*** Open dir + +Open dir is my IDE-mode. It navigates to a directory, loads custom +configuration from a ~.emacs.el~ file there if it exists, and opens dired. + +#+BEGIN_SRC emacs-lisp +(defun open-dir (dir) + (interactive (list (read-directory-name "Open directory: " nil nil t))) + (let ((dir (file-name-as-directory + (expand-file-name dir)))) + (setq-default default-directory dir) + (setq default-directory dir) + (setenv "PWD" dir) + (let ((file-name (concat default-directory ".emacs.el"))) + (unless (not (file-exists-p file-name)) + (load-file file-name) + (message "Loaded custom directory configuration."))) + (dired dir))) + +(global-set-key (kbd "C-c o") #'open-dir) +#+END_SRC + +*** Electric + +Electric, auto-fill and selection deletion. + +#+BEGIN_SRC emacs-lisp +(electric-indent-mode t) +(electric-pair-mode t) +(add-hook 'text-mode-hook + (lambda () + (auto-fill-mode t))) +(delete-selection-mode t) +#+END_SRC + +*** Multiple cursors + +#+BEGIN_SRC emacs-lisp +(use-package multiple-cursors + :bind ( + ("C-S-c" . mc/edit-lines) + ("C->" . #'mc/mark-next-like-this) + ("C-<" . #'mc/mark-previous-like-this))) +#+END_SRC + +Fixes org mode. + +#+BEGIN_SRC emacs-lisp +(with-eval-after-load 'multiple-cursors + (dolist (cmd '(org-self-insert-command org-delete-backward-char)) + (add-to-list 'mc/cmds-to-run-for-all cmd))) +#+END_SRC + +*** Xrefs + +So the editor is a little less dumb. + +#+BEGIN_SRC emacs-lisp +(with-eval-after-load 'etags + (add-hook 'prog-mode-hook + (lambda () + (etags-regen-mode t) + (xref-etags-mode t)))) +#+END_SRC + +** Utilities +*** Magit + +The best git UI in the world. + +#+BEGIN_SRC emacs-lisp +(use-package magit) +(use-package magit-gh + :after magit) +#+END_SRC + +*** Dired + +File management. + +#+BEGIN_SRC emacs-lisp +(setq dired-kill-when-opening-new-dired-buffer t) +(setq dired-delete-by-moving-to-trash t) +(setq dired-listing-switches "-D --group-directories-first") +#+END_SRC + +Enhanced appearance. + +#+BEGIN_SRC emacs-lisp +(use-package all-the-icons-dired + :hook (dired-mode . all-the-icons-dired-mode)) + +(use-package diredfl + :hook (dired-mode . diredfl-mode)) +#+END_SRC + +*** GitHub Copilot Chat + +Vibe coding but I'm forced to always review everything. And it only does +what I actually want it to do. + +#+BEGIN_SRC emacs-lisp +(use-package copilot-chat + :config + (setq copilot-chat-default-model "gpt-5-mini")) +#+END_SRC + +*** Task system + +Inspired by Zed tasks. Uses ~compile-mode~. Very neat. + +#+BEGIN_SRC emacs-lisp +(setq-default tasks '()) +(defvar tasks/history nil) +(defun run-task () + (interactive) + (let* ((choices (mapcar #'car tasks)) + (last (car tasks/history)) + (choice (completing-read + "Task: " + choices + nil t + nil 'tasks/history + last))) + (compile + (cadr (assoc choice tasks))))) +(global-set-key (kbd "C-c C-t") #'run-task) +(global-set-key (kbd "C-c t") #'run-task) +#+END_SRC + +*** Miscelaneous + +Lice to add licenses. + +#+BEGIN_SRC emacs-lisp +(use-package lice) +#+END_SRC + +** Language specific configuration +*** Emacs Lisp + +#+BEGIN_SRC emacs-lisp +(add-hook 'emacs-lisp-mode-hook + (lambda () + (prettify-symbols-mode t))) +#+END_SRC + +*** Go + +#+BEGIN_SRC emacs-lisp +(use-package go-mode + :config + (add-hook 'go-mode-hook + (lambda () + (setq tab-width 4) + (setq indent-tabs-mode t) + (add-hook 'before-save-hook #'gofmt-before-save nil t)))) +#+END_SRC + +*** C/C++ + +#+BEGIN_SRC emacs-lisp +(use-package clang-format) +(setq-default c-basic-offset 4) +(setq-default c-default-style "linux") +(defun c-configs () + (setq tab-width 4) + (setq indent-tabs-mode nil) + (add-hook 'before-save-hook #'clang-format nil t)) +(add-hook 'c-mode-hook #'c-configs) +(add-hook 'c++-mode-hook #'c-configs) +#+END_SRC + +*** Pascal + +#+BEGIN_SRC emacs-lisp +(setq-default pascal-indent-level 4) +(add-hook 'pascal-mode-hook + (lambda () + (setq tab-width 4) + (setq pascal-indent-level 4) + (setq pascal-auto-lineup '()) + (setq indent-tabs-mode nil) + (local-set-key (kbd "C-c C-c") #'compile))) +#+END_SRC + +*** Web + +#+BEGIN_SRC emacs-lisp +(use-package web-mode + :config + (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))) +#+END_SRC + +*** Markdown + +#+BEGIN_SRC emacs-lisp +(use-package markdown-mode) +#+END_SRC + +*** ASM + +#+BEGIN_SRC emacs-lisp +(use-package nasm-mode + :config + (add-to-list 'auto-mode-alist '("\\.asm\\'" . nasm-mode)) + (add-to-list 'auto-mode-alist '("\\.s\\'" . nasm-mode))) +#+END_SRC + +*** Zig + +#+BEGIN_SRC emacs-lisp +(use-package zig-mode) +#+END_SRC + +*** Odin + +#+BEGIN_SRC emacs-lisp +(use-package odin-mode + :commands odin-mode + :vc (:url "https://github.com/mattt-b/odin-mode.git" + :rev :last-release)) +#+END_SRC + +*** Elixir + +#+BEGIN_SRC emacs-lisp +(use-package elixir-mode + :config + (add-hook 'elixir-mode-hook + (lambda () (add-hook 'before-save-hook 'elixir-format nil t)))) +#+END_SRC + +*** Haskell + +#+BEGIN_SRC emacs-lisp +(use-package haskell-mode + :config + (setq haskell-stylish-on-save t)) +#+END_SRC + +*** Rust + +#+BEGIN_SRC emacs-lisp +(use-package rust-mode + :config + (setq rust-format-on-save t)) +#+END_SRC + +** Org mode +*** Appearance/Indenting + +#+BEGIN_SRC emacs-lisp +(add-hook 'org-mode-hook + (lambda () + (visual-line-mode 1) + (org-indent-mode) + (display-line-numbers-mode -1))) +#+END_SRC + +*** Hide everything. + +#+BEGIN_SRC emacs-lisp +(setq-default org-edit-src-content-indentation 0) +(setq-default org-hide-macro-markers t) +(setq-default org-hide-emphasis-markers t) +(setq-default org-hide-block-startup t) +(setq-default org-hide-drawer-startup t) +(setq-default org-startup-folded 'fold) +#+END_SRC + +*** Bullets + +Use prettier bullets. + +#+BEGIN_SRC emacs-lisp +(use-package org-bullets + :after org + :hook (org-mode-hook . org-bullets-mode)) #+END_SRC