0

Emacs won't let me bind C-c @ TAB to outline-cycle in outline-minor-mode. It complains "Lisp error: (error "Key sequence C-c @ TAB starts with non-prefix key C-c @") -- but C-c @ is bound to nothing.

Some minimal code to reproduce this experience would be the following:

(outline-minor-mode)
(setq-local outline-regexp "-- [*]+")
(setq outline-minor-mode-cycle t)

At this point, by running C-h k C-c @ you can verify that C-c @ is bound to nothing. Moreover, if you go on to press TAB, you can see that C-c @ TAB is bound to something. So it's a perfectly good key sequence.

Now try to redefine what it is bound to:

(define-key outline-mode-map (kbd "C-c @ TAB") 'outline-cycle)

and, if your system behaves like mine, you'll get the error.

5
  • "Emacs won't let me bind C-c @ TAB to outline-cycle in outline-minor-mode" -- but you're attempting to bind it in org-mode-map not in outline-minor-mode-map.
    – phils
    Nov 7, 2023 at 2:37
  • @phils You nailed it! Thank you! I just needed to rebind the right map, namely outline-minor-mode-map. Nov 8, 2023 at 1:49
  • @Drew Thanks! That question is about a similar but different problem. It includes a lot of discussion of :bind, which (to my knowledge) I'm not using. The other suggestion involved unbinding keys, but that appears to be unnecessary. In that one the OP really needed to create a prefix. In my case it was that I was trying to bind a key using a prefix that was not available as a prefix for the mode-map I was trying to redefine, because in fact I should have been redefining a different one. Nov 8, 2023 at 1:49
  • 3
    I’m voting to close this question because the problem is due to a typo Nov 8, 2023 at 16:04

2 Answers 2

1

org-mode-map has a keybinding for C-c @ in it, binding it to org-mark-subtree. That makes it a non–prefix key indeed. You could delete that keybinding first, if you wanted to. Or you could bind it in outline-mode-map instead, which seems to go better with the rest of the code you quoted.

1
  • Thanks! That would make sense, except I'm in a haskell buffer, not an org one. I'm running the emacs code I quoted from a file ending in .hs. The mode line at the bottom of the screen reads "(Haskell Interactive VHL Outl () yas)". Haskell and Interactive are bout about Haskell, VHL means volatile highlights, () means beacon-mode and yas means yasnippet. Nov 8, 2023 at 1:17
1

The problem was that I was trying to edit the wrong mode map. (define-key outline-mode-map (kbd "C-c @ TAB") 'outline-cycle) was not working (let alone (define-key org-mode-map (kbd "C-c @ TAB") 'outline-cycle), which I had written at some point). But (define-key outline-mode-map (kbd "C-c @ TAB") 'outline-cycle) works fine.

My confusion came from the fact that a prefix was not permitted in one mode even when it was available in another mode. I did not realize that. Apparently a prefix must be cleared for use on a per-mode-map basis, as described somewhat in this related question.

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