0

I'm trying to create a combination keybinding.

Here's an example:

(define-key my-minor-mode-map (kbd "x f") "\C-x\C-f")

(edit: Thanks you Stefan for pointing out the space between \C-x and \C-f.)

This however takes me to a random file and describe-key says this:

Macro: C-x C-f
Keyboard macro.

So I'm not really sure what that means. It seems that trying to bind s to C-s doesn't work either (As well as other interactive commands like C-r and M-x).

This does work:

(define-key my-minor-mode-map (kbd "x f") "\M-f")

So basically I want to be able to run C-x C-f (find-file) without having to type 'find-file as a function itself.

In other words; I don't want this:

(define-key my-minor-mode-map (kbd "x f") 'find-file)

I hope someone could help me out with this. My emacs knowledge is very limited.

Thanks in advance.

Complete code:

(defvar my-minor-mode-map (make-keymap) "my-minor-mode keymap")
(define-key my-minor-mode-map (kbd "x f") "\C-x\C-f")
(define-minor-mode my-minor-mode
"My minor-mode"

t "My minor mode" 'my-minor-mode-map)
(defun my-minibuffer-setup-hook ()
    (my-minor-mode 0))
"My minor-mode"

Edit:

What would even be better is if I could do this:

(define-key my-minor-mode-map (kbd "x") "\C-x")
(define-key my-minor-mode-map (kbd "f") "\C-f")

And then if I would type "x f" that it would exectue "\C-x C-f" aka find file. That way I wouldn't have to write out every possible key combination.

4

2 回答 2

3

"\C-x \C-f" has 3 elements: C-x, SPC, and C-f. You probably did not mean for that space to be there.

于 2013-03-30T02:34:55.517 回答
2

I'm not entirely certain what you believe should be happening here, but I suspect what you actually want is:

(define-key my-minor-mode-map (kbd "x f") (key-binding (kbd "C-x C-f")))

which is the same thing as the code you said you didn't want to use:

(define-key my-minor-mode-map (kbd "x f") 'find-file)

except that it obtains the function dynamically, based on the key binding.

p.s. It's also slightly odd that you're using a mixture of kbd and non-kbd syntax in the same form.

于 2013-03-30T13:11:48.530 回答