unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Scott Turner <srt19170@gmail.com>
To: 11474@debbugs.gnu.org
Subject: bug#11474: Patch for Emacsclient --eval bug
Date: Fri, 13 Dec 2013 10:30:17 -0500	[thread overview]
Message-ID: <CA+fxJPTKScTWsMaWNMoK9FVjVyxN9KbM-mfZXJ8w=EmFH0D_-Q@mail.gmail.com> (raw)
In-Reply-To: <86ehqmm2u2.fsf@dickson.st>

[-- Attachment #1: Type: text/plain, Size: 2283 bytes --]

In emacsclient, the --eval option tells emacsclient to treat all arguments
as Elisp to be evaluated by the Emacs server.

The --alternate-editor option specifies an program to start if emacsclient
cannot find an Emacs server.

If both options are used and a server is not found, a bug arises.
Emacsclient sends the arguments that are intended to be interpreted as
Elisp to the alternate editor.  If the alternate editor is Emacs, this
results in Emacs creating a buffer named after each argument.  So the
command:

emacsclient --alternate-editor "emacs" --eval "(make-frame-visible)"

results in an Emacs with a buffer named "(make-frame-visible)".

Sending the Elisp arguments to the alternate-editor as plain arguments is
clearly wrong.  If we knew that the alternate-editor was Emacs, we could
send the argument along with "--eval=" prepended to have the newly started
Emacs evaluate the Elisp, but of course the alternate editor could be
something else entirely, and it's probably not the case that you'd want to
execute the same Elisp on startup as on resume.

The patch provided below simply discards the Elisp arguments when
emacsclient falls through to the alternate editor.  There may be better
fixes, but this does the least harm while retaining compatibility.

*** emacsclient.c    Tue Jan  1 15:37:17 2013
--- emacsclient-strip-eval.c    Thu Dec 12 20:01:06 2013
***************
*** 694,700 ****
      {
        int i = optind - 1;

!       execvp (alternate_editor, main_argv + i);
        message (TRUE, "%s: error executing alternate editor \"%s\"\n",
             progname, alternate_editor);
      }
--- 694,713 ----
      {
        int i = optind - 1;

!       /*
!        *  If the --eval option has been used, then the remaining
!        *  arguments are Elisp expressions intended to be evaluated
!        *  by emacsclient.  It doesn't make any sense to pass them
!        *  along to the alternate_editor to be treated as files.
!        *
!        */
!       if (eval) {
!     char *t_argv[] = {alternate_editor, 0 };
!     execvp (alternate_editor, t_argv);
!       } else {
!     execvp (alternate_editor, main_argv + i);
!       };
!
        message (TRUE, "%s: error executing alternate editor \"%s\"\n",
             progname, alternate_editor);
      }

[-- Attachment #2: Type: text/html, Size: 2613 bytes --]

  reply	other threads:[~2013-12-13 15:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-15  5:27 bug#11474: 24.1.50; eval a command does the wrong thing with emacsclientw.exe Jason Lewis
2013-12-13 15:30 ` Scott Turner [this message]
2013-12-24 14:56   ` bug#11474: Patch for Emacsclient --eval bug Scott Turner
2013-12-24 16:03     ` Stefan Monnier
2013-12-24 16:11       ` Scott Turner
2014-04-02 14:57   ` Stefan Monnier
2014-04-02 15:34     ` Scott Turner
2014-04-02 16:34       ` Stefan Monnier
2019-06-27 15:29     ` Lars Ingebrigtsen
2019-06-27 18:17       ` Stefan Monnier
2019-06-27 18:40         ` Lars Ingebrigtsen
2019-06-27 18:56           ` Lars Ingebrigtsen
2019-06-27 19:00             ` Lars Ingebrigtsen
2019-06-27 19:14               ` Stefan Monnier
2019-06-27 19:19                 ` Lars Ingebrigtsen

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='CA+fxJPTKScTWsMaWNMoK9FVjVyxN9KbM-mfZXJ8w=EmFH0D_-Q@mail.gmail.com' \
    --to=srt19170@gmail.com \
    --cc=11474@debbugs.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).