aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2014-10-14 16:45:41 +0400
committerDmitry Antipov2014-10-14 16:45:41 +0400
commitbb75cdf9c74ab19b75532da1f953233a47eedab4 (patch)
treeb8b4d07acaf36cdce7485fb459e7376975ebd5f7 /src
parent5fa75d8eba2d43408fd7831dcfd69c21e31c21f3 (diff)
downloademacs-bb75cdf9c74ab19b75532da1f953233a47eedab4.tar.gz
emacs-bb75cdf9c74ab19b75532da1f953233a47eedab4.zip
Cleanup terminal handling code.
* dispextern.h (get_named_tty): Remove prototype but... * termhooks.h (get_named_terminal): ...resurrect it under more meaningful name. (get_terminal): Likewise, but with... (decode_live_terminal): ...this name. (decode_tty_terminal): Add prototype. * term.c (get_tty_terminal): Remove. (get_named_tty): Remove. (Ftty_display_color_p, Ftty_display_color_cells, Ftty_type) (Fcontrolling_tty_p, Fsuspend_tty, Fresume_tty): Use decode_tty_terminal. (Ftty_no_underline, Ftty_top_frame): Use decode_live_terminal. * terminal.c (get_terminal): Refactor to... (decode_terminal, decode_live_terminal): ...new functions. (decode_tty_terminal): Replacement for get_tty_terminal. (get_named_terminal): Likewise for get_named_tty. * coding.c (Fset_terminal_coding_system_internal) (Fterminal_coding_system, Fset_keyboard_coding_system_internal): (Fkeyboard_coding_system): * composite.c (Fcomposition_get_gstring): * dispnew.c (Fsend_string_to_terminal): * frame.c (Fmake_terminal_frame): * nsfns.m (check_ns_display_info): * w32fns.c, xfns.c (check_x_display_info): * xselect.c (frame_for_x_selection): Use decode_live_terminal. * keyboard.c (handle_interrupt_signal, handle_interrupt) (Fset_quit_char): Use get_named_terminal. (Fset_output_flow_control, Fset_input_meta_mode): Use decode_tty_terminal.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog33
-rw-r--r--src/coding.c8
-rw-r--r--src/composite.c2
-rw-r--r--src/dispextern.h1
-rw-r--r--src/dispnew.c5
-rw-r--r--src/frame.c2
-rw-r--r--src/keyboard.c18
-rw-r--r--src/nsfns.m4
-rw-r--r--src/term.c98
-rw-r--r--src/termhooks.h4
-rw-r--r--src/terminal.c95
-rw-r--r--src/w32fns.c2
-rw-r--r--src/xfns.c2
-rw-r--r--src/xselect.c2
14 files changed, 135 insertions, 141 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 3200a315daa..c1b7c6cc8c3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,36 @@
12014-10-14 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Cleanup terminal handling code.
4 * dispextern.h (get_named_tty): Remove prototype but...
5 * termhooks.h (get_named_terminal): ...resurrect it under
6 more meaningful name.
7 (get_terminal): Likewise, but with...
8 (decode_live_terminal): ...this name.
9 (decode_tty_terminal): Add prototype.
10 * term.c (get_tty_terminal): Remove.
11 (get_named_tty): Remove.
12 (Ftty_display_color_p, Ftty_display_color_cells, Ftty_type)
13 (Fcontrolling_tty_p, Fsuspend_tty, Fresume_tty):
14 Use decode_tty_terminal.
15 (Ftty_no_underline, Ftty_top_frame): Use decode_live_terminal.
16 * terminal.c (get_terminal): Refactor to...
17 (decode_terminal, decode_live_terminal): ...new functions.
18 (decode_tty_terminal): Replacement for get_tty_terminal.
19 (get_named_terminal): Likewise for get_named_tty.
20 * coding.c (Fset_terminal_coding_system_internal)
21 (Fterminal_coding_system, Fset_keyboard_coding_system_internal):
22 (Fkeyboard_coding_system):
23 * composite.c (Fcomposition_get_gstring):
24 * dispnew.c (Fsend_string_to_terminal):
25 * frame.c (Fmake_terminal_frame):
26 * nsfns.m (check_ns_display_info):
27 * w32fns.c, xfns.c (check_x_display_info):
28 * xselect.c (frame_for_x_selection): Use decode_live_terminal.
29 * keyboard.c (handle_interrupt_signal, handle_interrupt)
30 (Fset_quit_char): Use get_named_terminal.
31 (Fset_output_flow_control, Fset_input_meta_mode):
32 Use decode_tty_terminal.
33
12014-10-13 Eli Zaretskii <eliz@gnu.org> 342014-10-13 Eli Zaretskii <eliz@gnu.org>
2 35
3 * w32term.h (ALIGN_STACK): Use _WIN64, not _W64, to distinguish 36 * w32term.h (ALIGN_STACK): Use _WIN64, not _W64, to distinguish
diff --git a/src/coding.c b/src/coding.c
index f63d710ce9a..e4b52f6db48 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -9759,7 +9759,7 @@ DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_intern
9759 doc: /* Internal use only. */) 9759 doc: /* Internal use only. */)
9760 (Lisp_Object coding_system, Lisp_Object terminal) 9760 (Lisp_Object coding_system, Lisp_Object terminal)
9761{ 9761{
9762 struct terminal *term = get_terminal (terminal, 1); 9762 struct terminal *term = decode_live_terminal (terminal);
9763 struct coding_system *terminal_coding = TERMINAL_TERMINAL_CODING (term); 9763 struct coding_system *terminal_coding = TERMINAL_TERMINAL_CODING (term);
9764 CHECK_SYMBOL (coding_system); 9764 CHECK_SYMBOL (coding_system);
9765 setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding); 9765 setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding);
@@ -9800,7 +9800,7 @@ frame's terminal device. */)
9800 (Lisp_Object terminal) 9800 (Lisp_Object terminal)
9801{ 9801{
9802 struct coding_system *terminal_coding 9802 struct coding_system *terminal_coding
9803 = TERMINAL_TERMINAL_CODING (get_terminal (terminal, 1)); 9803 = TERMINAL_TERMINAL_CODING (decode_live_terminal (terminal));
9804 Lisp_Object coding_system = CODING_ID_NAME (terminal_coding->id); 9804 Lisp_Object coding_system = CODING_ID_NAME (terminal_coding->id);
9805 9805
9806 /* For backward compatibility, return nil if it is `undecided'. */ 9806 /* For backward compatibility, return nil if it is `undecided'. */
@@ -9812,7 +9812,7 @@ DEFUN ("set-keyboard-coding-system-internal", Fset_keyboard_coding_system_intern
9812 doc: /* Internal use only. */) 9812 doc: /* Internal use only. */)
9813 (Lisp_Object coding_system, Lisp_Object terminal) 9813 (Lisp_Object coding_system, Lisp_Object terminal)
9814{ 9814{
9815 struct terminal *t = get_terminal (terminal, 1); 9815 struct terminal *t = decode_live_terminal (terminal);
9816 CHECK_SYMBOL (coding_system); 9816 CHECK_SYMBOL (coding_system);
9817 if (NILP (coding_system)) 9817 if (NILP (coding_system))
9818 coding_system = Qno_conversion; 9818 coding_system = Qno_conversion;
@@ -9831,7 +9831,7 @@ DEFUN ("keyboard-coding-system",
9831 (Lisp_Object terminal) 9831 (Lisp_Object terminal)
9832{ 9832{
9833 return CODING_ID_NAME (TERMINAL_KEYBOARD_CODING 9833 return CODING_ID_NAME (TERMINAL_KEYBOARD_CODING
9834 (get_terminal (terminal, 1))->id); 9834 (decode_live_terminal (terminal))->id);
9835} 9835}
9836 9836
9837 9837
diff --git a/src/composite.c b/src/composite.c
index 1b1960d1c4d..8982c904096 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -1719,7 +1719,7 @@ should be ignored. */)
1719 if (! FONT_OBJECT_P (font_object)) 1719 if (! FONT_OBJECT_P (font_object))
1720 { 1720 {
1721 struct coding_system *coding; 1721 struct coding_system *coding;
1722 struct terminal *terminal = get_terminal (font_object, 1); 1722 struct terminal *terminal = decode_live_terminal (font_object);
1723 1723
1724 coding = ((TERMINAL_TERMINAL_CODING (terminal)->common_flags 1724 coding = ((TERMINAL_TERMINAL_CODING (terminal)->common_flags
1725 & CODING_REQUIRE_ENCODING_MASK) 1725 & CODING_REQUIRE_ENCODING_MASK)
diff --git a/src/dispextern.h b/src/dispextern.h
index 81e36d7b3c6..228502ca06a 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3500,7 +3500,6 @@ extern void calculate_costs (struct frame *);
3500extern void produce_glyphs (struct it *); 3500extern void produce_glyphs (struct it *);
3501extern bool tty_capable_p (struct tty_display_info *, unsigned); 3501extern bool tty_capable_p (struct tty_display_info *, unsigned);
3502extern void set_tty_color_mode (struct tty_display_info *, struct frame *); 3502extern void set_tty_color_mode (struct tty_display_info *, struct frame *);
3503extern struct terminal *get_named_tty (const char *);
3504extern void create_tty_output (struct frame *); 3503extern void create_tty_output (struct frame *);
3505extern struct terminal *init_tty (const char *, const char *, bool); 3504extern struct terminal *init_tty (const char *, const char *, bool);
3506extern void tty_append_glyph (struct it *); 3505extern void tty_append_glyph (struct it *);
diff --git a/src/dispnew.c b/src/dispnew.c
index fbad0edc018..3ab8bcf3e64 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5611,16 +5611,13 @@ the currently selected frame. In batch mode, STRING is sent to stdout
5611when TERMINAL is nil. */) 5611when TERMINAL is nil. */)
5612 (Lisp_Object string, Lisp_Object terminal) 5612 (Lisp_Object string, Lisp_Object terminal)
5613{ 5613{
5614 struct terminal *t = get_terminal (terminal, 1); 5614 struct terminal *t = decode_live_terminal (terminal);
5615 FILE *out; 5615 FILE *out;
5616 5616
5617 /* ??? Perhaps we should do something special for multibyte strings here. */ 5617 /* ??? Perhaps we should do something special for multibyte strings here. */
5618 CHECK_STRING (string); 5618 CHECK_STRING (string);
5619 block_input (); 5619 block_input ();
5620 5620
5621 if (!t)
5622 error ("Unknown terminal device");
5623
5624 if (t->type == output_initial) 5621 if (t->type == output_initial)
5625 out = stdout; 5622 out = stdout;
5626 else if (t->type != output_termcap && t->type != output_msdos_raw) 5623 else if (t->type != output_termcap && t->type != output_msdos_raw)
diff --git a/src/frame.c b/src/frame.c
index a3139173655..8fac06e2af7 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -964,7 +964,7 @@ affects all frames on the same terminal device. */)
964 if (CONSP (terminal)) 964 if (CONSP (terminal))
965 { 965 {
966 terminal = XCDR (terminal); 966 terminal = XCDR (terminal);
967 t = get_terminal (terminal, 1); 967 t = decode_live_terminal (terminal);
968 } 968 }
969#ifdef MSDOS 969#ifdef MSDOS
970 if (t && t != the_only_display_info.terminal) 970 if (t && t != the_only_display_info.terminal)
diff --git a/src/keyboard.c b/src/keyboard.c
index 6730536dc1d..e8143f26681 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -10349,7 +10349,7 @@ static void
10349handle_interrupt_signal (int sig) 10349handle_interrupt_signal (int sig)
10350{ 10350{
10351 /* See if we have an active terminal on our controlling tty. */ 10351 /* See if we have an active terminal on our controlling tty. */
10352 struct terminal *terminal = get_named_tty ("/dev/tty"); 10352 struct terminal *terminal = get_named_terminal ("/dev/tty");
10353 if (!terminal) 10353 if (!terminal)
10354 { 10354 {
10355 /* If there are no frames there, let's pretend that we are a 10355 /* If there are no frames there, let's pretend that we are a
@@ -10403,7 +10403,7 @@ handle_interrupt (bool in_signal_handler)
10403 cancel_echoing (); 10403 cancel_echoing ();
10404 10404
10405 /* XXX This code needs to be revised for multi-tty support. */ 10405 /* XXX This code needs to be revised for multi-tty support. */
10406 if (!NILP (Vquit_flag) && get_named_tty ("/dev/tty")) 10406 if (!NILP (Vquit_flag) && get_named_terminal ("/dev/tty"))
10407 { 10407 {
10408 if (! in_signal_handler) 10408 if (! in_signal_handler)
10409 { 10409 {
@@ -10615,9 +10615,10 @@ Emacs reads input in CBREAK mode; see `set-input-interrupt-mode'.
10615See also `current-input-mode'. */) 10615See also `current-input-mode'. */)
10616 (Lisp_Object flow, Lisp_Object terminal) 10616 (Lisp_Object flow, Lisp_Object terminal)
10617{ 10617{
10618 struct terminal *t = get_terminal (terminal, 1); 10618 struct terminal *t = decode_tty_terminal (terminal);
10619 struct tty_display_info *tty; 10619 struct tty_display_info *tty;
10620 if (t == NULL || (t->type != output_termcap && t->type != output_msdos_raw)) 10620
10621 if (!t)
10621 return Qnil; 10622 return Qnil;
10622 tty = t->display_info.tty; 10623 tty = t->display_info.tty;
10623 10624
@@ -10657,11 +10658,11 @@ the currently selected frame.
10657See also `current-input-mode'. */) 10658See also `current-input-mode'. */)
10658 (Lisp_Object meta, Lisp_Object terminal) 10659 (Lisp_Object meta, Lisp_Object terminal)
10659{ 10660{
10660 struct terminal *t = get_terminal (terminal, 1); 10661 struct terminal *t = decode_tty_terminal (terminal);
10661 struct tty_display_info *tty; 10662 struct tty_display_info *tty;
10662 int new_meta; 10663 int new_meta;
10663 10664
10664 if (t == NULL || (t->type != output_termcap && t->type != output_msdos_raw)) 10665 if (!t)
10665 return Qnil; 10666 return Qnil;
10666 tty = t->display_info.tty; 10667 tty = t->display_info.tty;
10667 10668
@@ -10698,9 +10699,10 @@ process.
10698See also `current-input-mode'. */) 10699See also `current-input-mode'. */)
10699 (Lisp_Object quit) 10700 (Lisp_Object quit)
10700{ 10701{
10701 struct terminal *t = get_named_tty ("/dev/tty"); 10702 struct terminal *t = get_named_terminal ("/dev/tty");
10702 struct tty_display_info *tty; 10703 struct tty_display_info *tty;
10703 if (t == NULL || (t->type != output_termcap && t->type != output_msdos_raw)) 10704
10705 if (!t)
10704 return Qnil; 10706 return Qnil;
10705 tty = t->display_info.tty; 10707 tty = t->display_info.tty;
10706 10708
diff --git a/src/nsfns.m b/src/nsfns.m
index 5cf8387123e..a93b2724403 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -133,7 +133,7 @@ check_ns_display_info (Lisp_Object object)
133 } 133 }
134 else if (TERMINALP (object)) 134 else if (TERMINALP (object))
135 { 135 {
136 struct terminal *t = get_terminal (object, 1); 136 struct terminal *t = decode_live_terminal (object);
137 137
138 if (t->type != output_ns) 138 if (t->type != output_ns)
139 error ("Terminal %d is not a Nextstep display", t->id); 139 error ("Terminal %d is not a Nextstep display", t->id);
@@ -2541,7 +2541,7 @@ the attributes:
2541Internal use only, use `display-monitor-attributes-list' instead. */) 2541Internal use only, use `display-monitor-attributes-list' instead. */)
2542 (Lisp_Object terminal) 2542 (Lisp_Object terminal)
2543{ 2543{
2544 struct terminal *term = get_terminal (terminal, 1); 2544 struct terminal *term = decode_live_terminal (terminal);
2545 NSArray *screens; 2545 NSArray *screens;
2546 NSUInteger i, n_monitors; 2546 NSUInteger i, n_monitors;
2547 struct MonitorInfo *monitors; 2547 struct MonitorInfo *monitors;
diff --git a/src/term.c b/src/term.c
index 572435bdd1a..0c36469f655 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);
@@ -2032,11 +2031,9 @@ selected frame's terminal). This function always returns nil if
2032TERMINAL does not refer to a text terminal. */) 2031TERMINAL does not refer to a text terminal. */)
2033 (Lisp_Object terminal) 2032 (Lisp_Object terminal)
2034{ 2033{
2035 struct terminal *t = get_tty_terminal (terminal, 0); 2034 struct terminal *t = decode_tty_terminal (terminal);
2036 if (!t) 2035
2037 return Qnil; 2036 return (t && t->display_info.tty->TN_max_colors > 0) ? Qt : Qnil;
2038 else
2039 return t->display_info.tty->TN_max_colors > 0 ? Qt : Qnil;
2040} 2037}
2041 2038
2042/* Return the number of supported colors. */ 2039/* Return the number of supported colors. */
@@ -2049,11 +2046,9 @@ selected frame's terminal). This function always returns 0 if
2049TERMINAL does not refer to a text terminal. */) 2046TERMINAL does not refer to a text terminal. */)
2050 (Lisp_Object terminal) 2047 (Lisp_Object terminal)
2051{ 2048{
2052 struct terminal *t = get_tty_terminal (terminal, 0); 2049 struct terminal *t = decode_tty_terminal (terminal);
2053 if (!t) 2050
2054 return make_number (0); 2051 return make_number (t ? t->display_info.tty->TN_max_colors : 0);
2055 else
2056 return make_number (t->display_info.tty->TN_max_colors);
2057} 2052}
2058 2053
2059#ifndef DOS_NT 2054#ifndef DOS_NT
@@ -2168,52 +2163,6 @@ set_tty_color_mode (struct tty_display_info *tty, struct frame *f)
2168 2163
2169#endif /* !DOS_NT */ 2164#endif /* !DOS_NT */
2170 2165
2171
2172
2173/* Return the tty display object specified by TERMINAL. */
2174
2175static struct terminal *
2176get_tty_terminal (Lisp_Object terminal, bool throw)
2177{
2178 struct terminal *t = get_terminal (terminal, throw);
2179
2180 if (t && t->type != output_termcap && t->type != output_msdos_raw)
2181 {
2182 if (throw)
2183 error ("Device %d is not a termcap terminal device", t->id);
2184 else
2185 return NULL;
2186 }
2187
2188 return t;
2189}
2190
2191/* Return an active termcap device that uses the tty device with the
2192 given name.
2193
2194 This function ignores suspended devices.
2195
2196 Returns NULL if the named terminal device is not opened. */
2197
2198struct terminal *
2199get_named_tty (const char *name)
2200{
2201 struct terminal *t;
2202
2203 eassert (name);
2204
2205 for (t = terminal_list; t; t = t->next_terminal)
2206 {
2207 if ((t->type == output_termcap || t->type == output_msdos_raw)
2208 && !strcmp (t->display_info.tty->name, name)
2209 && TERMINAL_ACTIVE_P (t))
2210 return t;
2211 }
2212
2213 return 0;
2214}
2215
2216
2217DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0, 2166DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0,
2218 doc: /* Return the type of the tty device that TERMINAL uses. 2167 doc: /* Return the type of the tty device that TERMINAL uses.
2219Returns nil if TERMINAL is not on a tty device. 2168Returns nil if TERMINAL is not on a tty device.
@@ -2222,15 +2171,10 @@ TERMINAL can be a terminal object, a frame, or nil (meaning the
2222selected frame's terminal). */) 2171selected frame's terminal). */)
2223 (Lisp_Object terminal) 2172 (Lisp_Object terminal)
2224{ 2173{
2225 struct terminal *t = get_terminal (terminal, 1); 2174 struct terminal *t = decode_tty_terminal (terminal);
2226
2227 if (t->type != output_termcap && t->type != output_msdos_raw)
2228 return Qnil;
2229 2175
2230 if (t->display_info.tty->type) 2176 return (t && t->display_info.tty->type
2231 return build_string (t->display_info.tty->type); 2177 ? build_string (t->display_info.tty->type) : Qnil);
2232 else
2233 return Qnil;
2234} 2178}
2235 2179
2236DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0, 2180DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0,
@@ -2241,13 +2185,9 @@ selected frame's terminal). This function always returns nil if
2241TERMINAL is not on a tty device. */) 2185TERMINAL is not on a tty device. */)
2242 (Lisp_Object terminal) 2186 (Lisp_Object terminal)
2243{ 2187{
2244 struct terminal *t = get_terminal (terminal, 1); 2188 struct terminal *t = decode_tty_terminal (terminal);
2245 2189
2246 if ((t->type != output_termcap && t->type != output_msdos_raw) 2190 return (t && !strcmp (t->display_info.tty->name, DEV_TTY) ? Qt : Qnil);
2247 || strcmp (t->display_info.tty->name, DEV_TTY) != 0)
2248 return Qnil;
2249 else
2250 return Qt;
2251} 2191}
2252 2192
2253DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0, 2193DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0,
@@ -2261,7 +2201,7 @@ selected frame's terminal). This function always returns nil if
2261TERMINAL does not refer to a text terminal. */) 2201TERMINAL does not refer to a text terminal. */)
2262 (Lisp_Object terminal) 2202 (Lisp_Object terminal)
2263{ 2203{
2264 struct terminal *t = get_terminal (terminal, 1); 2204 struct terminal *t = decode_live_terminal (terminal);
2265 2205
2266 if (t->type == output_termcap) 2206 if (t->type == output_termcap)
2267 t->display_info.tty->TS_enter_underline_mode = 0; 2207 t->display_info.tty->TS_enter_underline_mode = 0;
@@ -2276,7 +2216,7 @@ does not refer to a text terminal. Otherwise, it returns the
2276top-most frame on the text terminal. */) 2216top-most frame on the text terminal. */)
2277 (Lisp_Object terminal) 2217 (Lisp_Object terminal)
2278{ 2218{
2279 struct terminal *t = get_terminal (terminal, 1); 2219 struct terminal *t = decode_live_terminal (terminal);
2280 2220
2281 if (t->type == output_termcap) 2221 if (t->type == output_termcap)
2282 return t->display_info.tty->top_frame; 2222 return t->display_info.tty->top_frame;
@@ -2306,11 +2246,11 @@ suspended.
2306A suspended tty may be resumed by calling `resume-tty' on it. */) 2246A suspended tty may be resumed by calling `resume-tty' on it. */)
2307 (Lisp_Object tty) 2247 (Lisp_Object tty)
2308{ 2248{
2309 struct terminal *t = get_tty_terminal (tty, 1); 2249 struct terminal *t = decode_tty_terminal (tty);
2310 FILE *f; 2250 FILE *f;
2311 2251
2312 if (!t) 2252 if (!t)
2313 error ("Unknown tty device"); 2253 error ("Attempt to suspend a non-text terminal device");
2314 2254
2315 f = t->display_info.tty->input; 2255 f = t->display_info.tty->input;
2316 2256
@@ -2366,15 +2306,15 @@ TTY may be a terminal object, a frame, or nil (meaning the selected
2366frame's terminal). */) 2306frame's terminal). */)
2367 (Lisp_Object tty) 2307 (Lisp_Object tty)
2368{ 2308{
2369 struct terminal *t = get_tty_terminal (tty, 1); 2309 struct terminal *t = decode_tty_terminal (tty);
2370 int fd; 2310 int fd;
2371 2311
2372 if (!t) 2312 if (!t)
2373 error ("Unknown tty device"); 2313 error ("Attempt to resume a non-text terminal device");
2374 2314
2375 if (!t->display_info.tty->input) 2315 if (!t->display_info.tty->input)
2376 { 2316 {
2377 if (get_named_tty (t->display_info.tty->name)) 2317 if (get_named_terminal (t->display_info.tty->name))
2378 error ("Cannot resume display while another display is active on the same device"); 2318 error ("Cannot resume display while another display is active on the same device");
2379 2319
2380#ifdef MSDOS 2320#ifdef MSDOS
@@ -4007,7 +3947,7 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
4007 /* XXX Perhaps this should be made explicit by having init_tty 3947 /* XXX Perhaps this should be made explicit by having init_tty
4008 always create a new terminal and separating terminal and frame 3948 always create a new terminal and separating terminal and frame
4009 creation on Lisp level. */ 3949 creation on Lisp level. */
4010 terminal = get_named_tty (name); 3950 terminal = get_named_terminal (name);
4011 if (terminal) 3951 if (terminal)
4012 return terminal; 3952 return terminal;
4013 3953
diff --git a/src/termhooks.h b/src/termhooks.h
index 8d85fba8af8..9cab853ed3d 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -681,7 +681,9 @@ extern struct terminal *terminal_list;
681 (t->type == output_ns ? t->display_info.ns->name_list_element : Qnil) 681 (t->type == output_ns ? t->display_info.ns->name_list_element : Qnil)
682#endif 682#endif
683 683
684extern struct terminal *get_terminal (Lisp_Object terminal, bool); 684extern struct terminal *decode_live_terminal (Lisp_Object);
685extern struct terminal *decode_tty_terminal (Lisp_Object);
686extern struct terminal *get_named_terminal (const char *);
685extern struct terminal *create_terminal (enum output_method, 687extern struct terminal *create_terminal (enum output_method,
686 struct redisplay_interface *); 688 struct redisplay_interface *);
687extern void delete_terminal (struct terminal *); 689extern void delete_terminal (struct terminal *);
diff --git a/src/terminal.c b/src/terminal.c
index a827677a58d..0cd6a0bf602 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -37,7 +37,9 @@ static int next_terminal_id;
37/* The initial terminal device, created by initial_term_init. */ 37/* The initial terminal device, created by initial_term_init. */
38struct terminal *initial_terminal; 38struct terminal *initial_terminal;
39 39
40Lisp_Object Qrun_hook_with_args;
40static Lisp_Object Qterminal_live_p; 41static Lisp_Object Qterminal_live_p;
42static Lisp_Object Qdelete_terminal_functions;
41 43
42static void delete_initial_terminal (struct terminal *); 44static void delete_initial_terminal (struct terminal *);
43 45
@@ -194,34 +196,66 @@ ins_del_lines (struct frame *f, int vpos, int n)
194 (*FRAME_TERMINAL (f)->ins_del_lines_hook) (f, vpos, n); 196 (*FRAME_TERMINAL (f)->ins_del_lines_hook) (f, vpos, n);
195} 197}
196 198
199/* Return the terminal object specified by TERMINAL. TERMINAL may
200 be a terminal object, a frame, or nil for the terminal device of
201 the current frame. If TERMINAL is neither from the above or the
202 resulting terminal object is deleted, return NULL. */
197 203
198 204static struct terminal *
199 205decode_terminal (Lisp_Object terminal)
200/* Return the terminal object specified by TERMINAL. TERMINAL may be
201 a terminal object, a frame, or nil for the terminal device of the
202 current frame. If THROW is false, return NULL for failure,
203 otherwise throw an error. */
204
205struct terminal *
206get_terminal (Lisp_Object terminal, bool throw)
207{ 206{
208 struct terminal *result = NULL; 207 struct terminal *t;
209 208
210 if (NILP (terminal)) 209 if (NILP (terminal))
211 terminal = selected_frame; 210 terminal = selected_frame;
211 t = (TERMINALP (terminal)
212 ? XTERMINAL (terminal)
213 : FRAMEP (terminal) ? FRAME_TERMINAL (XFRAME (terminal)) : NULL);
214 return t && t->name ? t : NULL;
215}
212 216
213 if (TERMINALP (terminal)) 217/* Like above, but throw an error if TERMINAL is not valid or deleted. */
214 result = XTERMINAL (terminal);
215 else if (FRAMEP (terminal))
216 result = FRAME_TERMINAL (XFRAME (terminal));
217 218
218 if (result && !result->name) 219struct terminal *
219 result = NULL; 220decode_live_terminal (Lisp_Object terminal)
221{
222 struct terminal *t = decode_terminal (terminal);
220 223
221 if (result == NULL && throw) 224 if (!t)
222 wrong_type_argument (Qterminal_live_p, terminal); 225 wrong_type_argument (Qterminal_live_p, terminal);
226 return t;
227}
228
229/* Like decode_terminal, but ensure that the resulting terminal object refers
230 to a text-based terminal device. */
231
232struct terminal *
233decode_tty_terminal (Lisp_Object terminal)
234{
235 struct terminal *t = decode_live_terminal (terminal);
223 236
224 return result; 237 return (t->type == output_termcap || t->type == output_msdos_raw) ? t : NULL;
238}
239
240/* Return an active (not suspended) text-based terminal device that uses
241 the tty device with the given NAME, or NULL if the named terminal device
242 is not opened. */
243
244struct terminal *
245get_named_terminal (const char *name)
246{
247 struct terminal *t;
248
249 eassert (name);
250
251 for (t = terminal_list; t; t = t->next_terminal)
252 {
253 if ((t->type == output_termcap || t->type == output_msdos_raw)
254 && !strcmp (t->display_info.tty->name, name)
255 && TERMINAL_ACTIVE_P (t))
256 return t;
257 }
258 return NULL;
225} 259}
226 260
227/* Create a new terminal object of TYPE and add it to the terminal list. RIF 261/* Create a new terminal object of TYPE and add it to the terminal list. RIF
@@ -308,8 +342,6 @@ delete_terminal (struct terminal *terminal)
308 } 342 }
309} 343}
310 344
311Lisp_Object Qrun_hook_with_args;
312static Lisp_Object Qdelete_terminal_functions;
313DEFUN ("delete-terminal", Fdelete_terminal, Sdelete_terminal, 0, 2, 0, 345DEFUN ("delete-terminal", Fdelete_terminal, Sdelete_terminal, 0, 2, 0,
314 doc: /* Delete TERMINAL by deleting all frames on it and closing the terminal. 346 doc: /* Delete TERMINAL by deleting all frames on it and closing the terminal.
315TERMINAL may be a terminal object, a frame, or nil (meaning the 347TERMINAL may be a terminal object, a frame, or nil (meaning the
@@ -319,7 +351,7 @@ Normally, you may not delete a display if all other displays are suspended,
319but if the second argument FORCE is non-nil, you may do so. */) 351but if the second argument FORCE is non-nil, you may do so. */)
320 (Lisp_Object terminal, Lisp_Object force) 352 (Lisp_Object terminal, Lisp_Object force)
321{ 353{
322 struct terminal *t = get_terminal (terminal, 0); 354 struct terminal *t = decode_terminal (terminal);
323 355
324 if (!t) 356 if (!t)
325 return Qnil; 357 return Qnil;
@@ -380,9 +412,7 @@ sort of output terminal it uses. See the documentation of `framep' for
380possible return values. */) 412possible return values. */)
381 (Lisp_Object object) 413 (Lisp_Object object)
382{ 414{
383 struct terminal *t; 415 struct terminal *t = decode_terminal (object);
384
385 t = get_terminal (object, 0);
386 416
387 if (!t) 417 if (!t)
388 return Qnil; 418 return Qnil;
@@ -429,8 +459,7 @@ TERMINAL may be a terminal object, a frame, or nil (meaning the
429selected frame's terminal). */) 459selected frame's terminal). */)
430 (Lisp_Object terminal) 460 (Lisp_Object terminal)
431{ 461{
432 struct terminal *t 462 struct terminal *t = decode_live_terminal (terminal);
433 = TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
434 463
435 return t->name ? build_string (t->name) : Qnil; 464 return t->name ? build_string (t->name) : Qnil;
436} 465}
@@ -467,9 +496,7 @@ TERMINAL can be a terminal object, a frame, or nil (meaning the
467selected frame's terminal). */) 496selected frame's terminal). */)
468 (Lisp_Object terminal) 497 (Lisp_Object terminal)
469{ 498{
470 struct terminal *t 499 return Fcopy_alist (decode_live_terminal (terminal)->param_alist);
471 = TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
472 return Fcopy_alist (t->param_alist);
473} 500}
474 501
475DEFUN ("terminal-parameter", Fterminal_parameter, Sterminal_parameter, 2, 2, 0, 502DEFUN ("terminal-parameter", Fterminal_parameter, Sterminal_parameter, 2, 2, 0,
@@ -478,12 +505,8 @@ TERMINAL can be a terminal object, a frame, or nil (meaning the
478selected frame's terminal). */) 505selected frame's terminal). */)
479 (Lisp_Object terminal, Lisp_Object parameter) 506 (Lisp_Object terminal, Lisp_Object parameter)
480{ 507{
481 Lisp_Object value;
482 struct terminal *t
483 = TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
484 CHECK_SYMBOL (parameter); 508 CHECK_SYMBOL (parameter);
485 value = Fcdr (Fassq (parameter, t->param_alist)); 509 return Fcdr (Fassq (parameter, decode_live_terminal (terminal)->param_alist));
486 return value;
487} 510}
488 511
489DEFUN ("set-terminal-parameter", Fset_terminal_parameter, 512DEFUN ("set-terminal-parameter", Fset_terminal_parameter,
@@ -495,9 +518,7 @@ TERMINAL can be a terminal object, a frame or nil (meaning the
495selected frame's terminal). */) 518selected frame's terminal). */)
496 (Lisp_Object terminal, Lisp_Object parameter, Lisp_Object value) 519 (Lisp_Object terminal, Lisp_Object parameter, Lisp_Object value)
497{ 520{
498 struct terminal *t 521 return store_terminal_param (decode_live_terminal (terminal), parameter, value);
499 = TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
500 return store_terminal_param (t, parameter, value);
501} 522}
502 523
503/* Initial frame has no device-dependent output data, but has 524/* Initial frame has no device-dependent output data, but has
diff --git a/src/w32fns.c b/src/w32fns.c
index bfa69fb61cd..05da2a5c1d1 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -276,7 +276,7 @@ check_x_display_info (Lisp_Object object)
276 } 276 }
277 else if (TERMINALP (object)) 277 else if (TERMINALP (object))
278 { 278 {
279 struct terminal *t = get_terminal (object, 1); 279 struct terminal *t = decode_live_terminal (object);
280 280
281 if (t->type != output_w32) 281 if (t->type != output_w32)
282 error ("Terminal %d is not a W32 display", t->id); 282 error ("Terminal %d is not a W32 display", t->id);
diff --git a/src/xfns.c b/src/xfns.c
index 7fd6d9070b2..5edb635b182 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -159,7 +159,7 @@ check_x_display_info (Lisp_Object object)
159 } 159 }
160 else if (TERMINALP (object)) 160 else if (TERMINALP (object))
161 { 161 {
162 struct terminal *t = get_terminal (object, 1); 162 struct terminal *t = decode_live_terminal (object);
163 163
164 if (t->type != output_x_window) 164 if (t->type != output_x_window)
165 error ("Terminal %d is not an X display", t->id); 165 error ("Terminal %d is not an X display", t->id);
diff --git a/src/xselect.c b/src/xselect.c
index 9b57a95b26b..92e89822293 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -1901,7 +1901,7 @@ frame_for_x_selection (Lisp_Object object)
1901 } 1901 }
1902 else if (TERMINALP (object)) 1902 else if (TERMINALP (object))
1903 { 1903 {
1904 struct terminal *t = get_terminal (object, 1); 1904 struct terminal *t = decode_live_terminal (object);
1905 1905
1906 if (t->type == output_x_window) 1906 if (t->type == output_x_window)
1907 FOR_EACH_FRAME (tail, frame) 1907 FOR_EACH_FRAME (tail, frame)