Subject: Re: Adding --quiet option to emacsclient

From: Drake Wilson <[email-masked]>
Date: Wed, 6 Aug 2008 17:47:21 -0500

Quoth Chong Yidong <[email-masked]>, on 2008-08-06 18:32:27 -0400:
> > In the Debian BTS wishlist ticket #490253, I requested a --quiet
> > option for emacsclient; currently, it prints a "Waiting for Emacs..."
> > message that cannot be turned off, which I found annoying.  I have
> > updated the patch I provided in that report to apply against the CVS
> > version of Emacs; it would be nice if this feature could make it into
> > Emacs 23.
> 
> Emacs 23 is in feature freeze.  Could you please send your patch to
> [email-masked], so that it is entered in our bug tracker?
> Then after the release, we'll see if this can be included.  Thanks.

Very well.  Forwarding now.  Hello, emacs-pretest-bug.

(Also re-cc'ing emacs-devel, since I think my actual diff got eaten
somewhere along the way; probably I just miscommanded my mailer.)

   ---> Drake Wilson
Index: doc/emacs/misc.texi
===================================================================
RCS file: /sources/emacs/emacs/doc/emacs/misc.texi,v
retrieving revision 1.6
diff -u -r1.6 misc.texi
--- doc/emacs/misc.texi	13 Jun 2008 08:06:41 -0000	1.6
+++ doc/emacs/misc.texi	6 Aug 2008 19:12:31 -0000
@@ -1412,6 +1412,10 @@
 setting for the @env{EDITOR} environment variable will always give you
 an editor, even if no Emacs server is running:
 
+  The option @samp{-q} or @samp{--quiet} causes @code{emacsclient} to
+not display messages about waiting for Emacs or connecting to remote
+server sockets.
+
 @example
 EDITOR="emacsclient --alternate-editor emacs +%d %s"
 @end example
Index: lib-src/emacsclient.c
===================================================================
RCS file: /sources/emacs/emacs/lib-src/emacsclient.c,v
retrieving revision 1.130
diff -u -r1.130 emacsclient.c
--- lib-src/emacsclient.c	31 Jul 2008 05:33:38 -0000	1.130
+++ lib-src/emacsclient.c	6 Aug 2008 19:12:32 -0000
@@ -119,6 +119,9 @@
 /* Nonzero means don't wait for a response from Emacs.  --no-wait.  */
 int nowait = 0;
 
+/* Nonzero means don't print messages for successful operations.  --quiet. */
+int quiet = 0;
+
 /* Nonzero means args are expressions to be evaluated.  --eval.  */
 int eval = 0;
 
@@ -152,6 +155,7 @@
 struct option longopts[] =
 {
   { "no-wait",	no_argument,	   NULL, 'n' },
+  { "quiet",    no_argument,       NULL, 'q' },
   { "eval",	no_argument,	   NULL, 'e' },
   { "help",	no_argument,	   NULL, 'H' },
   { "version",	no_argument,	   NULL, 'V' },
@@ -476,9 +480,9 @@
     {
       int opt = getopt_long (argc, argv,
 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
-			     "VHnea:s:f:d:tc",
+			     "VHneqa:s:f:d:tc",
 #else
-			     "VHnea:f:d:tc",
+			     "VHneqa:f:d:tc",
 #endif
 			     longopts, 0);
 
@@ -524,6 +528,10 @@
 	  eval = 1;
 	  break;
 
+	case 'q':
+	  quiet = 1;
+	  break;
+
 	case 'V':
 	  message (FALSE, "emacsclient %s\n", VERSION);
 	  exit (EXIT_SUCCESS);
@@ -606,6 +614,7 @@
 			use the current Emacs frame\n\
 -e, --eval    		Evaluate the FILE arguments as ELisp expressions\n\
 -n, --no-wait		Don't wait for the server to return\n\
+-q, --quiet             Don't display messages on success\n\
 -d, --display=DISPLAY	Visit the file in the given display\n"
 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
 "-s, --socket-name=FILENAME\n\
@@ -950,7 +959,7 @@
   if (! get_server_config (&server, auth_string))
     return INVALID_SOCKET;
 
-  if (server.sin_addr.s_addr != inet_addr ("127.0.0.1"))
+  if (server.sin_addr.s_addr != inet_addr ("127.0.0.1") && !quiet)
     message (FALSE, "%s: connected to remote socket at %s\n",
              progname, inet_ntoa (server.sin_addr));
 
@@ -1549,7 +1558,7 @@
   send_to_emacs (emacs_socket, "\n");
 
   /* Wait for an answer. */
-  if (!eval && !tty && !nowait)
+  if (!eval && !tty && !nowait && !quiet)
     {
       printf ("Waiting for Emacs...");
       needlf = 2;