8.7 KiB
General Config
Disable Annoying Features
Disable the useless features that make Emacs bloated.
(setq ring-bell-function 'ignore
visual-bell nil
use-dialog-box nil
inhibit-startup-message t
scroll-margin 4) ; Scroll as cursor reaches bottom/top of page.
(scroll-bar-mode -1) ; Disable scrollbar
(tool-bar-mode -1) ; Disable toolbar
(tooltip-mode -1) ; Disable tooltips
(menu-bar-mode -1) ; Disable menu-bar
(set-fringe-mode 10) ; Add gaps on left and right
Global Auto Revert
Enabling global auto revert in Emacs so that changes across a shared file system are synced with emacs buffers.
(global-auto-revert-mode 1)
(setq auto-revert-use-notify nil)
(setq auto-revert-verbose 1)
Remap Quit Key
Remap quit command to make it easier to rescue a buffer. With this function, escape will be used instead of C-g.
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
Visualizing White Space
Add a nice visualization for tabs and spaces. This can be helpful to identify which is which quickly to avoid submitting poorly spaced code.
(global-whitespace-mode)
(setq whitespace-global-modes '(not org-mode dired-mode erc-mode))
(setq whitespace-style '(face tabs spaces tab-mark space-mark trailing))
(custom-set-faces
'(whitespace-tab ((t (:foreground "#384551"))))
'(whitespace-space ((t (:foreground "#384551")))))
(setq whitespace-display-mappings
'((tab-mark 9 [187 9] [92 9])
(space-mark 32 [183] [46])))
Line Numbers
This adds relative line numbers while excluding certain modes.
; Disable line numbers for certain modes
(dolist (mode '(org-mode-hook
erc-mode-hook
mu4e-main-mode-hook
term-mode-hook
vterm-mode-hook
shell-mode-hook
eshell-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
; Enable relative line numbers
(setq-default display-line-numbers-type 'visual)
(global-display-line-numbers-mode t)
Package Manager Setup
Setting up package archives:
(require 'package)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("elpa" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
Installing use-package macros:
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)
(setq use-package-compute-statistics t)
Cosmetics
Update Font
(defun jm/set-font-faces ()
(set-face-attribute 'default nil :font "Maple Mono" :height 140))
; Fix for fonts when running Emacs as a daemon.
(if (daemonp)
(add-hook 'after-make-frame-functions
(lambda (frame)
(with-selected-frame frame
(jm/set-font-faces))))
(jm/set-font-faces))
Doom Packages
(use-package all-the-icons)
(use-package doom-modeline
:init (doom-modeline-mode 1)
:config
(setq doom-modeline-height 45)
(display-time))
(use-package doom-themes
:init (load-theme 'doom-city-lights t))
Rainbow Delimiters
Colors parenthesis for better lisp syntax highlighting.
(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))
Keybindings
General
General allows you to setup a prefix key easily. This makes it really easy to setup a bunch of keybindings with ease.
(use-package general
:config
(general-create-definer jm/leader-keys
:keymaps '(normal insert visual emacs)
:prefix "SPC"
:global-prefix "C-SPC"))
Emacs related keybindings:
(jm/leader-keys
"r" '(rename-buffer :which-key "Rename buffer")
"er" '((lambda () (interactive) (load-file "~/.emacs")) :which-key "Reload emacs config")
"es" '(eshell :which-key "Open eshell terminal"))
Which-Key
(use-package which-key
:init (which-key-mode)
:diminish which-key-mode)
Evil
evil is a package that adds vim keybindings to Emacs.
(use-package evil
:init
(setq evil-want-keybinding nil)
:config
(evil-mode 1))
Evil Collection
Collection of evil keybindings for parts of emacs that are not properly covered by default (eg. help-mode and M-x calendar).
(use-package evil-collection
:after evil
:config (evil-collection-init))
Undo-Tree
Undo tree's use is self explanatory. While the built-in Emacs undo system is fine for me, undo-tree is required as it fixes an issue with evil where you can't redo.
(use-package undo-tree
:after evil
:config
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))
(evil-set-undo-system 'undo-tree)
(global-undo-tree-mode 1))
Programming
Auto-completion
Corfu
corfu is a package that allows for in-buffer completion.
(use-package corfu
:custom
(corfu-cycle t)
(tab-always-indent 'complete)
(text-mode-ispell-word-completion nil)
:init
(global-corfu-mode)
(corfu-history-mode))
(use-package dabbrev
:bind (("M-/" . dabbrev-completion)
("C-M-/" . dabbrev-expand))
:config
(add-to-list 'dabbrev-ignored-buffer-regexps "\\` ")
(add-to-list 'dabbrev-ignored-buffer-modes 'authinfo-mode)
(add-to-list 'dabbrev-ignored-buffer-modes 'doc-view-mode)
(add-to-list 'dabbrev-ignored-buffer-modes 'pdf-view-mode)
(add-to-list 'dabbrev-ignored-buffer-modes 'tags-table-mode))
(use-package cape
:defer 10
:init
(add-to-list 'completion-at-point-functions #'cape-file)
(add-to-list 'completion-at-point-functions #'cape-dabbrev))
Vertico
vertico is a package that implements a drop-down like menu in the mini buffer allowing for much better searching.
(use-package vertico
:init
(vertico-mode))
When installing Vertico, the documentation mentions a few other packages that add some nice features that would come by default with something like ivy. I've added some descriptions of these below:
savehist- One feature of Vertico that is really helpful is it's seamless integration with the built-in emacs package,savehist, to save command history when navigating.marginalia- Similar to the definition of marginalia, this emacs package implements descriptions besides each option in Vertico completion. Some eamples of this would be definitions for Elisp functions, more verbose file information, etc.orderless- By default, Vertico starts its completion from the start of the search the same way as default emacs completion. Theorderlesspackage changes this by implementing a nicer completion that searches for any similar options based on the provided search terms.consult- Adds a bunch of helpful search and navigation commands such as recursive file grepping, etc.
(use-package savehist
:init (savehist-mode))
(use-package marginalia
:after vertico
:init (marginalia-mode))
(use-package orderless
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides '((file (styles partial-completion)))))
(use-package consult
:after vertico
:config
(jm/leader-keys
"pg" 'consult-git-grep
"pf" 'consult-find))
Projectile
Projectile is a package for managing various projects in emacs. It adds functionality to let you interact with various projects such as quickly searching filenames, switching between all projects, grepping all files, etc.
(use-package projectile
:bind-keymap
("C-x p" . projectile-command-map)
:config
(projectile-mode +1)
:init
(when (file-directory-p "~/Developer")
(setq projectile-project-search-path '("~/Developer"))))
Magit
magit adds several features to Emacs that make using git easier.
(use-package magit
:bind (("C-x g" . magit-status)
("C-x C-g" . magit-status)))
Import Other Files
Function to include other config files.
(defun jm/load-config-if-exists (file-path)
(if (file-exists-p file-path)
(org-babel-load-file file-path)
(warn (concat "Failed to load config: " file-path))))
Load other files:
(jm/load-config-if-exists "~/.emacs.d/functions.org") ; Personal Elisp Functions
(jm/load-config-if-exists "~/.emacs.d/org.org") ; Org-mode
(jm/load-config-if-exists "~/.emacs.d/lsp.org") ; Language Server Protocol