aboutsummaryrefslogtreecommitdiffstats
path: root/src/terminal.c
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/terminal.c
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/terminal.c')
-rw-r--r--src/terminal.c95
1 files changed, 58 insertions, 37 deletions
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