Mercurial > emacs
changeset 99333:a999ab783eff
(window_system): Delete redundant variable.
(decode_options): Don't use it.
(find_tty): New function.
(main): Use find_tty, and don't use window_system.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 02 Nov 2008 21:41:57 +0000 |
parents | 978a7dcd9c72 |
children | e6ec0b2ebf47 |
files | lib-src/emacsclient.c |
diffstat | 1 files changed, 85 insertions(+), 79 deletions(-) [+] |
line wrap: on
line diff
--- a/lib-src/emacsclient.c Sun Nov 02 21:41:49 2008 +0000 +++ b/lib-src/emacsclient.c Sun Nov 02 21:41:57 2008 +0000 @@ -129,9 +129,6 @@ /* Nonzero means don't open a new frame. Inverse of --create-frame. */ int current_frame = 1; -/* Nonzero means open a new graphical frame. */ -int window_system = 0; - /* The display on which Emacs should work. --display. */ char *display = NULL; @@ -527,11 +524,9 @@ to allow it, for the occasional case where the user is connecting with a w32 client to a server compiled with X11 support. */ -#if 1 /* !defined WINDOWS */ case 'd': display = optarg; break; -#endif case 'n': nowait = 1; @@ -566,38 +561,27 @@ } } - /* We used to set `display' to $DISPLAY by default, but this changed the - default behavior and is sometimes inconvenient. So instead of forcing - users to say "--display ''" when they want to use Emacs's existing tty - or display connection, we force them to use "--display $DISPLAY" if - they want Emacs to connect to their current display. - -c still implicitly passes --display $DISPLAY unless -t was specified - so as to try and mimick the behavior of `emacs' which either uses - the current tty or the current $DISPLAY. */ + /* If the -c option is used (without -t) and no --display argument + is provided, try $DISPLAY. + Without the -c option, we used to set `display' to $DISPLAY by + default, but this changed the default behavior and is sometimes + inconvenient. So we force users to use "--display $DISPLAY" if + they want Emacs to connect to their current display. */ if (!current_frame && !tty && !display) display = egetenv ("DISPLAY"); + /* A null-string display is invalid. */ if (display && strlen (display) == 0) display = NULL; - if (!tty && display) - window_system = 1; - else if (!current_frame) + /* If no display is available, new frames are tty frames. */ + if (!current_frame && !display) tty = 1; /* --no-wait implies --current-frame on ttys when there are file - arguments or expressions given. */ + arguments or expressions given. */ if (nowait && tty && argc - optind > 0) current_frame = 1; - - if (current_frame) - { - tty = 0; - window_system = 0; - } - - if (tty) - window_system = 0; } @@ -1099,6 +1083,60 @@ errno = old_errno; } + + +/* Get tty name and type. If successful, return the type in TTY_TYPE + and the name in TTY_NAME, and return 1. Otherwise, fail if NOABORT + is zero, or return 0 if NOABORT is non-zero. */ + +int +find_tty (char **tty_type, char **tty_name, int noabort) +{ + char *type = egetenv ("TERM"); + char *name = ttyname (fileno (stdout)); + + if (!name) + { + if (noabort) + return 0; + else + { + message (TRUE, "%s: could not get terminal name\n", progname); + fail (); + } + } + + if (!type) + { + if (noabort) + return 0; + else + { + message (TRUE, "%s: please set the TERM variable to your terminal type\n", + progname); + fail (); + } + } + + if (strcmp (type, "eterm") == 0) + { + if (noabort) + return 0; + else + { + /* This causes nasty, MULTI_KBOARD-related input lockouts. */ + message (TRUE, "%s: opening a frame in an Emacs term buffer" + " is not supported\n", progname); + fail (); + } + } + + *tty_name = name; + *tty_type = type; + return 1; +} + + /* Set up signal handlers before opening a frame on the current tty. */ void @@ -1384,7 +1422,7 @@ /* Process options. */ decode_options (argc, argv); - if ((argc - optind < 1) && !eval && !tty && !window_system) + if ((argc - optind < 1) && !eval && current_frame) { message (TRUE, "%s: file name or argument required\n" "Try `%s --help' for more information\n", @@ -1409,7 +1447,7 @@ w32_give_focus (); #endif - /* Send over our environment. */ + /* Send over our environment and current directory. */ if (!current_frame) { extern char **environ; @@ -1422,11 +1460,6 @@ quote_argument (emacs_socket, environ[i]); send_to_emacs (emacs_socket, " "); } - } - - /* Send over our current directory. */ - if (!current_frame) - { send_to_emacs (emacs_socket, "-dir "); quote_argument (emacs_socket, cwd); send_to_emacs (emacs_socket, "/"); @@ -1452,43 +1485,22 @@ frame is available. */ if (tty || (current_frame && !eval)) { - char *type = egetenv ("TERM"); - char *tty_name = NULL; - - tty_name = ttyname (fileno (stdout)); - - if (! tty_name) - { - message (TRUE, "%s: could not get terminal name\n", progname); - fail (); - } + char *tty_type, *tty_name; - if (! type) - { - message (TRUE, "%s: please set the TERM variable to your terminal type\n", - progname); - fail (); - } - - if (! strcmp (type, "eterm")) - { - /* This causes nasty, MULTI_KBOARD-related input lockouts. */ - message (TRUE, "%s: opening a frame in an Emacs term buffer" - " is not supported\n", progname); - fail (); - } + if (find_tty (&tty_type, &tty_name, !tty)) + { #if !defined (NO_SOCKETS_IN_FILE_SYSTEM) - init_signals (); + init_signals (); #endif - - send_to_emacs (emacs_socket, "-tty "); - quote_argument (emacs_socket, tty_name); - send_to_emacs (emacs_socket, " "); - quote_argument (emacs_socket, type); - send_to_emacs (emacs_socket, " "); + send_to_emacs (emacs_socket, "-tty "); + quote_argument (emacs_socket, tty_name); + send_to_emacs (emacs_socket, " "); + quote_argument (emacs_socket, tty_type); + send_to_emacs (emacs_socket, " "); + } } - if (window_system) + if (!current_frame && !tty) send_to_emacs (emacs_socket, "-window-system "); if ((argc - optind > 0)) @@ -1555,20 +1567,15 @@ send_to_emacs (emacs_socket, " "); } } - else + else if (eval) { - if (!tty && !window_system) - { - while ((str = fgets (string, BUFSIZ, stdin))) - { - if (eval) - send_to_emacs (emacs_socket, "-eval "); - else - send_to_emacs (emacs_socket, "-file "); - quote_argument (emacs_socket, str); - } - send_to_emacs (emacs_socket, " "); - } + /* Read expressions interactively. */ + while ((str = fgets (string, BUFSIZ, stdin))) + { + send_to_emacs (emacs_socket, "-eval "); + quote_argument (emacs_socket, str); + } + send_to_emacs (emacs_socket, " "); } send_to_emacs (emacs_socket, "\n"); @@ -1601,7 +1608,6 @@ { /* -window-system-unsupported: Emacs was compiled without X support. Try again on the terminal. */ - window_system = 0; nowait = 0; tty = 1; goto retry;