Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defvar transliterate-custom
- '((?— . " , ")
- (?– . " through "))
- "Custom transliterations when the Unicode table isn't useful.")
- (defun transliterate-char (c)
- "Return ASCII string for C, or nil for combining characters."
- (if (<= c 127)
- (char-to-string c)
- (let ((name (downcase (or (get-char-code-property c 'old-name)
- (get-char-code-property c 'name))))
- (category (get-char-code-property c 'general-category))
- (custom (cdr (assoc c transliterate-custom))))
- (cond (custom custom)
- ((member category '(Mn Mc Me)) nil)
- ((replace-regexp-in-string " sign$" "" name))))))
- (defun transliterate-buffer ()
- "Run `transliterate-char' over entire buffer."
- (interactive)
- (save-excursion
- (setf (point) (point-min))
- (while (< (point) (point-max))
- (let* ((char (char-after))
- (translation (transliterate-char char)))
- (delete-char 1)
- (when translation
- (insert translation))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement