* 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.
+2014-10-14 Dmitry Antipov <dmantipov@yandex.ru>
+
+ 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.
+
2014-10-13 Eli Zaretskii <eliz@gnu.org>
* w32term.h (ALIGN_STACK): Use _WIN64, not _W64, to distinguish
doc: /* Internal use only. */)
(Lisp_Object coding_system, Lisp_Object terminal)
{
- struct terminal *term = get_terminal (terminal, 1);
+ struct terminal *term = decode_live_terminal (terminal);
struct coding_system *terminal_coding = TERMINAL_TERMINAL_CODING (term);
CHECK_SYMBOL (coding_system);
setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding);
(Lisp_Object terminal)
{
struct coding_system *terminal_coding
- = TERMINAL_TERMINAL_CODING (get_terminal (terminal, 1));
+ = TERMINAL_TERMINAL_CODING (decode_live_terminal (terminal));
Lisp_Object coding_system = CODING_ID_NAME (terminal_coding->id);
/* For backward compatibility, return nil if it is `undecided'. */
doc: /* Internal use only. */)
(Lisp_Object coding_system, Lisp_Object terminal)
{
- struct terminal *t = get_terminal (terminal, 1);
+ struct terminal *t = decode_live_terminal (terminal);
CHECK_SYMBOL (coding_system);
if (NILP (coding_system))
coding_system = Qno_conversion;
(Lisp_Object terminal)
{
return CODING_ID_NAME (TERMINAL_KEYBOARD_CODING
- (get_terminal (terminal, 1))->id);
+ (decode_live_terminal (terminal))->id);
}
\f
if (! FONT_OBJECT_P (font_object))
{
struct coding_system *coding;
- struct terminal *terminal = get_terminal (font_object, 1);
+ struct terminal *terminal = decode_live_terminal (font_object);
coding = ((TERMINAL_TERMINAL_CODING (terminal)->common_flags
& CODING_REQUIRE_ENCODING_MASK)
extern void produce_glyphs (struct it *);
extern bool tty_capable_p (struct tty_display_info *, unsigned);
extern void set_tty_color_mode (struct tty_display_info *, struct frame *);
-extern struct terminal *get_named_tty (const char *);
extern void create_tty_output (struct frame *);
extern struct terminal *init_tty (const char *, const char *, bool);
extern void tty_append_glyph (struct it *);
when TERMINAL is nil. */)
(Lisp_Object string, Lisp_Object terminal)
{
- struct terminal *t = get_terminal (terminal, 1);
+ struct terminal *t = decode_live_terminal (terminal);
FILE *out;
/* ??? Perhaps we should do something special for multibyte strings here. */
CHECK_STRING (string);
block_input ();
- if (!t)
- error ("Unknown terminal device");
-
if (t->type == output_initial)
out = stdout;
else if (t->type != output_termcap && t->type != output_msdos_raw)
if (CONSP (terminal))
{
terminal = XCDR (terminal);
- t = get_terminal (terminal, 1);
+ t = decode_live_terminal (terminal);
}
#ifdef MSDOS
if (t && t != the_only_display_info.terminal)
handle_interrupt_signal (int sig)
{
/* See if we have an active terminal on our controlling tty. */
- struct terminal *terminal = get_named_tty ("/dev/tty");
+ struct terminal *terminal = get_named_terminal ("/dev/tty");
if (!terminal)
{
/* If there are no frames there, let's pretend that we are a
cancel_echoing ();
/* XXX This code needs to be revised for multi-tty support. */
- if (!NILP (Vquit_flag) && get_named_tty ("/dev/tty"))
+ if (!NILP (Vquit_flag) && get_named_terminal ("/dev/tty"))
{
if (! in_signal_handler)
{
See also `current-input-mode'. */)
(Lisp_Object flow, Lisp_Object terminal)
{
- struct terminal *t = get_terminal (terminal, 1);
+ struct terminal *t = decode_tty_terminal (terminal);
struct tty_display_info *tty;
- if (t == NULL || (t->type != output_termcap && t->type != output_msdos_raw))
+
+ if (!t)
return Qnil;
tty = t->display_info.tty;
See also `current-input-mode'. */)
(Lisp_Object meta, Lisp_Object terminal)
{
- struct terminal *t = get_terminal (terminal, 1);
+ struct terminal *t = decode_tty_terminal (terminal);
struct tty_display_info *tty;
int new_meta;
- if (t == NULL || (t->type != output_termcap && t->type != output_msdos_raw))
+ if (!t)
return Qnil;
tty = t->display_info.tty;
See also `current-input-mode'. */)
(Lisp_Object quit)
{
- struct terminal *t = get_named_tty ("/dev/tty");
+ struct terminal *t = get_named_terminal ("/dev/tty");
struct tty_display_info *tty;
- if (t == NULL || (t->type != output_termcap && t->type != output_msdos_raw))
+
+ if (!t)
return Qnil;
tty = t->display_info.tty;
}
else if (TERMINALP (object))
{
- struct terminal *t = get_terminal (object, 1);
+ struct terminal *t = decode_live_terminal (object);
if (t->type != output_ns)
error ("Terminal %d is not a Nextstep display", t->id);
Internal use only, use `display-monitor-attributes-list' instead. */)
(Lisp_Object terminal)
{
- struct terminal *term = get_terminal (terminal, 1);
+ struct terminal *term = decode_live_terminal (terminal);
NSArray *screens;
NSUInteger i, n_monitors;
struct MonitorInfo *monitors;
static void tty_show_cursor (struct tty_display_info *);
static void tty_hide_cursor (struct tty_display_info *);
static void tty_background_highlight (struct tty_display_info *tty);
-static struct terminal *get_tty_terminal (Lisp_Object, bool);
static void clear_tty_hooks (struct terminal *terminal);
static void set_tty_hooks (struct terminal *terminal);
static void dissociate_if_controlling_tty (int fd);
TERMINAL does not refer to a text terminal. */)
(Lisp_Object terminal)
{
- struct terminal *t = get_tty_terminal (terminal, 0);
- if (!t)
- return Qnil;
- else
- return t->display_info.tty->TN_max_colors > 0 ? Qt : Qnil;
+ struct terminal *t = decode_tty_terminal (terminal);
+
+ return (t && t->display_info.tty->TN_max_colors > 0) ? Qt : Qnil;
}
/* Return the number of supported colors. */
TERMINAL does not refer to a text terminal. */)
(Lisp_Object terminal)
{
- struct terminal *t = get_tty_terminal (terminal, 0);
- if (!t)
- return make_number (0);
- else
- return make_number (t->display_info.tty->TN_max_colors);
+ struct terminal *t = decode_tty_terminal (terminal);
+
+ return make_number (t ? t->display_info.tty->TN_max_colors : 0);
}
#ifndef DOS_NT
#endif /* !DOS_NT */
-\f
-
-/* Return the tty display object specified by TERMINAL. */
-
-static struct terminal *
-get_tty_terminal (Lisp_Object terminal, bool throw)
-{
- struct terminal *t = get_terminal (terminal, throw);
-
- if (t && t->type != output_termcap && t->type != output_msdos_raw)
- {
- if (throw)
- error ("Device %d is not a termcap terminal device", t->id);
- else
- return NULL;
- }
-
- return t;
-}
-
-/* Return an active termcap device that uses the tty device with the
- given name.
-
- This function ignores suspended devices.
-
- Returns NULL if the named terminal device is not opened. */
-
-struct terminal *
-get_named_tty (const char *name)
-{
- struct terminal *t;
-
- eassert (name);
-
- for (t = terminal_list; t; t = t->next_terminal)
- {
- if ((t->type == output_termcap || t->type == output_msdos_raw)
- && !strcmp (t->display_info.tty->name, name)
- && TERMINAL_ACTIVE_P (t))
- return t;
- }
-
- return 0;
-}
-
-\f
DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0,
doc: /* Return the type of the tty device that TERMINAL uses.
Returns nil if TERMINAL is not on a tty device.
selected frame's terminal). */)
(Lisp_Object terminal)
{
- struct terminal *t = get_terminal (terminal, 1);
-
- if (t->type != output_termcap && t->type != output_msdos_raw)
- return Qnil;
+ struct terminal *t = decode_tty_terminal (terminal);
- if (t->display_info.tty->type)
- return build_string (t->display_info.tty->type);
- else
- return Qnil;
+ return (t && t->display_info.tty->type
+ ? build_string (t->display_info.tty->type) : Qnil);
}
DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0,
TERMINAL is not on a tty device. */)
(Lisp_Object terminal)
{
- struct terminal *t = get_terminal (terminal, 1);
+ struct terminal *t = decode_tty_terminal (terminal);
- if ((t->type != output_termcap && t->type != output_msdos_raw)
- || strcmp (t->display_info.tty->name, DEV_TTY) != 0)
- return Qnil;
- else
- return Qt;
+ return (t && !strcmp (t->display_info.tty->name, DEV_TTY) ? Qt : Qnil);
}
DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0,
TERMINAL does not refer to a text terminal. */)
(Lisp_Object terminal)
{
- struct terminal *t = get_terminal (terminal, 1);
+ struct terminal *t = decode_live_terminal (terminal);
if (t->type == output_termcap)
t->display_info.tty->TS_enter_underline_mode = 0;
top-most frame on the text terminal. */)
(Lisp_Object terminal)
{
- struct terminal *t = get_terminal (terminal, 1);
+ struct terminal *t = decode_live_terminal (terminal);
if (t->type == output_termcap)
return t->display_info.tty->top_frame;
A suspended tty may be resumed by calling `resume-tty' on it. */)
(Lisp_Object tty)
{
- struct terminal *t = get_tty_terminal (tty, 1);
+ struct terminal *t = decode_tty_terminal (tty);
FILE *f;
if (!t)
- error ("Unknown tty device");
+ error ("Attempt to suspend a non-text terminal device");
f = t->display_info.tty->input;
frame's terminal). */)
(Lisp_Object tty)
{
- struct terminal *t = get_tty_terminal (tty, 1);
+ struct terminal *t = decode_tty_terminal (tty);
int fd;
if (!t)
- error ("Unknown tty device");
+ error ("Attempt to resume a non-text terminal device");
if (!t->display_info.tty->input)
{
- if (get_named_tty (t->display_info.tty->name))
+ if (get_named_terminal (t->display_info.tty->name))
error ("Cannot resume display while another display is active on the same device");
#ifdef MSDOS
/* XXX Perhaps this should be made explicit by having init_tty
always create a new terminal and separating terminal and frame
creation on Lisp level. */
- terminal = get_named_tty (name);
+ terminal = get_named_terminal (name);
if (terminal)
return terminal;
(t->type == output_ns ? t->display_info.ns->name_list_element : Qnil)
#endif
-extern struct terminal *get_terminal (Lisp_Object terminal, bool);
+extern struct terminal *decode_live_terminal (Lisp_Object);
+extern struct terminal *decode_tty_terminal (Lisp_Object);
+extern struct terminal *get_named_terminal (const char *);
extern struct terminal *create_terminal (enum output_method,
struct redisplay_interface *);
extern void delete_terminal (struct terminal *);
/* The initial terminal device, created by initial_term_init. */
struct terminal *initial_terminal;
+Lisp_Object Qrun_hook_with_args;
static Lisp_Object Qterminal_live_p;
+static Lisp_Object Qdelete_terminal_functions;
static void delete_initial_terminal (struct terminal *);
(*FRAME_TERMINAL (f)->ins_del_lines_hook) (f, vpos, n);
}
+/* Return the terminal object specified by TERMINAL. TERMINAL may
+ be a terminal object, a frame, or nil for the terminal device of
+ the current frame. If TERMINAL is neither from the above or the
+ resulting terminal object is deleted, return NULL. */
-\f
-
-/* Return the terminal object specified by TERMINAL. TERMINAL may be
- a terminal object, a frame, or nil for the terminal device of the
- current frame. If THROW is false, return NULL for failure,
- otherwise throw an error. */
-
-struct terminal *
-get_terminal (Lisp_Object terminal, bool throw)
+static struct terminal *
+decode_terminal (Lisp_Object terminal)
{
- struct terminal *result = NULL;
+ struct terminal *t;
if (NILP (terminal))
terminal = selected_frame;
+ t = (TERMINALP (terminal)
+ ? XTERMINAL (terminal)
+ : FRAMEP (terminal) ? FRAME_TERMINAL (XFRAME (terminal)) : NULL);
+ return t && t->name ? t : NULL;
+}
- if (TERMINALP (terminal))
- result = XTERMINAL (terminal);
- else if (FRAMEP (terminal))
- result = FRAME_TERMINAL (XFRAME (terminal));
+/* Like above, but throw an error if TERMINAL is not valid or deleted. */
- if (result && !result->name)
- result = NULL;
+struct terminal *
+decode_live_terminal (Lisp_Object terminal)
+{
+ struct terminal *t = decode_terminal (terminal);
- if (result == NULL && throw)
+ if (!t)
wrong_type_argument (Qterminal_live_p, terminal);
+ return t;
+}
+
+/* Like decode_terminal, but ensure that the resulting terminal object refers
+ to a text-based terminal device. */
+
+struct terminal *
+decode_tty_terminal (Lisp_Object terminal)
+{
+ struct terminal *t = decode_live_terminal (terminal);
- return result;
+ return (t->type == output_termcap || t->type == output_msdos_raw) ? t : NULL;
+}
+
+/* Return an active (not suspended) text-based terminal device that uses
+ the tty device with the given NAME, or NULL if the named terminal device
+ is not opened. */
+
+struct terminal *
+get_named_terminal (const char *name)
+{
+ struct terminal *t;
+
+ eassert (name);
+
+ for (t = terminal_list; t; t = t->next_terminal)
+ {
+ if ((t->type == output_termcap || t->type == output_msdos_raw)
+ && !strcmp (t->display_info.tty->name, name)
+ && TERMINAL_ACTIVE_P (t))
+ return t;
+ }
+ return NULL;
}
/* Create a new terminal object of TYPE and add it to the terminal list. RIF
}
}
-Lisp_Object Qrun_hook_with_args;
-static Lisp_Object Qdelete_terminal_functions;
DEFUN ("delete-terminal", Fdelete_terminal, Sdelete_terminal, 0, 2, 0,
doc: /* Delete TERMINAL by deleting all frames on it and closing the terminal.
TERMINAL may be a terminal object, a frame, or nil (meaning the
but if the second argument FORCE is non-nil, you may do so. */)
(Lisp_Object terminal, Lisp_Object force)
{
- struct terminal *t = get_terminal (terminal, 0);
+ struct terminal *t = decode_terminal (terminal);
if (!t)
return Qnil;
possible return values. */)
(Lisp_Object object)
{
- struct terminal *t;
-
- t = get_terminal (object, 0);
+ struct terminal *t = decode_terminal (object);
if (!t)
return Qnil;
selected frame's terminal). */)
(Lisp_Object terminal)
{
- struct terminal *t
- = TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
+ struct terminal *t = decode_live_terminal (terminal);
return t->name ? build_string (t->name) : Qnil;
}
selected frame's terminal). */)
(Lisp_Object terminal)
{
- struct terminal *t
- = TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
- return Fcopy_alist (t->param_alist);
+ return Fcopy_alist (decode_live_terminal (terminal)->param_alist);
}
DEFUN ("terminal-parameter", Fterminal_parameter, Sterminal_parameter, 2, 2, 0,
selected frame's terminal). */)
(Lisp_Object terminal, Lisp_Object parameter)
{
- Lisp_Object value;
- struct terminal *t
- = TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
CHECK_SYMBOL (parameter);
- value = Fcdr (Fassq (parameter, t->param_alist));
- return value;
+ return Fcdr (Fassq (parameter, decode_live_terminal (terminal)->param_alist));
}
DEFUN ("set-terminal-parameter", Fset_terminal_parameter,
selected frame's terminal). */)
(Lisp_Object terminal, Lisp_Object parameter, Lisp_Object value)
{
- struct terminal *t
- = TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
- return store_terminal_param (t, parameter, value);
+ return store_terminal_param (decode_live_terminal (terminal), parameter, value);
}
/* Initial frame has no device-dependent output data, but has
}
else if (TERMINALP (object))
{
- struct terminal *t = get_terminal (object, 1);
+ struct terminal *t = decode_live_terminal (object);
if (t->type != output_w32)
error ("Terminal %d is not a W32 display", t->id);
}
else if (TERMINALP (object))
{
- struct terminal *t = get_terminal (object, 1);
+ struct terminal *t = decode_live_terminal (object);
if (t->type != output_x_window)
error ("Terminal %d is not an X display", t->id);
}
else if (TERMINALP (object))
{
- struct terminal *t = get_terminal (object, 1);
+ struct terminal *t = decode_live_terminal (object);
if (t->type == output_x_window)
FOR_EACH_FRAME (tail, frame)