(let ((reqs (assoc :requests c))
(current (assoc :current c)))
(setcdr current (prog1 (cadr reqs) (setcdr reqs (cddr reqs))))
- (if (and current (fuel-con--request-deactivated-p current))
+ (if (and (cdr current)
+ (fuel-con--request-deactivated-p (cdr current)))
(fuel-con--connection-pop-request c)
current)))
(add-hook 'comint-redirect-filter-functions
'fuel-con--comint-redirect-filter t t))
+\f
+;;; Logging:
+
+(defvar fuel-con--log-size 32000
+ "Maximum size of the Factor messages log.")
+
+(defvar fuel-con--log-verbose-p t
+ "Log level for Factor messages.")
+
+(define-derived-mode factor-messages-mode fundamental-mode "Factor Messages"
+ "Simple mode to log interactions with the factor listener"
+ (kill-all-local-variables)
+ (buffer-disable-undo)
+ (set (make-local-variable 'comint-redirect-subvert-readonly) t)
+ (add-hook 'after-change-functions
+ '(lambda (b e len)
+ (let ((inhibit-read-only t))
+ (when (> b fuel-con--log-size)
+ (delete-region (point-min) b))))
+ nil t)
+ (setq buffer-read-only t))
+
+(defun fuel-con--log-buffer ()
+ (or (get-buffer "*factor messages*")
+ (save-current-buffer
+ (set-buffer (get-buffer-create "*factor messages*"))
+ (factor-messages-mode)
+ (current-buffer))))
+
+(defsubst fuel-con--log-msg (type &rest args)
+ (format "\n%s: %s\n" type (apply 'format args)))
+
+(defsubst fuel-con--log-warn (&rest args)
+ (apply 'fuel-con--log-msg 'WARNING args))
+
+(defsubst fuel-con--log-error (&rest args)
+ (apply 'fuel-con--log-msg 'ERROR args))
+
+(defsubst fuel-con--log-info (&rest args)
+ (if fuel-con--log-verbose-p (apply 'fuel-con--log-msg 'INFO args) ""))
+
\f
;;; Requests handling:
(str (and req (fuel-con--request-string req))))
(when (and buffer req str)
(set-buffer buffer)
- (comint-redirect-send-command str
- (get-buffer-create "*factor messages*")
- nil
- t)))))
+ (when fuel-con--log-verbose-p
+ (with-current-buffer (fuel-con--log-buffer)
+ (let ((inhibit-read-only t))
+ (insert (fuel-con--log-info "<%s>: %s"
+ (fuel-con--request-id req) str)))))
+ (comint-redirect-send-command str (fuel-con--log-buffer) nil t)))))
(defun fuel-con--comint-redirect-filter (str)
(if (not fuel-con--connection)
- (format "\nERROR: No connection in buffer (%s)\n" str)
+ (fuel-con--log-error "No connection in buffer (%s)" str)
(let ((req (fuel-con--connection-current-request fuel-con--connection)))
- (if (not req) (format "\nERROR: No current request (%s)\n" str)
+ (if (not req) (fuel-con--log-error "No current request (%s)" str)
(let ((cont (fuel-con--request-continuation req))
(id (fuel-con--request-id req))
(rstr (fuel-con--request-string req))
(buffer (fuel-con--request-buffer req)))
(prog1
(if (not cont)
- (format "\nWARNING: Droping result for request %s:%S (%s)\n"
- id rstr str)
+ (fuel-con--log-warn "<%s> Droping result for request %S (%s)"
+ id rstr str)
(condition-case cerr
(with-current-buffer (or buffer (current-buffer))
(funcall cont str)
- (format "\nINFO: %s:%S processed\nINFO: %s\n" id rstr str))
- (error (format "\nERROR: continuation failed %s:%S \nERROR: %s\n"
- id rstr cerr))))
+ (fuel-con--log-info "<%s>: processed\n\t%s" id str))
+ (error (fuel-con--log-error "<%s>: continuation failed %S \n\t%s"
+ id rstr cerr))))
(fuel-con--connection-clean-current-request fuel-con--connection)))))))
\f