Xah Talk Show 2023-04-20 Emacs Lisp Coding. Keyboard Shortcut Notation to HTML Markup
- Windows: Keyboard Shortcuts
- Microsoft Windows Logo history
- Keyboard Menu Key
- Elisp: Convert/Join List/Vector/String
- write a emacs command so that
C-w
becomes Ctrl+w
more examples
C-a C-c
→ Ctrl+a Ctrl+cc-s-a
→ Ctrl+Shift+ac-a-a
→ Ctrl+Alt+ac-s-a-a
→ Ctrl+Shift+Alt+aw-s
→ ❖ Windows+sw-s-s
→ ❖ Windows+Shift+s
(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)))