2

I'm using or-mode 9.2 and when I hit C-c C-, and I got the following message:

Before first headline at position 480 in buffer index.org

The message indicates that the key actually get translated as C-c ,, which maps to org-priority. I turn on M-x toggle-debug-on-error and see the following when I press C-c C-,

Debugger entered--Lisp error: (error "Before first headline at position 470 in buffer index.org")
  signal(error ("Before first headline at position 470 in buffer index.org"))
  error("Before first headline at position %d in buffer %s" 470 #<buffer index.org>)
  org-back-to-heading(t)
  org-priority(nil)
  funcall-interactively(org-priority nil)
  call-interactively(org-priority nil nil)
  command-execute(org-priority)

Does anyone run into issue like this?

4
  • What is the contents of the buffer (and where is the cursor) where you see this error? Commented Jan 26, 2020 at 11:50
  • And what does this have to do with org-insert-structure or a key binding clash? Commented Jan 26, 2020 at 11:50
  • 1
    @DanRobertson: C-c C-, is bound to org-insert-structure-template by default (in recent versions of Org mode, certainly after 9.0 but possibly later). OP: is this in GUI emacs or in terminal emacs?
    – NickD
    Commented Jan 26, 2020 at 13:00
  • @NickD I'm using emacs 26.3 in iTerm2 on a Mac
    – zack
    Commented Jan 26, 2020 at 21:08

1 Answer 1

2

I don't know anything about Macs or iTerm2, but running emacs in a terminal will sometimes cause problems like this. E.g. I work on Linux under X with a GUI emacs, but if I start an xterm or gnome-terminal and run emacs -nw in it, the key C-, does not exist: if I hold down the Control key and press , what I get is just ,. This is probably what you are running into.

In GUI Emacs under X, the window system allows emacs to synthesize keys: it knows that you pressed down the Control key and then you pressed down , so emacs can pretend that it saw a C-,.

Try it: say C-h c C-, - if you try this in GUI emacs, it will most probably say C-, is undefined because most modes don't define it. But note that it actually saw a C-,. If you try the same thing in your terminal emacs, it'll say , runs the command self-insert-command: it does not know that you pressed the Control key; it only sees the comma.

What to do? You can run GUI emacs instead; or you can bind org-insert-structure-template to some key that you can press - function keys might be useful here, because terminal emacs (at least xterm and gnome-terminal on linux - YMMV) recognizes not just the bare key (e.g. F1), but also modified versions: S-F1 is known as <f13> (there are usually twelve function keys on standard US keyboards) and C-F1 is known as <f25>. You can check these things out with the C-h c trick above.

So you can try something like this:

(define-key org-mode-map (kbd "<f25>") 'org-insert-structure-template)

Then pressing C-F1 would invoke the org-insert-structure-template command.

Your Answer

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

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