aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.c
diff options
context:
space:
mode:
authorEli Zaretskii2014-10-14 21:10:37 +0300
committerEli Zaretskii2014-10-14 21:10:37 +0300
commite3060a0c4d2f418ac786775109d71e5843ccf42e (patch)
tree347b37fc39d0db9cd23b3e9f79ee81b4bbc40f08 /src/term.c
parent1a3eca0656bdb764200e10a4f264138e94b1f3ce (diff)
parent980d78b3587560c13a46aef352ed8d5ed744acf6 (diff)
downloademacs-e3060a0c4d2f418ac786775109d71e5843ccf42e.tar.gz
emacs-e3060a0c4d2f418ac786775109d71e5843ccf42e.zip
Merge from trunk and resolve conflicts.
Diffstat (limited to 'src/term.c')
-rw-r--r--src/term.c110
1 files changed, 26 insertions, 84 deletions
diff --git a/src/term.c b/src/term.c
index c8ff6f31575..04f6e3318a0 100644
--- a/src/term.c
+++ b/src/term.c
@@ -77,7 +77,6 @@ static void tty_turn_off_highlight (struct tty_display_info *);
77static void tty_show_cursor (struct tty_display_info *); 77static void tty_show_cursor (struct tty_display_info *);
78static void tty_hide_cursor (struct tty_display_info *); 78static void tty_hide_cursor (struct tty_display_info *);
79static void tty_background_highlight (struct tty_display_info *tty); 79static void tty_background_highlight (struct tty_display_info *tty);
80static struct terminal *get_tty_terminal (Lisp_Object, bool);
81static void clear_tty_hooks (struct terminal *terminal); 80static void clear_tty_hooks (struct terminal *terminal);
82static void set_tty_hooks (struct terminal *terminal); 81static void set_tty_hooks (struct terminal *terminal);
83static void dissociate_if_controlling_tty (int fd); 82static void dissociate_if_controlling_tty (int fd);
@@ -2029,11 +2028,9 @@ selected frame's terminal). This function always returns nil if
2029TERMINAL does not refer to a text terminal. */) 2028TERMINAL does not refer to a text terminal. */)
2030 (Lisp_Object terminal) 2029 (Lisp_Object terminal)
2031{ 2030{
2032 struct terminal *t = get_tty_terminal (terminal, 0); 2031 struct terminal *t = decode_tty_terminal (terminal);
2033 if (!t) 2032
2034 return Qnil; 2033 return (t && t->display_info.tty->TN_max_colors > 0) ? Qt : Qnil;
2035 else
2036 return t->display_info.tty->TN_max_colors > 0 ? Qt : Qnil;
2037} 2034}
2038 2035
2039/* Return the number of supported colors. */ 2036/* Return the number of supported colors. */
@@ -2046,11 +2043,9 @@ selected frame's terminal). This function always returns 0 if
2046TERMINAL does not refer to a text terminal. */) 2043TERMINAL does not refer to a text terminal. */)
2047 (Lisp_Object terminal) 2044 (Lisp_Object terminal)
2048{ 2045{
2049 struct terminal *t = get_tty_terminal (terminal, 0); 2046 struct terminal *t = decode_tty_terminal (terminal);
2050 if (!t) 2047
2051 return make_number (0); 2048 return make_number (t ? t->display_info.tty->TN_max_colors : 0);
2052 else
2053 return make_number (t->display_info.tty->TN_max_colors);
2054} 2049}
2055 2050
2056#ifndef DOS_NT 2051#ifndef DOS_NT
@@ -2165,52 +2160,6 @@ set_tty_color_mode (struct tty_display_info *tty, struct frame *f)
2165 2160
2166#endif /* !DOS_NT */ 2161#endif /* !DOS_NT */
2167 2162
2168
2169
2170/* Return the tty display object specified by TERMINAL. */
2171
2172static struct terminal *
2173get_tty_terminal (Lisp_Object terminal, bool throw)
2174{
2175 struct terminal *t = get_terminal (terminal, throw);
2176
2177 if (t && t->type != output_termcap && t->type != output_msdos_raw)
2178 {
2179 if (throw)
2180 error ("Device %d is not a termcap terminal device", t->id);
2181 else
2182 return NULL;
2183 }
2184
2185 return t;
2186}
2187
2188/* Return an active termcap device that uses the tty device with the
2189 given name.
2190
2191 This function ignores suspended devices.
2192
2193 Returns NULL if the named terminal device is not opened. */
2194
2195struct terminal *
2196get_named_tty (const char *name)
2197{
2198 struct terminal *t;
2199
2200 eassert (name);
2201
2202 for (t = terminal_list; t; t = t->next_terminal)
2203 {
2204 if ((t->type == output_termcap || t->type == output_msdos_raw)
2205 && !strcmp (t->display_info.tty->name, name)
2206 && TERMINAL_ACTIVE_P (t))
2207 return t;
2208 }
2209
2210 return 0;
2211}
2212
2213
2214DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0, 2163DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0,
2215 doc: /* Return the type of the tty device that TERMINAL uses. 2164 doc: /* Return the type of the tty device that TERMINAL uses.
2216Returns nil if TERMINAL is not on a tty device. 2165Returns nil if TERMINAL is not on a tty device.
@@ -2219,15 +2168,10 @@ TERMINAL can be a terminal object, a frame, or nil (meaning the
2219selected frame's terminal). */) 2168selected frame's terminal). */)
2220 (Lisp_Object terminal) 2169 (Lisp_Object terminal)
2221{ 2170{
2222 struct terminal *t = get_terminal (terminal, 1); 2171 struct terminal *t = decode_tty_terminal (terminal);
2223
2224 if (t->type != output_termcap && t->type != output_msdos_raw)
2225 return Qnil;
2226 2172
2227 if (t->display_info.tty->type) 2173 return (t && t->display_info.tty->type
2228 return build_string (t->display_info.tty->type); 2174 ? build_string (t->display_info.tty->type) : Qnil);
2229 else
2230 return Qnil;
2231} 2175}
2232 2176
2233DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0, 2177DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0,
@@ -2238,13 +2182,9 @@ selected frame's terminal). This function always returns nil if
2238TERMINAL is not on a tty device. */) 2182TERMINAL is not on a tty device. */)
2239 (Lisp_Object terminal) 2183 (Lisp_Object terminal)
2240{ 2184{
2241 struct terminal *t = get_terminal (terminal, 1); 2185 struct terminal *t = decode_tty_terminal (terminal);
2242 2186
2243 if ((t->type != output_termcap && t->type != output_msdos_raw) 2187 return (t && !strcmp (t->display_info.tty->name, DEV_TTY) ? Qt : Qnil);
2244 || strcmp (t->display_info.tty->name, DEV_TTY) != 0)
2245 return Qnil;
2246 else
2247 return Qt;
2248} 2188}
2249 2189
2250DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0, 2190DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0,
@@ -2258,7 +2198,7 @@ selected frame's terminal). This function always returns nil if
2258TERMINAL does not refer to a text terminal. */) 2198TERMINAL does not refer to a text terminal. */)
2259 (Lisp_Object terminal) 2199 (Lisp_Object terminal)
2260{ 2200{
2261 struct terminal *t = get_terminal (terminal, 1); 2201 struct terminal *t = decode_live_terminal (terminal);
2262 2202
2263 if (t->type == output_termcap) 2203 if (t->type == output_termcap)
2264 t->display_info.tty->TS_enter_underline_mode = 0; 2204 t->display_info.tty->TS_enter_underline_mode = 0;
@@ -2273,7 +2213,7 @@ does not refer to a text terminal. Otherwise, it returns the
2273top-most frame on the text terminal. */) 2213top-most frame on the text terminal. */)
2274 (Lisp_Object terminal) 2214 (Lisp_Object terminal)
2275{ 2215{
2276 struct terminal *t = get_terminal (terminal, 1); 2216 struct terminal *t = decode_live_terminal (terminal);
2277 2217
2278 if (t->type == output_termcap) 2218 if (t->type == output_termcap)
2279 return t->display_info.tty->top_frame; 2219 return t->display_info.tty->top_frame;
@@ -2303,11 +2243,11 @@ suspended.
2303A suspended tty may be resumed by calling `resume-tty' on it. */) 2243A suspended tty may be resumed by calling `resume-tty' on it. */)
2304 (Lisp_Object tty) 2244 (Lisp_Object tty)
2305{ 2245{
2306 struct terminal *t = get_tty_terminal (tty, 1); 2246 struct terminal *t = decode_tty_terminal (tty);
2307 FILE *f; 2247 FILE *f;
2308 2248
2309 if (!t) 2249 if (!t)
2310 error ("Unknown tty device"); 2250 error ("Attempt to suspend a non-text terminal device");
2311 2251
2312 f = t->display_info.tty->input; 2252 f = t->display_info.tty->input;
2313 2253
@@ -2363,15 +2303,15 @@ TTY may be a terminal object, a frame, or nil (meaning the selected
2363frame's terminal). */) 2303frame's terminal). */)
2364 (Lisp_Object tty) 2304 (Lisp_Object tty)
2365{ 2305{
2366 struct terminal *t = get_tty_terminal (tty, 1); 2306 struct terminal *t = decode_tty_terminal (tty);
2367 int fd; 2307 int fd;
2368 2308
2369 if (!t) 2309 if (!t)
2370 error ("Unknown tty device"); 2310 error ("Attempt to resume a non-text terminal device");
2371 2311
2372 if (!t->display_info.tty->input) 2312 if (!t->display_info.tty->input)
2373 { 2313 {
2374 if (get_named_tty (t->display_info.tty->name)) 2314 if (get_named_terminal (t->display_info.tty->name))
2375 error ("Cannot resume display while another display is active on the same device"); 2315 error ("Cannot resume display while another display is active on the same device");
2376 2316
2377#ifdef MSDOS 2317#ifdef MSDOS
@@ -2537,7 +2477,7 @@ term_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
2537 (*fp)->mouse_moved = 0; 2477 (*fp)->mouse_moved = 0;
2538 2478
2539 *bar_window = Qnil; 2479 *bar_window = Qnil;
2540 *part = 0; 2480 *part = scroll_bar_above_handle;
2541 2481
2542 XSETINT (*x, last_mouse_x); 2482 XSETINT (*x, last_mouse_x);
2543 XSETINT (*y, last_mouse_y); 2483 XSETINT (*y, last_mouse_y);
@@ -3188,6 +3128,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
3188 Lisp_Object selectface; 3128 Lisp_Object selectface;
3189 int first_item = 0; 3129 int first_item = 0;
3190 int col, row; 3130 int col, row;
3131 USE_SAFE_ALLOCA;
3191 3132
3192 /* Don't allow non-positive x0 and y0, lest the menu will wrap 3133 /* Don't allow non-positive x0 and y0, lest the menu will wrap
3193 around the display. */ 3134 around the display. */
@@ -3196,7 +3137,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
3196 if (y0 <= 0) 3137 if (y0 <= 0)
3197 y0 = 1; 3138 y0 = 1;
3198 3139
3199 state = alloca (menu->panecount * sizeof (struct tty_menu_state)); 3140 SAFE_NALLOCA (state, 1, menu->panecount);
3200 memset (state, 0, sizeof (*state)); 3141 memset (state, 0, sizeof (*state));
3201 faces[0] 3142 faces[0]
3202 = lookup_derived_face (sf, intern ("tty-menu-disabled-face"), 3143 = lookup_derived_face (sf, intern ("tty-menu-disabled-face"),
@@ -3418,6 +3359,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
3418 discard_mouse_events (); 3359 discard_mouse_events ();
3419 if (!kbd_buffer_events_waiting ()) 3360 if (!kbd_buffer_events_waiting ())
3420 clear_input_pending (); 3361 clear_input_pending ();
3362 SAFE_FREE ();
3421 return result; 3363 return result;
3422} 3364}
3423 3365
@@ -3603,6 +3545,7 @@ tty_menu_show (struct frame *f, int x, int y, int menuflags,
3603 item_y = y += f->top_pos; 3545 item_y = y += f->top_pos;
3604 3546
3605 /* Create all the necessary panes and their items. */ 3547 /* Create all the necessary panes and their items. */
3548 USE_SAFE_ALLOCA;
3606 maxwidth = maxlines = lines = i = 0; 3549 maxwidth = maxlines = lines = i = 0;
3607 lpane = TTYM_FAILURE; 3550 lpane = TTYM_FAILURE;
3608 while (i < menu_items_used) 3551 while (i < menu_items_used)
@@ -3671,9 +3614,7 @@ tty_menu_show (struct frame *f, int x, int y, int menuflags,
3671 3614
3672 if (!NILP (descrip)) 3615 if (!NILP (descrip))
3673 { 3616 {
3674 /* If alloca is fast, use that to make the space, 3617 item_data = SAFE_ALLOCA (maxwidth + SBYTES (descrip) + 1);
3675 to reduce gc needs. */
3676 item_data = (char *) alloca (maxwidth + SBYTES (descrip) + 1);
3677 memcpy (item_data, SSDATA (item_name), SBYTES (item_name)); 3618 memcpy (item_data, SSDATA (item_name), SBYTES (item_name));
3678 for (j = SCHARS (item_name); j < maxwidth; j++) 3619 for (j = SCHARS (item_name); j < maxwidth; j++)
3679 item_data[j] = ' '; 3620 item_data[j] = ' ';
@@ -3826,6 +3767,7 @@ tty_menu_show (struct frame *f, int x, int y, int menuflags,
3826 3767
3827 tty_menu_end: 3768 tty_menu_end:
3828 3769
3770 SAFE_FREE ();
3829 unbind_to (specpdl_count, Qnil); 3771 unbind_to (specpdl_count, Qnil);
3830 return entry; 3772 return entry;
3831} 3773}
@@ -4002,7 +3944,7 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
4002 /* XXX Perhaps this should be made explicit by having init_tty 3944 /* XXX Perhaps this should be made explicit by having init_tty
4003 always create a new terminal and separating terminal and frame 3945 always create a new terminal and separating terminal and frame
4004 creation on Lisp level. */ 3946 creation on Lisp level. */
4005 terminal = get_named_tty (name); 3947 terminal = get_named_terminal (name);
4006 if (terminal) 3948 if (terminal)
4007 return terminal; 3949 return terminal;
4008 3950