aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schwab2012-03-11 18:53:07 +0100
committerAndreas Schwab2012-03-11 18:53:07 +0100
commite29ab36b489e14bda49a2c0e61dac3a7e13e75f1 (patch)
tree5f54f5bf289ebffa04cd6fb3d577a44cf64305a2
parentde5939bafc0d06ad65bfc13498b14a2dd1c82db4 (diff)
downloademacs-e29ab36b489e14bda49a2c0e61dac3a7e13e75f1.tar.gz
emacs-e29ab36b489e14bda49a2c0e61dac3a7e13e75f1.zip
Define -print-nonl client command
* lib-src/emacsclient.c (main): Handle -print-nonl command. * lisp/server.el (server-msg-size): New constant. (server-reply-print): New function. (server-eval-and-print): Use it. (server-eval-at): Use server-quote-arg and server-unquote-arg. Handle -print-nonl.
-rw-r--r--lib-src/ChangeLog2
-rw-r--r--lib-src/emacsclient.c8
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/server.el49
4 files changed, 56 insertions, 11 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 1478b3715f1..2384599caf2 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,5 +1,7 @@
12012-03-11 Andreas Schwab <schwab@linux-m68k.org> 12012-03-11 Andreas Schwab <schwab@linux-m68k.org>
2 2
3 * emacsclient.c (main): Handle -print-nonl command.
4
3 * emacsclient.c (main): Handle multiple messages in a single 5 * emacsclient.c (main): Handle multiple messages in a single
4 datagram. 6 datagram.
5 7
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 97ae029751d..049886ed2ba 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1812,6 +1812,14 @@ main (int argc, char **argv)
1812 printf ("%s", str); 1812 printf ("%s", str);
1813 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; 1813 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
1814 } 1814 }
1815 else if (strprefix ("-print-nonl ", p))
1816 {
1817 /* -print-nonl STRING: Print STRING on the terminal.
1818 Used to continue a preceding -print command. */
1819 str = unquote_argument (p + strlen ("-print-nonl "));
1820 printf ("%s", str);
1821 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
1822 }
1815 else if (strprefix ("-error ", p)) 1823 else if (strprefix ("-error ", p))
1816 { 1824 {
1817 /* -error DESCRIPTION: Signal an error on the terminal. */ 1825 /* -error DESCRIPTION: Signal an error on the terminal. */
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0db75714768..abb3872d1ac 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12012-03-11 Andreas Schwab <schwab@linux-m68k.org>
2
3 * server.el (server-msg-size): New constant.
4 (server-reply-print): New function.
5 (server-eval-and-print): Use it.
6 (server-eval-at): Use server-quote-arg and server-unquote-arg.
7 Handle -print-nonl.
8
12012-03-11 Christopher Schmidt <christopher@ch.ristopher.com> 92012-03-11 Christopher Schmidt <christopher@ch.ristopher.com>
2 10
3 * ibuffer.el (ibuffer-redisplay): Remove gratuitous error 11 * ibuffer.el (ibuffer-redisplay): Remove gratuitous error
diff --git a/lisp/server.el b/lisp/server.el
index 34ac5d7ba23..78b81e0b05b 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.
716QTEXT must be already quoted.
717This 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
@@ -1560,20 +1585,22 @@ This function requires the use of TCP sockets. "
1560 (process-send-string 1585 (process-send-string
1561 process 1586 process
1562 (concat "-auth " secret " -eval " 1587 (concat "-auth " secret " -eval "
1563 (replace-regexp-in-string 1588 (server-quote-arg (format "%S" form))
1564 " " "&_" (format "%S" form))
1565 "\n")) 1589 "\n"))
1566 (while (memq (process-status process) '(open run)) 1590 (while (memq (process-status process) '(open run))
1567 (accept-process-output process 0 10)) 1591 (accept-process-output process 0 10))
1568 (goto-char (point-min)) 1592 (goto-char (point-min))
1569 ;; If the result is nil, there's nothing in the buffer. If the 1593 ;; If the result is nil, there's nothing in the buffer. If the
1570 ;; result is non-nil, it's after "-print ". 1594 ;; result is non-nil, it's after "-print ".
1571 (when (search-forward "\n-print" nil t) 1595 (let ((answer ""))
1572 (let ((start (point))) 1596 (while (re-search-forward "\n-print\\(-nonl\\)? " nil t)
1573 (while (search-forward "&_" nil t) 1597 (setq answer
1574 (replace-match " " t t)) 1598 (concat answer
1575 (goto-char start) 1599 (buffer-substring (point)
1576 (read (current-buffer))))))) 1600 (progn (skip-chars-forward "^\n")
1601 (point))))))
1602 (if (not (equal answer ""))
1603 (read (server-unquote-arg answer)))))))
1577 1604
1578 1605
1579(provide 'server) 1606(provide 'server)