--- rcirc.el 2012-07-25 23:52:41.813226461 +0800 +++ rcirc-1.el 2012-07-25 23:55:20.813220626 +0800 @@ -792,21 +792,40 @@ (defvar rcirc-max-message-length 420 "Messages longer than this value will be split.") +(defun rcirc-multibyte-position-at-byte (str bytes) + (if (multibyte-string-p str) + (rcirc-multibyte-position-at-byte-1 str bytes 0 0) + bytes)) + +(defun rcirc-multibyte-position-at-byte-1 (str bytes now-chars now-bytes) + (let ((len (length str))) + (if (<= len 1) + now-chars + (let* ((half-len (/ len 2)) + (lstr (substring str 0 half-len)) + (rstr (substring str half-len len)) + (now-bytes-1 (+ now-bytes (string-bytes lstr)))) + (if (> now-bytes-1 bytes) + (rcirc-multibyte-position-at-byte-1 lstr bytes now-chars now-bytes) + (rcirc-multibyte-position-at-byte-1 rstr bytes (+ half-len now-chars) now-bytes-1)))))) + (defun rcirc-send-message (process target message &optional noticep silent) "Send TARGET associated with PROCESS a privmsg with text MESSAGE. If NOTICEP is non-nil, send a notice instead of privmsg. If SILENT is non-nil, do not print the message in any irc buffer." ;; max message length is 512 including CRLF (let* ((response (if noticep "NOTICE" "PRIVMSG")) - (oversize (> (length message) rcirc-max-message-length)) + (oversize (> (string-bytes message) rcirc-max-message-length)) + (adjusted-pos (if oversize + (rcirc-multibyte-position-at-byte message rcirc-max-message-length))) (text (if oversize - (substring message 0 rcirc-max-message-length) + (substring message 0 adjusted-pos) message)) (text (if (string= text "") " " text)) (more (if oversize - (substring message rcirc-max-message-length)))) + (substring message adjusted-pos)))) (rcirc-get-buffer-create process target) (rcirc-send-string process (concat response " " target " :" text)) (unless silent