From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: peder@klingenberg.no (Peder O. Klingenberg) Newsgroups: gmane.emacs.bugs Subject: bug#26591: 26.0.50; Using local emacs+tramp with remote emacsclient Date: Sat, 29 Apr 2017 21:45:15 +0200 Message-ID: References: <83k264na0s.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1493495186 14152 195.159.176.226 (29 Apr 2017 19:46:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 29 Apr 2017 19:46:26 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (darwin) Cc: 26591@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 29 21:46:19 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d4YJr-0003KM-P7 for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Apr 2017 21:46:16 +0200 Original-Received: from localhost ([::1]:42261 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4YJq-0002Tu-VO for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Apr 2017 15:46:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4YJj-0002To-6d for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 15:46:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4YJf-0001bR-V0 for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 15:46:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:48457) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d4YJf-0001bF-Ql for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 15:46:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d4YJe-0002dQ-FM for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 15:46:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: peder@klingenberg.no (Peder O. Klingenberg) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 29 Apr 2017 19:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26591 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 26591-submit@debbugs.gnu.org id=B26591.149349514110089 (code B ref 26591); Sat, 29 Apr 2017 19:46:02 +0000 Original-Received: (at 26591) by debbugs.gnu.org; 29 Apr 2017 19:45:41 +0000 Original-Received: from localhost ([127.0.0.1]:46656 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d4YJI-0002cf-MK for submit@debbugs.gnu.org; Sat, 29 Apr 2017 15:45:41 -0400 Original-Received: from tarrant.klingenberg.no ([80.91.231.253]:37188) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d4YJG-0002cU-2q for 26591@debbugs.gnu.org; Sat, 29 Apr 2017 15:45:38 -0400 Original-Received: from 179.51-175-138.customer.lyse.net ([51.175.138.179] helo=modesty.local) by tarrant.klingenberg.no with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1d4YJ1-0003d1-21; Sat, 29 Apr 2017 21:45:35 +0200 Original-Received: by modesty.local (Postfix, from userid 502) id 2AEBB17E8E4C; Sat, 29 Apr 2017 21:45:15 +0200 (CEST) In-Reply-To: <83k264na0s.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 28 Apr 2017 12:42:27 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:132116 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > 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. I added a new node to the manual, "TCP Emacs server", and collected/wrote documentation on the various related variables there. Does this type of doc reorganization require its own NEWS entry? I didn't see the point, and so didn't write any. As this is only tangentially related to the new feature, I made it into a separate patch. The updated feature patch applies on top of this documentation patch, and references the new node. > "/home" should be in @file, not @samp. Also, I don't see "/home" used > anywhere in the example, so something is missing here. I have hopefully clarified the wording and fixed the tagging and typos. I noticed while writing the TCP server doc that Emacs was capitalized elsewhere in the docs, so I updated the capitalization in the paragraphs on the new option. Jeez, writing good docs is hard. Criticisms welcome. :) > 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. As I explained in my previous mail, both absolute and relative filenames are supported. There are no code changes in this updated patch set. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Improve-documentation-of-TCP-mode-of-server.el.patch >From f5a4c2ef877a476a1f2bfb8f3eb07cba7c641234 Mon Sep 17 00:00:00 2001 From: "Peder O. Klingenberg" Date: Sat, 29 Apr 2017 01:18:30 +0200 Subject: [PATCH] Improve documentation of TCP mode of server.el * doc/emacs/misc.texi (TCP Emacs server): New subsection describing the various knobs to tune server.el for TCP opereation. (emacsclient Options): Reference "TCP Emacs server" from description of --server-file. --- doc/emacs/misc.texi | 80 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index bcc20a6db1..c8504fef49 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1661,10 +1661,66 @@ Emacs Server signaled.) Currently, this feature is mainly useful for developers. @menu +* TCP Emacs server:: Listening to a TCP socket. * Invoking emacsclient:: Connecting to the Emacs server. * emacsclient Options:: Emacs client startup options. @end menu +@node TCP Emacs server +@subsection TCP Emacs server +@cindex TCP Emacs server + +@vindex server-use-tcp + By default, the Emacs server will listen to a local unix domain +socket. In some cases it is useful to have it listen on a TCP socket +instead. Examples of such cases are operating systems like Microsoft +Windows that don't support local sockets, and if you need to contact +the Emacs server from a remote machine. You can set +@code{server-use-tcp} to non-@code{nil} to have Emacs listen on a TCP +socket instead of a local socket. This is the default if your OS does +not support local sockets. + +@vindex server-host +@vindex server-port + If the Emacs server is set to use TCP, it will by default listen to +a random port on the localhost interface. This can be changed to +another interface and/or a fixed port using the variables +@code{server-host} and @code{server-port}. + +@vindex server-auth-key + A TCP socket is not subject to file system permissions. To retain +some control over who can talk to a TCP Emacs server, the +@command{emacsclient} program must send an authorization key to the +server. This key is normally randomly generated by the Emacs server. +This is the recommended mode of operation. + +@findex server-generate-key + If needed, you can set it to a static value by setting the +@code{server-auth-key} variable. The key must consist of 64 ASCII +printable characters except for space (this means characters from ! to +~; or from code 33 to 126). You can use @kbd{M-x server-generate-key} +to get a random key. + +@vindex server-auth-dir +@cindex server file + When you start a TCP Emacs server, Emacs creates a @dfn{server file} +containing the TCP information to be used by @command{emacsclient} to +connect to the server. The variable @code{server-auth-dir} specifies +the directory containing the server file; by default, this is +@file{~/.emacs.d/server/}. In the absence of a local socket with file +permissions, it is the permissions of this directory that determines +who can talk to the Emacs server. + +@cindex @env{EMACS_SERVER_FILE} environment variable + To tell @command{emacsclient} to connect to the server over TCP with a +specific server file, use the @samp{-f} or @samp{--server-file} +option, or set the @env{EMACS_SERVER_FILE} environment variable +(@pxref{emacsclient Options}). If @code{server-auth-dir} is set to a +non-standard value, @command{emacsclient} needs an absolute path to the +server file, as the default @code{server-auth-dir} is hardcoded in +@command{emacsclient} as the base of relative filenames. + + @node Invoking emacsclient @subsection Invoking @code{emacsclient} @cindex @code{emacsclient} invocation @@ -1810,25 +1866,15 @@ emacsclient Options @item -f @var{server-file} @itemx --server-file=@var{server-file} -@cindex @env{EMACS_SERVER_FILE} environment variable Specify a @dfn{server file} for connecting to an Emacs server via TCP. -An Emacs server usually uses a -local socket to listen for connections. Some operating systems, -such as Microsoft Windows, do not support local sockets; in that case, -the server communicates with @command{emacsclient} via TCP. - -@vindex server-auth-dir -@cindex server file -@vindex server-port -When you start a TCP Emacs server, Emacs creates a @dfn{server file} -containing the TCP information to be used by @command{emacsclient} to -connect to the server. The variable @code{server-auth-dir} specifies -the directory containing the server file; by default, this is -@file{~/.emacs.d/server/}. To tell @command{emacsclient} to connect -to the server over TCP with a specific server file, use the @samp{-f} -or @samp{--server-file} option, or set the @env{EMACS_SERVER_FILE} -environment variable. +An Emacs server usually uses a local socket to listen for connections, +but also supports connections over TCP. To connect to a TCP Emacs +server, @command{emacsclient} needs to read a @dfn{server file} +containing the connection details of the Emacs server. The name of +this file is specified with this option, either as a file name +relative to @file{~/.emacs.d/server} or as an absolute file name. +@xref{TCP Emacs server}. @item -n @itemx --no-wait -- 2.11.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-New-option-T-tramp-for-remote-editing-with-emacsclie.patch >From 724e7d83948e7efd93f22c18d534321c461f6cbc 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. (Bug#26591) --- doc/emacs/misc.texi | 34 +++++++++++++++++++++++++++++++++- etc/NEWS | 6 ++++++ lib-src/emacsclient.c | 20 ++++++++++++++++++-- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index c8504fef49..3c6a192ca6 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1720,7 +1720,6 @@ TCP Emacs server server file, as the default @code{server-auth-dir} is hardcoded in @command{emacsclient} as the base of relative filenames. - @node Invoking emacsclient @subsection Invoking @code{emacsclient} @cindex @code{emacsclient} invocation @@ -1918,6 +1917,39 @@ 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 +using the Emacs server over TCP. By ssh-forwarding the listening port +and making the @var{server-file} available on a remote machine, +programs on the remote machine can 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}, and +that the local Emacs listens on tcp port 12345. Assume further that +@file{/home} is on a shared file system, so that the server file +@file{~/.emacs.d/server/server} is readable on both hosts without +further magic. + +@example +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. +@end example + +@xref{TCP Emacs server}, and @xref{Top, 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 --=-=-= Content-Type: text/plain ...Peder... --=-=-=--