boon/boon-keys.el

114 lines
4.6 KiB
EmacsLisp
Raw Normal View History

;;; boon-keys.el --- An Ergonomic Command Mode -*- lexical-binding: t -*-
2014-10-19 13:59:12 +02:00
;;; Commentary:
2014-10-19 23:01:11 +02:00
;; This module defines various keymaps and portions of keymaps, common
;; to all keyboard layouts.
2014-10-19 13:59:12 +02:00
;;; Code:
(require 'boon-core)
2016-11-13 19:05:44 +01:00
(define-prefix-command 'boon-backward-search-map)
(define-prefix-command 'boon-forward-search-map)
(define-key boon-forward-search-map " " 'isearch-forward)
(define-key boon-forward-search-map "t" 'boon-qsearch-next-at-point)
(define-key boon-forward-search-map "s" 'boon-qsearch-next-at-point)
(define-key boon-forward-search-map "p" 'boon-qsearch-next)
(define-key boon-forward-search-map "e" 'next-error)
(define-key boon-forward-search-map "k" 'flycheck-next-error)
(define-key boon-forward-search-map "b" 'next-buffer)
(define-key boon-forward-search-map "u" 'mc/cycle-forward)
(define-key boon-backward-search-map " " 'isearch-backward)
(define-key boon-backward-search-map "t" 'boon-qsearch-previous-at-point)
(define-key boon-backward-search-map "s" 'boon-qsearch-previous-at-point)
(define-key boon-backward-search-map "p" 'boon-qsearch-previous)
(define-key boon-backward-search-map "e" 'previous-error)
(define-key boon-backward-search-map "k" 'flycheck-previous-error)
(define-key boon-backward-search-map "b" 'previous-buffer)
(define-key boon-backward-search-map "u" 'mc/cycle-backward)
2016-02-02 21:55:22 +01:00
(defvar boon-goto-map (make-sparse-keymap))
2016-09-10 20:28:02 +02:00
(set-keymap-parent boon-goto-map goto-map)
(define-key boon-goto-map "l" 'goto-line)
(define-key boon-goto-map "." 'find-tag)
(define-key boon-x-map "x" 'execute-extended-command)
2016-02-02 21:55:22 +01:00
2016-08-29 20:10:07 +02:00
(define-key boon-select-map "@" 'boon-select-occurences)
(define-key boon-select-map "#" 'boon-select-all)
2015-11-30 23:22:50 +01:00
(define-key boon-select-map " " 'boon-select-line)
2016-08-29 20:10:07 +02:00
(define-key boon-moves-map "'" 'boon-switch-mark)
2016-10-30 09:48:03 +01:00
(define-key boon-moves-map (kbd "<left>") 'left-char)
(define-key boon-moves-map (kbd "<right>") 'right-char)
(define-key boon-moves-map (kbd "<up>") 'previous-line)
(define-key boon-moves-map (kbd "<down>") 'next-line)
2015-11-30 23:22:50 +01:00
2016-08-29 20:10:07 +02:00
(define-key boon-command-map "'" 'boon-toggle-mark)
2014-10-19 22:29:29 +02:00
(define-key boon-command-map [(return)] 'undefined)
2014-10-29 20:31:03 +01:00
(define-key boon-command-map (kbd "<RET>") 'undefined)
2014-10-19 22:29:29 +02:00
(define-key boon-command-map [(backspace)] 'undefined)
(define-key boon-command-map "`" 'boon-toggle-case)
2014-10-19 23:01:11 +02:00
2015-12-11 20:38:53 +01:00
(define-key boon-command-map "!" 'shell-command)
(define-key boon-command-map "|" 'shell-command-on-region)
2014-10-19 22:29:29 +02:00
(define-key boon-command-map "-" 'undo)
2016-08-14 22:21:07 +02:00
(dolist (number '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))
2016-08-27 20:30:47 +02:00
(define-key boon-command-map number 'digit-argument))
2016-08-14 22:21:07 +02:00
2014-10-19 22:29:29 +02:00
(define-key boon-command-map " " 'boon-drop-mark)
2016-11-06 16:06:44 +01:00
(define-key boon-command-map [escape] 'boon-quit)
2014-10-19 13:59:12 +02:00
2016-08-30 20:43:19 +02:00
;; Special mode rebinds
(define-key boon-special-map "`" 'boon-quote-character)
(define-key boon-special-map "'" 'boon-quote-character)
(define-key boon-special-map "x" boon-x-map)
(define-key boon-special-map [escape] 'boon-set-command-state)
2014-10-19 22:29:29 +02:00
;; Insert mode rebinds
(define-key boon-insert-map [remap newline] 'boon-newline-dwim)
2016-11-06 16:06:44 +01:00
(define-key boon-insert-map [escape] 'boon-set-command-state)
2014-10-19 13:59:12 +02:00
2014-10-19 22:29:29 +02:00
;; Global rebinds
2014-10-19 13:59:12 +02:00
(define-key global-map [escape] 'keyboard-quit)
(define-key minibuffer-local-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-ns-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-completion-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-must-match-map [escape] 'minibuffer-keyboard-quit)
(define-key isearch-mode-map [escape] 'isearch-abort)
2016-08-31 21:58:55 +02:00
(defun boon-god-control-swap (event)
"Swap the control 'bit' in EVENT, if that is a good choice."
(interactive (list (read-key)))
(cond
2016-11-13 21:20:28 +01:00
((memq event '(9 13 ?{ ?} ?[ ?] ?$ ?< ?> ?: ?\; ?/ ?? ?. ?,)) event)
2016-08-31 21:58:55 +02:00
((<= event 27) (+ 96 event))
((not (eq 0 (logand (lsh 1 26) event))) (logxor (lsh 1 26) event))
(t (list 'control event))))
(defun boon-c-god ()
2016-11-06 16:06:44 +01:00
"Input a key sequence, prepend C- if that is a good choice, and run the command bound to that sequence."
2016-08-31 21:58:55 +02:00
(interactive)
(let ((keys '((control c)))
(binding (key-binding (kbd "C-c")))
(key-vector (kbd "C-c"))
(prompt "C-c-"))
(while (and binding (not (symbolp binding)))
(let ((key (read-key (format "%s" prompt))))
(if (eq key ?h) (describe-bindings key-vector)
(push (boon-god-control-swap key) keys)
(setq key-vector (vconcat (reverse keys)))
(setq prompt (key-description key-vector))
(setq binding (key-binding key-vector)))))
(cond
((not binding) (error "No command bound to %s" prompt))
((commandp binding) (call-interactively binding))
(t (error "Key not bound to a command: %s" binding)))))
2014-10-19 14:17:46 +02:00
(provide 'boon-keys)
;;; boon-keys.el ends here