aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/emacs/emacs.texi1
-rw-r--r--doc/emacs/misc.texi120
-rw-r--r--etc/NEWS8
-rw-r--r--lib-src/emacsclient.c20
4 files changed, 128 insertions, 21 deletions
diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi
index 5c8977c6b09..a3eb4225a75 100644
--- a/doc/emacs/emacs.texi
+++ b/doc/emacs/emacs.texi
@@ -1082,6 +1082,7 @@ Shell Command History
1082 1082
1083Using Emacs as a Server 1083Using Emacs as a Server
1084 1084
1085* TCP Emacs server:: Listening to a TCP socket.
1085* Invoking emacsclient:: Connecting to the Emacs server. 1086* Invoking emacsclient:: Connecting to the Emacs server.
1086* emacsclient Options:: Emacs client startup options. 1087* emacsclient Options:: Emacs client startup options.
1087 1088
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index bcc20a6db16..84681f2269a 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -1661,10 +1661,68 @@ expression @code{(+ 1 2)} on the @samp{foo} server, and returns
1661signaled.) Currently, this feature is mainly useful for developers. 1661signaled.) Currently, this feature is mainly useful for developers.
1662 1662
1663@menu 1663@menu
1664* TCP Emacs server:: Listening to a TCP socket.
1664* Invoking emacsclient:: Connecting to the Emacs server. 1665* Invoking emacsclient:: Connecting to the Emacs server.
1665* emacsclient Options:: Emacs client startup options. 1666* emacsclient Options:: Emacs client startup options.
1666@end menu 1667@end menu
1667 1668
1669@node TCP Emacs server
1670@subsection TCP Emacs server
1671@cindex TCP Emacs server
1672
1673@vindex server-use-tcp
1674 An Emacs server usually listens to connections on a local Unix
1675domain socket. Some operating systems, such as MS-Windows, do not
1676support local sockets; in that case, the server uses TCP sockets
1677instead. In some cases it is useful to have the server listen on a
1678TCP socket even if local sockets are supported, e.g., if you need to
1679contact the Emacs server from a remote machine. You can set
1680@code{server-use-tcp} to non-@code{nil} to have Emacs listen on a TCP
1681socket instead of a local socket. This is the default if your OS does
1682not support local sockets.
1683
1684@vindex server-host
1685@vindex server-port
1686 If the Emacs server is set to use TCP, it will by default listen to
1687a random port on the localhost interface. This can be changed to
1688another interface and/or a fixed port using the variables
1689@code{server-host} and @code{server-port}.
1690
1691@vindex server-auth-key
1692 A TCP socket is not subject to file system permissions. To retain
1693some control over which users can talk to an Emacs server over TCP
1694sockets, the @command{emacsclient} program must send an authorization
1695key to the server. This key is normally randomly generated by the
1696Emacs server. This is the recommended mode of operation.
1697
1698@findex server-generate-key
1699 If needed, you can set the authorization key to a static value by
1700setting the @code{server-auth-key} variable. The key must consist of
170164 ASCII printable characters except for space (this means characters
1702from @samp{!} to @samp{~}, or from decimal code 33 to 126). You can
1703use @kbd{M-x server-generate-key} to get a random key.
1704
1705@vindex server-auth-dir
1706@cindex server file
1707 When you start a TCP Emacs server, Emacs creates a @dfn{server file}
1708containing the TCP information to be used by @command{emacsclient} to
1709connect to the server. The variable @code{server-auth-dir} specifies
1710the directory containing the server file; by default, this is
1711@file{~/.emacs.d/server/}. In the absence of a local socket with file
1712permissions, the permissions of this directory determine which users
1713can have their @command{emacsclient} processes talk to the Emacs
1714server.
1715
1716@vindex EMACS_SERVER_FILE@r{, environment variable}
1717 To tell @command{emacsclient} to connect to the server over TCP with
1718a specific server file, use the @samp{-f} or @samp{--server-file}
1719option, or set the @env{EMACS_SERVER_FILE} environment variable
1720(@pxref{emacsclient Options}). If @code{server-auth-dir} is set to a
1721non-standard value, @command{emacsclient} needs an absolute file name
1722to the server file, as the default @code{server-auth-dir} is
1723hard-coded in @command{emacsclient} to be used as the directory for
1724resolving relative filenames.
1725
1668@node Invoking emacsclient 1726@node Invoking emacsclient
1669@subsection Invoking @code{emacsclient} 1727@subsection Invoking @code{emacsclient}
1670@cindex @code{emacsclient} invocation 1728@cindex @code{emacsclient} invocation
@@ -1810,25 +1868,18 @@ evaluate, @emph{not} as a list of files to visit.
1810 1868
1811@item -f @var{server-file} 1869@item -f @var{server-file}
1812@itemx --server-file=@var{server-file} 1870@itemx --server-file=@var{server-file}
1813@cindex @env{EMACS_SERVER_FILE} environment variable 1871Specify a server file (@pxref{TCP Emacs server}) for connecting to an
1814Specify a @dfn{server file} for connecting to an Emacs server via TCP. 1872Emacs server via TCP. Alternatively, you can set the
1815 1873@env{EMACS_SERVER_FILE} environment variable to point to the server
1816An Emacs server usually uses a 1874file.
1817local socket to listen for connections. Some operating systems, 1875
1818such as Microsoft Windows, do not support local sockets; in that case, 1876An Emacs server usually uses a local socket to listen for connections,
1819the server communicates with @command{emacsclient} via TCP. 1877but also supports connections over TCP. To connect to a TCP Emacs
1820 1878server, @command{emacsclient} needs to read a @dfn{server file}
1821@vindex server-auth-dir 1879containing the connection details of the Emacs server. The name of
1822@cindex server file 1880this file is specified with this option, either as a file name
1823@vindex server-port 1881relative to @file{~/.emacs.d/server} or as an absolute file name.
1824When you start a TCP Emacs server, Emacs creates a @dfn{server file} 1882@xref{TCP Emacs server}.
1825containing the TCP information to be used by @command{emacsclient} to
1826connect to the server. The variable @code{server-auth-dir} specifies
1827the directory containing the server file; by default, this is
1828@file{~/.emacs.d/server/}. To tell @command{emacsclient} to connect
1829to the server over TCP with a specific server file, use the @samp{-f}
1830or @samp{--server-file} option, or set the @env{EMACS_SERVER_FILE}
1831environment variable.
1832 1883
1833@item -n 1884@item -n
1834@itemx --no-wait 1885@itemx --no-wait
@@ -1872,6 +1923,37 @@ On MS-Windows, @samp{-t} behaves just like @samp{-c} if the Emacs
1872server is using the graphical display, but if the Emacs server is 1923server is using the graphical display, but if the Emacs server is
1873running on a text terminal, it creates a new frame in the current text 1924running on a text terminal, it creates a new frame in the current text
1874terminal. 1925terminal.
1926
1927@item -T @var{tramp-prefix}
1928@itemx --tramp-prefix=@var{tramp-prefix}
1929Set the prefix to add to filenames for Emacs to locate files on remote
1930machines using TRAMP (@pxref{Top, The Tramp Manual,, tramp, The Tramp
1931Manual}). This is mostly useful in combination with using the Emacs
1932server over TCP (@pxref{TCP Emacs server}). By ssh-forwarding the
1933listening port and making the @var{server-file} available on a remote
1934machine, programs on the remote machine can use @command{emacsclient}
1935as the value for the @env{EDITOR} and similar environment variables,
1936but instead of talking to an Emacs server on the remote machine, the
1937files will be visited in the local Emacs session using TRAMP.
1938
1939@vindex EMACSCLIENT_TRAMP@r{, environment variable}
1940Setting the environment variable @env{EMACSCLIENT_TRAMP} has the same
1941effect as using the @samp{-T} option. If both are specified, the
1942command-line option takes precedence.
1943
1944For example, assume two hosts, @samp{local} and @samp{remote}, and
1945that the local Emacs listens on tcp port 12345. Assume further that
1946@file{/home} is on a shared file system, so that the server file
1947@file{~/.emacs.d/server/server} is readable on both hosts.
1948
1949@example
1950local$ ssh -R12345:localhost:12345 remote
1951remote$ export EDITOR="emacsclient \
1952 --server-file=server \
1953 --tramp=/ssh:remote:"
1954remote$ $EDITOR /tmp/foo.txt #Should open in local emacs.
1955@end example
1956
1875@end table 1957@end table
1876 1958
1877 The new graphical or text terminal frames created by the @samp{-c} 1959 The new graphical or text terminal frames created by the @samp{-c}
diff --git a/etc/NEWS b/etc/NEWS
index 4121c44b0c2..340718ecbc4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -344,6 +344,14 @@ for DNS-querying functions 'nslookup-host', 'dns-lookup-host',
344and 'run-dig'. Each function now accepts an optional name server 344and 'run-dig'. Each function now accepts an optional name server
345argument interactively (with a prefix argument) and non-interactively. 345argument interactively (with a prefix argument) and non-interactively.
346 346
347+++
348** Emacsclient has a new option -T/--tramp.
349This helps with using a local Emacs session as the server for a remote
350emacsclient. With appropriate setup, one can now set the EDITOR
351environment variable on a remote machine to emacsclient, and
352use the local Emacs to edit remote files via Tramp. See the node
353"emacsclient Options" in the user manual for the details.
354
347 355
348* Editing Changes in Emacs 26.1 356* Editing Changes in Emacs 26.1
349 357
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 7b735dfb05d..c21ee6bd395 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -149,6 +149,9 @@ const char *socket_name = NULL;
149/* If non-NULL, the filename of the authentication file. */ 149/* If non-NULL, the filename of the authentication file. */
150const char *server_file = NULL; 150const char *server_file = NULL;
151 151
152/* If non-NULL, the tramp prefix emacs must use to find the files. */
153const char *tramp_prefix = NULL;
154
152/* PID of the Emacs server process. */ 155/* PID of the Emacs server process. */
153int emacs_pid = 0; 156int emacs_pid = 0;
154 157
@@ -178,6 +181,7 @@ struct option longopts[] =
178 { "server-file", required_argument, NULL, 'f' }, 181 { "server-file", required_argument, NULL, 'f' },
179 { "display", required_argument, NULL, 'd' }, 182 { "display", required_argument, NULL, 'd' },
180 { "parent-id", required_argument, NULL, 'p' }, 183 { "parent-id", required_argument, NULL, 'p' },
184 { "tramp", required_argument, NULL, 'T' },
181 { 0, 0, 0, 0 } 185 { 0, 0, 0, 0 }
182}; 186};
183 187
@@ -468,14 +472,15 @@ static void
468decode_options (int argc, char **argv) 472decode_options (int argc, char **argv)
469{ 473{
470 alternate_editor = egetenv ("ALTERNATE_EDITOR"); 474 alternate_editor = egetenv ("ALTERNATE_EDITOR");
475 tramp_prefix = egetenv ("EMACSCLIENT_TRAMP");
471 476
472 while (1) 477 while (1)
473 { 478 {
474 int opt = getopt_long_only (argc, argv, 479 int opt = getopt_long_only (argc, argv,
475#ifndef NO_SOCKETS_IN_FILE_SYSTEM 480#ifndef NO_SOCKETS_IN_FILE_SYSTEM
476 "VHnequa:s:f:d:F:tc", 481 "VHnequa:s:f:d:F:tcT:",
477#else 482#else
478 "VHnequa:f:d:F:tc", 483 "VHnequa:f:d:F:tcT:",
479#endif 484#endif
480 longopts, 0); 485 longopts, 0);
481 486
@@ -554,6 +559,10 @@ decode_options (int argc, char **argv)
554 frame_parameters = optarg; 559 frame_parameters = optarg;
555 break; 560 break;
556 561
562 case 'T':
563 tramp_prefix = optarg;
564 break;
565
557 default: 566 default:
558 message (true, "Try '%s --help' for more information\n", progname); 567 message (true, "Try '%s --help' for more information\n", progname);
559 exit (EXIT_FAILURE); 568 exit (EXIT_FAILURE);
@@ -654,6 +663,9 @@ The following OPTIONS are accepted:\n\
654 Editor to fallback to if the server is not running\n" 663 Editor to fallback to if the server is not running\n"
655" If EDITOR is the empty string, start Emacs in daemon\n\ 664" If EDITOR is the empty string, start Emacs in daemon\n\
656 mode and try connecting again\n" 665 mode and try connecting again\n"
666"-T PREFIX, --tramp=PREFIX\n\
667 PREFIX to prepend to filenames sent by emacsclient\n\
668 for locating files remotely via Tramp\n"
657"\n\ 669"\n\
658Report bugs with M-x report-emacs-bug.\n"); 670Report bugs with M-x report-emacs-bug.\n");
659 exit (EXIT_SUCCESS); 671 exit (EXIT_SUCCESS);
@@ -1687,6 +1699,8 @@ main (int argc, char **argv)
1687 } 1699 }
1688 } 1700 }
1689 send_to_emacs (emacs_socket, "-dir "); 1701 send_to_emacs (emacs_socket, "-dir ");
1702 if (tramp_prefix)
1703 quote_argument (emacs_socket, tramp_prefix);
1690 quote_argument (emacs_socket, cwd); 1704 quote_argument (emacs_socket, cwd);
1691 send_to_emacs (emacs_socket, "/"); 1705 send_to_emacs (emacs_socket, "/");
1692 send_to_emacs (emacs_socket, " "); 1706 send_to_emacs (emacs_socket, " ");
@@ -1791,6 +1805,8 @@ main (int argc, char **argv)
1791#endif 1805#endif
1792 1806
1793 send_to_emacs (emacs_socket, "-file "); 1807 send_to_emacs (emacs_socket, "-file ");
1808 if (tramp_prefix && file_name_absolute_p (argv[i]))
1809 quote_argument (emacs_socket, tramp_prefix);
1794 quote_argument (emacs_socket, argv[i]); 1810 quote_argument (emacs_socket, argv[i]);
1795 send_to_emacs (emacs_socket, " "); 1811 send_to_emacs (emacs_socket, " ");
1796 } 1812 }