2020-01-18 23:47:11 +01:00
|
|
|
;;; keybindings.el --- Centralizing my keybindings -*- lexical-binding: t -*-
|
2020-09-01 11:17:43 +02:00
|
|
|
|
2020-01-18 23:47:11 +01:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
2020-09-01 11:17:43 +02:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; URL: https://git.wpcarro.dev/wpcarro/briefcase
|
|
|
|
;; Package-Requires: ((emacs "25.1"))
|
2020-01-18 23:47:11 +01:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Attempting to centralize my keybindings to simplify my configuration.
|
2020-08-19 13:42:11 +02:00
|
|
|
;;
|
2020-09-01 14:44:18 +02:00
|
|
|
;; I have some expectations about my keybindings. Here are some of those
|
2020-08-19 13:42:11 +02:00
|
|
|
;; defined:
|
|
|
|
;; - In insert mode:
|
|
|
|
;; - C-a: beginning-of-line
|
|
|
|
;; - C-e: end-of-line
|
|
|
|
;; - C-b: backwards-char
|
|
|
|
;; - C-f: forwards-char
|
2020-01-18 23:47:11 +01:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-02 15:09:15 +02:00
|
|
|
(require 'functions)
|
2020-01-18 23:47:11 +01:00
|
|
|
(require 'clipboard)
|
|
|
|
(require 'screen-brightness)
|
2020-09-04 22:04:10 +02:00
|
|
|
(require 'pulse-audio)
|
2020-01-20 17:48:42 +01:00
|
|
|
(require 'scrot)
|
2020-01-27 12:25:32 +01:00
|
|
|
(require 'ivy-clipmenu)
|
2020-02-02 13:14:34 +01:00
|
|
|
(require 'general)
|
2020-08-19 17:47:57 +02:00
|
|
|
(require 'exwm)
|
2020-02-08 17:00:31 +01:00
|
|
|
(require 'vterm-mgt)
|
|
|
|
(require 'buffer)
|
2020-02-11 12:00:24 +01:00
|
|
|
(require 'display)
|
|
|
|
(require 'device)
|
2020-09-04 22:04:56 +02:00
|
|
|
(require 'fonts)
|
2020-09-07 17:11:18 +02:00
|
|
|
(require 'bookmark)
|
2020-01-18 23:47:11 +01:00
|
|
|
|
2020-08-19 17:34:30 +02:00
|
|
|
;; Note: The following lines must be sorted this way.
|
|
|
|
(setq evil-want-integration t)
|
|
|
|
(setq evil-want-keybinding nil)
|
|
|
|
(general-evil-setup)
|
|
|
|
(require 'evil)
|
|
|
|
(require 'evil-collection)
|
|
|
|
(require 'evil-magit)
|
|
|
|
(require 'evil-commentary)
|
|
|
|
(require 'evil-surround)
|
|
|
|
(require 'key-chord)
|
|
|
|
|
2020-09-02 15:09:15 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; General Keybindings
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-07 17:11:18 +02:00
|
|
|
;; Install KBDs like <SPC>jb to search through my monorepo.
|
|
|
|
(bookmark-install-kbds)
|
|
|
|
|
2020-08-19 17:34:30 +02:00
|
|
|
;; 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)
|
|
|
|
|
|
|
|
(general-mmap
|
|
|
|
:keymaps 'override
|
|
|
|
"RET" #'evil-goto-line
|
|
|
|
"H" #'evil-first-non-blank
|
|
|
|
"L" #'evil-end-of-line
|
|
|
|
"_" #'ranger
|
|
|
|
"-" #'dired-jump
|
2020-09-01 11:17:43 +02:00
|
|
|
"sl" #'functions-evil-window-vsplit-right
|
2020-08-19 17:34:30 +02:00
|
|
|
"sh" #'evil-window-vsplit
|
|
|
|
"sk" #'evil-window-split
|
2020-09-01 11:17:43 +02:00
|
|
|
"sj" #'functions-evil-window-split-down)
|
2020-08-19 17:34:30 +02:00
|
|
|
|
|
|
|
(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)
|
|
|
|
(evil-collection-init)
|
|
|
|
(evil-commentary-mode)
|
|
|
|
(global-evil-surround-mode 1)
|
2020-08-19 13:42:11 +02:00
|
|
|
|
|
|
|
;; Ensure the Evil search results get centered vertically.
|
2020-09-07 17:12:27 +02:00
|
|
|
;; When Emacs is run from a terminal, this forces Emacs to redraw itself, which
|
|
|
|
;; is visually disruptive.
|
|
|
|
(when window-system
|
|
|
|
(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)))))
|
2020-08-19 13:42:11 +02:00
|
|
|
|
2020-08-19 17:34:30 +02:00
|
|
|
(key-chord-mode 1)
|
|
|
|
(key-chord-define evil-insert-state-map "jk" 'evil-normal-state)
|
2020-08-19 13:42:11 +02:00
|
|
|
|
|
|
|
;; 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")
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defmacro keybindings-exwm (c fn)
|
2020-01-18 23:47:11 +01:00
|
|
|
"Bind C to FN using `exwm-input-set-key' with `kbd' applied to C."
|
|
|
|
`(exwm-input-set-key (kbd ,c) ,fn))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(keybindings-exwm "C-M-v" #'ivy-clipmenu-copy)
|
2020-09-01 14:44:18 +02:00
|
|
|
(keybindings-exwm "<XF86MonBrightnessUp>" #'screen-brightness-increase)
|
|
|
|
(keybindings-exwm "<XF86MonBrightnessDown>" #'screen-brightness-decrease)
|
2020-09-04 22:04:10 +02:00
|
|
|
(keybindings-exwm "<XF86AudioMute>" #'pulse-audio-toggle-mute)
|
|
|
|
(keybindings-exwm "<XF86AudioLowerVolume>" #'pulse-audio-decrease-volume)
|
|
|
|
(keybindings-exwm "<XF86AudioRaiseVolume>" #'pulse-audio-increase-volume)
|
|
|
|
(keybindings-exwm "<XF86AudioMicMute>" #'pulse-audio-toggle-microphone)
|
2020-09-01 11:17:43 +02:00
|
|
|
(keybindings-exwm (kbd-raw 'x11 "s") #'scrot-select)
|
|
|
|
(keybindings-exwm "<C-M-tab>" #'window-manager-switch-to-exwm-buffer)
|
2020-09-04 22:04:56 +02:00
|
|
|
(keybindings-exwm (kbd-raw 'workspace "k") #'fonts-increase-size)
|
|
|
|
(keybindings-exwm (kbd-raw 'workspace "j") #'fonts-decrease-size)
|
|
|
|
(keybindings-exwm (kbd-raw 'workspace "0") #'fonts-reset-size)
|
2020-02-02 14:20:55 +01:00
|
|
|
|
2020-08-19 13:42:11 +02:00
|
|
|
(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)
|
|
|
|
|
2020-02-18 12:01:57 +01:00
|
|
|
(general-define-key
|
|
|
|
:prefix "<SPC>"
|
|
|
|
:states '(normal)
|
2020-08-19 13:27:15 +02:00
|
|
|
"." #'ffap
|
|
|
|
"gn" #'notmuch
|
|
|
|
"i" #'counsel-semantic-or-imenu
|
|
|
|
"I" #'ibuffer
|
|
|
|
"hk" #'helpful-callable
|
|
|
|
"hf" #'helpful-function
|
|
|
|
"hm" #'helpful-macro
|
|
|
|
"hc" #'helpful-command
|
|
|
|
"hk" #'helpful-key
|
|
|
|
"hv" #'helpful-variable
|
|
|
|
"hp" #'helpful-at-point
|
|
|
|
"s" #'flyspell-mode
|
|
|
|
"S" #'sort-lines
|
|
|
|
"=" #'align
|
|
|
|
"p" #'flycheck-previous-error
|
|
|
|
"f" #'project-find-file
|
|
|
|
"n" #'flycheck-next-error
|
|
|
|
"N" #'smerge-next
|
|
|
|
"W" #'balance-windows
|
|
|
|
"gs" #'magit-status
|
|
|
|
"E" #'refine
|
2020-09-01 11:17:43 +02:00
|
|
|
"es" #'functions-create-snippet
|
2020-08-19 13:27:15 +02:00
|
|
|
"l" #'linum-mode
|
|
|
|
"B" #'magit-blame
|
|
|
|
"w" #'save-buffer
|
2020-09-01 11:17:43 +02:00
|
|
|
"r" #'functions-evil-replace-under-point
|
2020-08-19 13:27:15 +02:00
|
|
|
"R" #'deadgrep)
|
2020-02-18 12:01:57 +01:00
|
|
|
|
2020-02-08 17:00:31 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Vterm
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
;; Show or hide a vterm buffer. I'm intentionally not defining this in
|
2020-09-01 11:17:43 +02:00
|
|
|
;; vterm-mgt.el because it consumes `buffer-show-previous', and I'd like to
|
2020-02-08 17:00:31 +01:00
|
|
|
;; avoid bloating vterm-mgt.el with dependencies that others may not want.
|
2020-09-01 11:17:43 +02:00
|
|
|
(general-define-key (kbd-raw 'x11 "t")
|
2020-02-08 17:00:31 +01:00
|
|
|
(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(if (vterm-mgt--instance? (current-buffer))
|
2020-09-01 11:17:43 +02:00
|
|
|
(switch-to-buffer (first (buffer-source-code-buffers)))
|
2020-02-08 17:00:31 +01:00
|
|
|
(call-interactively #'vterm-mgt-find-or-create))))
|
|
|
|
|
|
|
|
(general-define-key
|
|
|
|
:keymaps '(vterm-mode-map)
|
|
|
|
"C-S-n" #'vterm-mgt-instantiate
|
|
|
|
"C-S-w" #'vterm-mgt-kill
|
|
|
|
"<C-tab>" #'vterm-mgt-next
|
|
|
|
"<C-S-iso-lefttab>" #'vterm-mgt-prev
|
|
|
|
"<s-backspace>" #'vterm-mgt-rename-buffer)
|
2020-02-02 13:14:34 +01:00
|
|
|
|
2020-02-11 12:00:24 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Displays
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(when (device-work-laptop?)
|
|
|
|
(keybindings-exwm "<XF86Display>" #'display-cycle-display-states)
|
2020-02-11 12:00:24 +01:00
|
|
|
(general-define-key
|
|
|
|
:prefix "<SPC>"
|
|
|
|
:states '(normal)
|
2020-09-01 11:17:43 +02:00
|
|
|
"d0" #'display-disable-laptop
|
|
|
|
"d1" #'display-enable-laptop
|
|
|
|
"D0" #'display-disable-4k
|
|
|
|
"D1" #'display-enable-4k))
|
2020-02-11 12:00:24 +01:00
|
|
|
|
2020-02-14 16:38:28 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; notmuch
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
;; evil-collection adds many KBDs to notmuch modes. Some of these I find
|
|
|
|
;; disruptive.
|
|
|
|
(general-define-key
|
|
|
|
:states '(normal)
|
|
|
|
:keymaps '(notmuch-show-mode-map)
|
|
|
|
"M-j" nil
|
|
|
|
"M-k" nil
|
|
|
|
"<C-S-iso-lefttab>" #'notmuch-show-previous-thread-show
|
|
|
|
"<C-tab>" #'notmuch-show-next-thread-show
|
|
|
|
"e" #'notmuch-show-archive-message-then-next-or-next-thread)
|
|
|
|
|
|
|
|
;; TODO(wpcarro): Consider moving this to a separate module
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun keybindings--evil-ex-define-cmd-local (cmd f)
|
2020-02-14 16:38:28 +01:00
|
|
|
"Define CMD to F locally to a buffer."
|
|
|
|
(unless (local-variable-p 'evil-ex-commands)
|
|
|
|
(setq-local evil-ex-commands (copy-alist evil-ex-commands)))
|
|
|
|
(evil-ex-define-cmd cmd f))
|
|
|
|
|
|
|
|
;; TODO(wpcarro): Support a macro that can easily define evil-ex commands for a
|
|
|
|
;; particular mode.
|
|
|
|
;; Consumption:
|
|
|
|
;; (evil-ex-for-mode 'notmuch-message-mode
|
|
|
|
;; "x" #'notmuch-mua-send-and-exit)
|
|
|
|
|
|
|
|
(add-hook 'notmuch-message-mode-hook
|
|
|
|
(lambda ()
|
2020-09-01 11:17:43 +02:00
|
|
|
(keybindings--evil-ex-define-cmd-local "x" #'notmuch-mua-send-and-exit)))
|
2020-02-14 16:38:28 +01:00
|
|
|
|
|
|
|
;; For now, I'm mimmicking Gmail KBDs that I have memorized and enjoy
|
|
|
|
(general-define-key
|
2020-02-16 18:13:21 +01:00
|
|
|
:states '(normal visual)
|
2020-02-14 16:38:28 +01:00
|
|
|
:keymaps '(notmuch-search-mode-map)
|
2020-02-16 18:13:21 +01:00
|
|
|
"M" (lambda ()
|
|
|
|
(interactive)
|
|
|
|
(notmuch-search-tag '("-inbox" "+muted")))
|
|
|
|
"mi" (lambda ()
|
|
|
|
(interactive)
|
|
|
|
(notmuch-search-tag '("+inbox" "-action" "-review" "-waiting" "-muted")))
|
|
|
|
"ma" (lambda ()
|
|
|
|
(interactive)
|
|
|
|
(notmuch-search-tag '("-inbox" "+action" "-review" "-waiting")))
|
|
|
|
"mr" (lambda ()
|
|
|
|
(interactive)
|
|
|
|
(notmuch-search-tag '("-inbox" "-action" "+review" "-waiting")))
|
|
|
|
"mw" (lambda ()
|
|
|
|
(interactive)
|
|
|
|
(notmuch-search-tag '("-inbox" "-action" "-review" "+waiting")))
|
2020-02-14 16:38:28 +01:00
|
|
|
"e" #'notmuch-search-archive-thread)
|
|
|
|
|
2020-08-28 18:40:24 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; magit
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(general-define-key
|
|
|
|
:states '(normal)
|
|
|
|
:keymaps '(magit-status-mode-map)
|
|
|
|
"l" #'evil-forward-char
|
|
|
|
"L" #'magit-log)
|
|
|
|
|
2020-01-18 23:47:11 +01:00
|
|
|
(provide 'keybindings)
|
|
|
|
;;; keybindings.el ends here
|