summaryrefslogtreecommitdiff
path: root/lisp/net/rcirc.el
diff options
context:
space:
mode:
authorLeo Liu <sdl.web@gmail.com>2012-08-14 01:22:42 +0800
committerLeo Liu <sdl.web@gmail.com>2012-08-14 01:22:42 +0800
commit4432d2e25bc56cd06c9ed0c987d6570b2d57f230 (patch)
treeb4e8307ebc973f70d7392cf84d6fdbc62197862b /lisp/net/rcirc.el
parent170aedb97ebee3edb81d2c447e6baa465978b03f (diff)
downloademacs-4432d2e25bc56cd06c9ed0c987d6570b2d57f230.tar.gz
emacs-4432d2e25bc56cd06c9ed0c987d6570b2d57f230.tar.bz2
emacs-4432d2e25bc56cd06c9ed0c987d6570b2d57f230.zip
* lisp/net/rcirc.el (rcirc-split-message): New function.
(rcirc-send-message): Use it. Fixes: debbugs:12051
Diffstat (limited to 'lisp/net/rcirc.el')
-rw-r--r--lisp/net/rcirc.el39
1 files changed, 24 insertions, 15 deletions
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index e34b7c79b3b..0eb6c7ea51b 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -794,26 +794,35 @@ With no argument or nil as argument, use the current buffer."
(defvar rcirc-max-message-length 420
"Messages longer than this value will be split.")
+(defun rcirc-split-message (message)
+ "Split MESSAGE into chunks within `rcirc-max-message-length'."
+ (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)
+ rcirc-encode-coding-system t))
+ rcirc-max-message-length))
+ (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.
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))
- (text (if oversize
- (substring message 0 rcirc-max-message-length)
- message))
- (text (if (string= text "")
- " "
- text))
- (more (if oversize
- (substring message rcirc-max-message-length))))
+ (let ((response (if noticep "NOTICE" "PRIVMSG")))
(rcirc-get-buffer-create process target)
- (rcirc-send-string process (concat response " " target " :" text))
- (unless silent
- (rcirc-print process (rcirc-nick process) response target text))
- (when more (rcirc-send-message process target more noticep))))
+ (dolist (msg (rcirc-split-message message))
+ (rcirc-send-string process (concat response " " target " :" msg))
+ (unless silent
+ (rcirc-print process (rcirc-nick process) response target msg)))))
(defvar rcirc-input-ring nil)
(defvar rcirc-input-ring-index 0)