feat: Leader key and General.el
This commit is contained in:
12
README.org
12
README.org
@@ -123,6 +123,18 @@ The difference connects to another silly obsession of the Emacs hacker: startup
|
|||||||
|
|
||||||
~on-first-input~ is one of many useful hooks provided by the package [[https://github.com/emacsmirror/on][on.el]] specialised for fine-grained control of package loading.
|
~on-first-input~ is one of many useful hooks provided by the package [[https://github.com/emacsmirror/on][on.el]] specialised for fine-grained control of package loading.
|
||||||
|
|
||||||
|
** Naming conventions in my Emacs config
|
||||||
|
|
||||||
|
As with the rest of the config, these are largely adapted from Doom's ([cite:@lissner2022contributing]). }:3
|
||||||
|
|
||||||
|
- ~syd-[-]«NAME»~ :: Typical 'namespaced' Elisp convention ([cite:@gnu2020conventions]).
|
||||||
|
|
||||||
|
- ~syd/«NAME»~ :: Commands intended for interactive use.
|
||||||
|
|
||||||
|
- ~+syd-[-]«NAME»~ :: Indicates a [[https://en.wikipedia.org/wiki/Strategy_pattern][strategy]] function.
|
||||||
|
|
||||||
|
- ~syd-«NAME»-initialise~, where ~modules/«NAME» ∈ modules/*.el~ :: Instead of using top-level side-effects, (bar e.g. ~use-package~ invocations) should be wrapped in this kind of initialisation procedure.
|
||||||
|
|
||||||
>>>>>>> Conflict 1 of 1 ends
|
>>>>>>> Conflict 1 of 1 ends
|
||||||
* Tasks
|
* Tasks
|
||||||
|
|
||||||
|
|||||||
@@ -14,4 +14,5 @@
|
|||||||
(require 'syd-autosave)
|
(require 'syd-autosave)
|
||||||
(require 'syd-display-startup-time)
|
(require 'syd-display-startup-time)
|
||||||
(require 'syd-evil)
|
(require 'syd-evil)
|
||||||
|
(require 'syd-keybinds)
|
||||||
(require 'syd-ui)
|
(require 'syd-ui)
|
||||||
|
|||||||
76
users/crumb/programs/emacs/modules/syd-keybinds.el
Normal file
76
users/crumb/programs/emacs/modules/syd-keybinds.el
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
;;; syd-keybinds.el -*- lexical-binding: t; -*-
|
||||||
|
;;; Universal keybindings, not /too/ tied to any particular packages.
|
||||||
|
|
||||||
|
(use-package general
|
||||||
|
:custom (general-use-package-emit-autoloads t))
|
||||||
|
|
||||||
|
(require 'general)
|
||||||
|
|
||||||
|
(defvar syd-leader-key "SPC"
|
||||||
|
"A prefix key akin to Vim's <Leader>.")
|
||||||
|
|
||||||
|
(defvar syd-localleader-key "SPC m"
|
||||||
|
"A prefix key akin to Vim's <LocalLeader>.")
|
||||||
|
|
||||||
|
(defvar syd-alt-leader-key "M-SPC"
|
||||||
|
"`syd-leader', but for the states specified in `syd-alt-leader-key-states'.
|
||||||
|
|
||||||
|
Often, your \"usual\" leader key will be something unavailable in the Insert
|
||||||
|
state. This key exists as a fallback for when you need your Leader, but must
|
||||||
|
remain in the Insert state. Substitute \"Insert state\" for your states of
|
||||||
|
choice with `syd-alt-leader-key-states'.")
|
||||||
|
|
||||||
|
(defvar syd-alt-localleader-key "M-SPC m"
|
||||||
|
"`syd-localleader', but for the states specified in `syd-alt-leader-key-states'.
|
||||||
|
|
||||||
|
See `syd-alt-leader-key' for rationale.")
|
||||||
|
|
||||||
|
(defvar syd-leader-key-states '(normal visual motion)
|
||||||
|
"States for which the Leader keys (`syd-leader-key', `syd-localleader-key')
|
||||||
|
are active.")
|
||||||
|
|
||||||
|
(defvar syd-alt-leader-key-states '(emacs insert)
|
||||||
|
"States for which the alternative Leader keys are active. See
|
||||||
|
`syd-alt-leader-key' and `syd-alt-localleader-key'.")
|
||||||
|
|
||||||
|
(defvar-keymap syd-leader-map
|
||||||
|
:doc "Leader-prefixed commands")
|
||||||
|
|
||||||
|
(defvar-keymap syd-leader-window-map
|
||||||
|
:doc "Window commands")
|
||||||
|
|
||||||
|
(defun syd--initialise-leader ()
|
||||||
|
"Set up the (empty) keymap associated with `syd-leader-key',
|
||||||
|
`syd-localleader-key', `syd-alt-leader-key', and `syd-alt-localleader-key'."
|
||||||
|
;; Define `syd/leader' as a command corresponding to the prefix map
|
||||||
|
;; `syd-leader-map'.
|
||||||
|
(define-prefix-command 'syd/leader 'syd-leader-map)
|
||||||
|
;; This should help make the Leader key close to universally available.
|
||||||
|
;; Ideally, *nothing* takes precedence over Leader — it's an incredibly
|
||||||
|
;; important key!
|
||||||
|
;; https://github.com/noctuid/evil-guide?tab=readme-ov-file#undoprevent-overridingintercept-maps
|
||||||
|
;; Really, we do this because Doom does. I'm honestly not entirely sure what
|
||||||
|
;; it does. I can't find anything useful online.
|
||||||
|
(define-key syd-leader-map [override-state] 'all)
|
||||||
|
;; Finally, we shall bind the damned keys. }:)
|
||||||
|
(let ((map general-override-mode-map))
|
||||||
|
(require 'evil)
|
||||||
|
(evil-define-key* syd-leader-key-states map (kbd syd-leader-key) 'syd/leader)
|
||||||
|
(evil-define-key* syd-alt-leader-key-states map (kbd syd-leader-key) 'syd/leader))
|
||||||
|
(general-override-mode 1))
|
||||||
|
|
||||||
|
(defun syd-keybinds-initialise ()
|
||||||
|
(syd--initialise-leader)
|
||||||
|
(general-define-key
|
||||||
|
:keymaps 'syd-leader-map
|
||||||
|
"." #'find-file))
|
||||||
|
|
||||||
|
(syd-keybinds-initialise)
|
||||||
|
|
||||||
|
;; Show possible completions for a partially-entered key sequence.
|
||||||
|
(use-package which-key
|
||||||
|
:hook (on-first-input . which-key-mode)
|
||||||
|
:custom ((which-key-allow-evil-operators t)
|
||||||
|
(which-key-show-operator-state-maps t)))
|
||||||
|
|
||||||
|
(provide 'syd-keybinds)
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
;;; syd-ui.el -*- lexical-binding: t; -*-
|
;;; syd-ui.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Show possible completions for a partially-entered key sequence.
|
|
||||||
(use-package which-key
|
|
||||||
:hook (on-first-input . which-key-mode)
|
|
||||||
:custom ((which-key-allow-evil-operators t)
|
|
||||||
(which-key-show-operator-state-maps t)))
|
|
||||||
|
|
||||||
;; Beautiful theme in dark and light.
|
;; Beautiful theme in dark and light.
|
||||||
(use-package kanagawa-themes
|
(use-package kanagawa-themes
|
||||||
:config
|
:config
|
||||||
|
|||||||
Reference in New Issue
Block a user