Skip to content

Commit

Permalink
Small cleanup of old code. Use 'ignore-errors' to skip stack limit hi…
Browse files Browse the repository at this point in the history
…ts; needs better approach.
  • Loading branch information
sanel committed Oct 24, 2014
1 parent f89ce9b commit 80e0f66
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions monroe.el
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ to the one used on nrepl side.")
(string-to-number (match-string 1)))
((looking-at "\\([0-9]+\\):")
(goto-char (match-end 0))
(let ((start (point))
(end (byte-to-position (+ (position-bytes (point)) (string-to-number (match-string 1))))))
(when (and start end)
(goto-char end)
(buffer-substring-no-properties start end))))
(let* ((start (point))
(end (byte-to-position (+ (position-bytes start) (string-to-number (match-string 1))))))
(goto-char end)
(buffer-substring-no-properties start end)))
((looking-at "l")
(goto-char (match-end 0))
(let (result item)
Expand Down Expand Up @@ -289,12 +288,18 @@ monroe-repl-buffer."
(with-current-buffer (process-buffer process)
(goto-char (point-max))
(insert string)
;; Wait until receive the end of the message. Idea stolen from Cider.
(when (eq ?e (aref string (1- (length string))))
(unless (accept-process-output process 0.01)
(while (> (buffer-size) 1)
(dolist (response (monroe-net-decode))
(monroe-dispatch response)))))))
;; Stolen from Cider. Assure we have end of the message so decoding can work;
;; to make sure we are at the real end (session id can contain 'e' character), we call
;; 'accept-process-output' once more.
;;
;; This 'ignore-errors' is a hard hack here since 'accept-process-output' will call filter
;; which will be this function causing Emacs to hit max stack size limit.
(ignore-errors
(when (eq ?e (aref string (- (length string) 1)))
(unless (accept-process-output process 0.01)
(while (> (buffer-size) 1)
(dolist (response (monroe-net-decode))
(monroe-dispatch response))))))))

(defun monroe-new-session-handler (process)
"Returns callback that is called when new connection is established."
Expand Down

0 comments on commit 80e0f66

Please sign in to comment.