From: Leo <sdl.web@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Li Ian-Xue <b4283@bephor.org>, 12051@debbugs.gnu.org
Subject: bug#12051: 24.1; rcirc-send-message doesn't take multibyte into account.
Date: Wed, 15 Aug 2012 21:10:45 +0800 [thread overview]
Message-ID: <m1k3x02td6.fsf@gmail.com> (raw)
In-Reply-To: <83628kkgjw.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 15 Aug 2012 05:57:55 +0300")
On 2012-08-15 10:57 +0800, Eli Zaretskii wrote:
> You can always stop at known characters, like whitespace.
>
> Anyway, another way is simply to assume the worst possible expansion
> ratio, and estimate the byte count before encoding.
I make a small optimisation that calls encode-coding-region char by
char. Comments?
=== modified file 'lisp/net/rcirc.el'
--- lisp/net/rcirc.el 2012-08-15 12:26:48 +0000
+++ lisp/net/rcirc.el 2012-08-15 13:06:15 +0000
@@ -797,22 +797,24 @@
(defun rcirc-split-message (message)
"Split MESSAGE into chunks within `rcirc-max-message-length'."
;; `rcirc-encode-coding-system' can have buffer-local value.
- (let ((encoding rcirc-encode-coding-system))
+ (let ((encoding rcirc-encode-coding-system)
+ result oversize)
(with-temp-buffer
(insert message)
(goto-char (point-min))
- (let (result)
- (while (not (eobp))
- (goto-char (or (byte-to-position rcirc-max-message-length)
- (point-max)))
- ;; max message length is 512 including CRLF
- (while (and (not (bobp))
- (> (length (encode-coding-region
- (point-min) (point) encoding t))
- rcirc-max-message-length))
- (forward-char -1))
- (push (delete-and-extract-region (point-min) (point)) result))
- (nreverse result)))))
+ (while (not (eobp))
+ (goto-char (or (byte-to-position rcirc-max-message-length)
+ (point-max)))
+ ;; Max message length is 512 including CRLF
+ (setq oversize (- (length (encode-coding-region
+ (point-min) (point) encoding t))
+ rcirc-max-message-length))
+ (while (and (not (bobp)) (> oversize 0))
+ (decf oversize (length (encode-coding-region
+ (1- (point)) (point) encoding t)))
+ (forward-char -1))
+ (push (delete-and-extract-region (point-min) (point)) result)))
+ (nreverse result)))
(defun rcirc-send-message (process target message &optional noticep silent)
"Send TARGET associated with PROCESS a privmsg with text MESSAGE.
next prev parent reply other threads:[~2012-08-15 13:10 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 16:18 bug#12051: 24.1; rcirc-send-message doesn't take multibyte into account Li Ian-Xue
2012-08-13 1:53 ` Leo
2012-08-14 13:11 ` Leo
2012-08-14 15:45 ` Eli Zaretskii
[not found] ` <874no4apau.fsf@acerpad.localdomain>
2012-08-15 2:57 ` Eli Zaretskii
2012-08-15 13:10 ` Leo [this message]
2012-08-15 13:29 ` Chong Yidong
2012-08-15 15:45 ` Chong Yidong
2012-08-15 22:55 ` Leo
2012-08-15 16:59 ` Eli Zaretskii
2012-08-15 17:53 ` Li Ian-Xue
2012-08-15 22:54 ` Leo
2012-08-15 23:00 ` Leo
2012-08-16 2:50 ` Eli Zaretskii
2012-08-16 3:16 ` Leo
2012-08-16 15:20 ` Eli Zaretskii
2012-08-16 17:17 ` Leo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1k3x02td6.fsf@gmail.com \
--to=sdl.web@gmail.com \
--cc=12051@debbugs.gnu.org \
--cc=b4283@bephor.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).