about summary refs log tree commit diff
path: root/emacs/.emacs.d/wpc/keybindings.el
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-08-19T11·42+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-20T10·26+0100
commit3dc7f7758b4be2792979e5ae18c54ed7da5950b3 (patch)
treebab962b6bdd8bd54a3bdf77ae31e55f577e08787 /emacs/.emacs.d/wpc/keybindings.el
parent4ae6eff607a5ebd52f8a271bf34c32f2e2fe60f6 (diff)
Drop support for wpc-keybindings
In favor of keybindings.el!

Now I have:
- kbd.el: There are no keybindings in this file. It's just a library for working
  with keybindings in Emacs.
- keybindings.el: (hopefully) all of my keybindings for EXWM, evil, etc.
Diffstat (limited to 'emacs/.emacs.d/wpc/keybindings.el')
-rw-r--r--emacs/.emacs.d/wpc/keybindings.el122
1 files changed, 121 insertions, 1 deletions
diff --git a/emacs/.emacs.d/wpc/keybindings.el b/emacs/.emacs.d/wpc/keybindings.el
index 7a1805ac55..8f3114ccd9 100644
--- a/emacs/.emacs.d/wpc/keybindings.el
+++ b/emacs/.emacs.d/wpc/keybindings.el
@@ -3,6 +3,14 @@
 
 ;;; Commentary:
 ;; Attempting to centralize my keybindings to simplify my configuration.
+;;
+;; I have some expectations about my keybindings. Here are some of those
+;; defined:
+;; - In insert mode:
+;;   - C-a: beginning-of-line
+;;   - C-e: end-of-line
+;;   - C-b: backwards-char
+;;   - C-f: forwards-char
 
 ;;; Code:
 
@@ -23,10 +31,106 @@
 (require 'device)
 (require 'evil-ex)
 
+(use-package evil
+  :init
+  ;; Should remove the warning messages on init.
+  (setq evil-want-integration t)
+  ;; TODO: Troubleshoot why this binding causes the following warning:
+  ;; "Warning (evil-collection): `evil-want-keybinding' was set to nil but not
+  ;; before loading evil."
+  (setq evil-want-keybinding nil)
+  (general-evil-setup)
+  :config
+  ;; Ensure that evil's command mode behaves with readline bindings.
+  (general-define-key
+   :keymaps 'evil-ex-completion-map
+   "C-a" #'move-beginning-of-line
+   "C-e" #'move-end-of-line
+   "C-k" #'kill-line
+   "C-u" #'evil-delete-whole-line
+   "C-v" #'evil-paste-after
+   "C-d" #'delete-char
+   "C-f" #'forward-char
+   "M-b" #'backward-word
+   "M-f" #'forward-word
+   "M-d" #'kill-word
+   "M-DEL" #'backward-kill-word
+   "C-b" #'backward-char)
+  ;; TODO: Ensure all of my custom keybindings end up in a single map that is
+  ;; easy to enable or disable.
+  (general-mmap
+    :keymaps 'override
+    "RET" #'evil-goto-line
+    "H"   #'evil-first-non-blank
+    "L"   #'evil-end-of-line
+    "_"   #'ranger
+    "-"   #'dired-jump
+    "sl"  #'wpc/evil-window-vsplit-right
+    "sh"  #'evil-window-vsplit
+    "sk"  #'evil-window-split
+    "sj"  #'wpc/evil-window-split-down)
+  (general-nmap
+    :keymaps 'override
+    "gd" #'xref-find-definitions
+    ;; Wrapping `xref-find-references' in the `let' binding to prevent xref from
+    ;; prompting.  There are other ways to handle this variable, such as setting
+    ;; it globally with `setq' or buffer-locally with `setq-local'.  For now, I
+    ;; prefer setting it with `let', which should bind it in the dynamic scope
+    ;; for the duration of the `xref-find-references' function call.
+    "gx" (lambda ()
+           (interactive)
+           (let ((xref-prompt-for-identifier nil))
+             (call-interactively #'xref-find-references))))
+  (general-unbind 'motion "M-." "C-p" "<SPC>")
+  (general-unbind 'normal "s"   "M-." "C-p" "C-n")
+  (general-unbind 'insert "C-v" "C-d" "C-a" "C-e" "C-n" "C-p" "C-k")
+  (setq evil-symbol-word-search t)
+  (evil-mode 1))
+
+;; Ensure the Evil search results get centered vertically.
+(progn
+  (defadvice isearch-update
+      (before advice-for-isearch-update activate)
+    (evil-scroll-line-to-center (line-number-at-pos)))
+  (defadvice evil-search-next
+      (after advice-for-evil-search-next activate)
+    (evil-scroll-line-to-center (line-number-at-pos)))
+  (defadvice evil-search-previous
+      (after advice-for-evil-search-previous activate)
+    (evil-scroll-line-to-center (line-number-at-pos))))
+
+(use-package evil-collection
+  :after (evil)
+  :config
+  (evil-collection-init))
+
+(use-package evil-magit)
+
+;; create comments easily
+(use-package evil-commentary
+  :after (evil)
+  :config
+  (evil-commentary-mode))
+
+(use-package evil-surround
+  :after (evil)
+  :config
+  (global-evil-surround-mode 1))
+
+(use-package key-chord
+  :after (evil)
+  :config
+  (key-chord-mode 1)
+  (key-chord-define evil-insert-state-map "jk" 'evil-normal-state))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Configuration
+;; General KBDs
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+;; This may be contraversial, but I never use the prefix key, and I'd prefer to
+;; have to bound to the readline function that deletes the entire line.
+(general-unbind "C-u")
+
 (defmacro keybinding/exwm (c fn)
   "Bind C to FN using `exwm-input-set-key' with `kbd' applied to C."
   `(exwm-input-set-key (kbd ,c) ,fn))
@@ -43,6 +147,22 @@
 (keybinding/exwm "<C-M-tab>" #'exwm/switch-to-exwm-buffer)
 
 (general-define-key
+ :keymaps 'override
+ "M-q" #'delete-window
+ "<s-return>" #'toggle-frame-fullscreen
+ "M-h" #'windmove-left
+ "M-l" #'windmove-right
+ "M-k" #'windmove-up
+ "M-j" #'windmove-down
+ "M-q" #'delete-window)
+
+;; Support pasting in M-:.
+(general-define-key
+ :keymaps 'read-expression-map
+ "C-v"   #'clipboard-yank
+ "C-S-v" #'clipboard-yank)
+
+(general-define-key
  :prefix "<SPC>"
  :states '(normal)
  "." #'ffap