(You don't say what you mean by "it didn't work". Error?)
I don't use Evil, and I don't have its source code. So this probably won't help. Anyway...
Googling a bit, this doc page says that evil-define-key
is a macro, not a function, which means it doesn't necessarily evaluate all of its arguments, and it returns Lisp code (the macro expansion), which then gets evaluated.
Even though it's a macro, that doc page indicates that it does evaluate all of its args ("The remaining arguments [besides STATE
] are like those of define-key", which is a function), so it's not too clear why it's a macro. Presumably it does something else. (Or maybe that statement is just false.)
On the other hand, that page also kinda suggests that the KEYMAP
argument is not evaluated, because it says "Note that foo-mode-map is unquoted, and that this form is safe before foo-mode-map is loaded.". So to me at least, that doc is not too clear.
A guess is that KEYMAP
is not evaluated, which would mean that evil-define-key
expects a keymap variable, that is, a symbol, for KEYMAP
. That would explain why your code wouldn't work: because you're passing the values of those keymap variables, not the variables (symbols) themselves, to evil-define-key
.
(Note that define-key
does not accept a keymap variable as arg; it accepts only a keymap, that is, the value of a keymap variable, as arg.)
If this guess is correct, you could try quoting the keymap symbols: instead of (list c-mode-map c++-mode-map glsl-mode-map)
, try '(c-mode-map c++-mode-map glsl-mode-map)
.
Another thing that suggests this interpretation is the doc string mention that you can pass a quoted symbol instead of a keymap or keymap symbol, in which case the quoted symbol indicates a mode. This is no proof, but it does suggest that the arg isn't evaluated first.
Just a wild guess. No doubt some Evil user or someone with the definition of evil-define-key
will give you a good answer.
(This answer might also help a bit. Dunno.)
OK, I found the source code and took a very quick peek at the definition of macro evil-define-key
.
It seems you can pass either an (unquoted) keymap variable (symbol) or its value, and that evaluation is delayed in either case. My quick peek didn't tell me just what the problem is with your code, however...
c-mode-common-hook
. So you could do something like(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
, withmy-c-mode-common-hook
containing(local-set-key (kbd "C-M-?") 'c-comment-from-c++)