2019-01-14 17:21:36 +00:00
|
|
|
;;; john_titor --- Enables RPC for john titor client
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
|
|
(require 'epc)
|
|
|
|
|
|
|
|
(defvar epc-connection nil
|
|
|
|
"The EPC connection to the john titor client.")
|
|
|
|
|
|
|
|
(defun john_titor/connect ()
|
|
|
|
"Connect to john titor via RPC."
|
|
|
|
(setq epc-connection
|
2019-01-14 22:14:29 +00:00
|
|
|
(if debug-on-error
|
2019-03-19 21:06:04 +00:00
|
|
|
(epc:start-epc "node" (list (concat
|
|
|
|
(getenv "HOME")
|
|
|
|
"/.fg42/john_titor/target/main.js")))
|
|
|
|
(epc:start-epc "node" (list (concat
|
|
|
|
(getenv "HOME")
|
|
|
|
"/.fg42/john_titor/app.js"))))))
|
2019-01-14 17:21:36 +00:00
|
|
|
|
|
|
|
(defun john_titor/call-sync (command args)
|
|
|
|
"Call the given COMMAND with the given ARGS via john titor epc."
|
2019-03-19 21:06:04 +00:00
|
|
|
(epc:call-sync epc-connection command args))
|
2019-01-14 17:21:36 +00:00
|
|
|
|
2019-03-19 21:06:04 +00:00
|
|
|
(defun eval-string (str)
|
|
|
|
"Evaluate the given STR."
|
|
|
|
(message str)
|
|
|
|
(eval (car (read-from-string (format "(progn %s)" str)))))
|
2019-01-14 17:21:36 +00:00
|
|
|
|
|
|
|
(defun john_titor/call (command args f)
|
|
|
|
"Call the COMMAND with the given ARGS in async fashion and call F as callback."
|
|
|
|
(deferred:$
|
|
|
|
(epc:call-deferred epc-connection command args)
|
2019-03-19 21:06:04 +00:00
|
|
|
(deferred:nextc it
|
|
|
|
(lambda (x)
|
|
|
|
(funcall f x)))
|
|
|
|
(deferred:error it
|
|
|
|
(lambda (err)
|
|
|
|
(message "ERROR: %s" err)))))
|
2019-01-14 17:21:36 +00:00
|
|
|
|
|
|
|
(defun john_titor/disconnect ()
|
|
|
|
"Disconnect from the john titor client."
|
2019-03-19 21:06:04 +00:00
|
|
|
(epc:stop-epc epc-connection)
|
|
|
|
(setq epc-connection nil))
|
2019-01-14 17:21:36 +00:00
|
|
|
|
2019-03-19 21:06:04 +00:00
|
|
|
(defun john_titor/restart ()
|
|
|
|
"Restart the epc server."
|
|
|
|
(john_titor/disconnect)
|
|
|
|
(john_titor/connect))
|
2019-01-14 17:21:36 +00:00
|
|
|
|
|
|
|
(provide 'john_titor)
|
|
|
|
;;; john_titor.el ends here
|