diff --git a/.gitignore b/.gitignore index 5735458..af2c5f8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ .vim/plugged/* neovim/.config/nvim/plugged neovim/.config/nvim/spell/ -git/.git-credentials \ No newline at end of file +git/.git-credentials +*~ \ No newline at end of file diff --git a/emacs/.config/emacs/config.org b/emacs/.config/emacs/config.org new file mode 100644 index 0000000..b47c2ba --- /dev/null +++ b/emacs/.config/emacs/config.org @@ -0,0 +1,552 @@ ++TITLE:PWL's GNU Emacs Config +#+AUTHOR: Paul Lödige (PWL) +#+DESCRIPTION: Paul's personal Emacs config. Based on DT's videos +#+STARTUP: showeverything +#+OPTIONS: toc:2 + +* TABLE OF CONTENTS :toc: +- [[#important-programs-to-load-first][IMPORTANT PROGRAMS TO LOAD FIRST]] + - [[#package-manager][Package Manager]] + - [[#load-evil-mode][Load Evil Mode]] + - [[#general-keybindings][General Keybindings]] +- [[#all-the-icons][ALL THE ICONS]] +- [[#buffer-move][BUFFER-MOVE]] +- [[#fonts][FONTS]] + - [[#setting-the-font-face][Setting the Font Face]] + - [[#zooming-inout][Zooming In/Out]] +- [[#graphical-user-interface-tweaks][GRAPHICAL USER INTERFACE TWEAKS]] + - [[#disable-menubar-toolbars-and-scrollbars][Disable Menubar, Toolbars and Scrollbars]] + - [[#display-line-numbers-and-truncated-lines][Display Line Numbers and Truncated Lines]] +- [[#ivy-counsel][IVY (COUNSEL)]] +- [[#org-mode][ORG MODE]] + - [[#enable-toc][Enable TOC]] + - [[#enable-org-bullets][Enable Org Bullets]] + - [[#disable-electric-indent][Disable Electric Indent]] + - [[#enable-org-tempo][Enable Org-Tempo]] +- [[#rainbow-mode][RAINBOW MODE]] +- [[#reload-emacs][RELOAD EMACS]] +- [[#shells-and-terminals][SHELLS AND TERMINALS]] + - [[#eshell][Eshell]] + - [[#vterm][Vterm]] + - [[#vterm-toggle][Vterm-Toggle]] +- [[#sudo-edit][SUDO EDIT]] +- [[#theme][THEME]] +- [[#which-key][WHICH-KEY]] + +* IMPORTANT PROGRAMS TO LOAD FIRST +** Package Manager +#+begin_src emacs-lisp + (defvar elpaca-installer-version 0.5) + (defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory)) + (defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory)) + (defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory)) + (defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git" + :ref nil + :files (:defaults (:exclude "extensions")) + :build (:not elpaca--activate-package))) + (let* ((repo (expand-file-name "elpaca/" elpaca-repos-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 (call-process "git" nil buffer t "clone" + (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) + (load "./elpaca-autoloads"))) + (add-hook 'after-init-hook #'elpaca-process-queues) + (elpaca `(,@elpaca-order)) +#+end_src + +** Load Evil Mode +#+begin_src emacs-lisp + ;; Install use-package support + (elpaca elpaca-use-package + ;; Enable :elpaca use-package keyword. + (elpaca-use-package-mode) + ;; Assume :elpaca t unless otherwise specified. + (setq elpaca-use-package-by-default t)) + + ;; Block until current queue processed. + (elpaca-wait) + + ;;When installing a package which modifies a form used at the top-level + ;;(e.g. a package which adds a use-package key word), + ;;use `elpaca-wait' to block until that package has been installed/configured. + ;;For example: + ;;(use-package general :demand t) + ;;(elpaca-wait) + + ;; Expands to: (elpaca evil (use-package evil :demand t)) + (use-package evil + :init ;;tweak evil's configuration before loading it + (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 + :after evil + :config + (setq evil-collection-mode-list '(dashboard dired ibuffer)) + (evil-collection-init)) + (use-package evil-tutor) + + ;;Turns off elpaca-use-package-mode current declartion + ;;Note this will cause the declaration to be interpreted immediately (not deferred). + ;;Useful for configuring built-in emacs features. + (use-package emacs :elpaca nil :config (setq ring-bell-function #'ignore)) + + ;; Don't install anything. Defer execution of BODY + ;;(elpaca nil (message "deferred")) +#+end_src + + +** General Keybindings +#+begin_src emacs-lisp + (use-package general + :config + (general-evil-setup) + + ;; set up 'SPC' as the global leader key + (general-create-definer pwl/leader-keys + :states '(normal insert visual emacs) + :keymaps 'override + :prefix "SPC" ;; set leader + :global-prefix "M-SPC") ;; access leader in insert mode + + ;; File Navigation + (pwl/leader-keys + "." '(find-file :wk "Find file") + "f c" '((lambda () (interactive) (find-file "~/.config/emacs/config.org")) :wk "Edit emacs config") + "f r" '(counsel-recentf :wk "Find recent files") + ) + + ;; Buffer Management + (pwl/leader-keys + "b" '(:ignore t :wk "buffer") + "bb" '(switch-to-buffer :wk "Switch buffer") + "bi" '(ibuffer :wk "List buffers (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") + ) + + ;; Elisp Evaluation / Eshell + (pwl/leader-keys + "e" '(:ignore t :wk "Eshell/Evaluate") + "e b" '(eval-buffer :wk "Evaluate elisp in buffer") + "e d" '(eval-defun :wk "Evaluate defun containing or after point") + "e e" '(eval-expression :wk "Evaluate an elisp espression") + "e h" '(counsel-esh-history :which-key "Eshell history") + "e l" '(eval-last-sexp :wk "Evaluate elisp expression before point") + "e r" '(eval-region :wk "Evaluate elisp in region") + "e s" '(eshell :which-key "Eshell") + ) + + ;; Help + (pwl/leader-keys + "h" '(:ignore t :wk "Help") + "h f" '(describe-function :wk "Describe function") + "h v" '(describe-variable :wk "Describe variable") + "h r r" '(reload-init-file :wk "Reload emacs config") + ) + + ;; Toggle + (pwl/leader-keys + "t" '(:ignore t :wk "Toggle") + "t l" '(display-line-numbers-mode :wk "Toggle line numbers") + "t t" '(visual-line-mode :wk "Toggle truncated lines") + "t v" '(vterm-toggle :wk "Toggle vterm") + ) + + ;; Window Commands + (pwl/leader-keys + "w" '(:ignore t :wk "Windows") + ;; Window splits + "w c" '(evil-window-delete :wk "Close window") + "w n" '(evil-window-new :wk "New window") + "w s" '(evil-window-split :wk "Horizontal split window") + "w v" '(evil-window-vsplit :wk "Vertical split window") + ;; Window motions + "w h" '(evil-window-left :wk "Window left") + "w j" '(evil-window-down :wk "Window down") + "w k" '(evil-window-up :wk "Window up") + "w l" '(evil-window-right :wk "Window right") + "w w" '(evil-window-next :wk "Goto next window") + ;; Move Windows + "w H" '(buf-move-left :wk "Buffer move left") + "w J" '(buf-move-down :wk "Buffer move down") + "w K" '(buf-move-up :wk "Buffer move up") + "w L" '(buf-move-right :wk "Buffer move right") + ) + ) +#+end_src + +* ALL THE ICONS +This is an icon set that can be used with dashboard, dired, ibuffer and other Emacs programs. + +#+begin_src emacs-lisp + (use-package all-the-icons + :ensure t + :if (display-graphic-p)) + + (use-package all-the-icons-dired + :hook (dired-mode . (lambda () (all-the-icons-dired-mode t)))) +#+end_src + +* BUFFER-MOVE +Creating some functions to allow us to easily move windows (splits) around. The following block of code was taken from buffer-move.el found on the EmacsWiki: +https://www.emacswiki.org/emacs/buffer-move.el + +#+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 +#+begin_src emacs-lisp + (set-face-attribute 'default nil + :font "UbuntuMonoNerdFont" + :height 160 + :weight 'medium) + (set-face-attribute 'variable-pitch nil + :font "UbuntuNerdFont" + :height 160 + :weight 'medium) + (set-face-attribute 'fixed-pitch nil + :font "UbuntuMonoNerdFont" + :height 160 + :weight 'medium) + ;; make commented text and keywords italic + (set-face-attribute 'font-lock-comment-face nil + :slant 'italic) + (set-face-attribute 'font-lock-keyword-face nil + :slant 'italic) + ;; set default font on all graphical frames created after restarting + (add-to-list 'default-frame-alist '(font . "UbuntuMonoNerdFont-16")) + +#+end_src + +** Zooming In/Out +CTRL plus +/- for zooming in/out. You can also use CTRL plus the mouse wheel for 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 + +* GRAPHICAL USER INTERFACE TWEAKS +** 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 Truncated Lines +#+begin_src emacs-lisp + ;; set type of line numbering + (setq display-line-numbers-type 'relative) + ;;activate line numbering in all buffers/modes + (global-display-line-numbers-mode 1) +#+end_src + +* IVY (COUNSEL) ++ Ivy, a generic completion mechanism for Emacs. ++ Counsel, a collection of Ivy-enhanced versions of common Emacs commands. ++ Ivy-rich allows us to add descriptions alongside the commands in M-x. + +#+begin_src emacs-lisp + (use-package counsel + :after ivy + :config (counsel-mode)) + + (use-package ivy + :bind + ;; ivy-resume resumes the last Ivy-based completion. + (("C-c C-r" . ivy-resume) + ("C-x B" . ivy-switch-buffer-other-window)) + :custom + (setq ivy-use-virtual-buffers t) + (setq ivy-count-format "(%d/%d) ") + (setq enable-recursive-minibuffers t) + :config + (ivy-mode)) + + (use-package all-the-icons-ivy-rich + :ensure t + :init (all-the-icons-ivy-rich-mode 1)) + + (use-package ivy-rich + :after ivy + :ensure t + :init (ivy-rich-mode 1) ;; this gets us descriptions in M-x. + :custom + (ivy-virtual-abbreviate 'full + ivy-rich-switch-buffer-align-virtual-buffer t + ivy-rich-path-style 'abbrev) + :config + (ivy-set-display-transformer 'ivy-switch-buffer + 'ivy-rich-switch-buffer-transformer)) +#+end_src + +* ORG MODE +** Enable TOC +#+begin_src emacs-lisp + (use-package toc-org + :commands toc-org-enable + :init (add-hook 'org-mode-hook 'toc-org-enable) + ) +#+end_src + +** Enable Org Bullets +#+begin_src emacs-lisp + (add-hook 'org-mode-hook 'org-indent-mode) + (use-package org-bullets) + (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))) +#+end_src + +** Disable Electric Indent +Org Mode likes to do weird indentation. This turns that off. +#+begin_src emacs-lisp + (electric-indent-mode -1) +#+end_src + +** Enable Org-Tempo +faster creation of code blocks in Org Mode. + +| Typing the below + TAB | Expands to ... | +|------------------------+-----------------------------------------| +|