feat: Leader key and General.el

This commit is contained in:
Madeleine Sydney
2025-01-12 11:13:15 -07:00
parent f788cd8b34
commit 4366fa163d
4 changed files with 89 additions and 6 deletions

View File

@@ -14,4 +14,5 @@
(require 'syd-autosave)
(require 'syd-display-startup-time)
(require 'syd-evil)
(require 'syd-keybinds)
(require 'syd-ui)

View 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)

View File

@@ -1,11 +1,5 @@
;;; 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.
(use-package kanagawa-themes
:config