keys.el 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. ;;; keys.el --- Miscellaneous global key bindings and relative settings
  2. ;; Copyright © 2013–2018 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. (require 'al-key)
  16. ;;; Frame specific settings
  17. (defun al/frame-keys-actions (&optional frame)
  18. "Configure key bindings specific to a FRAME type."
  19. (keyboard-translate ?\C-x ?\C-t)
  20. (keyboard-translate ?\C-t ?\C-x)
  21. (when (display-graphic-p)
  22. ;; This is not possible because the index of "C-M-m" character is
  23. ;; too big for the char-table.
  24. ;;
  25. ;; (keyboard-translate ?\M-\r 'ctrl-alt-m)
  26. (keyboard-translate ?\C-m 'ctrl-m)
  27. (keyboard-translate ?\C-i 'ctrl-i)))
  28. (al/add-hook-maybe
  29. '(after-make-frame-functions window-setup-hook)
  30. 'al/frame-keys-actions)
  31. ;;; Keys for multiple maps
  32. (defconst al/free-moving-keys
  33. '("C-o" "M-o" "C-M-o" "M-O"
  34. "C-u" "M-u" "C-M-u" "M-U"
  35. "C-." "M-." "C-M-." "M->"
  36. "C-e" "M-e" "C-M-e" "M-E"
  37. "C-a" "M-a" "C-M-a" "M-A"
  38. "<ctrl-i>" "M-i" "C-M-i" "M-I")
  39. "Alist of moving keys that should be unbound.")
  40. (defconst al/free-editing-keys
  41. '("C-," "M-," "C-M-," "M-<"
  42. "C-p" "M-p" "C-M-p" "M-P"
  43. "C-M-q" "M-Q"
  44. "C-k" "M-k" "C-M-k" "M-K"
  45. "C-'" "M-'" "C-M-'" "M-\""
  46. "C-;" "M-;" "C-M-;"
  47. "C-t" "M-x" "C-M-x")
  48. "Alist of editing keys that should be unbound.")
  49. (defconst al/free-important-keys
  50. '("M-g")
  51. "Alist of important keys that should be unbound.")
  52. (defconst al/free-misc-keys
  53. '("M-_" "M-+"
  54. "M-/" "C-M-/" "M-?"
  55. "C-w"
  56. "C-M-t" "<C-tab>" "<M-tab>" "<C-M-tab>")
  57. "Alist of miscellaneous keys that should be unbound.")
  58. (defconst al/lazy-moving-keys
  59. '(("o" . backward-char)
  60. ("u" . forward-char)
  61. ("." . previous-line)
  62. ("e" . next-line))
  63. "Alist of auxiliary keys for lazy moving.")
  64. (defconst al/lazy-scrolling-keys
  65. '(("SPC" . scroll-up-command)
  66. ("DEL" . scroll-down-command))
  67. "Alist of auxiliary keys for lazy scrolling.")
  68. (defconst al/button-keys
  69. '(("." . backward-button)
  70. ("e" . forward-button))
  71. "Alist of auxiliary keys for modes with buttons.")
  72. (defconst al/minibuffer-keys
  73. '("C-j" ; to insert newlines during evaluating expressions
  74. ("M-." . previous-history-element)
  75. ("M-e" . next-history-element))
  76. "Alist of auxiliary keys for minibuffer modes.")
  77. (setq al/default-keys-variables
  78. '(al/free-moving-keys al/free-editing-keys al/free-important-keys))
  79. ;;; Hydra
  80. (with-eval-after-load 'hydra
  81. (setq hydra-verbose t)
  82. (al/bind-keys
  83. :map hydra-base-map
  84. ("C-4" . hydra--universal-argument)
  85. ("C-u"))
  86. (hydra-add-font-lock))
  87. ;;; Global keys
  88. (al/bind-keys
  89. :map ctl-x-map
  90. ("A" (apply #'al/update-autoloads
  91. (if current-prefix-arg
  92. (al/subdirs al/emacs-my-packages-dir)
  93. (list al/emacs-utils-dir))))
  94. ("C" . save-buffers-kill-emacs)
  95. ("C-8" . insert-char))
  96. (al/bind-keys
  97. :map universal-argument-map
  98. ("C-4" . universal-argument-more)
  99. ("C-u"))
  100. (al/bind-keys
  101. ("C-4" . universal-argument)
  102. ("H-u" . undo)
  103. ("H-M-u" . undo-only)
  104. ("C-\\" (toggle-input-method t))
  105. ("s-7" (set-input-method nil))
  106. ("s-8" . dvorak-russian-computer)
  107. ("s-9" . dvorak-qwerty)
  108. ("s-0" (set-input-method "greek"))
  109. ("s-M-7" (ispell-change-dictionary "en"))
  110. ("s-M-8" (ispell-change-dictionary "ru-yeyo"))
  111. ("C-M-c" . calc)
  112. ("<f4>" . kmacro-end-or-call-macro)
  113. ("<XF86New>" . kmacro-end-or-call-macro)
  114. ("<C-f4>" . kmacro-start-macro-or-insert-counter)
  115. ("<C-XF86New>" . kmacro-start-macro-or-insert-counter)
  116. ("<M-f4>" . kmacro-edit-macro)
  117. ("<M-XF86New>" . kmacro-edit-macro)
  118. ("<f5>" . compile)
  119. ("C-=" . describe-char)
  120. ("C-c x" . exit-recursive-edit)
  121. ("C-c r" . revert-buffer)
  122. ("C-c p" . list-processes)
  123. ("C-c e" . list-environment)
  124. ("C-c k" . al/kill-process))
  125. (defalias 'ctl-x-r-prefix ctl-x-r-map)
  126. (al/bind-key "M-R" ctl-x-r-prefix)
  127. (al/bind-keys
  128. :map ctl-x-r-map
  129. ("a" . append-to-register)
  130. ("p" . prepend-to-register))
  131. (defalias 'goto-prefix goto-map)
  132. (al/bind-key "C-M-g" goto-prefix)
  133. (al/bind-keys
  134. :map goto-map
  135. ("C-M-g" . goto-line)
  136. ("c" . move-to-column)
  137. ("p" . goto-char)
  138. ("h" . previous-error)
  139. ("C-M-h" . previous-error)
  140. ("C-M-n" . next-error))
  141. (al/bind-keys
  142. :prefix-map al/modes-map
  143. :prefix-docstring "Map for enabling/disabling modes."
  144. :prefix "M-M"
  145. ("M-M" . al/major-mode-to-kill-ring)
  146. ("a" . artist-mode)
  147. ("A" . auto-fill-mode)
  148. ("c" . conf-unix-mode)
  149. ("e" . emacs-lisp-mode)
  150. ("f" . font-lock-mode)
  151. ("o" . org-mode)
  152. ("p" . python-mode)
  153. ("r" . rainbow-mode)
  154. ("l" . nlinum-mode)
  155. ("s" . sh-mode)
  156. ("t" . toggle-truncate-lines)
  157. ("v" . view-mode)
  158. ("T" . text-mode)
  159. ("|" . indent-guide-mode))
  160. ;;; keys.el ends here