>From 8a9b508809bf5bef2a797340614cbc4cb0c73a5a Mon Sep 17 00:00:00 2001 From: "Peder O. Klingenberg" Date: Fri, 21 Apr 2017 17:16:08 +0200 Subject: [PATCH] New option -T / --tramp for remote editing with emacsclient In combination with existing functionality for having server.el listen on tcp ports, enables emacsclient on a remote machine to instruct the local emacs to open remote files via Tramp. Useful with remote programs that invoke EDITOR. * lib-src/emacsclient.c (main, decode_options) (print_help_and_exit, longopts): New option --tramp / -T which specifies how emacs should use tramp to find remote files. * doc/emacs/misc.texi (emacsclient Options): Document new --tramp / -T options. --- doc/emacs/misc.texi | 30 ++++++++++++++++++++++++++++++ etc/NEWS | 6 ++++++ lib-src/emacsclient.c | 20 ++++++++++++++++++-- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index bcc20a6db1..34a9d885bf 100644 --- 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. + address@hidden -T @var{tramp-prefix} address@hidden address@hidden address@hidden @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 address@hidden, ssh-forwarding the +listening port, and making the @var{server-file} available to address@hidden This combination allows programs on a remote +machine to use @command{emacsclient} as @env{EDITOR}, but instead of +starting emacs on the remote machine, the files will be opened in the +local emacs through TRAMP. + +Setting the environment variable @env{EMACSCLIENT_TRAMP} has the same +effect as using this option. If both are specified, the explicit +option will take precedence. + +For example, assume two hosts, @samp{local} and @samp{remote}, with address@hidden/home} on a shared file system, and that the local emacs listens +on tcp port 12345: + address@hidden +local$ ssh -R12345:localhost:12345 remote +remote$ export EDITOR="emacsclient \ + --server-file=server \ + --tramp=/ssh:remote:' +remote$ $EDITOR /tmp/foo.txt #Should open in local emacs. address@hidden example + address@hidden, The Tramp Manual,,tramp, The Tramp Manual} @end table The new graphical or text terminal frames created by the @samp{-c} diff --git a/etc/NEWS b/etc/NEWS index 76c9dbc331..4599efd7da 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -340,6 +340,12 @@ want to reverse the direction of the scroll, customize ** Emacsclient has a new option -u/--suppress-output. The option suppresses display of return values from the server process. ++++ +** Emacsclient has a new option -T/--tramp. This helps with using a +local emacs as the target for a remote emacsclient. With appropriate +setup, one can now set EDITOR on a remote machine to emacsclient, and +use the local emacs to edit remote files via Tramp. + * Editing Changes in Emacs 26.1 diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 7b735dfb05..0661480f58 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -149,6 +149,9 @@ const char *socket_name = NULL; /* If non-NULL, the filename of the authentication file. */ const char *server_file = NULL; +/* If non-NULL, the tramp prefix emacs must use to find the files. */ +const char *tramp_prefix = NULL; + /* PID of the Emacs server process. */ int emacs_pid = 0; @@ -178,6 +181,7 @@ struct option longopts[] = { "server-file", required_argument, NULL, 'f' }, { "display", required_argument, NULL, 'd' }, { "parent-id", required_argument, NULL, 'p' }, + { "tramp", required_argument, NULL, 'T' }, { 0, 0, 0, 0 } }; @@ -468,14 +472,15 @@ static void decode_options (int argc, char **argv) { alternate_editor = egetenv ("ALTERNATE_EDITOR"); + tramp_prefix = egetenv ("EMACSCLIENT_TRAMP"); while (1) { int opt = getopt_long_only (argc, argv, #ifndef NO_SOCKETS_IN_FILE_SYSTEM - "VHnequa:s:f:d:F:tc", + "VHnequa:s:f:d:F:tcT:", #else - "VHnequa:f:d:F:tc", + "VHnequa:f:d:F:tcT:", #endif longopts, 0); @@ -554,6 +559,10 @@ decode_options (int argc, char **argv) frame_parameters = optarg; break; + case 'T': + tramp_prefix = optarg; + break; + default: message (true, "Try '%s --help' for more information\n", progname); exit (EXIT_FAILURE); @@ -654,6 +663,9 @@ The following OPTIONS are accepted:\n\ Editor to fallback to if the server is not running\n" " If EDITOR is the empty string, start Emacs in daemon\n\ mode and try connecting again\n" +"-T PREFIX, --tramp=PREFIX\n\ + PREFIX to filenames emacs needs to use to find files\n\ + local to emacsclient\n" "\n\ Report bugs with M-x report-emacs-bug.\n"); exit (EXIT_SUCCESS); @@ -1687,6 +1699,8 @@ main (int argc, char **argv) } } send_to_emacs (emacs_socket, "-dir "); + if (tramp_prefix) + quote_argument (emacs_socket, tramp_prefix); quote_argument (emacs_socket, cwd); send_to_emacs (emacs_socket, "/"); send_to_emacs (emacs_socket, " "); @@ -1791,6 +1805,8 @@ main (int argc, char **argv) #endif send_to_emacs (emacs_socket, "-file "); + if (tramp_prefix && file_name_absolute_p (argv[i])) + quote_argument (emacs_socket, tramp_prefix); quote_argument (emacs_socket, argv[i]); send_to_emacs (emacs_socket, " "); } -- 2.11.0