Download
(require 'quail)
(defconst fliptext-rules-alist
'((?a . ?\ɐ) (?b . ?\q) (?c . ?\ɔ) (?d . ?\p) (?e . ?\ǝ) (?f . ?\ɟ)
(?g . ?\ƃ) (?h . ?\ɥ) (?i . ?\ı) (?j . ?\ɾ) (?k . ?\ʞ) (?l . ?l)
(?m . ?\ɯ) (?n . ?u) (?o . ?o) (?p . ?d) (?q . ?b) (?r . ?\ɹ)
(?s . ?s) (?t . ?\ʇ) (?u . ?n) (?v . ?\ʌ) (?w . ?\ʍ) (?x . ?x)
(?y . ?\ʎ) (?z . ?z)
(?\[ . ?\]) (?\( . ?\)) (?\{ . ?\}) (?\< . ?\>) (?\« . ?\»)
(?\. . ?\˙) (?\? . ?\¿) (?\! . ?\¡) (?\' . ?\,)
(?\_ . ?\‾) (?\" . ?\„)
;;("‿" ?\⁀)
;;("⁅" ?\⁆)
;;("∴" ?\∵)
;; ∀ Ɔ Ǝ Ⅎ H I Ꮭ ℸ W N O d S ⊥ ⋂ Ʌ M X Z
))
(defun dassoc (key alist)
"Returns the cdr of the first cons of ALIST if KEY is `equal' to the car of that cons of ALIST.
If that fails, returns the car of the first cons of ALIST if KEY
is `equal' to the cdr of that cons of ALIST. Otherwise returns
nil."
(if (and key (setq new (cdr (assoc key alist))))
new
(car (rassoc key alist))))
(defun fliptext-input-method (key)
(if buffer-read-only
(list key)
(if (setq new (dassoc (downcase key) fliptext-rules-alist))
(list new ?\2) ;; ?\2 == backwards char
(list key ?\2))))
(defun fliptext-input-activate (&optional arg)
"Activate fliptext input method.
With arg, activate fliptext input method if and only if arg is
positive.
While this input method is active, the variable
`input-method-function' is bound to the function
`fliptext-input-method'."
(if (and arg
(< (prefix-numeric-value arg) 0))
(unwind-protect
(progn
(quail-hide-guidance)
(quail-delete-overlays)
(setq describe-current-input-method-function nil))
;;(local-unset-key "\C-d")
;;(local-unset-key [delete])
;;(local-unset-key "\d")
;;(local-unset-key [backspace])
(kill-local-variable 'input-method-function))
;;(local-set-key "\C-d" 'delete-backward-char)
;;(local-set-key [delete] 'delete-backward-char)
;;(local-set-key "\d" 'delete-char)
;;(local-set-key [backspace] 'delete-char)
(setq inactivate-current-input-method-function 'fliptext-input-inactivate)
(setq describe-current-input-method-function 'fliptext-input-help)
(quail-delete-overlays)
(if (eq (selected-window) (minibuffer-window))
(add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))
(set (make-local-variable 'input-method-function)
'fliptext-input-method)))
(defun fliptext-input-inactivate ()
"Inactivate fliptext input method."
(interactive)
(fliptext-input-activate -1))
(defun fliptext-input-help ()
(interactive)
(with-output-to-temp-buffer "*Help*"
(princ "Flips text upside down.
E.g. hello world -> plɹoʍ ollǝɥ")))
(provide 'fliptext)
(register-input-method "fliptext" "UTF-8" 'fliptext-input-activate "ɐ"
"Input method for \"flipping characters upside down\".")