GNU Emacs config from video: Leaving Doom For GNU Emacs

This commit is contained in:
Derek Taylor 2021-04-15 20:29:11 -05:00
parent f1052af2c9
commit ffb0c5f888
2 changed files with 535 additions and 0 deletions

518
.emacs.d/config.org Normal file
View File

@ -0,0 +1,518 @@
#+TITLE: DT's GNU Emacs Config
#+AUTHOR: Derek Taylor (DT)
#+DESCRIPTION: DT's personal Emacs config.
#+STARTUP: showeverything
#+EXPORT_FILE_NAME: /home/dt/Org/html/config.html
#+SETUPFILE: https://fniessen.github.io/org-html-themes/org/theme-readtheorg.setup
#+OPTIONS: num:nil ^:{}
* TABLE OF CONTENTS :TOC:
- [[#put-this-in-your-initel][PUT THIS IN YOUR INIT.EL]]
- [[#about-this-config][ABOUT THIS CONFIG]]
- [[#package-management][PACKAGE MANAGEMENT]]
- [[#setup-packageel-to-work-with-melpa][Setup package.el to work with MELPA]]
- [[#installing-use-package][Installing use-package]]
- [[#all-the-icons][ALL THE ICONS]]
- [[#general-keybindings][GENERAL KEYBINDINGS]]
- [[#dashboard][DASHBOARD]]
- [[#evil-mode][EVIL MODE]]
- [[#finding-files][FINDING FILES]]
- [[#dired][DIRED]]
- [[#fonts][FONTS]]
- [[#setting-the-font-face][Setting The Font Face]]
- [[#zooming-in-and-out][Zooming In and Out]]
- [[#graphical-user-interface-tweaks][GRAPHICAL USER INTERFACE TWEAKS]]
- [[#disable-menu-toolbars-and-scrollbars][Disable Menu, Toolbars and Scrollbars]]
- [[#display-line-numbers-and-truncated-lines][Display Line Numbers and Truncated Lines]]
- [[#change-modeline-to-dooms-modeline][Change Modeline To Doom's Modeline]]
- [[#ivy-counselswiper][IVY (COUNSEL/SWIPER)]]
- [[#ivy-posframe][IVY-POSFRAME]]
- [[#magit][MAGIT]]
- [[#org-mode][ORG MODE]]
- [[#enabling-org-bullets][Enabling Org Bullets]]
- [[#defining-a-few-things][Defining A Few Things]]
- [[#org-link-abbreviations][Org Link Abbreviations]]
- [[#org-todo-keywords][Org Todo Keywords]]
- [[#source-code-block-tag-expansion][Source Code Block Tag Expansion]]
- [[#source-code-block-syntax-highlighting][Source Code Block Syntax Highlighting]]
- [[#automatically-create-table-of-contents][Automatically Create Table of Contents]]
- [[#projectile][PROJECTILE]]
- [[#scrolling][SCROLLING]]
- [[#shells][SHELLS]]
- [[#eshell][Eshell]]
- [[#vterm][Vterm]]
- [[#language-support][LANGUAGE SUPPORT]]
- [[#theme][THEME]]
- [[#which-key][WHICH KEY]]
* PUT THIS IN YOUR INIT.EL
#+begin_verse
(org-babel-load-file
(expand-file-name
"config.org"
user-emacs-directory))
#+end_verse
* ABOUT THIS CONFIG
This is my personal Emacs config. I patterned my config to mimic Doom Emacs, which is a distribution of Emacs that uses the "evil" keybindings (Vim keybindings) and includes a number of nice extensions and a bit of configuration out of the box. I am maintaining this config not just for myself, but also for those that want to explore some of what is possible with Emacs. I will add a lot of examples of plugins and settings, some of them I may not even use personally. I do this because many people following me on YouTube and Odysee look at my configs as "documentation".
* PACKAGE MANAGEMENT
** Setup package.el to work with MELPA
#+begin_src emacs-lisp
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-refresh-contents)
(package-initialize)
#+end_src
** Installing use-package
#+begin_src emacs-lisp
(unless (package-installed-p 'use-package)
(package-install 'use-package))
#+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)
#+end_src
* GENERAL KEYBINDINGS
General.el allows us to set keybindings. As a longtime Doom Emacs user, I have grown accustomed to using SPC as the prefix key. It certainly is easier on the hands than constantly using CTRL for a prefix.
#+begin_src emacs-lisp
(use-package general
:ensure t ;; install general if not installed
:config
(general-evil-setup t))
(nvmap :prefix "SPC"
"SPC" '(counsel-M-x :which-key "M-x")
"." '(find-file :which-key "Find file")
;; Buffers
"b b" '(ibuffer :which-key "Ibuffer")
"b k" '(kill-current-buffer :which-key "Kill current buffer")
"b n" '(next-buffer :which-key "Next buffer")
"b p" '(previous-buffer :which-key "Previous buffer")
"b B" '(ibuffer-list-buffers :which-key "Ibuffer list buffers")
"b K" '(kill-buffer :which-key "Kill buffer")
;; Eshell
"e h" '(counsel-esh-history :which-key "Eshell history")
"e s" '(eshell :which-key "Eshell")
"f r" '(counsel-recentf :which-key "Recent files")
"h r r" '((lambda () (interactive) (load-file "~/.emacs.d/init.el")) :which-key "Reload emacs config")
"t t" '(toggle-truncate-lines :which-key "Toggle truncate lines")
;; Window splits
"w c" '(evil-window-delete :which-key "Close window")
"w n" '(evil-window-new :which-key "New window")
"w s" '(evil-window-split :which-key "Horizontal split window")
"w v" '(evil-window-vsplit :which-key "Vertical split window")
;; Window motions
"w h" '(evil-window-left :which-key "Window left")
"w j" '(evil-window-down :which-key "Window down")
"w k" '(evil-window-up :which-key "Window up")
"w l" '(evil-window-right :which-key "Window right")
"w w" '(evil-window-next :which-key "Goto next window"))
#+end_src
* DASHBOARD
Emacs Dashboard is an extensible startup screen showing you recent files, bookmarks, agenda items and an Emacs banner.
#+begin_src emacs-lisp
(use-package dashboard
:ensure t ;; install dashboard if not installed
:init ;; tweak dashboard config before loading it
(setq dashboard-set-heading-icons t)
(setq dashboard-set-file-icons t)
(setq dashboard-banner-logo-title "Emacs Is More Than A Text Editor!")
;;(setq dashboard-startup-banner 'logo) ;; use standard emacs logo as banner
(setq dashboard-startup-banner "/home/dt/.emacs.d/emacs-dash.png") ;; use custom image as banner
(setq dashboard-center-content nil) ;; set to 't' for centered content
(setq dashboard-items '((recents . 10)
(agenda . 5 )
(bookmarks . 5)
(projects . 5)
(registers . 5)))
:config
(dashboard-setup-startup-hook)
(dashboard-modify-heading-icons '((recents . "file-text")
(bookmarks . "book"))))
#+end_src
This setting ensures that emacsclient always opens on *dashboard* rather than *scratch*.
#+begin_src emacs-lisp
(setq initial-buffer-choice (lambda () (get-buffer "*dashboard*")))
#+end_src
* EVIL MODE
Evil is an extensible 'vi' layer for Emacs. It emulates the main features of Vim, and provides facilities for writing custom extensions. Evil Collection is also installed since it adds 'evil' bindings to parts of Emacs that the standard Evil package does not cover, such as: calenda, help-mode adn ibuffer.
#+begin_src emacs-lisp
(use-package evil
:ensure t ;; install evil if not installed
:init ;; tweak evil's configuration before loading it
(setq evil-want-integration t) ;; This is optional since it's already set to t by default.
(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
:ensure t
:config
(evil-collection-init))
#+end_src
* FINDING FILES
Though 'recentf' is one way to find recent files although I prefer using 'projectile-find-file-in-directory'.
#+begin_src emacs-lisp
(use-package recentf
:ensure t
:config
(recentf-mode))
#+end_src
* DIRED
Dired is the file manager within Emacs. Below, I setup keybindings for image previews (peep-dired). Doom Emacs does not use 'SPC d' for any of its keybindings, so I've chosen the format of 'SPC d' plus 'key'.
| COMMAND | DESCRIPTION | KEYBINDING |
|-------------------------------------------+-------------------------------------------------+------------|
| dired | /Open dired file manager/ | SPC d d |
| dired-jump | /Jump to current directory in dired/ | SPC d j |
| (in dired) peep-dired | /Toggle image previews within dired/ | SPC d p |
| (in dired) dired-view-file | /View file in dired/ | SPC d v |
| (in dired) dired-up-directory | /Go up in the directory tree/ | h |
| (in dired) dired-find-file | /Go down in the directory tree (or open if file)/ | l |
| (in peep-dired-mode) peep-dired-next-file | /Move to next file in peep-dired-mode/ | j |
| (in peep-dired-mode) peep-dired-prev-file | /Move to previous file in peep-dired-mode/ | k |
#+begin_src emacs-lisp
(use-package dired-open
:ensure t)
(use-package peep-dired
:ensure t)
(nvmap :prefix "SPC"
"d d" '(dired :which-key "Open dired")
"d j" '(dired-jump :which-key "Dired jump to current"))
(with-eval-after-load 'dired
(define-key dired-mode-map (kbd "M-p") 'peep-dired)
(evil-define-key'(normal visual) dired-mode-map (kbd "h") 'dired-up-directory)
(evil-define-key'(normal visual) dired-mode-map (kbd "l") 'dired-open-file)) ; use dired-find-file instead if not using dired-open package
(evil-define-key'(normal visual) dired-mode-map (kbd "j") 'peep-dired-next-file)
(evil-define-key'(normal visual) dired-mode-map (kbd "k") 'peep-dired-prev-file)
;; Get file icons in dired
(add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
;; With dired-open plugin, you can launch external programs for certain extensions
;; For example, I set all .png files to open in 'sxiv' and all .mp4 files to open in 'mpv'
(setq dired-open-extensions '(("gif" . "sxiv")
("jpg" . "sxiv")
("png" . "sxiv")
("mkv" . "mpv")
("mp4" . "mpv")))
#+end_src
* FONTS
** Setting The Font Face
#+begin_src emacs-lisp
(set-face-attribute 'default nil
:font "SauceCodePro Nerd Font 11"
:weight 'medium)
(set-face-attribute 'variable-pitch nil
:font "Ubuntu Nerd Font 11"
:weight 'medium)
(set-face-attribute 'fixed-pitch nil
:font "SauceCodePro Nerd Font 11"
:weight 'medium)
;;(setq-default line-spacing 0.10)
;; Needed if using emacsclient. Otherwise, your fonts will be smaller than expected.
(add-to-list 'default-frame-alist '(font . "SauceCodePro Nerd Font 11"))
#+end_src
** Zooming In and Out
You can use the bindings CTRL plus =/- for zooming in/out. You can also use CTRL plus the mouse wheel for zooming in/out.
#+begin_src emacs-lisp
;; zoom in/out like we do everywhere else.
(global-set-key (kbd "C-=") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
;;(global-set-key (kbd "C-0")'(lambda () (interactive) (text-scale-adjust 0)))
(global-set-key (kbd "<C-wheel-down>") 'text-scale-decrease)
(global-set-key (kbd "<C-wheel-up>") 'text-scale-increase)
#+end_src
* GRAPHICAL USER INTERFACE TWEAKS
** Disable Menu, 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
(global-display-line-numbers-mode 1)
(global-visual-line-mode t)
#+end_src
** Change Modeline To Doom's Modeline
#+begin_src emacs-lisp
(use-package doom-modeline)
(doom-modeline-mode 1)
#+end_src
* IVY (COUNSEL/SWIPER)
Ivy is a generic completion mechanism for Emacs.
#+begin_src emacs-lisp
(use-package counsel
:ensure t
:after ivy
:config (counsel-mode))
(use-package ivy
:ensure t
:defer 0.1
:diminish
:bind (("C-c C-r" . ivy-resume)
("C-x B" . ivy-switch-buffer-other-window))
:custom
(ivy-count-format "(%d/%d) ")
(ivy-use-virtual-buffers t)
:config (ivy-mode))
(use-package ivy-rich
:ensure t
:after ivy
: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))
(use-package swiper
:ensure t
:after ivy
:bind (("C-s" . swiper)
("C-r" . swiper)))
#+end_src
** IVY-POSFRAME
Ivy-posframe is an ivy extension, which lets ivy use posframe to show its candidate menu. Some of the settings below involve:
+ ivy-posframe-display-functions-alist -- sets the display position for specific programs
+ ivy-posframe-height-alist -- sets the height of the list displayed for specific programs
Available functions (positions) for 'ivy-posframe-display-functions-alist'
+ ivy-posframe-display-at-frame-center
+ ivy-posframe-display-at-window-center
+ ivy-posframe-display-at-frame-bottom-left
+ ivy-posframe-display-at-window-bottom-left
+ ivy-posframe-display-at-frame-bottom-window-center
+ ivy-posframe-display-at-point
+ ivy-posframe-display-at-frame-top-center
=NOTE:= If the setting for 'ivy-posframe-display' is set to 'nil' (false), anything that is set to 'ivy-display-function-fallback' will just default to their normal position in Doom Emacs (usually a bottom split). However, if this is set to 't' (true), then the fallback position will be centered in the window.
#+begin_src emacs-lisp
(use-package ivy-posframe
:ensure t
:init
(setq ivy-posframe-display-functions-alist
'((swiper . ivy-posframe-display-at-point)
(complete-symbol . ivy-posframe-display-at-point)
(counsel-M-x . ivy-display-function-fallback)
(counsel-esh-history . ivy-posframe-display-at-window-center)
(counsel-describe-function . ivy-display-function-fallback)
(counsel-describe-variable . ivy-display-function-fallback)
(counsel-find-file . ivy-display-function-fallback)
(counsel-recentf . ivy-display-function-fallback)
(counsel-register . ivy-posframe-display-at-frame-bottom-window-center)
(dmenu . ivy-posframe-display-at-frame-top-center)
(nil . ivy-posframe-display))
ivy-posframe-height-alist
'((swiper . 20)
(dmenu . 20)
(t . 10)))
:config
(ivy-posframe-mode 1)) ; 1 enables posframe-mode, 0 disables it.
#+end_src
* MAGIT
#+begin_src emacs-lisp
(use-package magit
:ensure t)
(use-package magit-lfs
:ensure t)
(use-package magit-todos
:ensure t
:config (magit-todos-mode))
#+end_src
* ORG MODE
** Enabling Org Bullets
#+begin_src emacs-lisp
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
#+end_src
** Defining A Few Things
#+begin_src emacs-lisp
(add-hook 'org-mode-hook 'org-indent-mode)
(setq org-directory "~/Org/"
org-agenda-files '("~/Org/agenda.org")
org-default-notes-file (expand-file-name "notes.org" org-directory)
org-ellipsis " ▼ "
org-log-done 'time
org-journal-dir "~/Org/journal/"
org-journal-date-format "%B %d, %Y (%A) "
org-journal-file-format "%Y-%m-%d.org"
org-hide-emphasis-markers t)
(setq org-src-preserve-indentation nil
org-src-tab-acts-natively t
org-edit-src-content-indentation 0)
#+end_src
** Org Link Abbreviations
This allows for the use of abbreviations that will get expanded out into a lengthy URL.
#+begin_src emacs-lisp
;; An example of how this works.
;; [[arch-wiki:Name_of_Page][Description]]
(setq org-link-abbrev-alist ; This overwrites the default Doom org-link-abbrev-list
'(("google" . "http://www.google.com/search?q=")
("arch-wiki" . "https://wiki.archlinux.org/index.php/")
("ddg" . "https://duckduckgo.com/?q=")
("wiki" . "https://en.wikipedia.org/wiki/")))
#+end_src
** Org Todo Keywords
This lets us create the various TODO tags that we can use in Org.
#+begin_src emacs-lisp
(setq org-todo-keywords ; This overwrites the default Doom org-todo-keywords
'((sequence
"TODO(t)" ; A task that is ready to be tackled
"BLOG(b)" ; Blog writing assignments
"GYM(g)" ; Things to accomplish at the gym
"PROJ(p)" ; A project that contains other tasks
"VIDEO(v)" ; Video assignments
"WAIT(w)" ; Something is holding up this task
"|" ; The pipe necessary to separate "active" states and "inactive" states
"DONE(d)" ; Task has been completed
"CANCELLED(c)" ))) ; Task has been cancelled
#+end_src
** Source Code Block Tag Expansion
Org-tempo is a package that allows for '<s' followed by TAB to expand to a begin_src tag. Other expansions available include:
| Characters Preceding 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
(use-package org-tempo)
#+end_src
** Source Code Block Syntax Highlighting
#+begin_src emacs-lisp
(setq org-src-fontify-natively t
org-src-tab-acts-natively t
org-confirm-babel-evaluate nil
org-edit-src-content-indentation 0)
#+end_src
** Automatically Create Table of Contents
Toc-org helps you to have an up-to-date table of contents in org files without exporting (useful useful for README files on GitHub). Use :TOC: to create the table.
#+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
* PROJECTILE
#+begin_src emacs-lisp
(use-package projectile
:ensure t
:config
(projectile-global-mode 1))
#+end_src
* SCROLLING
#+begin_src emacs-lisp
(setq scroll-conservatively 101) ;; value greater than 100 gets rid of half page jumping
(setq mouse-wheel-scroll-amount '(3 ((shift) . 3))) ;; how many lines at a time
(setq mouse-wheel-progressive-speed t) ;; accelerate scrolling
(setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
#+end_src
* SHELLS
** Eshell
Eshell is an Emacs 'shell' that is written in Elisp.
+ 'eshell-syntax-highlighting' -- adds fish/zsh-like syntax highlighting.
+ 'eshell-aliases-file' -- sets an aliases file for the eshell.
#+begin_src emacs-lisp
(use-package eshell-syntax-highlighting
:after esh-mode
:ensure t ;; Install if not already installed.
:config
(eshell-syntax-highlighting-global-mode +1))
(setq eshell-aliases-file "~/.config/doom/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. By default, the shell is set to 'fish' but could change it to 'bash' or 'zsh' if you prefer.
#+begin_src emacs-lisp
(use-package vterm
:ensure t)
(setq shell-file-name "/bin/fish"
vterm-max-scrollback 5000)
#+end_src
* LANGUAGE SUPPORT
Adding packages for programming langauges, so we can have nice things like syntax highlighting.
#+begin_src emacs-lisp
(use-package haskell-mode
:ensure t)
#+end_src
* THEME
#+begin_src emacs-lisp
(use-package doom-themes)
(setq doom-themes-enable-bold t ; if nil, bold is universally disabled
doom-themes-enable-italic t) ; if nil, italics is universally disabled
(load-theme 'doom-one t)
#+end_src
* WHICH KEY
#+begin_src emacs-lisp
(use-package which-key)
(which-key-mode)
#+end_src

17
.emacs.d/init.el Normal file
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.
'(package-selected-packages
'(haskell-mode vterm eshell-syntax-highlighting toc-org magit-todos magit-lfs magit ivy-posframe ivy-rich counsel peep-dired dired-open projectile dashboard general doom-modeline which-key evil-collection evil use-package)))
(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.
)