Created
February 25, 2014 21:27
-
-
Save faried/9218183 to your computer and use it in GitHub Desktop.
pasting utf-8 into zenicb buffers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; very lightly tested. | |
;;; changes unicode text pasted into an icb buffer like | |
;;; The first novel to win the ‘Triple Crown’ of science fiction literature awards | |
;;; into | |
;;; <fn[13:12]> The first novel to win the xn--triple-vh0c xn--crown-3v3b of science fiction literature awards | |
;;; instead of | |
;;; <fn[13:12]> The first novel to win the ?Triple Crown? of science fiction literature awards | |
;; install the idn package, which gives you idna.el | |
(require 'idna) | |
;; M-x customize-variable RET idna-to-ascii-parameters RET | |
;; and remove the --usetd3asciirules entry | |
;; make sure your zenicb buffer has (set-buffer-multibyte t) | |
;; i don't know if setting it to multibyte breaks anything. | |
(defun zenicb-send-public (message proc) | |
(let ((s message) | |
(start 0)) | |
(loop while (string-match "\\([^\s]+\\)\\(\\s-*\\)" s start) | |
do (setf start (match-end 0)) | |
collect (idna-to-ascii (match-string 1 s)) into retstring | |
if (> (length (match-string 2 s)) 0) | |
collect (match-string 2 s) into retstring | |
finally (zenicb-send-string proc ?b (apply #'concat retstring))))) | |
;; the reverse process is something like this: | |
(let ((s "The first novel to win the xn--triple-vh0c xn--crown-3v3b of science fiction literature awards") | |
(start 0)) | |
(loop while (string-match "\\([^\s]+\\)\\(\\s-*\\)" s start) | |
do (setf start (match-end 0)) | |
collect (idna-to-unicode (match-string 1 s)) into retstring | |
if (> (length (match-string 2 s)) 0) | |
collect (match-string 2 s) into retstring | |
finally return (apply #'concat retstring))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment