noctuid / general.el

More convenient key definitions in emacs
GNU General Public License v3.0
1k stars 44 forks source link

SPC SPC as a leader key initialization Even in Insert state/mode or the Emacs Input mode. #555

Closed High-Flyer closed 10 months ago

High-Flyer commented 10 months ago

Greetings, Following is my config how can I add "SPC SPC" as my second global-prefix to access my leader key inside insert state / mode restricted by some timeout?

 (general-create-definer gm/leader-keys
      :states '(normal insert visual emacs)
      :keymaps 'override
      :prefix "SPC" ;; set leader
      :global-prefix "M-SPC") ;; access leader in insert mode

Taking inspiration from illustrated block below;

;; exmple block to exit insert moder with the keys which will be active inside insert mode.
  (general-imap "j"
    (general-key-dispatch 'self-insert-command
      :timeout 0.25
      "k" 'evil-normal-state))

Thank you, Warm regards.

noctuid commented 10 months ago

You can have your definer use a :prefix-map and only binds in normal/visual. You can then then bind SPC in insert/emacs to a general-key-dispatch that binds SPC to that prefix keymap.

High-Flyer commented 10 months ago

Thank you very much for the reply. If I may ask,

;; So the new block will look like,
(general-create-definer gm/leader-keys
    :states '(normal visual)
    :keymaps 'override
    :prefix "SPC" ;; set leader
    :global-prefix "M-SPC") ;; access leader in insert mode

;; and the edited dispatcher block for the insert and emacs mode:     
(general-imap "SPC"
    (general-key-dispatch 'self-insert-command
      :timeout 0.25
      "SPC" 'evil-normal-state))

Am safe to assume this is what you meant ? Apologies Am very new new to Emacs, from non programming background.

Regards

noctuid commented 10 months ago

It depends on what you want. If you want to be able to run a command with SPC a in normal state or with SPC SPC a in insert state, you can do something like this:

(general-create-definer gm/leader-keys
  :states '(normal visual)
  :keymaps 'override
  :prefix "SPC"
  :prefix-map 'gm-leader-prefix-map)

(gm/leader-keys "a" #'test)

(general-def '(insert emacs)
  "SPC" (general-key-dispatch 'self-insert-command
          :timeout 0.25
          "SPC" gm-leader-prefix-map))
High-Flyer commented 10 months ago

Thank you Very much for the package kind and explaining reply. And contributing in this: Emacs/Evil for Vim Users

Much appreciated Warm Regards o7