Advertisement
Guest User

transliterate.el

a guest
Sep 4th, 2016
113
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defvar transliterate-custom
  2.   '((?— . " , ")
  3.     (?– . " through "))
  4.   "Custom transliterations when the Unicode table isn't useful.")
  5.  
  6. (defun transliterate-char (c)
  7.   "Return ASCII string for C, or nil for combining characters."
  8.   (if (<= c 127)
  9.       (char-to-string c)
  10.     (let ((name (downcase (or (get-char-code-property c 'old-name)
  11.                               (get-char-code-property c 'name))))
  12.           (category (get-char-code-property c 'general-category))
  13.           (custom (cdr (assoc c transliterate-custom))))
  14.       (cond (custom custom)
  15.             ((member category '(Mn Mc Me)) nil)
  16.             ((replace-regexp-in-string " sign$" "" name))))))
  17.  
  18. (defun transliterate-buffer ()
  19.   "Run `transliterate-char' over entire buffer."
  20.   (interactive)
  21.   (save-excursion
  22.     (setf (point) (point-min))
  23.     (while (< (point) (point-max))
  24.       (let* ((char (char-after))
  25.              (translation (transliterate-char char)))
  26.         (delete-char 1)
  27.         (when translation
  28.           (insert translation))))))
Advertisement
RAW Paste Data Copied
Advertisement