Simplify key bindings.
(use-package general
:ensure t
:config
(general-evil-setup))
Use Vim keybindings to avoid Repetitive Strain Injury (RSI).
(use-package evil
:ensure t
:demand t
:requires general
:general
(:states '(normal visual emacs)
"SPC" 'hydra-leader/body)
:init
(setq evil-want-C-i-jump nil) ;; C-i is also <tab>; don't use it for evil.
(setq evil-want-keybinding nil) ;; Use evil-collection for bindings
;; in other packages.
;; For some reason, Magit's git-commit-mode defaults to emacs state instead of
;; normal or insert states. The with-editor-mode-hook below ensures that we
;; start that mode with insert instead of emacs state. See
;; https://github.com/emacs-evil/evil/issues/1145 and
;; https://emacs.stackexchange.com/questions/14008/default-magit-commit-state-in-evil.
:hook ((with-editor-mode . evil-insert-state)
(after-init . evil-mode)))
Common Evil keybindings for other modes. Don’t initialize the whole
package here; instead setup various components within the requiring
use-package
definition. See
https://github.com/emacs-evil/evil-collection.
(use-package evil-collection
:ensure t
:requires evil
:init
;; See evil-collection-mode-list definition in
;; https://github.com/emacs-evil/evil-collection/blob/master/evil-collection.el
;; for available modes and how to add them below.
(evil-collection-init
'((buff-menu "buff-menu")
dired
magit
(package-menu package))))
Hydras are configurable key command menus.
(use-package hydra
:ensure t)
See https://github.com/justbur/emacs-which-key.
(use-package which-key
:ensure t
:hook (after-init . which-key-mode))
Git interface. See https://github.com/magit/magit.
(use-package magit :ensure t)
Enable Evil keybindings for Magit. See https://github.com/emacs-evil/evil-magit.
(use-package evil-magit
:requires (evil magit)
:ensure t)
Definitions for Hydra menus. Requires the hydra
package installed above.
First, create a top-level menu launched by the leader key.
(defhydra hydra-leader (:color blue) "
Leader Hydra
"
("f" hydra-file/body "file")
("b" hydra-buffer/body "buffer")
("w" hydra-window/body "window")
("g" magit-status "magit")
("E" hydra-editor/body "editor")
("Q" save-buffers-kill-emacs "quit emacs")
("SPC" nil "cancel"))
Basic file navigation.
(defhydra hydra-file (:color blue :hint nil) "
File Hydra
"
("e" load-file "load elisp")
("f" find-file "find")
("s" save-buffer "save"))
Buffer manipulation.
(defhydra hydra-buffer (:color blue) "
Buffer Hydra
"
("b" switch-to-buffer "switch to buffer")
("r" revert-buffer-no-confirm "reload buffer contents")
("SPC" nil "cancel"))
Custom buffer functions used above.
;; See https://www.emacswiki.org/emacs/RevertBuffer#toc1.
(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation."
(interactive)
(revert-buffer :ignore-auto :noconfirm))
Window manipulation.
(defhydra hydra-window (:hint nil) "
Window Hydra
^Movement^ ^Manipulation^
^--------^ ^------------^---------
_j_: down _-_: split vertically
_k_: up _/_: split horizontally
_h_: left _c_: close window
_l_: right
"
("j" evil-window-down)
("k" evil-window-up)
("h" evil-window-left)
("l" evil-window-right)
("-" split-window-vertically)
("/" split-window-horizontally)
("c" delete-window)
("SPC" nil "cancel" :color blue))
Editor configuration.
(defhydra hydra-editor (:color blue :hint nil) "
Emacs Hydra
"
("r" load-editor-init "reload init file")
("i" find-editor-init "open init file")
("o" find-editor-config "open config")
("SPC" nil "cancel" :color blue))
Define custom functions for editor init and config files used above.
(defun load-editor-init ()
"Load editor initialization file."
(interactive)
(load-file user-init-file))
(defun find-editor-init ()
"Open the editor initialization file for modification."
(interactive)
(find-file user-init-file))
(defun find-editor-config ()
"Open the editor config file for modification."
(interactive)
(find-file user-config-file))
Show column numbers.
(setq-default column-number-mode t)
Show line numbers. See https://www.emacswiki.org/emacs/LineNumbers.
(when (version<= "26.0.50" emacs-version )
(global-display-line-numbers-mode)
;; https://github.com/coldnew/linum-relative#backends
(setq linum-relative-backend 'display-line-numbers-mode))
(use-package linum-relative
:ensure t
:hook (after-init . linum-relative-mode))
(use-package centered-cursor-mode
:ensure t
:hook (after-init . global-centered-cursor-mode))
Highlights uncomitted changes for various VC backends. See https://github.com/dgutov/diff-hl.
(use-package diff-hl
:ensure t
:config
(unless (display-graphic-p) (diff-hl-margin-mode))
:hook (after-init . global-diff-hl-mode))
See https://github.com/Wilfred/helpful.
(use-package helpful
:ensure t)
Save backups of open files to /tmp (or equivalent) directory.
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
Put custom autogenerated settings in a separate file.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
(load custom-file 'noerror))
Delete trailing whitespace on save.
(add-hook 'before-save-hook 'delete-trailing-whitespace)
Use up to 80 characters per line by default.
(setq-default fill-column 80)
Automatically wrap blocks of text.
(setq-default auto-fill-function 'do-auto-fill)
“COMPlete ANYthing” framework for text completion. See https://company-mode.github.io/.
(use-package company
:ensure t
:requires evil-collection
:custom
(evil-collection-company-use-tng nil "Disable company-tng frontend")
:init
(setq company-idle-delay 0)
(evil-collection-company-setup)
:config
(add-to-list 'company-backends 'company-ispell)
(add-to-list 'company-backends 'company-yasnippet)
:hook (after-init . global-company-mode))
On-the-fly syntax checking. See https://github.com/flycheck/flycheck.
(use-package flycheck
:ensure t
:hook (after-init . global-flycheck-mode))
Reusable text snippets. See https://github.com/joaotavora/yasnippet.
(use-package yasnippet
:ensure t
:config
:hook (after-init . yas-global-mode))
Yasnippet doesn’t include snippets out of the box, so include the official package of pre-written snippets. See https://github.com/AndreaCrotti/yasnippet-snippets.
(use-package yasnippet-snippets
:ensure t
:requires yasnippet)
Cool themes from https://github.com/hlissner/emacs-doom-themes.
(use-package doom-themes
:ensure t
:config
(load-theme 'doom-one t))
See https://github.com/seagle0128/doom-modeline.
(use-package doom-modeline
:ensure t
:hook (after-init . doom-modeline-mode))
Nice fonts used by Doom packages. For example, see https://github.com/jacktasia/beautiful-emacs/blob/master/init.org.
(use-package all-the-icons
:if window-system
:ensure t
:config
(when (not (member "all-the-icons" (font-family-list)))
(all-the-icons-install-fonts t)))
Language Server Protocol integration. See https://github.com/emacs-lsp/lsp-mode.
(use-package lsp-mode
:ensure t
:hook (c++-mode . lsp-deferred)
:commands lsp lsp-deferred)
Configs for the C/C++ mode included in Emacs.
(use-package cc-mode
:ensure t
:mode (("\\.h\\'" . c++-mode)))
Google style formatting for C/C++ modes.
(use-package google-c-style
:ensure t
:init
(add-hook 'c-mode-common-hook
(lambda ()
(google-set-c-style)
(google-make-newline-indent))))
Major mode for gn (Generate Ninja) from https://github.com/lashtear/gn-mode.
(use-package gn-mode
:ensure t
:mode (("\\.gn\\'" . gn-mode)
("\\.gni\\'" . gn-mode)))
See https://github.com/yoshiki/yaml-mode.
(use-package yaml-mode
:ensure t
:mode (("\\.yml\\'" . yaml-mode)
("\\.yaml\\'" . yaml-mode)))