I showed you my source code, pls respond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
4.4 KiB

  1. #+TITLE: Keys
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+PROPERTY: header-args:emacs-lisp :tangle keys.el :comments org
  5. #+PROPERTY: header-args :results silent :eval no-export :comments org
  6. #+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  7. #+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  8. Improve the keyboard experience within Emacs.
  9. * Config
  10. Some of the default keybindings in Emacs really do leave you wondering, for example, when you want to exit a prompt you have to use =C-g=. Offer =ESC= as an alternative to quit (most) prompts, which I have muscle memory for already from literally every program created since 1990.
  11. #+begin_src emacs-lisp
  12. (global-set-key (kbd "<escape>") 'keyboard-escape-quit)
  13. #+end_src
  14. ** Hints
  15. Since Emacs is keyboard driven software, there are a lot of keybindings. Sometimes it's useful to start pressing well-known key combinations, and view the available completions. This behaviour is implemented in the third-party package ~which-key~[fn:1]. It displays the current incomplete keybinding input in a mini-buffer. It also works in the other direction, showing the corresponding keybindings for each command when you run =M-x=.
  16. #+begin_src emacs-lisp
  17. (use-package which-key
  18. :diminish which-key-mode
  19. :custom (which-key-idle-delay dotfiles/idle)
  20. :config (which-key-mode))
  21. #+end_src
  22. ** Leader
  23. If like myself, you started using Emacs using a framework such as ~doom~[fn:2] or ~spacemacs~[fn:3], you probably have a considerable amount of muscle memory developed for using =SPC= as a leader key. In both of the previously mentioned frameworks, the package ~general.el~[fn:4] is used to implement this behaviour. It's a major improvement to the default way of creating custom keybindings in Emacs.
  24. #+begin_src emacs-lisp
  25. (use-package general
  26. :config
  27. (general-create-definer dotfiles/leader
  28. :states '(normal motion)
  29. :keymaps 'override
  30. :prefix dotfiles/leader-key
  31. :global-prefix dotfiles/leader-key-global))
  32. #+end_src
  33. ** Transient
  34. Create transient keybindings with a shared prefix through ~hydra~[fn:5]. This is also used by a number of third-party packages as a completion system. An implementation example is used to scale the font size.
  35. #+begin_src emacs-lisp
  36. (use-package hydra
  37. :defer t)
  38. #+end_src
  39. * Shortcuts
  40. Implement some shortcut bindings, with a significant portion of them cherry picked from ~doom~[fn:2]:
  41. + Close buffers with =SPC c=
  42. + Find files with =SPC . (period)=
  43. + Switch buffers with =SPC , (comma)=
  44. #+begin_src emacs-lisp
  45. (dotfiles/leader
  46. "." '(find-file :which-key "Files")
  47. "," '(switch-to-buffer :which-key "Buffers"))
  48. #+end_src
  49. ** Quitting Emacs
  50. Customize the behaviour of exiting emacs, with keybindings behind =SPC q=:
  51. + Save and quit =q=
  52. + Quit without saving =w=
  53. + Exit the Frame (daemon) =f=
  54. #+begin_src emacs-lisp
  55. (dotfiles/leader
  56. "q" '(:ignore t :which-key "Quit")
  57. "qq" '(save-buffers-kill-emacs :which-key "Save")
  58. "qw" '(kill-emacs :which-key "Now")
  59. "qf" '(delete-frame :which-key "Frame"))
  60. #+end_src
  61. ** Managing windows
  62. Screen space is divided into Frames inside of Emacs, manage them behind =SPC w=:
  63. + Swap with =w=
  64. + Close with =c=
  65. + Delete with =d=
  66. + Move with =h,j,k,l=
  67. + Split with =s - <motion>=
  68. #+begin_src emacs-lisp
  69. (dotfiles/leader
  70. "w" '(:ignore t :which-key "Window")
  71. "ww" '(window-swap-states :which-key "Swap")
  72. "wc" '(kill-buffer-and-window :which-key "Close")
  73. "wd" '(delete-window :which-key "Close")
  74. "wh" '(windmove-left :which-key "Left")
  75. "wj" '(windmove-down :which-key "Down")
  76. "wk" '(windmove-up :which-key "Up")
  77. "wl" '(windmove-right :which-key "Right")
  78. "ws" '(:ignore t :which-key "Split")
  79. "wsj" '(split-window-below :which-key "Down")
  80. "wsl" '(split-window-right :which-key "Right"))
  81. #+end_src
  82. ** Helper Functions
  83. Use the built-in ~describe-*~ functionality of Emacs to quickly access documentation for packages, variables, and functions. Run helper functions with =SPC h=:
  84. + Packages =p=
  85. + Variables =v=
  86. + Functions =f=
  87. #+begin_src emacs-lisp
  88. (dotfiles/leader
  89. "h" '(:ignore t :which-key "Help")
  90. "hp" '(describe-package :which-key "Package")
  91. "hv" '(describe-variable :which-key "Variable")
  92. "hf" '(describe-function :which-key "Function"))
  93. #+end_src
  94. * Footnotes
  95. [fn:1] https://github.com/justbur/emacs-which-key/
  96. [fn:2] https://github.com/hlissner/doom-emacs/
  97. [fn:3] https://spacemacs.org
  98. [fn:4] https://github.com/noctuid/general.el
  99. [fn:5] https://github.com/abo-abo/hydra