branch: elpa/idris-mode commit 7ba6e9b6abb0ba605d5d008a612f2c1cf4affb3a Author: Marek L <nospam.ke...@gmail.com> Commit: Marek L <nospam.ke...@gmail.com>
Preserve current source code buffer as current when receiving input from Idris compiler Why: Allows processing event hooks relatively to the current source code buffer. --- inferior-idris.el | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/inferior-idris.el b/inferior-idris.el index b54f52de5e..0901d74878 100644 --- a/inferior-idris.el +++ b/inferior-idris.el @@ -159,31 +159,30 @@ This is maintained to restart Idris when the arguments change.") (defun idris-connection-available-input (process) "Process all complete messages which arrived from Idris PROCESS." + (while (idris-have-input-p process) + (let ((event (idris-receive process))) + (idris-event-log event nil) + (idris-dispatch-event event process)))) + +(defun idris-have-input-p (process) + "Return `true' if a complete message is available in PROCESS buffer." + (with-current-buffer (process-buffer process) + (goto-char (point-min)) + (and (>= (buffer-size) 6) + (>= (- (buffer-size) 6) (idris-decode-length))))) + +(defun idris-receive (process) + "Read a message from the Idris PROCESS." (with-current-buffer (process-buffer process) - (while (idris-have-input-p) - (let ((event (idris-receive))) - (idris-event-log event nil) - (unwind-protect - (save-current-buffer - (idris-dispatch-event event process))))))) - -(defun idris-have-input-p () - "Return true if a complete message is available." - (goto-char (point-min)) - (and (>= (buffer-size) 6) - (>= (- (buffer-size) 6) (idris-decode-length)))) - -(defun idris-receive () - "Read a message from the Idris process." - (goto-char (point-min)) - (let* ((length (idris-decode-length)) - (start (+ 6 (point))) - (end (+ start length))) - (cl-assert (cl-plusp length)) - (prog1 (save-restriction - (narrow-to-region start end) - (read (current-buffer))) - (delete-region (point-min) end)))) + (goto-char (point-min)) + (let* ((length (idris-decode-length)) + (start (+ 6 (point))) + (end (+ start length))) + (cl-assert (cl-plusp length)) + (prog1 (save-restriction + (narrow-to-region start end) + (read (current-buffer))) + (delete-region (point-min) end))))) (defun idris-decode-length () "Read a 24-bit hex-encoded integer from buffer."