diff options
| -rw-r--r-- | doc/emacs/ChangeLog | 4 | ||||
| -rw-r--r-- | doc/emacs/misc.texi | 9 | ||||
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/server.el | 35 |
4 files changed, 52 insertions, 0 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index 92cd765b492..efe031d465b 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2011-05-02 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 2 | |||
| 3 | * misc.texi (Emacs Server): Document `server-eval-at'. | ||
| 4 | |||
| 1 | 2011-04-24 Chong Yidong <cyd@stupidchicken.com> | 5 | 2011-04-24 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 6 | ||
| 3 | * maintaining.texi (List Tags): Document next-file. Suggested by | 7 | * maintaining.texi (List Tags): Document next-file. Suggested by |
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 1299895a06e..06267851d4c 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi | |||
| @@ -1495,6 +1495,15 @@ server-name @key{RET} foo @key{RET}} sets the server name to | |||
| 1495 | @samp{foo}. The @code{emacsclient} program can specify a server by | 1495 | @samp{foo}. The @code{emacsclient} program can specify a server by |
| 1496 | name, using the @samp{-s} option (@pxref{emacsclient Options}). | 1496 | name, using the @samp{-s} option (@pxref{emacsclient Options}). |
| 1497 | 1497 | ||
| 1498 | @findex server-eval-at | ||
| 1499 | If you have defined a server by a unique server name, you can | ||
| 1500 | connect to this server from other Emacs instances and evaluate forms | ||
| 1501 | on it by using the @code{server-eval-at} function. | ||
| 1502 | |||
| 1503 | @code{(server-eval-at "foo" '(+ 1 2))} gives the result @code{3}, if | ||
| 1504 | there's a server with that name that is listening. If not, an error | ||
| 1505 | will be signaled. | ||
| 1506 | |||
| 1498 | @menu | 1507 | @menu |
| 1499 | * Invoking emacsclient:: Connecting to the Emacs server. | 1508 | * Invoking emacsclient:: Connecting to the Emacs server. |
| 1500 | * emacsclient Options:: Emacs client startup options. | 1509 | * emacsclient Options:: Emacs client startup options. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a111f30f6d5..f303f5d1e32 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2011-05-02 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 2 | |||
| 3 | * server.el (server-eval-at): New function. | ||
| 4 | |||
| 1 | 2011-05-01 Lars Magne Ingebrigtsen <larsi@gnus.org> | 5 | 2011-05-01 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 6 | ||
| 3 | * net/network-stream.el (open-network-stream): Take a :nowait | 7 | * net/network-stream.el (open-network-stream): Take a :nowait |
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 | ||