Emacs keyboard shortcuts are often written as inline code like C-c C-p.

How should this be written in kbd-style?

  1. C-c C-p
  2. C-c C-p
  3. C-c+C-p
  4. C+c C+p
  5. Ctrl+c > Ctrl+p
  6. or something else?

Version 5 is taken from https://keycombiner.com/collections/emacs/


1 Answer 1

  1. C-c C-p

This is my preference. You can generate it easily with this:

(defun my-insert-kbd (keyseq)
  "Read key sequence, and insert it with <kbd> markup."
  ;; Simplified from https://emacs.stackexchange.com/a/2208
  (interactive "kType key sequence: ")
  (insert "<kbd>"
          (mapconcat (lambda (s)
                       (replace-regexp-in-string "<" "&lt;" s))
                     (split-string (help-key-description keyseq nil))
  1. C-c C-p

Still understandable.

  1. C-c+C-p

Understandable, but no longer like the Emacs notation.

  1. C+c C+p

Gosh, no. Certain to cause confusion.

  1. Ctrl+c > Ctrl+p

Fairly understandable, but nothing like the Emacs notation.

Emacs notation should be used for consistency, so that's (1) or (2).

  • that is a handy snippet
    – nega
    Oct 5, 2021 at 5:23
  • Combined with the Edit with Emacs browser extension, it makes it very easy to use that markup for Q&As here at E.S.
    – phils
    Oct 5, 2021 at 7:28

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.