Another server.el overhaul.
lib-src/emacsclient.c (xstrdup): New function. (quote_argument): Use xmalloc, not malloc. (main): Send environment variable values. lisp/server.el (server-clients): Documentation update. (server-ttys, server-frames): Removed. (server-client, server-client-get, server-client-set) (server-clients-with, server-add-client) (server-delete-client): New functions. (server-sentinel, server-handle-suspend-tty) (server-handle-delete-tty, server-handle-delete-frame) (server-start, server-process-filter, server-visit-files) (server-buffer-done, server-kill-buffer-query-function) (server-kill-emacs-query-function, server-switch-buffer): Use them. (server-log): Handle both kinds of client references. (server-start): Set up all hooks here. (server-process-filter): Cleanup. Store version in client. Handle -env commands for passing environment variable values. (server-buffer-done): Don't close clients that were created bufferless. (server-switch-buffer): Only look at frameless clients. Don't switch away from current buffer if there is no next-buffer. (server-unload-hook): Remove frame/tty hooks, too. lisp/server.el (server-quote-arg, server-unquote-arg) (server-process-filter, server-kill-buffer-query-function) (server-kill-emacs-query-function): Doc update. (server-buffer-done, server-switch-buffer): Use buffer-live-p, not buffer-name. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-143
This commit is contained in:
parent
6839f1e289
commit
9002956fd8
3 changed files with 307 additions and 232 deletions
|
@ -212,6 +212,35 @@ Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
|
|||
exit (0);
|
||||
}
|
||||
|
||||
/* Like malloc but get fatal error if memory is exhausted. */
|
||||
|
||||
long *
|
||||
xmalloc (size)
|
||||
unsigned int size;
|
||||
{
|
||||
long *result = (long *) malloc (size);
|
||||
if (result == NULL)
|
||||
{
|
||||
perror ("malloc");
|
||||
exit (1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Like strdup but get a fatal error if memory is exhausted. */
|
||||
|
||||
char *
|
||||
xstrdup (const char *s)
|
||||
{
|
||||
char *result = strdup (s);
|
||||
if (result == NULL)
|
||||
{
|
||||
perror ("strdup");
|
||||
exit (1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* In STR, insert a & before each &, each space, each newline, and
|
||||
any initial -. Change spaces to underscores, too, so that the
|
||||
return value never contains a space.
|
||||
|
@ -223,7 +252,7 @@ quote_argument (str, stream)
|
|||
char *str;
|
||||
FILE *stream;
|
||||
{
|
||||
char *copy = (char *) malloc (strlen (str) * 2 + 1);
|
||||
char *copy = (char *) xmalloc (strlen (str) * 2 + 1);
|
||||
char *p, *q;
|
||||
|
||||
p = str;
|
||||
|
@ -291,20 +320,6 @@ unquote_argument (str)
|
|||
return str;
|
||||
}
|
||||
|
||||
/* Like malloc but get fatal error if memory is exhausted. */
|
||||
|
||||
long *
|
||||
xmalloc (size)
|
||||
unsigned int size;
|
||||
{
|
||||
long *result = (long *) malloc (size);
|
||||
if (result == NULL)
|
||||
{
|
||||
perror ("malloc");
|
||||
exit (1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Try to run a different command, or --if no alternate editor is
|
||||
|
@ -610,11 +625,11 @@ main (argc, argv)
|
|||
/* `stat' failed */
|
||||
if (saved_errno == ENOENT)
|
||||
fprintf (stderr,
|
||||
"%s: Can't find socket; have you started the server?\n\
|
||||
"%s: can't find socket; have you started the server?\n\
|
||||
To start the server in Emacs, type \"M-x server-start\".\n",
|
||||
argv[0]);
|
||||
else
|
||||
fprintf (stderr, "%s: Can't stat %s: %s\n",
|
||||
fprintf (stderr, "%s: can't stat %s: %s\n",
|
||||
argv[0], server.sun_path, strerror (saved_errno));
|
||||
fail ();
|
||||
break;
|
||||
|
@ -629,7 +644,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
|
|||
fail ();
|
||||
}
|
||||
|
||||
/* We use the stream OUT to send our command to the server. */
|
||||
/* We use the stream OUT to send our commands to the server. */
|
||||
if ((out = fdopen (s, "r+")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: ", argv[0]);
|
||||
|
@ -637,7 +652,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
|
|||
fail ();
|
||||
}
|
||||
|
||||
/* We use the stream IN to read the response.
|
||||
/* We use the stream IN to read the responses.
|
||||
We used to use just one stream for both output and input
|
||||
on the socket, but reversing direction works nonportably:
|
||||
on some systems, the output appears as the first input;
|
||||
|
@ -660,7 +675,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
|
|||
|
||||
#ifdef HAVE_GETCWD
|
||||
fprintf (stderr, "%s: %s (%s)\n", argv[0],
|
||||
"Cannot get current working directory", strerror (errno));
|
||||
"cannot get current working directory", strerror (errno));
|
||||
#else
|
||||
fprintf (stderr, "%s: %s (%s)\n", argv[0], string, strerror (errno));
|
||||
#endif
|
||||
|
@ -670,6 +685,28 @@ To start the server in Emacs, type \"M-x server-start\".\n",
|
|||
/* First of all, send our version number for verification. */
|
||||
fprintf (out, "-version %s ", VERSION);
|
||||
|
||||
/* Send over our environment. */
|
||||
{
|
||||
extern char **environ;
|
||||
int i;
|
||||
for (i = 0; environ[i]; i++)
|
||||
{
|
||||
char *name = xstrdup (environ[i]);
|
||||
char *value = strchr (name, '=');
|
||||
if (value && strlen (value) > 1)
|
||||
{
|
||||
*value++ = 0;
|
||||
fprintf (out, "-env ");
|
||||
quote_argument (name, out);
|
||||
fprintf (out, " ");
|
||||
quote_argument (value, out);
|
||||
fprintf (out, " ");
|
||||
fflush (out);
|
||||
}
|
||||
free (name);
|
||||
}
|
||||
}
|
||||
|
||||
if (nowait)
|
||||
fprintf (out, "-nowait ");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue