Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
emacs-lisp for entering digraphs (C-c d followed by two normal characters, to insert a unicode character)
; For vim's digraphs (in .el form) see:
; https://raw.githubusercontent.com/JNRowe/emacs-configs/master/digraphs.el
; This file omits characters I'd never use, and also uses my own mnemonics.
(define-prefix-command 'digraph-map)
(global-set-key (kbd "C-c d") digraph-map)
(defun register-digraphs (key digraphs &rest _description)
"Given a list of 2-char digraphs, and a resulting (unicode) character, enable each digraph via prefix-command `digraph-map`"
(mapc (lambda (d) (define-key digraph-map d `(lambda () (interactive) (insert ,key)))) digraphs))
; TODO: keep a set of all defined digraph-strings, and warn if one is repeated.
(register-digraphs "" '("<>" "()"))
(register-digraphs "" '("sp" " "))
(register-digraphs "" '("--" "em" "-m" "-3")) ; mdash
(register-digraphs "" '("en" "-n" "-2")) ; ndash
(register-digraphs "°" '("dg" "^o")) ; deg
(register-digraphs "±" '("+-")) ; pm
(register-digraphs "" '("-+")) ; mp
(register-digraphs "Ñ" '("~N"))
(register-digraphs "ñ" '("~n"))
(register-digraphs "Ç" '("C,"))
(register-digraphs "ç" '("c," ",c"))
(register-digraphs "Ç" '(",C" "C,"))
(register-digraphs "¿" '("i?")) ; iexcl
(register-digraphs "¡" '("i!")) ; iquest
(register-digraphs "ß" '("ss" "sz"))
(register-digraphs "Ǣ" '("AE"))
(register-digraphs "ǣ" '("ae"))
(register-digraphs "¢" '("c|"))
(register-digraphs "£" '("$$" "lb"))
(register-digraphs "¥" '("Y="))
(register-digraphs "¤" '("ox"))
(register-digraphs "" '("E="))
(register-digraphs "©" '("cO")) ; copy
(register-digraphs "®" '("rO")) ; reg
(register-digraphs "" '("TM")) ; trade
(register-digraphs "" '("SM"))
(register-digraphs "" '("co")) ; (c/o)
(register-digraphs "" '("N0"))
(register-digraphs "" '("PO"))
(register-digraphs "" '("Rx"))
; ligatures
(register-digraphs "" '("ff"))
(register-digraphs "" '("fi"))
(register-digraphs "" '("fl"))
(register-digraphs "" '("ft"))
(register-digraphs "" '("st"))
; superscripts
(register-digraphs "" '("^0"))
(register-digraphs "¹" '("^1"))
(register-digraphs "²" '("^2"))
(register-digraphs "³" '("^3"))
(register-digraphs "" '("^4"))
(register-digraphs "" '("^5"))
(register-digraphs "" '("^6"))
(register-digraphs "" '("^7"))
(register-digraphs "" '("^8"))
(register-digraphs "" '("^9"))
(register-digraphs "" '("^+"))
(register-digraphs "" '("^-"))
(register-digraphs "" '("^="))
(register-digraphs "" '("^("))
(register-digraphs "" '("^)"))
(register-digraphs "" '("^n"))
; subscripts
(register-digraphs "" '("_0"))
(register-digraphs "" '("_1"))
(register-digraphs "" '("_2"))
(register-digraphs "" '("_3"))
(register-digraphs "" '("_4"))
(register-digraphs "" '("_5"))
(register-digraphs "" '("_6"))
(register-digraphs "" '("_7"))
(register-digraphs "" '("_8"))
(register-digraphs "" '("_9"))
(register-digraphs "" '("_+"))
(register-digraphs "" '("_-"))
(register-digraphs "" '("_="))
(register-digraphs "" '("_("))
(register-digraphs "" '("_)"))
;fractions
(register-digraphs "¼" '("14"))
(register-digraphs "½" '("12"))
(register-digraphs "¾" '("34"))
(register-digraphs "" '("13"))
(register-digraphs "" '("23"))
(register-digraphs "" '("15"))
(register-digraphs "" '("25"))
(register-digraphs "" '("35"))
(register-digraphs "" '("45"))
(register-digraphs "" '("16"))
(register-digraphs "" '("56"))
(register-digraphs "" '("18"))
(register-digraphs "" '("38"))
(register-digraphs "" '("58"))
(register-digraphs "" '("78"))
; math-dot
(register-digraphs "·" '("md"))
(register-digraphs "×" '("mx")) ; times
; greek letters
(register-digraphs "Α" '("gA"))
(register-digraphs "Β" '("gB"))
(register-digraphs "Γ" '("gG"))
(register-digraphs "Δ" '("gD"))
(register-digraphs "Ε" '("gE"))
(register-digraphs "Ζ" '("gZ"))
(register-digraphs "Η" '("gY"))
(register-digraphs "Θ" '("gH"))
(register-digraphs "Ι" '("gI"))
(register-digraphs "Κ" '("gK"))
(register-digraphs "Λ" '("gL"))
(register-digraphs "Μ" '("gM"))
(register-digraphs "Ν" '("gN"))
(register-digraphs "Ξ" '("gC"))
(register-digraphs "Ο" '("gO"))
(register-digraphs "Π" '("gP"))
(register-digraphs "Ρ" '("gR"))
(register-digraphs "Σ" '("gS"))
(register-digraphs "Τ" '("gT"))
(register-digraphs "Υ" '("gU"))
(register-digraphs "Φ" '("gF"))
(register-digraphs "Χ" '("gX"))
(register-digraphs "Ψ" '("gQ"))
(register-digraphs "Ω" '("gW"))
(register-digraphs "α" '("ga"))
(register-digraphs "β" '("gb"))
(register-digraphs "γ" '("gg"))
(register-digraphs "δ" '("gd"))
(register-digraphs "ε" '("ge"))
(register-digraphs "ζ" '("gz"))
(register-digraphs "η" '("gy"))
(register-digraphs "θ" '("gh"))
(register-digraphs "ι" '("gi"))
(register-digraphs "κ" '("gk"))
(register-digraphs "λ" '("gl"))
(register-digraphs "μ" '("gm"))
(register-digraphs "ν" '("gn"))
(register-digraphs "ξ" '("gc"))
(register-digraphs "ο" '("go"))
(register-digraphs "π" '("gp"))
(register-digraphs "ρ" '("gr"))
(register-digraphs "σ" '("gs"))
(register-digraphs "τ" '("gt"))
(register-digraphs "υ" '("gu"))
(register-digraphs "φ" '("gf"))
(register-digraphs "χ" '("gx"))
(register-digraphs "ψ" '("gq"))
(register-digraphs "ω" '("gw"))
; Russian:
;(register-digraphs "а" '("ra"))
;(register-digraphs "б" '("rb"))
;(register-digraphs "в" '("rv"))
;(register-digraphs "г" '("rg"))
;(register-digraphs "д" '("rd"))
;(register-digraphs "е" '("re"))
;(register-digraphs "ж" '("rj"))
;(register-digraphs "з" '("rz"))
;(register-digraphs "и" '("ri"))
;(register-digraphs "й" '("rI"))
;(register-digraphs "к" '("rk"))
;(register-digraphs "л" '("rl"))
;(register-digraphs "м" '("rm"))
;(register-digraphs "н" '("rn"))
;(register-digraphs "о" '("ro"))
;(register-digraphs "п" '("rp"))
;(register-digraphs "р" '("rr"))
;(register-digraphs "с" '("rs"))
;(register-digraphs "т" '("rt"))
;(register-digraphs "у" '("ru"))
;(register-digraphs "ф" '("rf")) ; beware right-floor
;(register-digraphs "х" '("rh"))
;(register-digraphs "ц" '("rc")) ; cz or ts; beware right-ceiling
;(register-digraphs "ч" '("rC")) ; che
;(register-digraphs "ш" '("rS")) ; sh
; Hebrew:
;(register-digraphs "א" '("hA"))
;(register-digraphs "ב" '("hB"))
;(register-digraphs "ג" '("hG"))
;(register-digraphs "ד" '("hD"))
;(register-digraphs "ה" '("hH"))
;(register-digraphs "ו" '("hW"))
;(register-digraphs "ז" '("hZ"))
;(register-digraphs "ח" '("hX"))
;(register-digraphs "ט" '("ht")) ; Teth "t"
;(register-digraphs "ת" '("hT")) ; Taw "t"
;(register-digraphs "י" '("hJ"))
;(register-digraphs "ך" '("hK")) ; kaf
;(register-digraphs "כ" '("hK")) ; kaf
;(register-digraphs "ל" '("hL"))
;(register-digraphs "ם" '("hm")) ; mem
;(register-digraphs "מ" '("hM")) ; mem
;(register-digraphs "ן" '("hn")) ; nun
;(register-digraphs "נ" '("hN")) ; nun
;(register-digraphs "ס" '("hs")) ; samekh
;(register-digraphs "ע" '("hE"))
;(register-digraphs "ף" '("hp")) ; pe
;(register-digraphs "פ" '("hP")) ; pe
;(register-digraphs "ץ" '("hz")) ; tsade
;(register-digraphs "צ" '("hZ")) ; tsade
;(register-digraphs "ק" '("hQ"))
;(register-digraphs "ר" '("hR"))
;(register-digraphs "ש" '("hS")) ; shin
; Roman numerals (who knew?)
(register-digraphs "" '("1R"))
(register-digraphs "" '("2R"))
(register-digraphs "" '("3R"))
(register-digraphs "" '("4R"))
(register-digraphs "" '("5R"))
(register-digraphs "" '("6R"))
(register-digraphs "" '("7R"))
(register-digraphs "" '("8R"))
(register-digraphs "" '("9R"))
(register-digraphs "" '("aR"))
(register-digraphs "" '("bR"))
(register-digraphs "" '("cR"))
(register-digraphs "" '("1r"))
(register-digraphs "" '("2r"))
(register-digraphs "" '("3r"))
(register-digraphs "" '("4r"))
(register-digraphs "" '("5r"))
(register-digraphs "" '("6r"))
(register-digraphs "" '("7r"))
(register-digraphs "" '("8r"))
(register-digraphs "" '("9r"))
(register-digraphs "" '("ar"))
(register-digraphs "" '("br"))
(register-digraphs "" '("cr"))
(register-digraphs "" '("<-"))
(register-digraphs "" '("^|"))
(register-digraphs "" '("->"))
(register-digraphs "" '("v|"))
;(register-digraphs "↔" '())
(register-digraphs "" '("^v"))
(register-digraphs "" '("<="))
(register-digraphs "" '("=>"))
(register-digraphs "" '("=="))
(register-digraphs "¬" '("-,"))
(register-digraphs "" '("&&"))
(register-digraphs "" '("AN"))
(register-digraphs "" '("||"))
(register-digraphs "" '("OR"))
(register-digraphs "" '("FA"))
(register-digraphs "" '("TE"))
(register-digraphs "" '("/0"))
(register-digraphs "" '("(U"))
(register-digraphs "" '(")U"))
(register-digraphs "" '("(-"))
(register-digraphs "" '("-)"))
(register-digraphs "" '("*P"))
(register-digraphs "" '("+Z"))
(register-digraphs "" '("DE"))
(register-digraphs "" '("NB"))
(register-digraphs "" '("dP"))
(register-digraphs "" '("*-")) ; lowast
(register-digraphs "" '("Ob" "fg")) ; for function-composition, and hollow-bullet?
(register-digraphs "" '("Sb"))
(register-digraphs "" '("sq"))
(register-digraphs "" '("0("))
(register-digraphs "" '("00")) ; (infinity)
(register-digraphs "" '("-L"))
(register-digraphs "" '("-V"))
(register-digraphs "" '("PP")) ; (note: "||" used by LOGICAL-OR)
(register-digraphs "" '("<=" "le"))
(register-digraphs "" '(">=" "ge"))
(register-digraphs "" '("!=" "ne"))
(register-digraphs "" '("':")) ; TRICOLON
(register-digraphs "" '(":3"))
(register-digraphs "" '(":4")) ; VERTICAL FOUR DOTS
(register-digraphs "" '(".." ".3")) ; hellip
(register-digraphs "" '(".2"))
(register-digraphs "" '("''" "p'" "p1")) ; prime
(register-digraphs "" '("p2")) ; Prime DOUBLE PRIME
(register-digraphs "" '("p3")) ; TRIPLE PRIME
(register-digraphs "" '("p4")) ; QUADRUPLE PRIME
(register-digraphs "" '("??")) ; DOUBLE QUESTION MARK
(register-digraphs "" '("?!")) ; QUESTION EXCLAMATION MARK
(register-digraphs "" '("!?")) ; EXCLAMATION QUESTION MARK
(register-digraphs "" '("-T"))
; math-<
(register-digraphs "" '("m<"))
(register-digraphs "" '("m>"))
(register-digraphs "" '(".:"))
(register-digraphs "" '(":R"))
(register-digraphs "" '("::"))
(register-digraphs "" '("~1"))
(register-digraphs "" '("~2"))
(register-digraphs "" '("~~"))
(register-digraphs "" '("=3"))
;(register-digraphs "≪" '("<<"))
;(register-digraphs "≫" '(">>"))
(register-digraphs "" '("/<"))
(register-digraphs "" '("/>"))
(register-digraphs "" '("(C"))
(register-digraphs "" '(")C"))
(register-digraphs "" '("(_"))
(register-digraphs "" '(")_"))
(register-digraphs "" '(".P"))
(register-digraphs "" '( "lc")) ; "left ceiling"
(register-digraphs "" '( "rc")) ; "right ceiling"; beware "rc" used by russian
(register-digraphs "" '( "lf")) ; "left floor"; "fl" a ligature
(register-digraphs "" '( "rf")) ; "right floor"; beware "rf" used by russian
(register-digraphs "" '("(A"))
(register-digraphs "" '("Su")) ; sum
(register-digraphs "" '("Pr")) ; prod
(register-digraphs "" '("In")) ; int
(register-digraphs "" '("Iu"))
(register-digraphs "" '("Il"))
(register-digraphs "" '("DI"))
(register-digraphs "" '("Io"))
(register-digraphs "§" '("SS"))
(register-digraphs "" '("pa")) ; pilcrow
(register-digraphs "" '("%0")) ; PER MILLE SIGN
(register-digraphs "" '("%%")) ; PER TEN THOUSAND SIGN
(register-digraphs "" '("AO")) ; (angstrom)
(register-digraphs "" '("+|"))
(register-digraphs "" '("++"))
(register-digraphs "" '("dC"))
(register-digraphs "" '("dF"))
; cards
(register-digraphs "" '("cS"))
(register-digraphs "" '("cH"))
(register-digraphs "" '("cD"))
(register-digraphs "" '("cC"))
; Music
(register-digraphs "" '("M4"))
(register-digraphs "" '("M8"))
(register-digraphs "" '("MF"))
(register-digraphs "" '("Mb"))
(register-digraphs "" '("Mn"))
(register-digraphs "" '("M#"))
(register-digraphs "" '("ok"))
(register-digraphs "" '("ck"))
(register-digraphs "" '("xx"))
(register-digraphs "" '("XX"))
(register-digraphs "" '("YY"))
(register-digraphs "" '("*0"))
(register-digraphs "" '("*1"))
(register-digraphs "" '("SU"))
(register-digraphs "" '(":)"))
(register-digraphs "" '("1)"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment