added emacs config according to first 3 dt emacs videos

This commit is contained in:
paul-loedige
2023-08-09 00:42:58 +02:00
parent 0631bdfbb0
commit 6b87c40d71
6 changed files with 572 additions and 1 deletions
+2 -1
View File
@@ -3,4 +3,5 @@
.vim/plugged/* .vim/plugged/*
neovim/.config/nvim/plugged neovim/.config/nvim/plugged
neovim/.config/nvim/spell/ neovim/.config/nvim/spell/
git/.git-credentials git/.git-credentials
*~
+552
View File
@@ -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 "<C-wheel-up>") 'text-scale-increase)
(global-set-key (kbd "<C-wheel-down>") '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 ... |
|------------------------+-----------------------------------------|
| <a | '#+BEGIN_EXPORT ascii' … '#+END_EXPORT |
| <c | '#+BEGIN_CENTER' … '#+END_CENTER' |
| <C | '#+BEGIN_COMMENT' … '#+END_COMMENT' |
| <e | '#+BEGIN_EXAMPLE' … '#+END_EXAMPLE' |
| <E | '#+BEGIN_EXPORT' … '#+END_EXPORT' |
| <h | '#+BEGIN_EXPORT html' … '#+END_EXPORT' |
| <l | '#+BEGIN_EXPORT latex' … '#+END_EXPORT' |
| <q | '#+BEGIN_QUOTE' … '#+END_QUOTE' |
| <s | '#+BEGIN_SRC' … '#+END_SRC' |
| <v | '#+BEGIN_VERSE' … '#+END_VERSE' |
#+begin_src emacs-lisp
(require 'org-tempo)
#+end_src
* RAINBOW MODE
Display the actual color as a background for any hex color value (ex. #ffffff). The code block below enables rainbow-mode in all programming modes (prog-mode) as well as org-mode, which is why rainbow works in this document.
#+begin_src emacs-lisp
(use-package rainbow-mode
:hook org-mode prog-mode)
#+end_src
* RELOAD EMACS
This is just an example of how to create a simple function in Emacs. Use this function to reload Emacs after adding changes to the config. Yes, I am loading the user-init-file twice in this function, which is a hack because for some reason, just loading the user-init-file once does not work properly.
#+begin_src emacs-lisp
(defun reload-init-file ()
(interactive)
(load-file user-init-file)
(load-file user-init-file))
#+end_src
* SHELLS AND TERMINALS
** Eshell
Eshell is an Emacs 'shell' that is written in Elisp.
#+begin_src emacs-lisp
(use-package eshell-syntax-highlighting
:after esh-mode
:config
(eshell-syntax-highlighting-global-mode +1))
;; eshell-syntax-highlighting -- adds fish/zsh-like syntax highlighting.
;; eshell-rc-script -- your profile for eshell; like a bashrc for eshell.
;; eshell-aliases-file -- sets an aliases file for the eshell.
(setq eshell-rc-script (concat user-emacs-directory "eshell/profile")
eshell-aliases-file (concat user-emacs-directory "eshell/aliases")
eshell-history-size 5000
eshell-buffer-maximum-lines 5000
eshell-hist-ignoredups t
eshell-scroll-to-bottom-on-input t
eshell-destroy-buffer-when-process-dies t
eshell-visual-commands'("bash" "fish" "htop" "ssh" "top" "zsh"))
#+end_src
** Vterm
Vterm is a terminal emulator within Emacs. The 'shell-file-name' setting sets the shell to be used in M-x shell, M-x term, M-x ansi-term and M-x vterm.
#+begin_src emacs-lisp
(use-package vterm
:config
(setq shell-file-name "/bin/zsh"
vterm-max-scrollback 5000))
#+end_src
** Vterm-Toggle
[[https://github.com/jixiuf/vterm-toggle][vterm-toggle]] toggles between the vterm buffer and whatever buffer you are editing.
#+begin_src emacs-lisp
(use-package vterm-toggle
:after vterm
:config
(setq vterm-toggle-fullscreen-p nil)
(setq vterm-toggle-scope 'project)
(add-to-list 'display-buffer-alist
'((lambda (buffer-or-name _)
(let ((buffer (get-buffer buffer-or-name)))
(with-current-buffer buffer
(or (equal major-mode 'vterm-mode)
(string-prefix-p vterm-buffer-name (buffer-name buffer))))))
(display-buffer-reuse-window display-buffer-at-bottom)
;;(display-buffer-reuse-window display-buffer-in-direction)
;;display-buffer-in-direction/direction/dedicated is added in emacs27
;;(direction . bottom)
;;(dedicated . t) ;dedicated is supported in emacs27
(reusable-frames . visible)
(window-height . 0.3))))
#+end_src
* SUDO EDIT
[[https://github.com/nflath/sudo-edit][sudo-edit]] gives us the ability to open files with sudo privileges.
#+begin_src emacs-lisp
(use-package sudo-edit
:config
(pwl/leader-keys
"s" '(:ignore t :wk "SUDO")
"su" '(sudo-edit-find-file :wk "Sudo find file")
"sU" '(sudo-edit :wk "Sudo edit current file")
)
)
#+end_src
* THEME
#+begin_src emacs-lisp
(use-package gruvbox-theme
:ensure t
:config
(load-theme 'gruvbox-dark-hard t)
)
(use-package doom-themes
:ensure t
:config
;; Global settings (defaults)
(setq doom-themes-enable-bold t ; if nil, bold is universally disabled
doom-themes-enable-italic t) ; if nil, italics is universally disabled
;; Enable flashing mode-line on errors
(doom-themes-visual-bell-config)
;; Enable custom neotree theme (all-the-icons must be installed!)
(doom-themes-neotree-config)
;; or for treemacs users
(setq doom-themes-treemacs-theme "doom-atom") ; use "doom-colors" for less minimal icon theme
(doom-themes-treemacs-config)
;; Corrects (and improves) org-mode's native fontification.
(doom-themes-org-config))
#+end_src
* WHICH-KEY
#+begin_src emacs-lisp
(use-package which-key
:init
(which-key-mode 1)
:config
(setq which-key-side-window-location 'bottom
which-key-sort-order #'which-key-key-order-alpha
which-key-sort-uppercase-first nil
which-key-add-column-padding 1
which-key-max-display-columns nil
which-key-min-display-lines 6
which-key-side-window-slot -10
which-key-side-window-max-height 0.25
which-key-idle-delay 0.8
which-key-max-description-length 25
which-key-allow-imprecise-window-fit t
which-key-separator "" ))
#+end_src
+1
View File
@@ -0,0 +1 @@
(setq package-enable-at-startup nil)
View File
View File
+17
View File
@@ -0,0 +1,17 @@
(org-babel-load-file
(expand-file-name
"config.org"
user-emacs-directory))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes
'("a5270d86fac30303c5910be7403467662d7601b821af2ff0c4eb181153ebfc0a" "871b064b53235facde040f6bdfa28d03d9f4b966d8ce28fb1725313731a2bcc8" "046a2b81d13afddae309930ef85d458c4f5d278a69448e5a5261a5c78598e012" "0c08a5c3c2a72e3ca806a29302ef942335292a80c2934c1123e8c732bb2ddd77" "da75eceab6bea9298e04ce5b4b07349f8c02da305734f7c0c8c6af7b5eaa9738" "e3daa8f18440301f3e54f2093fe15f4fe951986a8628e98dcd781efbec7a46f2" "d445c7b530713eac282ecdeea07a8fa59692c83045bf84dd112dd738c7bcad1d" default)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)