Xah Talk Show 2023-04-20 Emacs Lisp Coding. Keyboard Shortcut Notation to HTML Markup

vidthumb vdiYO0YfEus

more examples

(defun xah-shortcut-markup ()
  "Turn text under cursor such as C-w to html markup, eg
<kbd>Ctrl</kbd>+<kbd>w</kbd>
version 2023-04-20"
  (interactive)
  (let (xp1 xp2 xinput xshortcuts)
    (setq xp1 (line-beginning-position))
    (setq xp2 (line-end-position))
    (setq xinput (buffer-substring-no-properties xp1 xp2))
    (delete-region xp1 xp2)
    (setq xshortcuts (split-string xinput " +"))
    ;; sample xshortcuts value: ("C-a" "C-M-a" "C-A-a")
    (mapc
     (lambda (x)
       ;; sample x: "C-a" or "C-M-a" or "C-A-a"
       (let ((xkeys (split-string x "-"))
             xkeysReversed xkeysSansLast xlast)
         (setq xkeysReversed (reverse xkeys))
         (setq xlast (car xkeysReversed))
         (setq xkeysSansLast (reverse (cdr xkeysReversed)))

         (insert "<kbd>")
         (insert (mapconcat
                  (lambda (x)
                    (cond
                     ((string-equal (downcase x) "c") "Ctrl")
                     ((string-equal (downcase x) "s") "Shift")
                     ((string-equal (downcase x) "a") "Alt")
                     ((string-equal (downcase x) "m") "Meta")
                     ((string-equal (downcase x) "w") "❖ Windows")
                     (t x)))
                  xkeysSansLast
                  "</kbd>+<kbd>"))
         (insert "</kbd>")
         (insert (format "+<kbd>%s</kbd> " xlast))))
     xshortcuts)))