diff options
| author | Karoly Lorentey | 2004-02-19 23:55:51 +0000 |
|---|---|---|
| committer | Karoly Lorentey | 2004-02-19 23:55:51 +0000 |
| commit | 77134727c9430ee77bff150206fce33f2045dfc0 (patch) | |
| tree | 4d288cd6b33a8f3ca914edbdbf8eed5d06e759a9 /lib-src | |
| parent | bfdfad9294d072ad12b670d23912998f7e439394 (diff) | |
| download | emacs-77134727c9430ee77bff150206fce33f2045dfc0.tar.gz emacs-77134727c9430ee77bff150206fce33f2045dfc0.zip | |
Added -w option to emacsclient for opening a new X frame.
lib-src/emacsclient.c (window_system): New variable.
(frame): Renamed to tty for consistency with the option name.
(longopts, print_help_and_exit): Added -w option. (Suggested by Ami
Fischman <ami at fischman dot org>.
(decode_options): Initialize display to $DISPLAY. Handle -w option.
(main): Implement the -w option. Changed to a more elaborate protocol
between Emacs and emacsclient, in preparation to suspend support.
lisp/server.el (server-frames): New variable.
(server-handle-delete-frame): New function.
(server-start): Add it to delete-frame-functions.
(server-select-display): Don't make the new frame invisible.
(server-with-errors-reported): New macro for brevity.
(server-process-filter): Implement the "-window-system" command.
Use server-with-errors-reported. Fixed regexp for +line:column syntax.
Use the new protocol.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-83
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/emacsclient.c | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 771eeac05e6..90224fe51ee 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -70,11 +70,14 @@ int nowait = 0; | |||
| 70 | /* Nonzero means args are expressions to be evaluated. --eval. */ | 70 | /* Nonzero means args are expressions to be evaluated. --eval. */ |
| 71 | int eval = 0; | 71 | int eval = 0; |
| 72 | 72 | ||
| 73 | /* Nonzero means open a new graphical frame. */ | ||
| 74 | int window_system = 0; | ||
| 75 | |||
| 73 | /* The display on which Emacs should work. --display. */ | 76 | /* The display on which Emacs should work. --display. */ |
| 74 | char *display = NULL; | 77 | char *display = NULL; |
| 75 | 78 | ||
| 76 | /* Nonzero means open a new Emacs frame on the current terminal. */ | 79 | /* Nonzero means open a new Emacs frame on the current terminal. */ |
| 77 | int frame = 0; | 80 | int tty = 0; |
| 78 | 81 | ||
| 79 | /* If non-NULL, the name of an editor to fallback to if the server | 82 | /* If non-NULL, the name of an editor to fallback to if the server |
| 80 | is not running. --alternate-editor. */ | 83 | is not running. --alternate-editor. */ |
| @@ -92,6 +95,7 @@ struct option longopts[] = | |||
| 92 | { "help", no_argument, NULL, 'H' }, | 95 | { "help", no_argument, NULL, 'H' }, |
| 93 | { "version", no_argument, NULL, 'V' }, | 96 | { "version", no_argument, NULL, 'V' }, |
| 94 | { "tty", no_argument, NULL, 't' }, | 97 | { "tty", no_argument, NULL, 't' }, |
| 98 | { "window-system", no_argument, NULL, 'w' }, | ||
| 95 | { "alternate-editor", required_argument, NULL, 'a' }, | 99 | { "alternate-editor", required_argument, NULL, 'a' }, |
| 96 | { "socket-name", required_argument, NULL, 's' }, | 100 | { "socket-name", required_argument, NULL, 's' }, |
| 97 | { "display", required_argument, NULL, 'd' }, | 101 | { "display", required_argument, NULL, 'd' }, |
| @@ -107,11 +111,12 @@ decode_options (argc, argv) | |||
| 107 | char **argv; | 111 | char **argv; |
| 108 | { | 112 | { |
| 109 | alternate_editor = getenv ("ALTERNATE_EDITOR"); | 113 | alternate_editor = getenv ("ALTERNATE_EDITOR"); |
| 114 | display = getenv ("DISPLAY"); | ||
| 110 | 115 | ||
| 111 | while (1) | 116 | while (1) |
| 112 | { | 117 | { |
| 113 | int opt = getopt_long (argc, argv, | 118 | int opt = getopt_long (argc, argv, |
| 114 | "VHnea:s:d:t", longopts, 0); | 119 | "VHnea:s:d:tw", longopts, 0); |
| 115 | 120 | ||
| 116 | if (opt == EOF) | 121 | if (opt == EOF) |
| 117 | break; | 122 | break; |
| @@ -149,7 +154,13 @@ decode_options (argc, argv) | |||
| 149 | break; | 154 | break; |
| 150 | 155 | ||
| 151 | case 't': | 156 | case 't': |
| 152 | frame = 1; | 157 | tty = 1; |
| 158 | window_system = 0; | ||
| 159 | break; | ||
| 160 | |||
| 161 | case 'w': | ||
| 162 | window_system = 1; | ||
| 163 | tty = 0; | ||
| 153 | break; | 164 | break; |
| 154 | 165 | ||
| 155 | case 'H': | 166 | case 'H': |
| @@ -163,11 +174,10 @@ decode_options (argc, argv) | |||
| 163 | } | 174 | } |
| 164 | } | 175 | } |
| 165 | 176 | ||
| 166 | if (frame) { | 177 | if (tty) { |
| 167 | nowait = 0; | 178 | nowait = 0; |
| 168 | display = 0; | 179 | display = 0; |
| 169 | } | 180 | } |
| 170 | |||
| 171 | } | 181 | } |
| 172 | 182 | ||
| 173 | void | 183 | void |
| @@ -182,6 +192,7 @@ The following OPTIONS are accepted:\n\ | |||
| 182 | -V, --version Just print a version info and return\n\ | 192 | -V, --version Just print a version info and return\n\ |
| 183 | -H, --help Print this usage information message\n\ | 193 | -H, --help Print this usage information message\n\ |
| 184 | -t, --tty Open a new Emacs frame on the current terminal\n\ | 194 | -t, --tty Open a new Emacs frame on the current terminal\n\ |
| 195 | -w, --window-system Open a new graphical Emacs frame\n\ | ||
| 185 | -n, --no-wait Don't wait for the server to return\n\ | 196 | -n, --no-wait Don't wait for the server to return\n\ |
| 186 | -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ | 197 | -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ |
| 187 | -d, --display=DISPLAY Visit the file in the given display\n\ | 198 | -d, --display=DISPLAY Visit the file in the given display\n\ |
| @@ -272,16 +283,6 @@ fail (void) | |||
| 272 | 283 | ||
| 273 | int emacs_pid; | 284 | int emacs_pid; |
| 274 | 285 | ||
| 275 | #ifdef nec_ews_svr4 | ||
| 276 | extern char *_sobuf ; | ||
| 277 | #else | ||
| 278 | #if defined (USG) || defined (DGUX) | ||
| 279 | unsigned char _sobuf[BUFSIZ+8]; | ||
| 280 | #else | ||
| 281 | char _sobuf[BUFSIZ]; | ||
| 282 | #endif | ||
| 283 | #endif | ||
| 284 | |||
| 285 | /* A signal handler that passes the signal to the Emacs process. | 286 | /* A signal handler that passes the signal to the Emacs process. |
| 286 | Useful for SIGWINCH. */ | 287 | Useful for SIGWINCH. */ |
| 287 | 288 | ||
| @@ -395,7 +396,7 @@ main (argc, argv) | |||
| 395 | /* Process options. */ | 396 | /* Process options. */ |
| 396 | decode_options (argc, argv); | 397 | decode_options (argc, argv); |
| 397 | 398 | ||
| 398 | if ((argc - optind < 1) && !eval && !frame) | 399 | if ((argc - optind < 1) && !eval && !tty && !window_system) |
| 399 | { | 400 | { |
| 400 | fprintf (stderr, "%s: file name or argument required\n", progname); | 401 | fprintf (stderr, "%s: file name or argument required\n", progname); |
| 401 | fprintf (stderr, "Try `%s --help' for more information\n", progname); | 402 | fprintf (stderr, "Try `%s --help' for more information\n", progname); |
| @@ -574,7 +575,7 @@ To start the server in Emacs, type \"M-x server-start\".\n", | |||
| 574 | fprintf (out, " "); | 575 | fprintf (out, " "); |
| 575 | } | 576 | } |
| 576 | 577 | ||
| 577 | if (frame) | 578 | if (tty) |
| 578 | { | 579 | { |
| 579 | char *tty_name = ttyname (fileno (stdin)); | 580 | char *tty_name = ttyname (fileno (stdin)); |
| 580 | if (! tty_name) | 581 | if (! tty_name) |
| @@ -588,6 +589,9 @@ To start the server in Emacs, type \"M-x server-start\".\n", | |||
| 588 | quote_file_name (getenv("TERM"), out); | 589 | quote_file_name (getenv("TERM"), out); |
| 589 | fprintf (out, " "); | 590 | fprintf (out, " "); |
| 590 | } | 591 | } |
| 592 | |||
| 593 | if (window_system) | ||
| 594 | fprintf (out, "-window-system "); | ||
| 591 | 595 | ||
| 592 | if ((argc - optind > 0)) | 596 | if ((argc - optind > 0)) |
| 593 | { | 597 | { |
| @@ -617,7 +621,7 @@ To start the server in Emacs, type \"M-x server-start\".\n", | |||
| 617 | } | 621 | } |
| 618 | else | 622 | else |
| 619 | { | 623 | { |
| 620 | if (!frame) | 624 | if (!tty && !window_system) |
| 621 | { | 625 | { |
| 622 | while ((str = fgets (string, BUFSIZ, stdin))) | 626 | while ((str = fgets (string, BUFSIZ, stdin))) |
| 623 | { | 627 | { |
| @@ -636,7 +640,7 @@ To start the server in Emacs, type \"M-x server-start\".\n", | |||
| 636 | return 0; | 640 | return 0; |
| 637 | } | 641 | } |
| 638 | 642 | ||
| 639 | if (!eval && !frame) | 643 | if (!eval && !tty) |
| 640 | { | 644 | { |
| 641 | printf ("Waiting for Emacs..."); | 645 | printf ("Waiting for Emacs..."); |
| 642 | needlf = 2; | 646 | needlf = 2; |
| @@ -646,18 +650,29 @@ To start the server in Emacs, type \"M-x server-start\".\n", | |||
| 646 | /* Now, wait for an answer and print any messages. */ | 650 | /* Now, wait for an answer and print any messages. */ |
| 647 | while ((str = fgets (string, BUFSIZ, in))) | 651 | while ((str = fgets (string, BUFSIZ, in))) |
| 648 | { | 652 | { |
| 649 | if (frame) | 653 | if (strprefix ("-emacs-pid ", str)) |
| 650 | { | 654 | { |
| 651 | if (strprefix ("emacs-pid ", str)) | 655 | emacs_pid = strtol (string + strlen ("-emacs-pid"), NULL, 10); |
| 652 | { | 656 | } |
| 653 | emacs_pid = strtol (string + strlen ("emacs-pid"), NULL, 10); | 657 | else if (strprefix ("-print ", str)) |
| 654 | } | 658 | { |
| 659 | if (needlf == 2) | ||
| 660 | printf ("\n"); | ||
| 661 | printf ("%s", str + strlen ("-print ")); | ||
| 662 | needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; | ||
| 663 | } | ||
| 664 | else if (strprefix ("-error ", str)) | ||
| 665 | { | ||
| 666 | if (needlf == 2) | ||
| 667 | printf ("\n"); | ||
| 668 | printf ("*ERROR*: %s", str + strlen ("-print ")); | ||
| 669 | needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; | ||
| 655 | } | 670 | } |
| 656 | else | 671 | else |
| 657 | { | 672 | { |
| 658 | if (needlf == 2) | 673 | if (needlf == 2) |
| 659 | printf ("\n"); | 674 | printf ("\n"); |
| 660 | printf ("%s", str); | 675 | printf ("*ERROR*: Unknown message: %s", str); |
| 661 | needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; | 676 | needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; |
| 662 | } | 677 | } |
| 663 | } | 678 | } |