Here’s what I use for my blog.
(define-key org-mode-map "\C-ck" #'endless/insert-key)
(defun endless/insert-key (key)
"Ask for a key then insert its description.
Will work on both org-mode and any mode that accepts plain html."
(interactive "kType key sequence: ")
(let* ((is-org-mode (derived-mode-p 'org-mode))
(tag (if is-org-mode
"@@html:<kbd>%s</kbd>@@"
"<kbd>%s</kbd>")))
(if (null (equal key "\r"))
(insert
(format tag (help-key-description key nil)))
(insert (format tag ""))
(forward-char (if is-org-mode -8 -6)))))
Invoke it by calling C-c k
.
- It will prompt you for a key just like
C-h k
would do.
- It inserts that key sorrounded in escaped
<kbd>
tags.
- If you just hit
RET
, it will insert the tags and leave point
inside (instead of inserting any key), so you can type more
complicated keys.
- It even has some code to make it usable outside of
org-mode
!