From: Mark Wooding Date: Thu, 14 Feb 2019 13:18:21 +0000 (+0000) Subject: dot/ercrc.el: Substitute problematic characters. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/8d190ffca441797f2297e1ea9cbef3a6eaa69400?ds=inline dot/ercrc.el: Substitute problematic characters. The problem is mostly emoji, arriving in Twitter announcements from Servus: I think that mosh and putty (and maybe Emacs) have different ideas about character width, and the terminal display ends up being a total mess. --- diff --git a/dot/ercrc.el b/dot/ercrc.el index 3881cc1..a0bc5a6 100644 --- a/dot/ercrc.el +++ b/dot/ercrc.el @@ -5,14 +5,36 @@ (setq erc-nick "mdw" erc-user-full-name "Mark Wooding") -(if (not (memq 'truncate erc-modules)) - (setq erc-modules (cons 'truncate erc-modules))) +(dolist (module '(replace truncate)) + (if (not (memq module erc-modules)) + (setq erc-modules (cons module erc-modules)))) (setq erc-fill-column 76 erc-timestamp-right-column 68 erc-fill-prefix " " erc-max-buffer-size (* 60 3000)) +;; Filter out emoji, which cause severe display confusion. +(defun mdw-replace-wide-characters (string) + (with-output-to-string + (let ((i 0) + (state nil)) + (while (< i (length string)) + (let ((ch (aref string i))) + (cond ((and (= (char-width ch) 1) + (not (or (<= #x1f200 ch #x1ffff)))) + (when state (princ "*]") (setf state nil)) + (write-char ch)) + (t + (princ (if state "*" "[*")) + (princ (format "#x%x" ch)) + (setf state t)))) + (setq i (1+ i))) + (when state (princ "*]"))))) + +(setq erc-replace-alist + '(("[[:nonascii:]+]" . mdw-replace-wide-characters))) + (setq erc-track-exclude-types '("NICK" "JOIN" "PART")) (setq erc-auto-query 'buffer)