0

I am trying to bind keys to a lambda function using bind-key.el. I have the following factor macro

;; taken from Emacs Doom
(defmacro cmd! (&rest body)
  (declare (doc-string 1) (pure t) (side-effect-free t))
  `(lambda (&rest _) (interactive) ,@body))

which creates a lambda interactive function. So at first, I tried using that to bind-keys with no success.

(use-package org
:bind (:map org-mode-map
("C-c C-f" . (cmd! (message "Test")))))

But then I get the error. use-package: org-super-agenda wants arguments acceptable to the 'bind-keys' macro.... I also tried

(bind-keys :map org-mode-map
     ("C-c C-f" . (cmd! (message "Test"))))

but then I get the error command-execute: Wrong type argument: commandp, (cmd! (message "Test")) when I press C-c C-f.

I then tried replacing (cmd! ... with (lambda () (interactive) ...)

(bind-keys :map org-mode-map
     ("C-c C-f" . (lambda () (interactive) (message "Test"))))

but then I get stuck in an infinite loop when executing the previous statement. When stopping with C-g, I find that I am stuck in a function called prin1-to-string with a seemingly infinite

(closure ((binding closure ((binding closure ((binding closure ... nil ... ...)

as an argument. I think the reason is that in my particular file with lexical binding, closing the lambda expression is expensive.

How am I supposed to do this efficiently?

Tohiko
  • 1,589
  • 1
  • 10
  • 22

1 Answers1

0

Here's the format.

(bind-key KEY-NAME COMMAND &optional KEYMAP PREDICATE)
(bind-key "M-h" #'some-interactive-function my-mode-map)

(bind-key "C-c iv" (lambda()(interactive) (my-function-here my-func-parameter)) my-mode-map)

Documentation is your friend. C-h f bind-key.

naugiedoggie
  • 334
  • 1
  • 8