summaryrefslogtreecommitdiff
path: root/lisp/server.el
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen <larsi@gnus.org>2011-05-02 04:06:53 +0200
committerLars Magne Ingebrigtsen <larsi@gnus.org>2011-05-02 04:06:53 +0200
commite793a9404da8d8cb0d318f5ba87998e2be6ecb50 (patch)
tree175ab5ecf4a07276597c981d174caf29e4dd87e0 /lisp/server.el
parent817bcc7cb0dbc976aa3e7bc2c3940bb54784869e (diff)
downloademacs-e793a9404da8d8cb0d318f5ba87998e2be6ecb50.tar.gz
Implement and document `server-eval-at'.
Diffstat (limited to 'lisp/server.el')
-rw-r--r--lisp/server.el35
1 files changed, 35 insertions, 0 deletions
diff --git a/lisp/server.el b/lisp/server.el
index ce14f133f0a..ab7dd409736 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1484,6 +1484,41 @@ only these files will be asked to be saved."
;; continue standard unloading
nil)
+(defun server-eval-at (server form)
+ "Eval FORM on Emacs Server SERVER."
+ (let ((auth-file (expand-file-name server server-auth-dir))
+ ;;(coding-system-for-read 'binary)
+ ;;(coding-system-for-write 'binary)
+ address port secret process)
+ (unless (file-exists-p auth-file)
+ (error "No such server definition: %s" auth-file))
+ (with-temp-buffer
+ (insert-file-contents auth-file)
+ (unless (looking-at "\\([0-9.]+\\):\\([0-9]+\\)")
+ (error "Invalid auth file"))
+ (setq address (match-string 1)
+ port (string-to-number (match-string 2)))
+ (forward-line 1)
+ (setq secret (buffer-substring (point) (line-end-position)))
+ (erase-buffer)
+ (unless (setq process (open-network-stream "eval-at" (current-buffer)
+ address port))
+ (error "Unable to contact the server"))
+ (set-process-query-on-exit-flag process nil)
+ (process-send-string
+ process
+ (concat "-auth " secret " -eval "
+ (replace-regexp-in-string
+ " " "&_" (format "%S" form))
+ "\n"))
+ (while (memq (process-status process) '(open run))
+ (accept-process-output process 0 10))
+ (goto-char (point-min))
+ ;; If the result is nil, there's nothing in the buffer. If the
+ ;; result is non-nil, it's after "-print ".
+ (and (search-forward "\n-print" nil t)
+ (read (current-buffer))))))
+
(provide 'server)