2

I have been recently fiddling a lot with Emacs org-mode. In this process suddenly my key-binding for showing the agenda menu is lost, so I have to access it with M-x org-agenda. The error I get when I press C-c a is " C-c a is undefined".

How do I restore the original keybinding?

Please answer the question with the following points in mind as I am trying to learn few things out of this problems.

  • Where are these default key-bindings stored?
  • What could I have done to cause the problem (So that I am more aware when I am doing it next time)?
  • How do I restore it? I do not want to add a custom key binding in .emacs as C-c a usually there by default in org-more.

1 Answer 1

4

It's not possible to know what you did to lose your original binding, so here's the basic upshot.

  • Your customizations (as with keybindings) will be stored in your init file, and any other elisp files you call from it.
  • If it was a temporary change (i.e., you didn't make changes to your init file manually or through customize), you can just restart Emacs.
  • If you did make changes to your init file (intentionally or not), the problem will persist into new Emacs sessions.
  • If you have no idea what code in the init file is causing you to lose your binding, do the following:
    • Start Emacs without your init file (emacs -Q) to confirm.
    • Recursively bisect your init file by successively commenting out halves until you isolate the problematic lines.

For a given keybinding, you can find out what it calls with C-h k KEY SEQUENCE, (where C-h k calls describe-key). For example, you can try C-h k C-c a.

For a given command, you can find out the keybindings with C-h f FUNCTIONNAME (where C-h f calls describe-function). For your case, you can try C-h f org-agenda to see what keybindings it has.

Note that the org manual's node on activation suggests using C-c a as a global keybinding to access org-agenda, but you're under no obligation to use that particular binding. If you want to bind it again, you can follow it's suggestion with:

(global-set-key "\C-ca" 'org-agenda)

You can put that in your scratch buffer and evaluate it, but it should be somewhere in your init file if you want it to persist through Emacs sessions.

As an aside, the reason C-c a is not a hard and fast binding is that it runs against keybinding conventions in Emacs, one of which states:

Don't define C-c letter as a key in Lisp programs. Sequences consisting of C-c and a letter (either upper or lower case) are reserved for users; they are the only sequences reserved for users, so do not block them.

More generally, have a look at the Emacs manual node on Customizing Key Bindings to find out how to bind keys as you like.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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