Subject: bug#26591: 26.0.50; Using local emacs+tramp with remote emacsclient

From: Eli Zaretskii <[email-masked]>
Date: Fri, 28 Apr 2017 12:42:27 +0300

> From: [email-masked] (Peder O. Klingenberg)
> Date: Fri, 21 Apr 2017 18:15:25 +0200
> 
> My workstation is running a bleeding edge emacs full-screen in a
> dedicated display.  When working on a server, from time to time I use
> programs that invoke the shell EDITOR.  I can set EDITOR to emacsclient,
> but that will just open emacs on the remote machine, which is not what I
> want.  I want whatever editing job needs doing to pop up in my local
> fullscreen emacs.
> 
> I can ssh to the server, so obviously I can use my local emacs to edit
> files there via Tramp.  And server.el already has functionality for
> listening on a TCP port, which is easily forwarded over ssh (there are
> various hacks out there for forwarding unix domain sockets as well,
> which I haven't tried).
> 
> The missing piece is simply a way to let emacsclient instruct emacs that
> the files it passes to emacs are remote.  Attached is a patch for your
> consideration which accomplishes this.
> 
> Additionally, it would be handy to have some tooling for conveniently
> forwarding the correct ports and setting up EDITOR with the correct -T
> option on the remote machine, but that is outside the scope of emacs
> code, I think.

Thanks, I think this will be a welcome feature.  Please see a few
comments below.

> --- a/doc/emacs/misc.texi
> +++ b/doc/emacs/misc.texi
> @@ -1872,6 +1872,36 @@ emacsclient Options
>  server is using the graphical display, but if the Emacs server is
>  running on a text terminal, it creates a new frame in the current text
>  terminal.
> +
> +@item -T @var{tramp-prefix}
> +@itemx --tramp-prefix=@var{tramp-prefix}
> +@cindex @env{EMACSCLIENT_TRAMP} environment variable
> +Prefix to add to filenames for emacs to locate files on remote
> +machines through TRAMP.  This is mostly useful in combination with
> +setting @code{server-use-tcp} to non-@code{nil}, ssh-forwarding the
> +listening port, and making the @var{server-file} available to
> +@command{emacsclient}.

server-use-tcp is not described in the manual, so I think we should
add its description somewhere, and then reference that place from this
text.

> +For example, assume two hosts, @samp{local} and @samp{remote}, with
> +@samp{/home} on a shared file system, and that the local emacs listens
> +on tcp port 12345:

"/home" should be in @file, not @samp.  Also, I don't see "/home" used
anywhere in the example, so something is missing here.

> +@example
> +local$ ssh -R12345:localhost:12345 remote
> +remote$ export EDITOR="emacsclient \
> +        --server-file=server \
> +        --tramp=/ssh:remote:'

The value of EDITOR begins with a ", but ends with a ', which is
probably a mistake.

> +	  if (tramp_prefix && file_name_absolute_p (argv[i]))
> +	    quote_argument (emacs_socket, tramp_prefix);

Why the test for argv[i] being an absolute file name?  And if relative
file names cannot be supported, I think emacsclient should emit an
error message rather than silently ignoring --tramp.