How to source key translations in emacs?

1

I'd like to use C-c B as a binding, only it seems to be already bound :

C-c b (translated from C-c B) runs the command …
  • How can I see where's the code that binds it ?

  • How to overrule it myself ?


B or S-b, is there a standard for that ?

Nikana Reklawyks

Posted 2012-11-16T03:09:32.307

Reputation: 501

Re note (1) imho - no, that's not clearer; S (2) standard is to use capitals when you mean capital, just as you have, S is used only with other modifiers, as in C-S-b – ckhan – 2012-11-16T03:16:06.747

Thanks. Does that mean C-B would be bad practice, or is just for, say, C-S-s and M-S-m, to distinguish them from Control-Shift-forgot-the-letter and so ? Now that I took it apart it looks oh so very much like a second question… Dunno if it deserves posting. – Nikana Reklawyks – 2012-11-16T03:21:35.430

Answers

2

C-h k C-c b to show what command is being run. Click/press space on the .el link in the first paragraph to see the code.

(global-unset-key "\C-cb") in your .emacs to unset the key.

Edit 1:

First find what command is being run with that keypress with describe-key: C-h k C-c B. If emacs reports C-c B is undefined It's probably falling back to the lowercase command, C-c b.

In the case of a fallback like this, binding a capital key with (global-set-key (kbd "C-c B") 'command) will leave the fallback key in place.

Otherwise, the *help* window that describe-key brings up will mention an .el file in the first paragraph, you can bring it up with a click, or space when the point is on it. Your command will likely be being set somewhere in that code.

To find the code try searching for describe-key, set-key, some variations of your kbd string, or if worst comes to worst, key.

Daniel

Posted 2012-11-16T03:09:32.307

Reputation: 121

That's the code of the function definition, not the code that binds the key. Also you're unbinding the lower-case key, which I want to stay as it is, I just want to overrule the upper-case one. – Nikana Reklawyks – 2012-11-30T15:51:48.287

1I meant that the binding will likely be in the library that you've been pointed to. Try doing a search for 'bind', 'set-key', 'defkey' etc, you might have some luck. In my case it was org-mode with org-defkey. – Daniel – 2012-11-30T18:48:01.523

As for the unset-key, according to this page on emacs bindings the correct way is (global-unset-key (kbd "C-c B")). Just tested it against a quick set-key in scratch, seems to work, but falls back to C-c b if the binding for the capital letter version doesn't exist.

– Daniel – 2012-11-30T19:00:36.633

The search didn't give me results, as I search for C-x <left> in simple.el. As for rebinding, yes, binding the uppercase one scraps the translation, but it's important for my question to keep the lowercase binding intact (but you could edit your answer to take that into account). – Nikana Reklawyks – 2012-12-07T02:35:38.263

Thanks, my answer's been edited. I take it you're after a few like this? C-x <left> isn't in the original question. It won't have a fallback case, I'm guessing. – Daniel – 2012-12-07T09:12:58.813