#+TITLE: Cori's GNU Emacs Config #+AUTHOR: Cori Barker #+DESCRIPTION: Cori's personal Emacs config. #+STARTUP: showeverything #+OPTIONS: toc:2 * TABLE OF CONTENTS :toc: - [[#important-programs-to-load-first][IMPORTANT PROGRAMS TO LOAD FIRST]] - [[#elpaca-package-manager][Elpaca Package Manager]] - [[#load-evil-mode][Load Evil Mode]] - [[#general-keybindings][General Keybindings]] - [[#all-the-icons][ALL THE ICONS]] - [[#fonts][FONTS]] - [[#setting-the-font-face][Setting The Font Face]] - [[#zooming-inout][Zooming In/Out]] - [[#gui-tweaks][GUI TWEAKS]] - [[#disable-menubar-toolbars-and-scrollbars][Disable Menubar, Toolbars and Scrollbars]] - [[#display-line-numbers-and-disable-truncated-lines][Display Line Numbers and Disable Truncated Lines]] - [[#org-mode][ORG MODE]] - [[#enabling-table-of-contents][Enabling Table of Contents]] - [[#enabling-org-bullets][Enabling Org Bullets]] - [[#source-code-block-tag-expansion][Source Code Block Tag Expansion]] - [[#sudo-edit][SUDO EDIT]] - [[#which-key][WHICH-KEY]] - [[#ivy-counsel][IVY (COUNSEL)]] * IMPORTANT PROGRAMS TO LOAD FIRST ** Elpaca Package Manager #+begin_src emacs-lisp (defvar elpaca-installer-version 0.12) (defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory)) (defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory)) (defvar elpaca-sources-directory (expand-file-name "sources/" elpaca-directory)) (defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git" :ref nil :depth 1 :inherit ignore :files (:defaults "elpaca-test.el" (:exclude "extensions")) :build (:not elpaca-activate))) (let* ((repo (expand-file-name "elpaca/" elpaca-sources-directory)) (build (expand-file-name "elpaca/" elpaca-builds-directory)) (order (cdr elpaca-order)) (default-directory repo)) (add-to-list 'load-path (if (file-exists-p build) build repo)) (unless (file-exists-p repo) (make-directory repo t) (when (<= emacs-major-version 28) (require 'subr-x)) (condition-case-unless-debug err (if-let* ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*")) ((zerop (apply #'call-process `("git" nil ,buffer t "clone" ,@(when-let* ((depth (plist-get order :depth))) (list (format "--depth=%d" depth) "--no-single-branch")) ,(plist-get order :repo) ,repo)))) ((zerop (call-process "git" nil buffer t "checkout" (or (plist-get order :ref) "--")))) (emacs (concat invocation-directory invocation-name)) ((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch" "--eval" "(byte-recompile-directory \".\" 0 'force)"))) ((require 'elpaca)) ((elpaca-generate-autoloads "elpaca" repo))) (progn (message "%s" (buffer-string)) (kill-buffer buffer)) (error "%s" (with-current-buffer buffer (buffer-string)))) ((error) (warn "%s" err) (delete-directory repo 'recursive)))) (unless (require 'elpaca-autoloads nil t) (require 'elpaca) (elpaca-generate-autoloads "elpaca" repo) (let ((load-source-file-function nil)) (load "./elpaca-autoloads")))) (add-hook 'after-init-hook #'elpaca-process-queues) (elpaca `(,@elpaca-order)) #+end_src ** Load Evil Mode #+begin_src emacs-lisp ;; Install a package via the elpaca macro ;; See the "recipes" section of the manual for more details. ;; (elpaca example-package) ;; Install use-package support (elpaca elpaca-use-package ;; Enable use-package :ensure support for Elpaca. (elpaca-use-package-mode) (setq use-package-always-ensure t)) ;;When installing a package used in the init file itself, ;;e.g. a package which adds a use-package key word, ;;use the :wait recipe keyword to block until that package is installed/configured. ;;For example: ;;(use-package general :ensure (:wait t) :demand t) ;; Expands to: (elpaca evil (use-package evil :demand t)) (use-package evil :ensure t :init (setq evil-want-integration t) (setq evil-want-keybinding nil) (setq evil-vsplit-window-right t) (setq evil-split-window-below t) (evil-mode)) (use-package evil-collection :ensure t :after evil :config (setq evil-collection-mode-list '(dashboard dired ibuffer)) (evil-collection-init)) (use-package evil-tutor :ensure t) ;;Turns off elpaca-use-package-mode current declaration ;;Note this will cause evaluate the declaration immediately. It is not deferred. ;;Useful for configuring built-in emacs features. (use-package emacs :ensure nil :config (setq ring-bell-function #'ignore)) #+end_src ** General Keybindings #+begin_src emacs-lisp (use-package general :ensure t :config (general-evil-setup) ;; setup SPACE as the global leader key (general-create-definer cb/leader-keys :states '(normal insert visual emacs) :keymaps 'override :prefix "SPC" ;; set leader :global-prefix "M-SPC") ;; access leader in insert mode (cb/leader-keys "." '(find-file :wk "Find file") "fc" '((lambda () (interactive) (find-file "~/.config/emacs/config.org")) :wk "Edit emacs config") "fr" '(counsel-recentf :wk "Find recent files") "TAB TAB" '(comment-line :wk "Comment lines")) (cb/leader-keys "b" '(:ignore t :wk "Buffer") "bb" '(switch-to-buffer :wk "Switch buffer") "bi" '(ibuffer :wk "Ibuffer") "bk" '(kill-this-buffer :wk "Kill this buffer") "bn" '(next-buffer :wk "Next buffer") "bp" '(previous-buffer :wk "Previous buffer") "br" '(revert-buffer :wk "Reload buffer")) (cb/leader-keys "e" '(:ignore t :wk "Eshell/Evaluate") "eb" '(eval-buffer :wk "Evaluate elisp in buffer") "ed" '(eval-defun :wk "Evaluate defun containing or after point") "ee" '(eval-expression :wk "Evaluate elisp expression") "el" '(eval-last-sexp :wk "Evaluate elisp expression before point") "er" '(eval-region :wk "Evaluate elisp in region") "es" '(eshell :wk "Eshell") "eh" '(counsel-esh-history :wk "Eshell history")) (cb/leader-keys "h" '(:ignore t :wk "Help") "hf" '(describe-function :wk "Describe function") "hv" '(describe-variable :wk "Describe variable") "hrr" '((lambda () (interactive) (load-file "~/.config/emacs/init.el")) :wk "Reload emacs config")) (cb/leader-keys "t" '(:ignore t :wk "Toggle") "tl" '(display-line-numbers-mode :wk "Toggle line numbers") "tt" '(visual-line-mode :wk "Toggle truncated lines") "tv" '(vterm-toggle :wk "Toggle vterm")) (cb/leader-keys "w" '(:ignore t :wk "Windows") ;; Window splits "wc" '(evil-window-delete :wk "Close window") "wn" '(evil-window-new :wk "New window") "ws" '(evil-window-split :wk "Horizontal split window") "wv" '(evil-window-vsplit :wk "Vertical split window") ;; Window motions "wh" '(evil-window-left :wk "Window left") "wj" '(evil-window-down :wk "Window down") "wk" '(evil-window-up :wk "Window up") "wl" '(evil-window-right :wk "Window right") "ww" '(evil-window-next :wk "Goto next window") ;; Move windows "wH" '(buf-move-left :wk "Buffer move left") "wJ" '(buf-move down :wk "Buffer move down") "wK" '(buf-move-up :wk "Buffer move up") "wL" '(buf-move-right :wk "Buffer move right")) ) #+end_src * ALL THE ICONS #+begin_src emacs-lisp (use-package all-the-icons :ensure t :defer t :hook (server-after-make-frame . (lambda () (when (display-graphic-p) (require 'all-the-icons))))) (use-package all-the-icons-dired :ensure t :hook (dired-mode . (lambda () (all-the-icons-dired-mode t)))) #+end_src * BUFFER MOVE #+begin_src emacs-lisp (require 'windmove) ;;;###autoload (defun buf-move-up () "Swap the current buffer and the buffer above the split. If there is no split, ie now window above the current one, an error is signaled." ;; "Switches between the current buffer, and the buffer above the ;; split, if possible." (interactive) (let* ((other-win (windmove-find-other-window 'up)) (buf-this-buf (window-buffer (selected-window)))) (if (null other-win) (error "No window above this one") ;; swap top with this one (set-window-buffer (selected-window) (window-buffer other-win)) ;; move this one to top (set-window-buffer other-win buf-this-buf) (select-window other-win)))) ;;;###autoload (defun buf-move-down () "Swap the current buffer and the buffer under the split. If there is no split, ie now window under the current one, an error is signaled." (interactive) (let* ((other-win (windmove-find-other-window 'down)) (buf-this-buf (window-buffer (selected-window)))) (if (or (null other-win) (string-match "^ \\*Minibuf" (buffer-name (window-buffer other-win)))) (error "No window under this one") ;; swap top with this one (set-window-buffer (selected-window) (window-buffer other-win)) ;; move this one to top (set-window-buffer other-win buf-this-buf) (select-window other-win)))) ;;;###autoload (defun buf-move-left () "Swap the current buffer and the buffer on the left of the split. If there is no split, ie now window on the left of the current one, an error is signaled." (interactive) (let* ((other-win (windmove-find-other-window 'left)) (buf-this-buf (window-buffer (selected-window)))) (if (null other-win) (error "No left split") ;; swap top with this one (set-window-buffer (selected-window) (window-buffer other-win)) ;; move this one to top (set-window-buffer other-win buf-this-buf) (select-window other-win)))) ;;;###autoload (defun buf-move-right () "Swap the current buffer and the buffer on the right of the split. If there is no split, ie now window on the right of the current one, an error is signaled." (interactive) (let* ((other-win (windmove-find-other-window 'right)) (buf-this-buf (window-buffer (selected-window)))) (if (null other-win) (error "No right split") ;; swap top with this one (set-window-buffer (selected-window) (window-buffer other-win)) ;; move this one to top (set-window-buffer other-win buf-this-buf) (select-window other-win)))) #+end_src * FONTS ** Setting The Font Face Defining the fonts that Emacs will use. #+begin_src emacs-lisp (defun cb/set-fonts () (set-face-attribute 'default nil :font "FiraMono Nerd Font" :height 100 :weight 'medium) (set-face-attribute 'variable-pitch nil :font "Hack" :height 110 :weight 'medium) (set-face-attribute 'fixed-pitch nil :font "FiraMono Nerd Font" :height 100 :weight 'medium)) (add-hook 'after-make-frame-functions (lambda (frame) (with-selected-frame frame (cb/set-fonts)))) (add-to-list 'default-frame-alist '(font . "FiraMono Nerd Font-11")) (setq-default line-spacing 0.12) #+end_src ** Zooming In/Out #+begin_src emacs-lisp (global-set-key (kbd "C-=") 'text-scale-increase) (global-set-key (kbd "C--") 'text-scale-decrease) (global-set-key (kbd "") 'text-scale-increase) (global-set-key (kbd "") 'text-scale-decrease) #+end_src * GUI TWEAKS Make GNU Emacs look better. ** Disable Menubar, Toolbars and Scrollbars #+begin_src emacs-lisp (menu-bar-mode -1) (tool-bar-mode -1) (scroll-bar-mode -1) #+end_src ** Display Line Numbers and Disable Truncated Lines #+begin_src emacs-lisp (global-display-line-numbers-mode 1) (global-visual-line-mode -1) #+end_src * ORG MODE ** Enabling Table of Contents #+begin_src emacs-lisp (use-package toc-org :ensure t :commands toc-org-enable :init (add-hook 'org-mode-hook 'toc-org-enable)) #+end_src ** Enabling Org Bullets #+begin_src emacs-lisp (add-hook 'org-mode-hook 'org-indent-mode) (use-package org-bullets :ensure t) (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))) #+end_src ** Source Code Block Tag Expansion Type "