Subject: [PATCH] Make emacsclient fail if --eval is used and no Emacs server connection established

From: Ilya Ostapyshyn <[email-masked]>
Date: Mon, 20 Apr 2020 15:22:43 +0300

Hello,

This patch makes emacsclient quit with an error message if both --eval
and --alternate-editor were specified.

According to the current implementation, the emacsclient runs
alternate-editor, treating the eval expression as the filename, which
is IMO not very intuitive.

Kind regards,
Illia.

>From dcc18914c7109c06d570790d24b44f99ceb2a5d7 Mon Sep 17 00:00:00 2001
From: Ilya Ostapyshyn <[email-masked]>
Date: Mon, 20 Apr 2020 15:06:07 +0300
Subject: [PATCH] exit if no connection and --eval used

---
 lib-src/emacsclient.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 380be95222..d74750ea5d 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -691,14 +691,21 @@ print_help_and_exit (void)
   exit (EXIT_SUCCESS);
 }
 
-/* Try to run a different command, or --if no alternate editor is
+/* If args were to be evaluated exit immediately with an error code.
+   Try to run a different command, or --if no alternate editor is
    defined-- exit with an error code.
    Uses argv, but gets it from the global variable main_argv.  */
 
 static _Noreturn void
 fail (void)
 {
-  if (alternate_editor)
+  if (eval)
+    {
+      /* No way to evaluate Lisp expressions if there is
+         no connection to an Emacs server.  */
+      message (true, "%s: unable evaluate ELisp expressions.\n", progname);
+    }
+  else if (alternate_editor)
     {
       size_t extra_args_size = (main_argc - optind + 1) * sizeof (char *);
       size_t new_argv_size = extra_args_size;
-- 
2.26.1