diff options
| author | Joakim Verona | 2012-03-13 08:23:14 +0100 |
|---|---|---|
| committer | Joakim Verona | 2012-03-13 08:23:14 +0100 |
| commit | 4b2cea2874f3a699ebe96349ef34fb7206cc0fa5 (patch) | |
| tree | bbd39cf660d9b79b2cff9e39ef6209af4cf9fb8b /lisp/server.el | |
| parent | 1de331c486475093aa6b75ef6c259f7164e7620c (diff) | |
| parent | 6ea7151ba66df966974060711512b49b9059566e (diff) | |
| download | emacs-4b2cea2874f3a699ebe96349ef34fb7206cc0fa5.tar.gz emacs-4b2cea2874f3a699ebe96349ef34fb7206cc0fa5.zip | |
upstream
Diffstat (limited to 'lisp/server.el')
| -rw-r--r-- | lisp/server.el | 107 |
1 files changed, 70 insertions, 37 deletions
diff --git a/lisp/server.el b/lisp/server.el index 34ac5d7ba23..ed83225eccd 100644 --- a/lisp/server.el +++ b/lisp/server.el | |||
| @@ -706,9 +706,29 @@ Server mode runs a process that accepts commands from the | |||
| 706 | (pp v) | 706 | (pp v) |
| 707 | (let ((text (buffer-substring-no-properties | 707 | (let ((text (buffer-substring-no-properties |
| 708 | (point-min) (point-max)))) | 708 | (point-min) (point-max)))) |
| 709 | (server-send-string | 709 | (server-reply-print (server-quote-arg text) proc))))))) |
| 710 | proc (format "-print %s\n" | 710 | |
| 711 | (server-quote-arg text))))))))) | 711 | (defconst server-msg-size 1024 |
| 712 | "Maximum size of a message sent to a client.") | ||
| 713 | |||
| 714 | (defun server-reply-print (qtext proc) | ||
| 715 | "Send a `-print QTEXT' command to client PROC. | ||
| 716 | QTEXT must be already quoted. | ||
| 717 | This handles splitting the command if it would be bigger than | ||
| 718 | `server-msg-size'." | ||
| 719 | (let ((prefix "-print ") | ||
| 720 | part) | ||
| 721 | (while (> (+ (length qtext) (length prefix) 1) server-msg-size) | ||
| 722 | ;; We have to split the string | ||
| 723 | (setq part (substring qtext 0 (- server-msg-size (length prefix) 1))) | ||
| 724 | ;; Don't split in the middle of a quote sequence | ||
| 725 | (if (string-match "\\(^\\|[^&]\\)\\(&&\\)+$" part) | ||
| 726 | ;; There is an uneven number of & at the end | ||
| 727 | (setq part (substring part 0 -1))) | ||
| 728 | (setq qtext (substring qtext (length part))) | ||
| 729 | (server-send-string proc (concat prefix part "\n")) | ||
| 730 | (setq prefix "-print-nonl ")) | ||
| 731 | (server-send-string proc (concat prefix qtext "\n")))) | ||
| 712 | 732 | ||
| 713 | (defun server-create-tty-frame (tty type proc) | 733 | (defun server-create-tty-frame (tty type proc) |
| 714 | (unless tty | 734 | (unless tty |
| @@ -911,6 +931,11 @@ The following commands are accepted by the client: | |||
| 911 | Print STRING on stdout. Used to send values | 931 | Print STRING on stdout. Used to send values |
| 912 | returned by -eval. | 932 | returned by -eval. |
| 913 | 933 | ||
| 934 | `-print-nonl STRING' | ||
| 935 | Print STRING on stdout. Used to continue a | ||
| 936 | preceding -print command that would be too big to send | ||
| 937 | in a single message. | ||
| 938 | |||
| 914 | `-error DESCRIPTION' | 939 | `-error DESCRIPTION' |
| 915 | Signal an error and delete process PROC. | 940 | Signal an error and delete process PROC. |
| 916 | 941 | ||
| @@ -1534,46 +1559,54 @@ only these files will be asked to be saved." | |||
| 1534 | Returns the result of the evaluation, or signals an error if it | 1559 | Returns the result of the evaluation, or signals an error if it |
| 1535 | cannot contact the specified server. For example: | 1560 | cannot contact the specified server. For example: |
| 1536 | \(server-eval-at \"server\" '(emacs-pid)) | 1561 | \(server-eval-at \"server\" '(emacs-pid)) |
| 1537 | returns the process ID of the Emacs instance running \"server\". | 1562 | returns the process ID of the Emacs instance running \"server\"." |
| 1538 | This function requires the use of TCP sockets. " | 1563 | (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir)) |
| 1539 | (or server-use-tcp | 1564 | (server-file (expand-file-name server server-dir)) |
| 1540 | (error "This function requires TCP sockets")) | 1565 | (coding-system-for-read 'binary) |
| 1541 | (let ((auth-file (expand-file-name server server-auth-dir)) | 1566 | (coding-system-for-write 'binary) |
| 1542 | (coding-system-for-read 'binary) | 1567 | address port secret process) |
| 1543 | (coding-system-for-write 'binary) | 1568 | (unless (file-exists-p server-file) |
| 1544 | address port secret process) | 1569 | (error "No such server: %s" server)) |
| 1545 | (unless (file-exists-p auth-file) | ||
| 1546 | (error "No such server definition: %s" auth-file)) | ||
| 1547 | (with-temp-buffer | 1570 | (with-temp-buffer |
| 1548 | (insert-file-contents auth-file) | 1571 | (when server-use-tcp |
| 1549 | (unless (looking-at "\\([0-9.]+\\):\\([0-9]+\\)") | 1572 | (let ((coding-system-for-read 'no-conversion)) |
| 1550 | (error "Invalid auth file")) | 1573 | (insert-file-contents server-file) |
| 1551 | (setq address (match-string 1) | 1574 | (unless (looking-at "\\([0-9.]+\\):\\([0-9]+\\)") |
| 1552 | port (string-to-number (match-string 2))) | 1575 | (error "Invalid auth file")) |
| 1553 | (forward-line 1) | 1576 | (setq address (match-string 1) |
| 1554 | (setq secret (buffer-substring (point) (line-end-position))) | 1577 | port (string-to-number (match-string 2))) |
| 1555 | (erase-buffer) | 1578 | (forward-line 1) |
| 1556 | (unless (setq process (open-network-stream "eval-at" (current-buffer) | 1579 | (setq secret (buffer-substring (point) (line-end-position))) |
| 1557 | address port)) | 1580 | (erase-buffer))) |
| 1558 | (error "Unable to contact the server")) | 1581 | (unless (setq process (make-network-process |
| 1559 | (set-process-query-on-exit-flag process nil) | 1582 | :name "eval-at" |
| 1560 | (process-send-string | 1583 | :buffer (current-buffer) |
| 1561 | process | 1584 | :host address |
| 1562 | (concat "-auth " secret " -eval " | 1585 | :service (if server-use-tcp port server-file) |
| 1563 | (replace-regexp-in-string | 1586 | :family (if server-use-tcp 'ipv4 'local) |
| 1564 | " " "&_" (format "%S" form)) | 1587 | :noquery t)) |
| 1565 | "\n")) | 1588 | (error "Unable to contact the server")) |
| 1589 | (if server-use-tcp | ||
| 1590 | (process-send-string process (concat "-auth " secret "\n"))) | ||
| 1591 | (process-send-string process | ||
| 1592 | (concat "-eval " | ||
| 1593 | (server-quote-arg (format "%S" form)) | ||
| 1594 | "\n")) | ||
| 1566 | (while (memq (process-status process) '(open run)) | 1595 | (while (memq (process-status process) '(open run)) |
| 1567 | (accept-process-output process 0 10)) | 1596 | (accept-process-output process 0 10)) |
| 1568 | (goto-char (point-min)) | 1597 | (goto-char (point-min)) |
| 1569 | ;; If the result is nil, there's nothing in the buffer. If the | 1598 | ;; If the result is nil, there's nothing in the buffer. If the |
| 1570 | ;; result is non-nil, it's after "-print ". | 1599 | ;; result is non-nil, it's after "-print ". |
| 1571 | (when (search-forward "\n-print" nil t) | 1600 | (let ((answer "")) |
| 1572 | (let ((start (point))) | 1601 | (while (re-search-forward "\n-print\\(-nonl\\)? " nil t) |
| 1573 | (while (search-forward "&_" nil t) | 1602 | (setq answer |
| 1574 | (replace-match " " t t)) | 1603 | (concat answer |
| 1575 | (goto-char start) | 1604 | (buffer-substring (point) |
| 1576 | (read (current-buffer))))))) | 1605 | (progn (skip-chars-forward "^\n") |
| 1606 | (point)))))) | ||
| 1607 | (if (not (equal answer "")) | ||
| 1608 | (read (decode-coding-string (server-unquote-arg answer) | ||
| 1609 | 'emacs-internal))))))) | ||
| 1577 | 1610 | ||
| 1578 | 1611 | ||
| 1579 | (provide 'server) | 1612 | (provide 'server) |