Files
dotfiles/Emacs/.config/emacs/config.org
dx f8ca6b9e1b +major refactors to vanilla Emacs config
Developed quite a bit of the config.

I've added a literate org config, loaded through the init.el file.
Furthermore, I've added some basic general maps and have gained a much
better understanding of Emacs than before. This refactor is one of the
main reasons I decided to so heavily refactor my doom config.
2020-07-15 15:31:56 +01:00

6.1 KiB

Config for Emacs

Notes

This setup uses emacs 27, with use-package and melpa. Code structure is pretty simple:

  • parent packages or packages that other packages leverage greatly are configured first.

I use :after as a depdence generator: in most circumstances.

Init

Set some details

Some basic details set for the purposes of Emacs

  (setq user-emacs-directory (expand-file-name "~/.config/emacs/")
 ring-bell-function 'ignore
 inhibit-startup-screen t)

Turn off those annoying bars

Annoying menu bars, tool bars, etc

  (tool-bar-mode -1)
  (scroll-bar-mode -1)
  (tab-bar-mode -1)
  (menu-bar-mode -1)

Set fonts and alpha

Make two constants that hold the values for font and alpha, then set them in Emacs.

  (defconst dx:font "IBM Plex Mono-12" "Default font for Emacs")
  (defconst dx:alpha 0.9 "Default alpha transparency for Emacs")

  (add-to-list 'default-frame-alist (cons 'font dx:font))
  (add-to-list 'default-frame-alist (cons 'alpha dx:alpha))
  (set-face-attribute 'default t :font dx:font)

  (add-hook 'prog-mode-hook #'hs-minor-mode)
  (add-hook 'prog-mode-hook #'display-line-numbers-mode)

Set some useful variables

Truncate lines, display number lines and stop making backup files (for now).

 (setq completion-ignore-case t
truncate-lines t
display-line-numbers-type t
make-backup-files nil)

ido mode

Setup ido mode, easy to use completion framework.

(ido-mode +1)

Keybindings

Keychord

Setup key chord, pretty basic config.

  (use-package key-chord
    :ensure t
    :config
    (key-chord-mode +1))

General

Setup for general, keybinding library. I use the function general-evil-setup to use the *map family of keymapping functions. In this case I setup two defines: gmap and lmap. gmap is for all global maps while lmap is for local, mode based keybindings I also have a good bit of bindings setup here, such that any default emacs functions that I use regularly is setup here.

  (use-package general
    :ensure t
    :init
    ;; Definers
    (general-def :states 'normal
"SPC" nil)
    (general-create-definer gmap :prefix "SPC") 
    (general-create-definer lmap :prefix "SPC m")
    (general-evil-setup t)
)

Which key

(use-package which-key
  :ensure t
  :config
  (which-key-mode +1))

Evil

Basic evil configuration with some keychords.

(use-package evil
:ensure t
:after key-chord general
:config
(evil-mode +1)
(key-chord-define evil-insert-state-map "jk" #'evil-normal-state)
     ;; Keybindgs
     (gmap "SPC" #'execute-extended-command)
     ;; Files
     (gmap
:infix "f" 
"f" #'find-file
"p" #'(lambda () (interactive) (find-file "~/.config/emacs/init.el"))
"-" #'dired
"s" #'save-buffer)
     ;; Buffers
     (gmap
:infix "b"
"b" #'switch-to-buffer
"d" #'kill-buffer
"n" #'next-buffer
"p" #'previous-buffer
"i" #'ibuffer)
     ;; Other
     (gmap
"c" #'compile)
     (vmap
:keymaps 'emacs-lisp-mode-map
"gr" #'eval-region)
)

Evil surround

(use-package evil-surround
  :ensure t
  :after evil 
  :config
  (global-evil-surround-mode +1))

Helpful

(use-package helpful
:after general
:ensure t
:config
(gmap
  :infix "h"
  "f" #'helpful-callable
  "v" #'helpful-variable
  "k" #'helpful-key))

Yasnippet

(use-package yasnippet
  :ensure t
  :after general
  :config
  (add-hook 'prog-mode-hook #'yas-minor-mode)
  (gmap
    "is" #'yas-insert-snippet))

(use-package yasnippet-snippets
  :ensure t
  :after yasnippet)

Doom-themes

Setup for doom themes. Allow bold themes but not italic (italic is harder to read). Allow doom themes to configure org mode to fix fonts on headers, etc. Define a function that does the same thing as counsel-load-function-action without the dependency on counsel. Load a theme using said function, in this case doom-monokai-classic.

(use-package doom-themes
  :ensure t
  :config
  (setq doom-themes-enable-bold t
 doom-themes-enable-italic nil)
  (doom-themes-org-config)
  (defun dx:load-theme (theme)
    "Load a given theme into Emacs, while unloading the rest"
    (mapc #'disable-theme custom-enabled-themes)
    (load-theme theme t))
  (dx:load-theme 'doom-monokai-classic))

Org-mode

Vanilla org mode

  (use-package org
    :ensure t
    :config
    (load (concat user-emacs-directory "+org.el"))
    (nmap
:keymaps 'org-mode-map
"M-j"   #'org-metadown
"M-k"   #'org-metaup
"C-RET" #'dx:org-insert-item-below))

Evil org mode

Setup evil org mode, which allows for some nicer abstractions of the interace.

  (use-package evil-org
    :ensure t
    :after org
    :config
    (add-hook 'org-mode-hook 'evil-org-mode)
    (add-hook 'evil-org-mode-hook
	      (lambda ()
		(evil-org-set-key-theme)))
    (require 'evil-org-agenda)
    (evil-org-agenda-set-keys))

Magit

(use-package magit
:ensure t
:after general
:config
(gmap
  "g" #'magit-status))

Ace window

(use-package ace-window
  :ensure t
  :after general
  :config
  (gmap "o" #'ace-window)
  (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)
	aw-dispatch-always t))

Counsel

(use-package counsel
  :ensure t
  :after general
  :config
  (gmap
    :infix "s" 
    "s" #'swiper
    "r" #'counsel-rg)
  (general-def
    :keymaps 'ivy-minibuffer-map
    "C-j" #'ivy-next-line-or-history
    "C-k" #'ivy-previous-line-or-history))