-(defun nntp-async-wait (process wait-for buffer decode callback)
- (save-excursion
- (set-buffer (process-buffer process))
- (unless nntp-inside-change-function
- (erase-buffer))
- (setq nntp-process-wait-for wait-for
- nntp-process-to-buffer buffer
- nntp-process-decode decode
- nntp-process-callback callback
- nntp-process-start-point (point-max))
- (setq after-change-functions '(nntp-after-change-function))
- (if nntp-async-needs-kluge
- (nntp-async-kluge process))))
-
-(defun nntp-async-kluge (process)
- ;; emacs 20.3 bug: process output with encoding 'binary
- ;; doesn't trigger after-change-functions.
- (unless nntp-async-timer
- (setq nntp-async-timer
- (nnheader-run-at-time 1 1 'nntp-async-timer-handler)))
- (add-to-list 'nntp-async-process-list process))
-
-(defun nntp-async-timer-handler ()
- (mapcar
- (lambda (proc)
- (if (memq (process-status proc) '(open run))
- (nntp-async-trigger proc)
- (nntp-async-stop proc)))
- nntp-async-process-list))
-
-(defun nntp-async-stop (proc)
- (setq nntp-async-process-list (delq proc nntp-async-process-list))
- (when (and nntp-async-timer (not nntp-async-process-list))
- (nnheader-cancel-timer nntp-async-timer)
- (setq nntp-async-timer nil)))
-
-(defun nntp-after-change-function (beg end len)
- (unwind-protect
- ;; we only care about insertions at eob
- (when (and (eq 0 len) (eq (point-max) end))
- (save-match-data
- (let ((proc (get-buffer-process (current-buffer))))
- (when proc
- (nntp-async-trigger proc)))))
- ;; any throw from after-change-functions will leave it
- ;; set to nil. so we reset it here, if necessary.
- (when quit-flag
- (setq after-change-functions '(nntp-after-change-function)))))
-
-(defun nntp-async-trigger (process)
- (save-excursion
- (set-buffer (process-buffer process))
- (when nntp-process-callback
- ;; do we have an error message?
- (goto-char nntp-process-start-point)
- (if (memq (following-char) '(?4 ?5))
- ;; wants credentials?
- (if (looking-at "480")
- (nntp-handle-authinfo nntp-process-to-buffer)
- ;; report error message.
- (nntp-snarf-error-message)
- (nntp-do-callback nil))
-
- ;; got what we expect?
- (goto-char (point-max))
- (when (re-search-backward
- nntp-process-wait-for nntp-process-start-point t)
- (nntp-async-stop process)
- ;; convert it.
+(defun nntp-after-change-function-callback (beg end len)
+ (when nntp-process-callback
+ (save-match-data
+ (if (and (= beg (point-min))
+ (memq (char-after beg) '(?4 ?5)))
+ ;; Report back error messages.
+ (save-excursion
+ (goto-char beg)
+ (if (looking-at "480")
+ (nntp-handle-authinfo nntp-process-to-buffer)
+ (nntp-snarf-error-message)
+ (funcall nntp-process-callback nil)))
+ (goto-char end)
+ (when (and (> (point) nntp-process-start-point)
+ (re-search-backward nntp-process-wait-for
+ nntp-process-start-point t))