I have the following snippet:

(setq evil-string-inflection-bind "g~")
(define-key evil-normal-state-map (kbd evil-string-inflection-bind) 'evil-operator-string-inflection)

The above snippet will not work.

Now I know for a fact that this works:

(define-key evil-normal-state-map (kbd "g~") 'evil-operator-string-inflection)

Why the first snippet does not work while the second does? At first look, they should be equal.

Is there a way to pass arguments to the (kdb) function or is it special somehow?

  • There's nothing wrong with what you're trying to do in general. I can't replicate your problem in 26.1 (albeit not using evil specifically). Exactly what do you mean when you say "The above snippet will not work" ? – phils Aug 18 at 0:13
  • 1
    Which version of Emacs are you using? IIRC kbd was a macro in the past, which could account for the problem. Does C-h f kbd say that it's a function or a macro? – phils Aug 18 at 0:13
  • @phils I mean that I cannot solve this issue because nothing is bound to my text-object. Using the second snippet, it works but it does not solves the issue. I'm using latest emacs from archlinux, which is 26.1 – ninrod Aug 18 at 3:56
  • kbd is a function in emacs 26.1, which is my case. – ninrod Aug 18 at 3:58
  • It all sounds rather specific to evil then. I've added the tag accordingly, and hopefully someone else who uses it will be better placed to answer this. – phils Aug 18 at 4:26

I think your stated question is perhaps not related to your problem. It sounds rather specific to evil. Certainly we can see that there is no fundamental difference between passing a string literal to kbd and passing a variable with that same value:

ELISP> emacs-version
"26.1"

ELISP> (setq map1 (make-sparse-keymap))
ELISP> (define-key map1 (kbd "g~") 'evil-operator-string-inflection)
ELISP> map1
(keymap
 (103 keymap
      (126 . evil-operator-string-inflection)))

ELISP> (setq map2 (make-sparse-keymap))
ELISP> (setq evil-string-inflection-bind "g~")
ELISP> (define-key map2 (kbd evil-string-inflection-bind) 'evil-operator-string-inflection)
ELISP> map2
(keymap
 (103 keymap
      (126 . evil-operator-string-inflection)))

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.