Fix watch so it doesn't throw errors
This commit is contained in:
parent
5b6fd432de
commit
a44a296296
19
watch.el
19
watch.el
@ -19,6 +19,8 @@
|
|||||||
"Seconds between polls. This is the watch rate, not the frame rate.")
|
"Seconds between polls. This is the watch rate, not the frame rate.")
|
||||||
|
|
||||||
(defvar clj-watch--timer nil)
|
(defvar clj-watch--timer nil)
|
||||||
|
(defvar clj-watch--connection nil
|
||||||
|
"The CIDER connection buffer to poll, captured when watching starts.")
|
||||||
|
|
||||||
(defun clj-watch--paint (text)
|
(defun clj-watch--paint (text)
|
||||||
"Replace the watch buffer's contents with TEXT."
|
"Replace the watch buffer's contents with TEXT."
|
||||||
@ -36,17 +38,24 @@
|
|||||||
|
|
||||||
(defun clj-watch--tick ()
|
(defun clj-watch--tick ()
|
||||||
"Poll the snapshot once, asynchronously."
|
"Poll the snapshot once, asynchronously."
|
||||||
(if (not (get-buffer clj-watch-buffer))
|
(cond
|
||||||
(clj-watch-stop)
|
((not (get-buffer clj-watch-buffer)) (clj-watch-stop))
|
||||||
|
((not (buffer-live-p clj-watch--connection))
|
||||||
|
(clj-watch--paint "error:\nCIDER connection lost")
|
||||||
|
(clj-watch-stop))
|
||||||
|
(t
|
||||||
;; Async, not `cider-nrepl-sync-request': a sync request on a timer blocks
|
;; Async, not `cider-nrepl-sync-request': a sync request on a timer blocks
|
||||||
;; Emacs's UI thread every tick.
|
;; Emacs's UI thread every tick. Pass the connection explicitly -- the
|
||||||
|
;; timer fires with no reliable "current buffer" to resolve one from.
|
||||||
(cider-nrepl-request:eval
|
(cider-nrepl-request:eval
|
||||||
"(watch/render)"
|
"(watch/render)"
|
||||||
(lambda (response)
|
(lambda (response)
|
||||||
(nrepl-dbind-response response (value err)
|
(nrepl-dbind-response response (value err)
|
||||||
(cond
|
(cond
|
||||||
(err (clj-watch--paint (format "error:\n%s" err)))
|
(err (clj-watch--paint (format "error:\n%s" err)))
|
||||||
(value (clj-watch--paint (car (read-from-string value))))))))))
|
(value (clj-watch--paint (car (read-from-string value)))))))
|
||||||
|
nil nil nil nil
|
||||||
|
clj-watch--connection))))
|
||||||
|
|
||||||
(define-derived-mode clj-watch-mode special-mode "clj-watch"
|
(define-derived-mode clj-watch-mode special-mode "clj-watch"
|
||||||
"Major mode for the pinned watch buffer."
|
"Major mode for the pinned watch buffer."
|
||||||
@ -56,7 +65,7 @@
|
|||||||
(defun clj-watch ()
|
(defun clj-watch ()
|
||||||
"Open the pinned watch buffer and start polling."
|
"Open the pinned watch buffer and start polling."
|
||||||
(interactive)
|
(interactive)
|
||||||
(cider-current-repl nil 'ensure)
|
(setq clj-watch--connection (cider-current-repl nil 'ensure))
|
||||||
(with-current-buffer (get-buffer-create clj-watch-buffer)
|
(with-current-buffer (get-buffer-create clj-watch-buffer)
|
||||||
(unless (eq major-mode 'clj-watch-mode)
|
(unless (eq major-mode 'clj-watch-mode)
|
||||||
(clj-watch-mode)))
|
(clj-watch-mode)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user