Doom-emacs: How to bind custom function to keys?

Created on 18 May 2019  路  2Comments  路  Source: hlissner/doom-emacs

I have a function in +bindings.el in .doom.d called jiayuan/org-capture-inbox, and I want to bind it to SPC I, here is my code:

(map! :leader
      :desc "Capture Inbox"                            "I" #'jiayuan/org-capture-inbox
      )
;;;###autoload
(defun jiayuan/org-capture-inbox ()
  "Direct capture tasks to inbox"
  (lambda () (interactive) (org-capture nil "t")))

But when I use this key, I have this error message:

command-execute: Wrong type argument: commandp, jiayuan/org-capture-inbox

And I can't use M-x to run my function. Do I miss something with lazy loading?

question keybinds resolved

Most helpful comment

The problem is that jiayuan/org-capture-inbox is not an interactive function, it is a function that _returns_ an interactive function. Here's what you want:

(defune jiayuan/org-capture-inbox ()
  "Direct capture tasks to inbox"
  (interactive)
  (org-capture nil "t"))

(map! :leader :desc "Capture Inbox" "I" #'jiayuan/org-capture-inbox)

OR

(map! :leader :desc "Capture Inbox" "I" (lambda () (interactive) (org-capture nil "t")))

OR

(map! :leader :desc "Capture Inbox" "I" (位! (org-capture nil "t")))

All 2 comments

The problem is that jiayuan/org-capture-inbox is not an interactive function, it is a function that _returns_ an interactive function. Here's what you want:

(defune jiayuan/org-capture-inbox ()
  "Direct capture tasks to inbox"
  (interactive)
  (org-capture nil "t"))

(map! :leader :desc "Capture Inbox" "I" #'jiayuan/org-capture-inbox)

OR

(map! :leader :desc "Capture Inbox" "I" (lambda () (interactive) (org-capture nil "t")))

OR

(map! :leader :desc "Capture Inbox" "I" (位! (org-capture nil "t")))

@hlissner Thanks, it works now!

Was this page helpful?
0 / 5 - 0 ratings