unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Juanma Barranquero" <lekktu@gmail.com>
Cc: emacs-pretest-bug@gnu.org, Emacs Devel <emacs-devel@gnu.org>
Subject: Re: Emacsclient/server filename quoting error
Date: Fri, 15 Dec 2006 11:31:18 +0100	[thread overview]
Message-ID: <f7ccd24b0612150231g1b09b2f5w3d69e0ce59c3b20c@mail.gmail.com> (raw)
In-Reply-To: <001701c71c53$1be9a9f0$041df159@Monolith>

On 12/10/06, Francis Wright <F.J.Wright@qmul.ac.uk> wrote:

> I execute all the following commands from a cmd command
> prompt (outside of Emacs).
>
> emacsclient -n -a runemacs "TO DO.txt"
>
> works correctly if Emacs IS already running, but if it is not
> already running then Emacs does not see the filename correctly;
> the quotes do not appear to be passed on to runemacs.

The following patch addresses the issue by allocating quoted copies of
any argument containing spaces before calling execvp.

Any objections to install this fix? As it stands, it affects also
non-Windows builds. Is requoting args the right behavior in these
environments?

                    /L/e/k/t/u



Index: lib-src/emacsclient.c
===================================================================
RCS file: /cvsroot/emacs/emacs/lib-src/emacsclient.c,v
retrieving revision 1.98
diff -u -2 -r1.98 emacsclient.c
--- lib-src/emacsclient.c	30 Nov 2006 22:49:38 -0000	1.98
+++ lib-src/emacsclient.c	15 Dec 2006 10:19:44 -0000
@@ -310,8 +310,20 @@
   if (alternate_editor)
     {
-      int i = optind - 1;
+      int j, i = optind - 1;
+
 #ifdef WINDOWSNT
-      argv[i] = (char *)alternate_editor;
+      argv[i] = (char *) alternate_editor;
 #endif
+
+      /* Arguments with spaces have been dequoted, so we
+	 have to requote them before calling execvp.  */
+      for (j = i; argv[j]; j++)
+	if (strchr (argv[j], ' '))
+	  {
+	    char *quoted = alloca (strlen (argv[j]) + 3);
+	    sprintf (quoted, "\"%s\"", argv[j]);
+	    argv[j] = quoted;
+	  }
+
       execvp (alternate_editor, argv + i);
       message (TRUE, "%s: error executing alternate editor \"%s\"\n",

       reply	other threads:[~2006-12-15 10:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <001701c71c53$1be9a9f0$041df159@Monolith>
2006-12-15 10:31 ` Juanma Barranquero [this message]
2006-12-15 11:06   ` Emacsclient/server filename quoting error Eli Zaretskii
2006-12-15 12:07     ` Juanma Barranquero
2006-12-15 14:19       ` Eli Zaretskii
2006-12-15 15:42         ` Juanma Barranquero
2006-12-15 15:50           ` David Kastrup
2006-12-15 16:03             ` Juanma Barranquero
2006-12-15 15:52           ` Eli Zaretskii
2006-12-15 15:14       ` Werner LEMBERG
2006-12-15 15:41         ` Juanma Barranquero
2006-12-15 15:54         ` Eli Zaretskii
2006-12-17 17:24       ` Francis Wright

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7ccd24b0612150231g1b09b2f5w3d69e0ce59c3b20c@mail.gmail.com \
    --to=lekktu@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=emacs-pretest-bug@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).