;;; -*- lexical-binding: t; -*-

(require 'syd/straight)
(require 'syd/general)


;;; Options

(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")


;;; Define the leader 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
;; See `evil-make-overriding-map'.
(define-key syd-leader-map [override-state] 'all)

(with-eval-after-load 'evil
  ;; Finally, we shall bind the damned keys. }:)
  (let ((map general-override-mode-map))
    (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-alt-leader-key) 'syd-leader)))

(general-override-mode 1)



(provide 'syd/leader)
