aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/server.el
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2011-05-02 04:06:53 +0200
committerLars Magne Ingebrigtsen2011-05-02 04:06:53 +0200
commite793a9404da8d8cb0d318f5ba87998e2be6ecb50 (patch)
tree175ab5ecf4a07276597c981d174caf29e4dd87e0 /lisp/server.el
parent817bcc7cb0dbc976aa3e7bc2c3940bb54784869e (diff)
downloademacs-e793a9404da8d8cb0d318f5ba87998e2be6ecb50.tar.gz
emacs-e793a9404da8d8cb0d318f5ba87998e2be6ecb50.zip
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."
1484 ;; continue standard unloading 1484 ;; continue standard unloading
1485 nil) 1485 nil)
1486 1486
1487(defun server-eval-at (server form)
1488 "Eval FORM on Emacs Server SERVER."
1489 (let ((auth-file (expand-file-name server server-auth-dir))
1490 ;;(coding-system-for-read 'binary)
1491 ;;(coding-system-for-write 'binary)
1492 address port secret process)
1493 (unless (file-exists-p auth-file)
1494 (error "No such server definition: %s" auth-file))
1495 (with-temp-buffer
1496 (insert-file-contents auth-file)
1497 (unless (looking-at "\\([0-9.]+\\):\\([0-9]+\\)")
1498 (error "Invalid auth file"))
1499 (setq address (match-string 1)
1500 port (string-to-number (match-string 2)))
1501 (forward-line 1)
1502 (setq secret (buffer-substring (point) (line-end-position)))
1503 (erase-buffer)
1504 (unless (setq process (open-network-stream "eval-at" (current-buffer)
1505 address port))
1506 (error "Unable to contact the server"))
1507 (set-process-query-on-exit-flag process nil)
1508 (process-send-string
1509 process
1510 (concat "-auth " secret " -eval "
1511 (replace-regexp-in-string
1512 " " "&_" (format "%S" form))
1513 "\n"))
1514 (while (memq (process-status process) '(open run))
1515 (accept-process-output process 0 10))
1516 (goto-char (point-min))
1517 ;; If the result is nil, there's nothing in the buffer. If the
1518 ;; result is non-nil, it's after "-print ".
1519 (and (search-forward "\n-print" nil t)
1520 (read (current-buffer))))))
1521
1487 1522
1488(provide 'server) 1523(provide 'server)
1489 1524