Mercurial > emacs
comparison src/term.c @ 82988:f82e3a6f5ccb
A few more bugfixes and new features.
(Sigh.) I obviously need to remember to separate individual changes
to multiple commits.
src/emacsclient.c: Improved error handling.
(decode_options): Changed frame option (again) from -f to -t.
(print_help_and_exit): Ditto.
(copy_from_to): Check EINTR after write, not EAGAIN. Removed SIGIO hack.
(pty_conversation): Handle errors transmitted through the socket.
Handle pty errors by not reading from it anymore.
(main): Restore correct errno after socket_status failed. Send -tty
on -t, not -pty.
lisp/server.el (server-process-filter): Watch -tty, not -pty.
Use make-frame-on-tty instead of make-terminal-frame.
Don't set newframe to t if make-frame-on-tty failed.
Don't delete frames here. Print correct message when there are no
files to edit, but a new frame was requested.
(server-sentinel): Delete the frame after the process.
(server-handle-delete-frame): New function for delete-frame-functions.
(server-start): Add server-handle-delete-frame to delete-frame-functions.
(server-buffer-done): Don't delete frames here.
src/alloc.c (mark_ttys): Add prototype.
(Fgarbage_collect): Call mark_ttys.
src/emacs.c: (shut_down_emacs): Don't flush stdout before
reset_sys_modes().
src/process.c (add_keyboard_wait_descriptor_called_flag): Removed.
(add_keyboard_wait_descriptor): Removed stdin hack.
src/sysdep.c: Unconditionally include sysselect.h.
(old_fcntl_flags): Changed to an array.
(init_sigio, reset_sigio): Use it.
(narrow_foreground_group, widen_foreground_group): Use setpgid, not
setpgrp.
(old_fcntl_owner): Changed to an array.
(init_sys_modes, reset_sys_modes): Use it. Fix fsync() and reset_sigio() calls.
src/term.c (Qframe_tty_name, Qframe_tty_type): New variables.
(syms_of_term): Initialize them.
(Fframe_tty_name, Fframe_tty_type): New functions.
(term_init): Call add_keyboard_wait_descriptor().
(Fdelete_tty): New function.
(delete_tty): Call delete_keyboard_wait_descriptor().
(get_current_tty): Removed.
(mark_ttys): New function.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-28
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Wed, 31 Dec 2003 05:09:29 +0000 |
parents | 1682917e56b4 |
children | f3845715a5f6 |
comparison
equal
deleted
inserted
replaced
82987:1682917e56b4 | 82988:f82e3a6f5ccb |
---|---|
107 /* Nonzero means no need to redraw the entire frame on resuming a | 107 /* Nonzero means no need to redraw the entire frame on resuming a |
108 suspended Emacs. This is useful on terminals with multiple | 108 suspended Emacs. This is useful on terminals with multiple |
109 pages, where one page is used for Emacs and another for all | 109 pages, where one page is used for Emacs and another for all |
110 else. */ | 110 else. */ |
111 int no_redraw_on_reenter; | 111 int no_redraw_on_reenter; |
112 | 112 |
113 Lisp_Object Qframe_tty_name, Qframe_tty_type; | |
114 | |
113 /* Hook functions that you can set to snap out the functions in this file. | 115 /* Hook functions that you can set to snap out the functions in this file. |
114 These are all extern'd in termhooks.h */ | 116 These are all extern'd in termhooks.h */ |
115 | 117 |
116 void (*cursor_to_hook) P_ ((int, int)); | 118 void (*cursor_to_hook) P_ ((int, int)); |
117 void (*raw_cursor_to_hook) P_ ((int, int)); | 119 void (*raw_cursor_to_hook) P_ ((int, int)); |
2105 | 2107 |
2106 return 0; | 2108 return 0; |
2107 } | 2109 } |
2108 | 2110 |
2109 | 2111 |
2112 | |
2113 DEFUN ("frame-tty-name", Fframe_tty_name, Sframe_tty_name, 0, 1, 0, | |
2114 doc: /* Return the name of the TTY device that FRAME is displayed on. */) | |
2115 (frame) | |
2116 Lisp_Object frame; | |
2117 { | |
2118 struct frame *f; | |
2119 | |
2120 if (NILP (frame)) | |
2121 { | |
2122 f = XFRAME (selected_frame); | |
2123 } | |
2124 else | |
2125 { | |
2126 CHECK_LIVE_FRAME (frame); | |
2127 f = XFRAME (frame); | |
2128 } | |
2129 | |
2130 if (f->output_method != output_termcap) | |
2131 wrong_type_argument (Qframe_tty_name, frame); | |
2132 | |
2133 if (f->output_data.tty->name) | |
2134 return build_string (f->output_data.tty->name); | |
2135 else | |
2136 return Qnil; | |
2137 } | |
2138 | |
2139 DEFUN ("frame-tty-type", Fframe_tty_type, Sframe_tty_type, 0, 1, 0, | |
2140 doc: /* Return the type of the TTY device that FRAME is displayed on. */) | |
2141 (frame) | |
2142 Lisp_Object frame; | |
2143 { | |
2144 struct frame *f; | |
2145 | |
2146 if (NILP (frame)) | |
2147 { | |
2148 f = XFRAME (selected_frame); | |
2149 } | |
2150 else | |
2151 { | |
2152 CHECK_LIVE_FRAME (frame); | |
2153 f = XFRAME (frame); | |
2154 } | |
2155 | |
2156 if (f->output_method != output_termcap) | |
2157 wrong_type_argument (Qframe_tty_type, frame); | |
2158 | |
2159 if (f->output_data.tty->type) | |
2160 return build_string (f->output_data.tty->type); | |
2161 else | |
2162 return Qnil; | |
2163 } | |
2164 | |
2165 | |
2110 /*********************************************************************** | 2166 /*********************************************************************** |
2111 Initialization | 2167 Initialization |
2112 ***********************************************************************/ | 2168 ***********************************************************************/ |
2113 | 2169 |
2114 struct tty_output * | 2170 struct tty_output * |
2184 TTY_OUTPUT (tty) = stdout; | 2240 TTY_OUTPUT (tty) = stdout; |
2185 } | 2241 } |
2186 | 2242 |
2187 TTY_TYPE (tty) = xstrdup (terminal_type); | 2243 TTY_TYPE (tty) = xstrdup (terminal_type); |
2188 | 2244 |
2245 add_keyboard_wait_descriptor (fileno (tty->input)); | |
2246 | |
2189 #ifdef WINDOWSNT | 2247 #ifdef WINDOWSNT |
2190 initialize_w32_display (); | 2248 initialize_w32_display (); |
2191 | 2249 |
2192 Wcm_clear (tty); | 2250 Wcm_clear (tty); |
2193 | 2251 |
2663 fprintf (stderr, "\n"); | 2721 fprintf (stderr, "\n"); |
2664 fflush (stderr); | 2722 fflush (stderr); |
2665 exit (1); | 2723 exit (1); |
2666 } | 2724 } |
2667 | 2725 |
2726 | |
2727 | |
2728 DEFUN ("delete-tty", Fdelete_tty, Sdelete_tty, 0, 1, 0, | |
2729 doc: /* Delete all frames on the terminal named TTY, and close the device. */) | |
2730 (tty) | |
2731 Lisp_Object tty; | |
2732 { | |
2733 struct tty_output *t; | |
2734 char *name = 0; | |
2735 | |
2736 CHECK_STRING (tty); | |
2737 | |
2738 if (SBYTES (tty) > 0) | |
2739 { | |
2740 name = (char *) alloca (SBYTES (tty) + 1); | |
2741 strncpy (name, SDATA (tty), SBYTES (tty)); | |
2742 name[SBYTES (tty)] = 0; | |
2743 } | |
2744 | |
2745 t = get_named_tty (name); | |
2746 | |
2747 if (! t) | |
2748 error ("No such tty device: %s", name); | |
2749 | |
2750 delete_tty (t); | |
2751 } | |
2752 | |
2753 static int deleting_tty = 0; | |
2754 | |
2755 void | |
2756 delete_tty (struct tty_output *tty) | |
2757 { | |
2758 Lisp_Object tail, frame; | |
2759 | |
2760 if (deleting_tty) | |
2761 /* We get a recursive call when we delete the last frame on this | |
2762 tty. */ | |
2763 return; | |
2764 | |
2765 deleting_tty = 1; | |
2766 | |
2767 if (tty == tty_list) | |
2768 tty_list = tty->next; | |
2769 else | |
2770 { | |
2771 struct tty_output *p; | |
2772 for (p = tty_list; p && p->next != tty; p = p->next) | |
2773 ; | |
2774 | |
2775 if (! p) | |
2776 /* This should not happen. */ | |
2777 abort (); | |
2778 | |
2779 p->next = tty->next; | |
2780 tty->next = 0; | |
2781 } | |
2782 | |
2783 FOR_EACH_FRAME (tail, frame) | |
2784 { | |
2785 struct frame *f = XFRAME (frame); | |
2786 if (FRAME_LIVE_P (f) && FRAME_TTY (f) == tty) | |
2787 { | |
2788 Fdelete_frame (frame, Qt); | |
2789 f->output_data.tty = 0; | |
2790 } | |
2791 } | |
2792 | |
2793 reset_sys_modes (tty); | |
2794 | |
2795 if (tty->name) | |
2796 xfree (tty->name); | |
2797 if (tty->type) | |
2798 xfree (tty->type); | |
2799 | |
2800 if (tty->input) | |
2801 { | |
2802 delete_keyboard_wait_descriptor (fileno (tty->input)); | |
2803 if (tty->input != stdin) | |
2804 fclose (tty->input); | |
2805 } | |
2806 if (tty->output && tty->output != stdout && tty->output != tty->input) | |
2807 fclose (tty->output); | |
2808 if (tty->termscript) | |
2809 fclose (tty->termscript); | |
2810 | |
2811 if (tty->old_tty) | |
2812 xfree (tty->old_tty); | |
2813 | |
2814 if (tty->Wcm) | |
2815 xfree (tty->Wcm); | |
2816 | |
2817 bzero (tty, sizeof (struct tty_output)); | |
2818 xfree (tty); | |
2819 deleting_tty = 0; | |
2820 } | |
2821 | |
2822 | |
2823 | |
2824 | |
2825 /* Mark the pointers in the tty_output objects. | |
2826 Called by the Fgarbage_collector. */ | |
2827 void | |
2828 mark_ttys () | |
2829 { | |
2830 struct tty_output *tty; | |
2831 Lisp_Object *p; | |
2832 for (tty = tty_list; tty; tty = tty->next) | |
2833 { | |
2834 if (tty->top_frame) | |
2835 mark_object (tty->top_frame); | |
2836 } | |
2837 } | |
2838 | |
2839 | |
2840 | |
2668 void | 2841 void |
2669 syms_of_term () | 2842 syms_of_term () |
2670 { | 2843 { |
2671 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo, | 2844 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo, |
2672 doc: /* Non-nil means the system uses terminfo rather than termcap. | 2845 doc: /* Non-nil means the system uses terminfo rather than termcap. |
2680 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function, | 2853 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function, |
2681 doc: /* Non-nil means call this function to ring the bell. | 2854 doc: /* Non-nil means call this function to ring the bell. |
2682 The function should accept no arguments. */); | 2855 The function should accept no arguments. */); |
2683 Vring_bell_function = Qnil; | 2856 Vring_bell_function = Qnil; |
2684 | 2857 |
2858 Qframe_tty_name = intern ("frame-tty-name"); | |
2859 staticpro (&Qframe_tty_name); | |
2860 | |
2861 Qframe_tty_type = intern ("frame-tty-type"); | |
2862 staticpro (&Qframe_tty_type); | |
2863 | |
2685 defsubr (&Stty_display_color_p); | 2864 defsubr (&Stty_display_color_p); |
2686 defsubr (&Stty_display_color_cells); | 2865 defsubr (&Stty_display_color_cells); |
2687 | 2866 defsubr (&Sframe_tty_name); |
2867 defsubr (&Sframe_tty_type); | |
2868 defsubr (&Sdelete_tty); | |
2869 | |
2688 Fprovide (intern ("multi-tty"), Qnil); | 2870 Fprovide (intern ("multi-tty"), Qnil); |
2689 } | 2871 } |
2690 | 2872 |
2691 static int deleting_tty = 0; | |
2692 | |
2693 void | |
2694 delete_tty (struct tty_output *tty) | |
2695 { | |
2696 Lisp_Object tail, frame; | |
2697 | |
2698 if (deleting_tty) | |
2699 /* We get a recursive call when we delete the last frame on this | |
2700 tty. */ | |
2701 return; | |
2702 | |
2703 deleting_tty = 1; | |
2704 | |
2705 if (tty == tty_list) | |
2706 tty_list = tty->next; | |
2707 else | |
2708 { | |
2709 struct tty_output *p; | |
2710 for (p = tty_list; p && p->next != tty; p = p->next) | |
2711 ; | |
2712 | |
2713 if (! p) | |
2714 /* This should not happen. */ | |
2715 abort (); | |
2716 | |
2717 p->next = tty->next; | |
2718 tty->next = 0; | |
2719 } | |
2720 | |
2721 FOR_EACH_FRAME (tail, frame) | |
2722 { | |
2723 struct frame *f = XFRAME (frame); | |
2724 if (FRAME_LIVE_P (f) && FRAME_TTY (f) == tty) | |
2725 { | |
2726 Fdelete_frame (frame, Qt); | |
2727 f->output_data.tty = 0; | |
2728 } | |
2729 } | |
2730 | |
2731 reset_sys_modes (tty); | |
2732 | |
2733 if (tty->name) | |
2734 xfree (tty->name); | |
2735 if (tty->type) | |
2736 xfree (tty->type); | |
2737 | |
2738 if (tty->input) | |
2739 fclose (tty->input); | |
2740 if (tty->output && tty->output != tty->input) | |
2741 fclose (tty->output); | |
2742 if (tty->termscript) | |
2743 fclose (tty->termscript); | |
2744 | |
2745 if (tty->old_tty) | |
2746 xfree (tty->old_tty); | |
2747 | |
2748 if (tty->Wcm) | |
2749 xfree (tty->Wcm); | |
2750 | |
2751 bzero (tty, sizeof (struct tty_output)); | |
2752 xfree (tty); | |
2753 deleting_tty = 0; | |
2754 } | |
2755 | |
2756 | |
2757 struct tty_output * | |
2758 get_current_tty () | |
2759 { | |
2760 return CURTTY(); | |
2761 } | |
2762 | |
2763 void | |
2764 print_all_frames () | |
2765 { | |
2766 /* XXX Debug function. */ | |
2767 Lisp_Object frame, tail; | |
2768 FOR_EACH_FRAME (tail, frame) | |
2769 { | |
2770 fprintf (stderr, "Frame: %x\n", XFRAME (frame)); | |
2771 fflush (stderr); | |
2772 } | |
2773 } | |
2774 | 2873 |
2775 | 2874 |
2776 /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193 | 2875 /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193 |
2777 (do not change this comment) */ | 2876 (do not change this comment) */ |