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?

zack
  • 133
  • 5

1 Answers1

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.

NickD
  • 29,717
  • 3
  • 27
  • 44