Emacs: define prefix/leader key (nested key maps)

Поделиться
HTML-код
  • Опубликовано: 19 янв 2025

Комментарии • 33

  • @anneallison6402
    @anneallison6402 7 месяцев назад +2

    Your help and videos have been invaluable to me I really appreciate your contributions to the comunity

    • @protesilaos
      @protesilaos  7 месяцев назад

      Good to know. Thank you!

  • @Fabojuno
    @Fabojuno 11 месяцев назад +8

    Another great video!
    I would like to share one alternative I prefer by using the `cons` keyword on `defvar-keymap`
    example: ` "b" (cons "Buffer" my-test-buffer-map) `
    Basically the same thing you are doing with grave and dots, but DRYer since you don't need to rebind all keys again with `which-key-add-keymap-based-replacements`

    • @protesilaos
      @protesilaos  11 месяцев назад

      It works, thank you! I have a vague memory trying the equivalent with 'define-key' but it did not do the right thing. Maybe defvar-keymap expands to something else. I will have to check.

    • @kristofernelson6083
      @kristofernelson6083 11 месяцев назад

      Thanks for this tip! Just confirmed it worked for me (at least in Emacs 29).

  • @NicholasScheurich
    @NicholasScheurich 11 месяцев назад +5

    As usual, there is plenty of practical, clearly-communicated knowledge to be gained here. Thanks for the excellent videos, Prot.

  • @GospodinStanoje
    @GospodinStanoje 11 месяцев назад +2

    Thank you! This is exactly what I was looking for.
    Your videos are comprehensive and very detailed-oriented. I appreciate that very much. Thanks again.

  • @rrregis
    @rrregis 11 месяцев назад

    Thanks! I really appreciate the details in the examples, especially the "test-hello" back tick vs single quote example.

  • @kristofernelson6083
    @kristofernelson6083 11 месяцев назад +1

    Excellent video, thanks! Was great timing, as I'm currently in the middle of setting up some key prefixes.
    Question for you: From my initial research on this, I ended up using "define-prefix-command" instead of just "defvar"-ing a new keymap, since it seemed like you still get the backing keymap created with the additional ability to treat it like you would a command when setting up the key binds. Any particular reason you would prefer to just go with the plain keymap approach, or any downsides to "define-prefix-command" I should consider?

  • @willemhbos
    @willemhbos 11 месяцев назад +3

    Pretends to just show us how to do some basic customization, then turns us into Elisp hackers 😀. Great content.

  • @thelimatheou
    @thelimatheou 11 месяцев назад +6

    In this video, Prot accidentally creates Evil mode 😂

    • @protesilaos
      @protesilaos  11 месяцев назад +2

      It's all about getting started, haha!

  • @boyuanning2879
    @boyuanning2879 11 месяцев назад

    clear and very helpful! THX for the great work!

  • @evior5215
    @evior5215 11 месяцев назад

    Any reason to change my general.el configuration into something like you have shown?

    • @protesilaos
      @protesilaos  11 месяцев назад

      No. If it works, keep it. Also, I believe general.el is a macro that expands into the usual key bindings: it's fine.

  • @sebc429
    @sebc429 11 месяцев назад

    thank you, great description

  • @yassinrian292
    @yassinrian292 11 месяцев назад +2

    This is nice ..Thank you

  • @chutygolpo
    @chutygolpo 3 месяца назад

    Thanks Prot. You are awesome as usual, I am trying the snippet but it works fine but i cannot see the menu like yours. when press C-t i dont see the menu. But it works. How can i get the interactive menu like yours?
    here is my snippet
    (defun test-command()
    (interactive)
    (message "This is a test" ))
    (keymap-set global-map "C-t" 'test-command
    (defvar-keymap my-test-prefix-map
    :doc "My prefix map"
    "f" 'find-file
    "d" 'dired
    "t" 'test-command)
    (keymap-set global-map "C-t" my-test-prefix-map)

    • @protesilaos
      @protesilaos  3 месяца назад

      You need to use 'which-key-mode'. It is provided by the 'which-key' package (this is built into Emacs 30, by the way).

  • @marcrohrer7130
    @marcrohrer7130 11 месяцев назад

    Perfect! But how can I add a lambda to defvar-keymap?

    • @protesilaos
      @protesilaos  11 месяцев назад +1

      Like this:
      (defvar-keymap test
      "a" (lambda () (interactive) (message "Hello!")))
      (keymap-set global-map "C-t" test)

    • @marcrohrer7130
      @marcrohrer7130 11 месяцев назад

      ​@@protesilaos
      Very strange, I had tried that 😮😅
      But can which-key display a meaningful name instead of lambda? Or only with a real function?

  • @tiberiuiurco
    @tiberiuiurco 11 месяцев назад

    Thank you for the good video. I learned a lot!
    Also, I saw that you're not using evil package anymore. Any reasons for that?

    • @protesilaos
      @protesilaos  11 месяцев назад

      I was using evil to help ease the pain on the left arm. But the hjkl only improve things for the right hand. I am experimenting with alternatives, including a different placement for modifiers keys. But, the real fix is to stay away from the keyboard as much as possible, which I have been doing for a while (if I type for ~30 minutes straight I start to fail a lot of pain).

  • @10cadr
    @10cadr 11 месяцев назад

    Great video as always! As you talked about the news in Emacs 29, could you make a new video on completion? The one you have is 3 years old and there are some news in Emacs 29 about this topic. Also, I cannot make lsp-mode/corfu work as intended, lol.

    • @protesilaos
      @protesilaos  11 месяцев назад

      Oh, I didn't realise it was that long ago... I will check. About lsp-mode+corfu, check that your language server is installed and everything is right with it.