
(provide (quote chat))

(require (quote backquote))

(defvar chat/data-marker nil "\
A buffer's data marker.")

(make-variable-buffer-local (quote chat/data-marker))

(defmacro chat/set-data-marker (location) "Set the current buffer's data marker to LOCATION.  Returns the data
marker." (byte-code "ÁÂE‡" [location set-marker (if (markerp chat/data-marker) chat/data-marker (setq chat/data-marker (make-marker)))] 3))

(put (quote no-process) (quote error-conditions) (quote (error no-process)))

(put (quote no-process) (quote error-message) "Connection is broken")

(defmacro chat/with-buffer-of (proc &rest forms) "Set the current buffer to PROC's buffer, and evaluate FORMS." (byte-code "ÂÃÄÅDDD	\"‡" [proc forms append save-excursion set-buffer process-buffer] 5))

(put (quote chat/with-buffer-of) (quote lisp-indent-hook) 1)

(defmacro chat/accept-from (proc) (byte-code "ÁÂÃDÄEÅDÆÇEF‡" [proc if memq process-status (quote (open run)) accept-process-output signal (quote no-process)] 6))

(defun chat/wait-for-length (size proc) "\
Wait until we have SIZE characters of data from PROC.  When
successful, returns true and sets PROC's data mark to the location
after SIZE.  Does not change the match data.  Signals 'no-process if
PROC has died." (byte-code "ŠÃ!qˆde	\\W…$ Ä!Å>ƒ Æ!‚  ÇÈ\"ˆ‚ ˆÉÊ
!ƒ0 
‚4 Ë ‰e	\\\")‡" [proc size chat/data-marker process-buffer process-status (open run) accept-process-output signal no-process set-marker markerp make-marker] 10))

(defun chat/wait-for-string (string proc) "\
Wait until we see STRING in PROC's data.  When successful, returns
true and sets PROC's data mark to the end of the STRING match.  Also
sets the match data.  Signals 'no-process if PROC has died." (byte-code "ŠÄ!qˆebˆÅ	ÂÆ#?…. `	GZÇ!È>ƒ$ É!‚( ÊË\"ˆbˆ‚	 ˆÌÍ!ƒ: ‚> Î ‰`\")‡" [proc string nil chat/data-marker process-buffer search-forward eob process-status (open run) accept-process-output signal no-process set-marker markerp make-marker] 10))

(defun chat/wait-for-regexp (regexp proc) "\
Wait until we see REGEXP in PROC's data.  When successful, returns
true and sets PROC's data mark to the end of the REGEXP match.  Also
sets the match data.  Signals 'no-process if PROC has died." (byte-code "ŠÅ!qˆŠebˆÆ	ÂÃ#?…, Ç!È>ƒ! É!‚% ÊË\"ˆebˆ‚
 ˆÌÍ!ƒ8 ‚< Î ‰`\"))‡" [proc regexp nil t chat/data-marker process-buffer re-search-forward process-status (open run) accept-process-output signal no-process set-marker markerp make-marker] 10))

(defun chat/wait-for-dot-crlf (proc) "\
The same as (chat/wait-for-regexp \"^\\\\.\\r\\n\" PROC), but
considerably faster." (byte-code "ŠÃ!qˆŠebˆÄÅ!?…? ÆÇÁÈ#… ÄÉ!?…? m…; `ÊZË!Ì>ƒ5 Í!‚9 ÎÏ\"ˆbˆ‚ ˆÐ ˆÑÒ
!ƒN 
‚R Ó ‰`\"))‡" [proc nil chat/data-marker process-buffer looking-at ".?
" search-forward "
." eob "?
" 3 process-status (open run) accept-process-output signal no-process forward-line set-marker markerp make-marker] 13))

(defmacro chat/with-data-of (proc &rest forms) "Set the current buffer to PROC's buffer, narrowed to the region up
to PROC's data mark, and evaluate FORMS.  And then the data up to the
data mark is deleted.  Returns the value of FORMS.

If you discover you didn't really need all the data and want to push
some back, use 'chat/set-data-marker to change the data mark.  Or
consider using 'chat/with-buffer-of instead." (byte-code "ÂÃÄÅ	\"ÆEE‡" [proc forms chat/with-buffer-of prog1 append (save-restriction (narrow-to-region (point-min) chat/data-marker)) (delete-region (point-min) chat/data-marker)] 6))

(put (quote chat/with-data-of) (quote lisp-indent-hook) 1)

(defun chat/data-of (proc) "\
Returns a string that contains PROC's data up to its data mark, and
deletes the data.  If you need to do any parsing, you probably want to
be using 'chat/with-data-of instead." (byte-code "ŠÂ!qˆŒÃe	\"ˆÄ Åed\"ˆ)Åe	\"ˆ)‡" [proc chat/data-marker process-buffer narrow-to-region buffer-string delete-region] 8))

(defun chat/delete-pending-data (proc) "\
Clear out as much of PROC's pending data that we can without
blocking.  Returns nothing." (byte-code "ŠÁ!qˆÂ ˆedW… Ãed\"ˆÄ ˆ‚	 )‡" [proc process-buffer widen delete-region accept-process-output] 6))

(defmacro chat/with-data-for-length (length proc &rest forms) "(LENGTH PROC FORMS ...).  Equivalent to
	(chat/wait-for-length LENGTH PROC)
	(chat/with-data-of PROC FORMS ...)
" (byte-code "ÃÄ	EÅÆ	D
\"E‡" [length proc forms progn chat/wait-for-length append chat/with-data-of] 5))

(put (quote chat/with-data-for-length) (quote lisp-indent-hook) 2)

(defmacro chat/with-data-until-string (string proc &rest forms) "(STRING PROC FORMS ...).  Equivalent to
	(chat/wait-for-string STRING PROC)
	(chat/with-data-of PROC FORMS ...)
" (byte-code "ÃÄ	EÅÆ	D
\"E‡" [string proc forms progn chat/wait-for-string append chat/with-data-of] 5))

(put (quote chat/with-data-until-string) (quote lisp-indent-hook) 2)

(defmacro chat/with-data-until-regexp (regexp proc &rest forms) "(REGEXP PROC FORMS ...).  Equivalent to
	(chat/wait-for-regexp REGEXP PROC)
	(chat/with-data-of PROC FORMS ...)
" (byte-code "ÃÄ	EÅÆ	D
\"E‡" [regexp proc forms progn chat/wait-for-regexp append chat/with-data-of] 5))

(put (quote chat/with-data-until-regexp) (quote lisp-indent-hook) 2)

(defmacro chat/with-data-until-dot-crlf (proc &rest forms) "(PROC FORMS ...).  Equivalent to
	(chat/wait-for-dot-crlf PROC)
	(chat/with-data-of PROC FORMS ...)
" (byte-code "ÂÃDÄÅD	\"E‡" [proc forms progn chat/wait-for-dot-crlf append chat/with-data-of] 5))

(put (quote chat/with-data-until-dot-crlf) (quote lisp-indent-hook) 1)
