* emacsclient: add support for Tramp
@ 2006-11-24 7:12 Michael Mauger
0 siblings, 0 replies; only message in thread
From: Michael Mauger @ 2006-11-24 7:12 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 1748 bytes --]
Emacsclient works great on a Unix host talking to a local w32 instance of Emacs. The difficulty is that you must include the Tramp prefix in the filename for the w32 Emacs to be able to locate the file. This patch allows the Tramp prefix to be supplied separately on the command line of Emacsclient or via the environment variable EMACS_TRAMP_PREFIX.
Thus, the following two sequences are equivalent (assuming EMACS_SERVER_FILE is properly setup):
$ emacsclient /me@unix-host:/export/home/me/.profile # must be an absolute filename
or
$ EMACS_TRAMP_PREFIX=/me@unix-host:
$ emacsclient .profile # relative and absolute filenames are supported
I set EMACS_TRAMP_PREFIX to "/$USER@`hostname`:" in my Unix .profile and can use emacsclient as if the Emacs instance were on the same machine.
This patch is mostly tested. The basic feature works. The command line handling has not been tested.
Here's the Changlog:
2006-11-24 Michael R. Mauger <mmaug@yahoo.com>
* emacsclient.c (SEND_FILENM): New macro for sending filename
(tramp_prefix): New global variable for new option
(longopts): Add -p, --tramp-prefix
(decode_options): Add -p value capture
(print_help_and_exit): Add -p, --tramp-prefix description
(send_file_name): New function. Send complete filename including
tramp-prefix
(main): tramp_prefix falls back to environment variable
EMACS_TRAMP_PREFIX and use SEND_FILENM to send filenames.
Attached is the patch.
BTW, Emacsclient will not port to openVMS properly now. It assumes Posix/Unix style filenames witha slash directory separator. My change factors the code that makes a relative filename an absolute filename so that the changes are only needed in one place.
[-- Attachment #2: ec-tramp.diff --]
[-- Type: text/plain, Size: 4290 bytes --]
Index: emacs/lib-src/emacsclient.c
===================================================================
RCS file: /cvsroot/emacs/emacs/lib-src/emacsclient.c,v
retrieving revision 1.93
diff -c -r1.93 emacsclient.c
*** emacs/lib-src/emacsclient.c 23 Nov 2006 01:50:59 -0000 1.93
--- emacs/lib-src/emacsclient.c 24 Nov 2006 07:05:18 -0000
***************
*** 86,91 ****
--- 86,92 ----
\f
#define SEND_STRING(data) (send_to_emacs (s, (data)))
#define SEND_QUOTED(data) (quote_file_name (s, (data)))
+ #define SEND_FILENM(cwd, filen) (send_file_name (s, (cwd), (filen)))
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
***************
*** 129,134 ****
--- 130,139 ----
/* If non-NULL, the filename of the authentication file. */
char *server_file = NULL;
+ /* If non-NULL, the Tramp prefix to access the local file from a
+ remote Emacs */
+ char *tramp_prefix = NULL;
+
void print_help_and_exit () NO_RETURN;
struct option longopts[] =
***************
*** 142,147 ****
--- 147,153 ----
{ "socket-name", required_argument, NULL, 's' },
#endif
{ "server-file", required_argument, NULL, 'f' },
+ { "tramp-prefix", required_argument, NULL, 'p' },
{ "display", required_argument, NULL, 'd' },
{ 0, 0, 0, 0 }
};
***************
*** 210,220 ****
{
int opt = getopt_long (argc, argv,
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
! "VHnea:s:f:d:",
#else
! "VHnea:f:d:",
#endif
! longopts, 0);
if (opt == EOF)
break;
--- 216,226 ----
{
int opt = getopt_long (argc, argv,
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
! "VHnea:s:f:p:d:",
#else
! "VHnea:f:p:d:",
#endif
! longopts, 0);
if (opt == EOF)
break;
***************
*** 240,245 ****
--- 246,255 ----
server_file = optarg;
break;
+ case 'p':
+ tramp_prefix = optarg;
+ break;
+
case 'd':
display = optarg;
break;
***************
*** 290,295 ****
--- 300,307 ----
#endif
"-f, --server-file=FILENAME\n\
Set filename of the TCP authentication file\n\
+ -p, --tramp-prefix=PREFIX\n\
+ Tramp prefix to address local files by a remote Emacs\n \
-a, --alternate-editor=EDITOR\n\
Editor to fallback to if server is not running\n\
\n\
***************
*** 462,467 ****
--- 474,501 ----
return FALSE;
}
+ void
+ send_file_name (s, cwd, filename)
+ HSOCKET s;
+ const unsigned char *cwd;
+ const unsigned char *filename;
+ {
+ if (! filename || filename[0] == 0) return;
+
+ /* Send tramp prefix */
+ SEND_QUOTED (tramp_prefix);
+
+ /* Make the filename absolute if it isn't already */
+ if (! file_name_absolute_p (filename))
+ {
+ SEND_QUOTED (cwd);
+ SEND_STRING ("/");
+ }
+
+ /* Send the filename */
+ SEND_QUOTED (filename);
+ }
+
#ifdef WINDOWSNT
/* Wrapper to make WSACleanup a cdecl, as required by atexit(). */
void
***************
*** 858,863 ****
--- 892,900 ----
if ((s = set_socket ()) == INVALID_SOCKET)
fail (argc, argv);
+ if (! tramp_prefix)
+ tramp_prefix = getenv ("EMACS_TRAMP_PREFIX");
+
#ifdef HAVE_GETCWD
cwd = getcwd (string, sizeof string);
#else
***************
*** 893,916 ****
for (i = optind; i < argc; i++)
{
if (eval)
! ; /* Don't prepend any cwd or anything like that. */
else if (*argv[i] == '+')
{
char *p = argv[i] + 1;
while (isdigit ((unsigned char) *p) || *p == ':') p++;
! if (*p != 0)
! {
! SEND_QUOTED (cwd);
! SEND_STRING ("/");
! }
! }
! else if (! file_name_absolute_p (argv[i]))
! {
! SEND_QUOTED (cwd);
! SEND_STRING ("/");
}
- SEND_QUOTED (argv[i]);
SEND_STRING (" ");
}
}
--- 930,949 ----
for (i = optind; i < argc; i++)
{
if (eval)
! {
! /* Don't prepend any cwd or anything like that. */
! SEND_QUOTED (argv[i]);
! }
else if (*argv[i] == '+')
{
char *p = argv[i] + 1;
while (isdigit ((unsigned char) *p) || *p == ':') p++;
!
! SEND_FILENM (cwd, p);
}
+ else
+ SEND_FILENM (cwd, argv[i]);
SEND_STRING (" ");
}
}
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-11-24 7:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-24 7:12 emacsclient: add support for Tramp Michael Mauger
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.