Updating_frame vs. selected_frame in term.c.
[bpt/emacs.git] / src / term.c
1 /* Terminal control module for terminals described by TERMCAP
2 Copyright (C) 1985, 86, 87, 93, 94, 95, 98, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 /* New redisplay, TTY faces by Gerd Moellmann <gerd@gnu.org>. */
23
24 #include <config.h>
25 #include <stdio.h>
26 #include <ctype.h>
27 #include <string.h>
28
29 #include <sys/file.h>
30
31 #include "systty.h" /* For emacs_tty in termchar.h */
32 #include "termchar.h"
33 #include "termopts.h"
34 #include "lisp.h"
35 #include "charset.h"
36 #include "coding.h"
37 #include "keyboard.h"
38 #include "frame.h"
39 #include "disptab.h"
40 #include "termhooks.h"
41 #include "dispextern.h"
42 #include "window.h"
43 #include "keymap.h"
44
45 /* For now, don't try to include termcap.h. On some systems,
46 configure finds a non-standard termcap.h that the main build
47 won't find. */
48
49 #if defined HAVE_TERMCAP_H && 0
50 #include <termcap.h>
51 #else
52 extern void tputs P_ ((const char *, int, int (*)(int)));
53 extern int tgetent P_ ((char *, const char *));
54 extern int tgetflag P_ ((char *id));
55 extern int tgetnum P_ ((char *id));
56 #endif
57
58 #include "cm.h"
59 #ifdef HAVE_X_WINDOWS
60 #include "xterm.h"
61 #endif
62 #ifdef MAC_OS
63 #include "macterm.h"
64 #endif
65
66 #ifndef O_RDWR
67 #define O_RDWR 2
68 #endif
69
70 static void turn_on_face P_ ((struct frame *, int face_id));
71 static void turn_off_face P_ ((struct frame *, int face_id));
72 static void tty_show_cursor P_ ((void));
73 static void tty_hide_cursor P_ ((void));
74
75 #define OUTPUT(tty, a) \
76 emacs_tputs ((tty), a, (int) (FRAME_LINES (XFRAME (selected_frame)) - curY), cmputc)
77 #define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
78 #define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
79
80 #define OUTPUT_IF(tty, a) \
81 do { \
82 if (a) \
83 emacs_tputs ((tty), a, (int) (FRAME_LINES (XFRAME (selected_frame)) \
84 - curY), cmputc); \
85 } while (0)
86
87 #define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
88
89 /* Function to use to ring the bell. */
90
91 Lisp_Object Vring_bell_function;
92
93 /* Terminal characteristics that higher levels want to look at. */
94
95 struct tty_output *tty_list;
96
97 /* Nonzero means no need to redraw the entire frame on resuming
98 a suspended Emacs. This is useful on terminals with multiple pages,
99 where one page is used for Emacs and another for all else. */
100 int no_redraw_on_reenter;
101
102 /* Hook functions that you can set to snap out the functions in this file.
103 These are all extern'd in termhooks.h */
104
105 void (*cursor_to_hook) P_ ((int, int));
106 void (*raw_cursor_to_hook) P_ ((int, int));
107 void (*clear_to_end_hook) P_ ((void));
108 void (*clear_frame_hook) P_ ((void));
109 void (*clear_end_of_line_hook) P_ ((int));
110
111 void (*ins_del_lines_hook) P_ ((int, int));
112
113 void (*delete_glyphs_hook) P_ ((int));
114
115 void (*ring_bell_hook) P_ ((void));
116
117 void (*reset_terminal_modes_hook) P_ ((void));
118 void (*set_terminal_modes_hook) P_ ((void));
119 void (*update_begin_hook) P_ ((struct frame *));
120 void (*update_end_hook) P_ ((struct frame *));
121 void (*set_terminal_window_hook) P_ ((int));
122 void (*insert_glyphs_hook) P_ ((struct glyph *, int));
123 void (*write_glyphs_hook) P_ ((struct glyph *, int));
124 void (*delete_glyphs_hook) P_ ((int));
125
126 int (*read_socket_hook) P_ ((int, struct input_event *, int, int));
127
128 void (*frame_up_to_date_hook) P_ ((struct frame *));
129
130 /* Return the current position of the mouse.
131
132 Set *f to the frame the mouse is in, or zero if the mouse is in no
133 Emacs frame. If it is set to zero, all the other arguments are
134 garbage.
135
136 If the motion started in a scroll bar, set *bar_window to the
137 scroll bar's window, *part to the part the mouse is currently over,
138 *x to the position of the mouse along the scroll bar, and *y to the
139 overall length of the scroll bar.
140
141 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
142 row of the character cell the mouse is over.
143
144 Set *time to the time the mouse was at the returned position.
145
146 This should clear mouse_moved until the next motion
147 event arrives. */
148
149 void (*mouse_position_hook) P_ ((FRAME_PTR *f, int insist,
150 Lisp_Object *bar_window,
151 enum scroll_bar_part *part,
152 Lisp_Object *x,
153 Lisp_Object *y,
154 unsigned long *time));
155
156 /* When reading from a minibuffer in a different frame, Emacs wants
157 to shift the highlight from the selected frame to the mini-buffer's
158 frame; under X, this means it lies about where the focus is.
159 This hook tells the window system code to re-decide where to put
160 the highlight. */
161
162 void (*frame_rehighlight_hook) P_ ((FRAME_PTR f));
163
164 /* If we're displaying frames using a window system that can stack
165 frames on top of each other, this hook allows you to bring a frame
166 to the front, or bury it behind all the other windows. If this
167 hook is zero, that means the device we're displaying on doesn't
168 support overlapping frames, so there's no need to raise or lower
169 anything.
170
171 If RAISE is non-zero, F is brought to the front, before all other
172 windows. If RAISE is zero, F is sent to the back, behind all other
173 windows. */
174
175 void (*frame_raise_lower_hook) P_ ((FRAME_PTR f, int raise));
176
177 /* Set the vertical scroll bar for WINDOW to have its upper left corner
178 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
179 indicate that we are displaying PORTION characters out of a total
180 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
181 have a scroll bar, create one for it. */
182
183 void (*set_vertical_scroll_bar_hook)
184 P_ ((struct window *window,
185 int portion, int whole, int position));
186
187
188 /* The following three hooks are used when we're doing a thorough
189 redisplay of the frame. We don't explicitly know which scroll bars
190 are going to be deleted, because keeping track of when windows go
191 away is a real pain - can you say set-window-configuration?
192 Instead, we just assert at the beginning of redisplay that *all*
193 scroll bars are to be removed, and then save scroll bars from the
194 fiery pit when we actually redisplay their window. */
195
196 /* Arrange for all scroll bars on FRAME to be removed at the next call
197 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
198 `*redeem_scroll_bar_hook' is applied to its window before the judgment.
199
200 This should be applied to each frame each time its window tree is
201 redisplayed, even if it is not displaying scroll bars at the moment;
202 if the HAS_SCROLL_BARS flag has just been turned off, only calling
203 this and the judge_scroll_bars_hook will get rid of them.
204
205 If non-zero, this hook should be safe to apply to any frame,
206 whether or not it can support scroll bars, and whether or not it is
207 currently displaying them. */
208
209 void (*condemn_scroll_bars_hook) P_ ((FRAME_PTR frame));
210
211 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
212 Note that it's okay to redeem a scroll bar that is not condemned. */
213
214 void (*redeem_scroll_bar_hook) P_ ((struct window *window));
215
216 /* Remove all scroll bars on FRAME that haven't been saved since the
217 last call to `*condemn_scroll_bars_hook'.
218
219 This should be applied to each frame after each time its window
220 tree is redisplayed, even if it is not displaying scroll bars at the
221 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
222 calling this and condemn_scroll_bars_hook will get rid of them.
223
224 If non-zero, this hook should be safe to apply to any frame,
225 whether or not it can support scroll bars, and whether or not it is
226 currently displaying them. */
227
228 void (*judge_scroll_bars_hook) P_ ((FRAME_PTR FRAME));
229
230 /* Strings, numbers and flags taken from the termcap entry. */
231
232 char *TS_ins_line; /* "al" */
233 char *TS_ins_multi_lines; /* "AL" (one parameter, # lines to insert) */
234 char *TS_bell; /* "bl" */
235 char *TS_clr_to_bottom; /* "cd" */
236 char *TS_clr_line; /* "ce", clear to end of line */
237 char *TS_clr_frame; /* "cl" */
238 char *TS_set_scroll_region; /* "cs" (2 params, first line and last line) */
239 char *TS_set_scroll_region_1; /* "cS" (4 params: total lines,
240 lines above scroll region, lines below it,
241 total lines again) */
242 char *TS_del_char; /* "dc" */
243 char *TS_del_multi_chars; /* "DC" (one parameter, # chars to delete) */
244 char *TS_del_line; /* "dl" */
245 char *TS_del_multi_lines; /* "DL" (one parameter, # lines to delete) */
246 char *TS_delete_mode; /* "dm", enter character-delete mode */
247 char *TS_end_delete_mode; /* "ed", leave character-delete mode */
248 char *TS_end_insert_mode; /* "ei", leave character-insert mode */
249 char *TS_ins_char; /* "ic" */
250 char *TS_ins_multi_chars; /* "IC" (one parameter, # chars to insert) */
251 char *TS_insert_mode; /* "im", enter character-insert mode */
252 char *TS_pad_inserted_char; /* "ip". Just padding, no commands. */
253 char *TS_end_keypad_mode; /* "ke" */
254 char *TS_keypad_mode; /* "ks" */
255 char *TS_pad_char; /* "pc", char to use as padding */
256 char *TS_repeat; /* "rp" (2 params, # times to repeat
257 and character to be repeated) */
258 char *TS_end_standout_mode; /* "se" */
259 char *TS_fwd_scroll; /* "sf" */
260 char *TS_standout_mode; /* "so" */
261 char *TS_rev_scroll; /* "sr" */
262 char *TS_end_termcap_modes; /* "te" */
263 char *TS_termcap_modes; /* "ti" */
264 char *TS_visible_bell; /* "vb" */
265 char *TS_cursor_normal; /* "ve" */
266 char *TS_cursor_visible; /* "vs" */
267 char *TS_cursor_invisible; /* "vi" */
268 char *TS_set_window; /* "wi" (4 params, start and end of window,
269 each as vpos and hpos) */
270
271 /* Value of the "NC" (no_color_video) capability, or 0 if not
272 present. */
273
274 static int TN_no_color_video;
275
276 /* Meaning of bits in no_color_video. Each bit set means that the
277 corresponding attribute cannot be combined with colors. */
278
279 enum no_color_bit
280 {
281 NC_STANDOUT = 1 << 0,
282 NC_UNDERLINE = 1 << 1,
283 NC_REVERSE = 1 << 2,
284 NC_BLINK = 1 << 3,
285 NC_DIM = 1 << 4,
286 NC_BOLD = 1 << 5,
287 NC_INVIS = 1 << 6,
288 NC_PROTECT = 1 << 7,
289 NC_ALT_CHARSET = 1 << 8
290 };
291
292 /* "md" -- turn on bold (extra bright mode). */
293
294 char *TS_enter_bold_mode;
295
296 /* "mh" -- turn on half-bright mode. */
297
298 char *TS_enter_dim_mode;
299
300 /* "mb" -- enter blinking mode. */
301
302 char *TS_enter_blink_mode;
303
304 /* "mr" -- enter reverse video mode. */
305
306 char *TS_enter_reverse_mode;
307
308 /* "us"/"ue" -- start/end underlining. */
309
310 char *TS_exit_underline_mode, *TS_enter_underline_mode;
311
312 /* "as"/"ae" -- start/end alternate character set. Not really
313 supported, yet. */
314
315 char *TS_enter_alt_charset_mode, *TS_exit_alt_charset_mode;
316
317 /* "me" -- switch appearances off. */
318
319 char *TS_exit_attribute_mode;
320
321 /* "Co" -- number of colors. */
322
323 int TN_max_colors;
324
325 /* "pa" -- max. number of color pairs on screen. Not handled yet.
326 Could be a problem if not equal to TN_max_colors * TN_max_colors. */
327
328 int TN_max_pairs;
329
330 /* "op" -- SVr4 set default pair to its original value. */
331
332 char *TS_orig_pair;
333
334 /* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color.
335 1 param, the color index. */
336
337 char *TS_set_foreground, *TS_set_background;
338
339 int TF_hazeltine; /* termcap hz flag. */
340 int TF_insmode_motion; /* termcap mi flag: can move while in insert mode. */
341 int TF_standout_motion; /* termcap mi flag: can move while in standout mode. */
342 int TF_underscore; /* termcap ul flag: _ underlines if over-struck on
343 non-blank position. Must clear before writing _. */
344 int TF_teleray; /* termcap xt flag: many weird consequences.
345 For t1061. */
346
347 static int RPov; /* # chars to start a TS_repeat */
348
349 static int delete_in_insert_mode; /* delete mode == insert mode */
350
351 static int se_is_so; /* 1 if same string both enters and leaves
352 standout mode */
353
354 /* internal state */
355
356 /* The largest frame width in any call to calculate_costs. */
357
358 int max_frame_cols;
359
360 /* The largest frame height in any call to calculate_costs. */
361
362 int max_frame_lines;
363
364 static int costs_set; /* Nonzero if costs have been calculated. */
365
366 int insert_mode; /* Nonzero when in insert mode. */
367 int standout_mode; /* Nonzero when in standout mode. */
368
369 /* Size of window specified by higher levels.
370 This is the number of lines, from the top of frame downwards,
371 which can participate in insert-line/delete-line operations.
372
373 Effectively it excludes the bottom frame_lines - specified_window_size
374 lines from those operations. */
375
376 int specified_window;
377
378 /* Frame currently being redisplayed; 0 if not currently redisplaying.
379 (Direct output does not count). */
380
381 FRAME_PTR updating_frame;
382
383 /* Provided for lisp packages. */
384
385 static int system_uses_terminfo;
386
387 /* Flag used in tty_show/hide_cursor. */
388
389 static int tty_cursor_hidden;
390
391 char *tparam ();
392
393 extern char *tgetstr ();
394 \f
395
396 #ifdef WINDOWSNT
397 /* We aren't X windows, but we aren't termcap either. This makes me
398 uncertain as to what value to use for frame.output_method. For
399 this file, we'll define FRAME_TERMCAP_P to be zero so that our
400 output hooks get called instead of the termcap functions. Probably
401 the best long-term solution is to define an output_windows_nt... */
402
403 #undef FRAME_TERMCAP_P
404 #define FRAME_TERMCAP_P(_f_) 0
405 #endif /* WINDOWSNT */
406
407 void
408 ring_bell ()
409 {
410 if (!NILP (Vring_bell_function))
411 {
412 Lisp_Object function;
413
414 /* Temporarily set the global variable to nil
415 so that if we get an error, it stays nil
416 and we don't call it over and over.
417
418 We don't specbind it, because that would carefully
419 restore the bad value if there's an error
420 and make the loop of errors happen anyway. */
421
422 function = Vring_bell_function;
423 Vring_bell_function = Qnil;
424
425 call0 (function);
426
427 Vring_bell_function = function;
428 }
429 else if (!FRAME_TERMCAP_P (XFRAME (selected_frame)))
430 (*ring_bell_hook) ();
431 else {
432 OUTPUT (CURTTY (), TS_visible_bell && visible_bell ? TS_visible_bell : TS_bell);
433 }
434 }
435
436 void
437 set_terminal_modes (struct tty_output *tty)
438 {
439 if (FRAME_TERMCAP_P (XFRAME (selected_frame)))
440 {
441 OUTPUT_IF (tty, TS_termcap_modes);
442 OUTPUT_IF (tty, TS_cursor_visible);
443 OUTPUT_IF (tty, TS_keypad_mode);
444 losecursor ();
445 }
446 else
447 (*set_terminal_modes_hook) ();
448 }
449
450 void
451 reset_terminal_modes (struct tty_output *tty)
452 {
453 if (FRAME_TERMCAP_P (XFRAME (selected_frame)))
454 {
455 turn_off_highlight ();
456 turn_off_insert ();
457 OUTPUT_IF (tty, TS_end_keypad_mode);
458 OUTPUT_IF (tty, TS_cursor_normal);
459 OUTPUT_IF (tty, TS_end_termcap_modes);
460 OUTPUT_IF (tty, TS_orig_pair);
461 /* Output raw CR so kernel can track the cursor hpos. */
462 current_tty = tty;
463 cmputc ('\r');
464 }
465 else if (reset_terminal_modes_hook)
466 (*reset_terminal_modes_hook) ();
467 }
468
469 void
470 update_begin (f)
471 struct frame *f;
472 {
473 updating_frame = f;
474 if (!FRAME_TERMCAP_P (f))
475 update_begin_hook (f);
476 }
477
478 void
479 update_end (f)
480 struct frame *f;
481 {
482 if (FRAME_TERMCAP_P (f))
483 {
484 if (!XWINDOW (selected_window)->cursor_off_p)
485 tty_show_cursor ();
486 turn_off_insert ();
487 background_highlight ();
488 }
489 else
490 update_end_hook (f);
491
492 updating_frame = NULL;
493 }
494
495 void
496 set_terminal_window (size)
497 int size;
498 {
499 if (FRAME_TERMCAP_P (updating_frame))
500 {
501 specified_window = size ? size : FRAME_LINES (updating_frame);
502 if (TTY_SCROLL_REGION_OK (FRAME_TTY (updating_frame)))
503 set_scroll_region (0, specified_window);
504 }
505 else
506 set_terminal_window_hook (size);
507 }
508
509 void
510 set_scroll_region (start, stop)
511 int start, stop;
512 {
513 char *buf;
514 struct frame *f = (updating_frame
515 ? updating_frame
516 : XFRAME (selected_frame));
517
518 if (TS_set_scroll_region)
519 buf = tparam (TS_set_scroll_region, 0, 0, start, stop - 1);
520 else if (TS_set_scroll_region_1)
521 buf = tparam (TS_set_scroll_region_1, 0, 0,
522 FRAME_LINES (f), start,
523 FRAME_LINES (f) - stop,
524 FRAME_LINES (f));
525 else
526 buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (f));
527
528 OUTPUT (FRAME_TTY (f), buf);
529 xfree (buf);
530 losecursor ();
531 }
532
533 \f
534 static void
535 turn_on_insert ()
536 {
537 struct frame *f = (updating_frame
538 ? updating_frame
539 : XFRAME (selected_frame));
540 if (!insert_mode)
541 OUTPUT (FRAME_TTY (f), TS_insert_mode);
542 insert_mode = 1;
543 }
544
545 void
546 turn_off_insert ()
547 {
548 struct frame *f = (updating_frame
549 ? updating_frame
550 : XFRAME (selected_frame));
551 if (insert_mode)
552 OUTPUT (FRAME_TTY (f), TS_end_insert_mode);
553 insert_mode = 0;
554 }
555 \f
556 /* Handle highlighting. */
557
558 void
559 turn_off_highlight ()
560 {
561 struct frame *f = (updating_frame
562 ? updating_frame
563 : XFRAME (selected_frame));
564 if (standout_mode)
565 OUTPUT_IF (FRAME_TTY (f), TS_end_standout_mode);
566 standout_mode = 0;
567 }
568
569 static void
570 turn_on_highlight ()
571 {
572 struct frame *f = (updating_frame
573 ? updating_frame
574 : XFRAME (selected_frame));
575 if (!standout_mode)
576 OUTPUT_IF (FRAME_TTY (f), TS_standout_mode);
577 standout_mode = 1;
578 }
579
580 static void
581 toggle_highlight ()
582 {
583 if (standout_mode)
584 turn_off_highlight ();
585 else
586 turn_on_highlight ();
587 }
588
589
590 /* Make cursor invisible. */
591
592 static void
593 tty_hide_cursor ()
594 {
595 struct frame *f = (updating_frame
596 ? updating_frame
597 : XFRAME (selected_frame));
598
599 if (tty_cursor_hidden == 0)
600 {
601 tty_cursor_hidden = 1;
602 OUTPUT_IF (FRAME_TTY (f), TS_cursor_invisible);
603 }
604 }
605
606
607 /* Ensure that cursor is visible. */
608
609 static void
610 tty_show_cursor ()
611 {
612 struct frame *f = (updating_frame
613 ? updating_frame
614 : XFRAME (selected_frame));
615
616 if (tty_cursor_hidden)
617 {
618 tty_cursor_hidden = 0;
619 OUTPUT_IF (FRAME_TTY (f), TS_cursor_normal);
620 OUTPUT_IF (FRAME_TTY (f), TS_cursor_visible);
621 }
622 }
623
624
625 /* Set standout mode to the state it should be in for
626 empty space inside windows. What this is,
627 depends on the user option inverse-video. */
628
629 void
630 background_highlight ()
631 {
632 if (inverse_video)
633 turn_on_highlight ();
634 else
635 turn_off_highlight ();
636 }
637
638 /* Set standout mode to the mode specified for the text to be output. */
639
640 static void
641 highlight_if_desired ()
642 {
643 if (inverse_video)
644 turn_on_highlight ();
645 else
646 turn_off_highlight ();
647 }
648 \f
649
650 /* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
651 frame-relative coordinates. */
652
653 void
654 cursor_to (vpos, hpos)
655 int vpos, hpos;
656 {
657 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame);
658
659 if (! FRAME_TERMCAP_P (f) && cursor_to_hook)
660 {
661 (*cursor_to_hook) (vpos, hpos);
662 return;
663 }
664
665 /* Detect the case where we are called from reset_sys_modes
666 and the costs have never been calculated. Do nothing. */
667 if (! costs_set)
668 return;
669
670 if (curY == vpos && curX == hpos)
671 return;
672 if (!TF_standout_motion)
673 background_highlight ();
674 if (!TF_insmode_motion)
675 turn_off_insert ();
676 cmgoto (FRAME_TTY (f), vpos, hpos);
677 }
678
679 /* Similar but don't take any account of the wasted characters. */
680
681 void
682 raw_cursor_to (row, col)
683 int row, col;
684 {
685 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame);
686 if (! FRAME_TERMCAP_P (f))
687 {
688 (*raw_cursor_to_hook) (row, col);
689 return;
690 }
691 if (curY == row && curX == col)
692 return;
693 if (!TF_standout_motion)
694 background_highlight ();
695 if (!TF_insmode_motion)
696 turn_off_insert ();
697 cmgoto (FRAME_TTY (f), row, col);
698 }
699 \f
700 /* Erase operations */
701
702 /* clear from cursor to end of frame */
703 void
704 clear_to_end ()
705 {
706 register int i;
707
708 struct frame *f = (updating_frame
709 ? updating_frame
710 : XFRAME (selected_frame));
711
712 if (clear_to_end_hook && ! FRAME_TERMCAP_P (f))
713 {
714 (*clear_to_end_hook) ();
715 return;
716 }
717 if (TS_clr_to_bottom)
718 {
719 background_highlight ();
720 OUTPUT (FRAME_TTY (f), TS_clr_to_bottom);
721 }
722 else
723 {
724 for (i = curY; i < FRAME_LINES (f); i++)
725 {
726 cursor_to (i, 0);
727 clear_end_of_line (FRAME_COLS (f));
728 }
729 }
730 }
731
732 /* Clear entire frame */
733
734 void
735 clear_frame ()
736 {
737 struct frame *f = (updating_frame
738 ? updating_frame
739 : XFRAME (selected_frame));
740
741 if (clear_frame_hook && ! FRAME_TERMCAP_P (f))
742 {
743 (*clear_frame_hook) ();
744 return;
745 }
746 if (TS_clr_frame)
747 {
748 background_highlight ();
749 OUTPUT (FRAME_TTY (f), TS_clr_frame);
750 cmat (0, 0);
751 }
752 else
753 {
754 cursor_to (0, 0);
755 clear_to_end ();
756 }
757 }
758
759 /* Clear from cursor to end of line.
760 Assume that the line is already clear starting at column first_unused_hpos.
761
762 Note that the cursor may be moved, on terminals lacking a `ce' string. */
763
764 void
765 clear_end_of_line (first_unused_hpos)
766 int first_unused_hpos;
767 {
768 register int i;
769
770 struct frame *f = (updating_frame
771 ? updating_frame
772 : XFRAME (selected_frame));
773
774 if (clear_end_of_line_hook
775 && ! FRAME_TERMCAP_P (f))
776 {
777 (*clear_end_of_line_hook) (first_unused_hpos);
778 return;
779 }
780
781 /* Detect the case where we are called from reset_sys_modes
782 and the costs have never been calculated. Do nothing. */
783 if (! costs_set)
784 return;
785
786 if (curX >= first_unused_hpos)
787 return;
788 background_highlight ();
789 if (TS_clr_line)
790 {
791 OUTPUT1 (FRAME_TTY (f), TS_clr_line);
792 }
793 else
794 { /* have to do it the hard way */
795 struct frame *sf = XFRAME (selected_frame);
796 turn_off_insert ();
797
798 /* Do not write in last row last col with Auto-wrap on. */
799 if (AutoWrap && curY == FRAME_LINES (sf) - 1
800 && first_unused_hpos == FRAME_COLS (sf))
801 first_unused_hpos--;
802
803 for (i = curX; i < first_unused_hpos; i++)
804 {
805 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
806 fputc (' ', TTY_TERMSCRIPT (FRAME_TTY (f)));
807 fputc (' ', TTY_OUTPUT (FRAME_TTY (f)));
808 }
809 cmplus (first_unused_hpos - curX);
810 }
811 }
812 \f
813 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes and
814 store them at DST. Do not write more than DST_LEN bytes. That may
815 require stopping before all SRC_LEN input glyphs have been
816 converted.
817
818 We store the number of glyphs actually converted in *CONSUMED. The
819 return value is the number of bytes store in DST. */
820
821 int
822 encode_terminal_code (src, dst, src_len, dst_len, consumed)
823 struct glyph *src;
824 int src_len;
825 unsigned char *dst;
826 int dst_len, *consumed;
827 {
828 struct glyph *src_start = src, *src_end = src + src_len;
829 unsigned char *dst_start = dst, *dst_end = dst + dst_len;
830 register GLYPH g;
831 unsigned char workbuf[MAX_MULTIBYTE_LENGTH];
832 const unsigned char *buf;
833 int len;
834 register int tlen = GLYPH_TABLE_LENGTH;
835 register Lisp_Object *tbase = GLYPH_TABLE_BASE;
836 int result;
837 struct coding_system *coding;
838
839 /* If terminal_coding does any conversion, use it, otherwise use
840 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
841 because it always return 1 if the member src_multibyte is 1. */
842 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK
843 ? &terminal_coding
844 : &safe_terminal_coding);
845
846 while (src < src_end)
847 {
848 /* We must skip glyphs to be padded for a wide character. */
849 if (! CHAR_GLYPH_PADDING_P (*src))
850 {
851 g = GLYPH_FROM_CHAR_GLYPH (src[0]);
852
853 if (g < 0 || g >= tlen)
854 {
855 /* This glyph doesn't has an entry in Vglyph_table. */
856 if (! CHAR_VALID_P (src->u.ch, 0))
857 {
858 len = 1;
859 buf = " ";
860 coding->src_multibyte = 0;
861 }
862 else
863 {
864 len = CHAR_STRING (src->u.ch, workbuf);
865 buf = workbuf;
866 coding->src_multibyte = 1;
867 }
868 }
869 else
870 {
871 /* This glyph has an entry in Vglyph_table,
872 so process any alias before testing for simpleness. */
873 GLYPH_FOLLOW_ALIASES (tbase, tlen, g);
874
875 if (GLYPH_SIMPLE_P (tbase, tlen, g))
876 {
877 /* We set the multi-byte form of a character in G
878 (that should be an ASCII character) at
879 WORKBUF. */
880 workbuf[0] = FAST_GLYPH_CHAR (g);
881 len = 1;
882 buf = workbuf;
883 coding->src_multibyte = 0;
884 }
885 else
886 {
887 /* We have a string in Vglyph_table. */
888 len = GLYPH_LENGTH (tbase, g);
889 buf = GLYPH_STRING (tbase, g);
890 coding->src_multibyte = STRING_MULTIBYTE (tbase[g]);
891 }
892 }
893
894 result = encode_coding (coding, buf, dst, len, dst_end - dst);
895 len -= coding->consumed;
896 dst += coding->produced;
897 if (result == CODING_FINISH_INSUFFICIENT_DST
898 || (result == CODING_FINISH_INSUFFICIENT_SRC
899 && len > dst_end - dst))
900 /* The remaining output buffer is too short. We must
901 break the loop here without increasing SRC so that the
902 next call of this function starts from the same glyph. */
903 break;
904
905 if (len > 0)
906 {
907 /* This is the case that a code of the range 0200..0237
908 exists in buf. We must just write out such a code. */
909 buf += coding->consumed;
910 while (len--)
911 *dst++ = *buf++;
912 }
913 }
914 src++;
915 }
916
917 *consumed = src - src_start;
918 return (dst - dst_start);
919 }
920
921
922 void
923 write_glyphs (string, len)
924 register struct glyph *string;
925 register int len;
926 {
927 int produced, consumed;
928 struct frame *sf = XFRAME (selected_frame);
929 struct frame *f = updating_frame ? updating_frame : sf;
930 unsigned char conversion_buffer[1024];
931 int conversion_buffer_size = sizeof conversion_buffer;
932
933 if (write_glyphs_hook
934 && ! FRAME_TERMCAP_P (f))
935 {
936 (*write_glyphs_hook) (string, len);
937 return;
938 }
939
940 turn_off_insert ();
941 tty_hide_cursor ();
942
943 /* Don't dare write in last column of bottom line, if Auto-Wrap,
944 since that would scroll the whole frame on some terminals. */
945
946 if (AutoWrap
947 && curY + 1 == FRAME_LINES (sf)
948 && (curX + len) == FRAME_COLS (sf))
949 len --;
950 if (len <= 0)
951 return;
952
953 cmplus (len);
954
955 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
956 the tail. */
957 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK;
958
959 while (len > 0)
960 {
961 /* Identify a run of glyphs with the same face. */
962 int face_id = string->face_id;
963 int n;
964
965 for (n = 1; n < len; ++n)
966 if (string[n].face_id != face_id)
967 break;
968
969 /* Turn appearance modes of the face of the run on. */
970 highlight_if_desired ();
971 turn_on_face (f, face_id);
972
973 while (n > 0)
974 {
975 /* We use a fixed size (1024 bytes) of conversion buffer.
976 Usually it is sufficient, but if not, we just repeat the
977 loop. */
978 produced = encode_terminal_code (string, conversion_buffer,
979 n, conversion_buffer_size,
980 &consumed);
981 if (produced > 0)
982 {
983 fwrite (conversion_buffer, 1, produced,
984 TTY_OUTPUT (FRAME_TTY (f)));
985 if (ferror (TTY_OUTPUT (FRAME_TTY (f))))
986 clearerr (TTY_OUTPUT (FRAME_TTY (f)));
987 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
988 fwrite (conversion_buffer, 1, produced,
989 TTY_TERMSCRIPT (FRAME_TTY (f)));
990 }
991 len -= consumed;
992 n -= consumed;
993 string += consumed;
994 }
995
996 /* Turn appearance modes off. */
997 turn_off_face (f, face_id);
998 turn_off_highlight ();
999 }
1000
1001 /* We may have to output some codes to terminate the writing. */
1002 if (CODING_REQUIRE_FLUSHING (&terminal_coding))
1003 {
1004 terminal_coding.mode |= CODING_MODE_LAST_BLOCK;
1005 encode_coding (&terminal_coding, "", conversion_buffer,
1006 0, conversion_buffer_size);
1007 if (terminal_coding.produced > 0)
1008 {
1009 fwrite (conversion_buffer, 1, terminal_coding.produced,
1010 TTY_OUTPUT (FRAME_TTY (f)));
1011 if (ferror (TTY_OUTPUT (FRAME_TTY (f))))
1012 clearerr (TTY_OUTPUT (FRAME_TTY (f)));
1013 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
1014 fwrite (conversion_buffer, 1, terminal_coding.produced,
1015 TTY_TERMSCRIPT (FRAME_TTY (f)));
1016 }
1017 }
1018
1019 cmcheckmagic (FRAME_TTY (f));
1020 }
1021
1022 /* If start is zero, insert blanks instead of a string at start */
1023
1024 void
1025 insert_glyphs (start, len)
1026 register struct glyph *start;
1027 register int len;
1028 {
1029 char *buf;
1030 struct glyph *glyph = NULL;
1031 struct frame *f, *sf;
1032
1033 if (len <= 0)
1034 return;
1035
1036 if (insert_glyphs_hook)
1037 {
1038 (*insert_glyphs_hook) (start, len);
1039 return;
1040 }
1041
1042 sf = XFRAME (selected_frame);
1043 f = updating_frame ? updating_frame : sf;
1044
1045 if (TS_ins_multi_chars)
1046 {
1047 buf = tparam (TS_ins_multi_chars, 0, 0, len);
1048 OUTPUT1 (FRAME_TTY (f), buf);
1049 xfree (buf);
1050 if (start)
1051 write_glyphs (start, len);
1052 return;
1053 }
1054
1055 turn_on_insert ();
1056 cmplus (len);
1057 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */
1058 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK;
1059 while (len-- > 0)
1060 {
1061 int produced, consumed;
1062 unsigned char conversion_buffer[1024];
1063 int conversion_buffer_size = sizeof conversion_buffer;
1064
1065 OUTPUT1_IF (FRAME_TTY (f), TS_ins_char);
1066 if (!start)
1067 {
1068 conversion_buffer[0] = SPACEGLYPH;
1069 produced = 1;
1070 }
1071 else
1072 {
1073 highlight_if_desired ();
1074 turn_on_face (f, start->face_id);
1075 glyph = start;
1076 ++start;
1077 /* We must open sufficient space for a character which
1078 occupies more than one column. */
1079 while (len && CHAR_GLYPH_PADDING_P (*start))
1080 {
1081 OUTPUT1_IF (FRAME_TTY (f), TS_ins_char);
1082 start++, len--;
1083 }
1084
1085 if (len <= 0)
1086 /* This is the last glyph. */
1087 terminal_coding.mode |= CODING_MODE_LAST_BLOCK;
1088
1089 /* The size of conversion buffer (1024 bytes) is surely
1090 sufficient for just one glyph. */
1091 produced = encode_terminal_code (glyph, conversion_buffer, 1,
1092 conversion_buffer_size, &consumed);
1093 }
1094
1095 if (produced > 0)
1096 {
1097 fwrite (conversion_buffer, 1, produced,
1098 TTY_OUTPUT (FRAME_TTY (f)));
1099 if (ferror (TTY_OUTPUT (FRAME_TTY (f))))
1100 clearerr (TTY_OUTPUT (FRAME_TTY (f)));
1101 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
1102 fwrite (conversion_buffer, 1, produced,
1103 TTY_TERMSCRIPT (FRAME_TTY (f)));
1104 }
1105
1106 OUTPUT1_IF (FRAME_TTY (f), TS_pad_inserted_char);
1107 if (start)
1108 {
1109 turn_off_face (f, glyph->face_id);
1110 turn_off_highlight ();
1111 }
1112 }
1113
1114 cmcheckmagic (FRAME_TTY (f));
1115 }
1116
1117 void
1118 delete_glyphs (n)
1119 register int n;
1120 {
1121 char *buf;
1122 register int i;
1123
1124 if (delete_glyphs_hook && ! FRAME_TERMCAP_P (updating_frame))
1125 {
1126 (*delete_glyphs_hook) (n);
1127 return;
1128 }
1129
1130 if (delete_in_insert_mode)
1131 {
1132 turn_on_insert ();
1133 }
1134 else
1135 {
1136 turn_off_insert ();
1137 OUTPUT_IF (FRAME_TTY (updating_frame), TS_delete_mode);
1138 }
1139
1140 if (TS_del_multi_chars)
1141 {
1142 buf = tparam (TS_del_multi_chars, 0, 0, n);
1143 OUTPUT1 (FRAME_TTY (updating_frame), buf);
1144 xfree (buf);
1145 }
1146 else
1147 for (i = 0; i < n; i++)
1148 OUTPUT1 (FRAME_TTY (updating_frame), TS_del_char);
1149 if (!delete_in_insert_mode)
1150 OUTPUT_IF (FRAME_TTY (updating_frame), TS_end_delete_mode);
1151 }
1152 \f
1153 /* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
1154
1155 void
1156 ins_del_lines (vpos, n)
1157 int vpos, n;
1158 {
1159 char *multi = n > 0 ? TS_ins_multi_lines : TS_del_multi_lines;
1160 char *single = n > 0 ? TS_ins_line : TS_del_line;
1161 char *scroll = n > 0 ? TS_rev_scroll : TS_fwd_scroll;
1162 struct frame *sf;
1163
1164 register int i = n > 0 ? n : -n;
1165 register char *buf;
1166
1167 if (ins_del_lines_hook && ! FRAME_TERMCAP_P (updating_frame))
1168 {
1169 (*ins_del_lines_hook) (vpos, n);
1170 return;
1171 }
1172
1173 sf = XFRAME (selected_frame);
1174
1175 /* If the lines below the insertion are being pushed
1176 into the end of the window, this is the same as clearing;
1177 and we know the lines are already clear, since the matching
1178 deletion has already been done. So can ignore this. */
1179 /* If the lines below the deletion are blank lines coming
1180 out of the end of the window, don't bother,
1181 as there will be a matching inslines later that will flush them. */
1182 if (TTY_SCROLL_REGION_OK (FRAME_TTY (sf))
1183 && vpos + i >= specified_window)
1184 return;
1185 if (!TTY_MEMORY_BELOW_FRAME (FRAME_TTY (sf))
1186 && vpos + i >= FRAME_LINES (sf))
1187 return;
1188
1189 if (multi)
1190 {
1191 raw_cursor_to (vpos, 0);
1192 background_highlight ();
1193 buf = tparam (multi, 0, 0, i);
1194 OUTPUT (FRAME_TTY (sf), buf);
1195 xfree (buf);
1196 }
1197 else if (single)
1198 {
1199 raw_cursor_to (vpos, 0);
1200 background_highlight ();
1201 while (--i >= 0)
1202 OUTPUT (FRAME_TTY (sf), single);
1203 if (TF_teleray)
1204 curX = 0;
1205 }
1206 else
1207 {
1208 set_scroll_region (vpos, specified_window);
1209 if (n < 0)
1210 raw_cursor_to (specified_window - 1, 0);
1211 else
1212 raw_cursor_to (vpos, 0);
1213 background_highlight ();
1214 while (--i >= 0)
1215 OUTPUTL (FRAME_TTY (sf), scroll, specified_window - vpos);
1216 set_scroll_region (0, specified_window);
1217 }
1218
1219 if (!TTY_SCROLL_REGION_OK (FRAME_TTY (sf))
1220 && TTY_MEMORY_BELOW_FRAME (FRAME_TTY (sf))
1221 && n < 0)
1222 {
1223 cursor_to (FRAME_LINES (sf) + n, 0);
1224 clear_to_end ();
1225 }
1226 }
1227 \f
1228 /* Compute cost of sending "str", in characters,
1229 not counting any line-dependent padding. */
1230
1231 int
1232 string_cost (str)
1233 char *str;
1234 {
1235 cost = 0;
1236 if (str)
1237 tputs (str, 0, evalcost);
1238 return cost;
1239 }
1240
1241 /* Compute cost of sending "str", in characters,
1242 counting any line-dependent padding at one line. */
1243
1244 static int
1245 string_cost_one_line (str)
1246 char *str;
1247 {
1248 cost = 0;
1249 if (str)
1250 tputs (str, 1, evalcost);
1251 return cost;
1252 }
1253
1254 /* Compute per line amount of line-dependent padding,
1255 in tenths of characters. */
1256
1257 int
1258 per_line_cost (str)
1259 register char *str;
1260 {
1261 cost = 0;
1262 if (str)
1263 tputs (str, 0, evalcost);
1264 cost = - cost;
1265 if (str)
1266 tputs (str, 10, evalcost);
1267 return cost;
1268 }
1269
1270 #ifndef old
1271 /* char_ins_del_cost[n] is cost of inserting N characters.
1272 char_ins_del_cost[-n] is cost of deleting N characters.
1273 The length of this vector is based on max_frame_cols. */
1274
1275 int *char_ins_del_vector;
1276
1277 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
1278 #endif
1279
1280 /* ARGSUSED */
1281 static void
1282 calculate_ins_del_char_costs (frame)
1283 FRAME_PTR frame;
1284 {
1285 int ins_startup_cost, del_startup_cost;
1286 int ins_cost_per_char, del_cost_per_char;
1287 register int i;
1288 register int *p;
1289
1290 if (TS_ins_multi_chars)
1291 {
1292 ins_cost_per_char = 0;
1293 ins_startup_cost = string_cost_one_line (TS_ins_multi_chars);
1294 }
1295 else if (TS_ins_char || TS_pad_inserted_char
1296 || (TS_insert_mode && TS_end_insert_mode))
1297 {
1298 ins_startup_cost = (30 * (string_cost (TS_insert_mode)
1299 + string_cost (TS_end_insert_mode))) / 100;
1300 ins_cost_per_char = (string_cost_one_line (TS_ins_char)
1301 + string_cost_one_line (TS_pad_inserted_char));
1302 }
1303 else
1304 {
1305 ins_startup_cost = 9999;
1306 ins_cost_per_char = 0;
1307 }
1308
1309 if (TS_del_multi_chars)
1310 {
1311 del_cost_per_char = 0;
1312 del_startup_cost = string_cost_one_line (TS_del_multi_chars);
1313 }
1314 else if (TS_del_char)
1315 {
1316 del_startup_cost = (string_cost (TS_delete_mode)
1317 + string_cost (TS_end_delete_mode));
1318 if (delete_in_insert_mode)
1319 del_startup_cost /= 2;
1320 del_cost_per_char = string_cost_one_line (TS_del_char);
1321 }
1322 else
1323 {
1324 del_startup_cost = 9999;
1325 del_cost_per_char = 0;
1326 }
1327
1328 /* Delete costs are at negative offsets */
1329 p = &char_ins_del_cost (frame)[0];
1330 for (i = FRAME_COLS (frame); --i >= 0;)
1331 *--p = (del_startup_cost += del_cost_per_char);
1332
1333 /* Doing nothing is free */
1334 p = &char_ins_del_cost (frame)[0];
1335 *p++ = 0;
1336
1337 /* Insert costs are at positive offsets */
1338 for (i = FRAME_COLS (frame); --i >= 0;)
1339 *p++ = (ins_startup_cost += ins_cost_per_char);
1340 }
1341
1342 void
1343 calculate_costs (frame)
1344 FRAME_PTR frame;
1345 {
1346 register char *f = (TS_set_scroll_region
1347 ? TS_set_scroll_region
1348 : TS_set_scroll_region_1);
1349
1350 FRAME_COST_BAUD_RATE (frame) = baud_rate;
1351
1352 if (FRAME_TERMCAP_P (frame))
1353 TTY_SCROLL_REGION_COST (frame->output_data.tty) = string_cost (f);
1354
1355 /* These variables are only used for terminal stuff. They are allocated
1356 once for the terminal frame of X-windows emacs, but not used afterwards.
1357
1358 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1359 X turns off char_ins_del_ok. */
1360
1361 max_frame_lines = max (max_frame_lines, FRAME_LINES (frame));
1362 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame));
1363
1364 costs_set = 1;
1365
1366 if (char_ins_del_vector != 0)
1367 char_ins_del_vector
1368 = (int *) xrealloc (char_ins_del_vector,
1369 (sizeof (int)
1370 + 2 * max_frame_cols * sizeof (int)));
1371 else
1372 char_ins_del_vector
1373 = (int *) xmalloc (sizeof (int)
1374 + 2 * max_frame_cols * sizeof (int));
1375
1376 bzero (char_ins_del_vector, (sizeof (int)
1377 + 2 * max_frame_cols * sizeof (int)));
1378
1379 if (f && (!TS_ins_line && !TS_del_line))
1380 do_line_insertion_deletion_costs (frame,
1381 TS_rev_scroll, TS_ins_multi_lines,
1382 TS_fwd_scroll, TS_del_multi_lines,
1383 f, f, 1);
1384 else
1385 do_line_insertion_deletion_costs (frame,
1386 TS_ins_line, TS_ins_multi_lines,
1387 TS_del_line, TS_del_multi_lines,
1388 0, 0, 1);
1389
1390 calculate_ins_del_char_costs (frame);
1391
1392 /* Don't use TS_repeat if its padding is worse than sending the chars */
1393 if (TS_repeat && per_line_cost (TS_repeat) * baud_rate < 9000)
1394 RPov = string_cost (TS_repeat);
1395 else
1396 RPov = FRAME_COLS (frame) * 2;
1397
1398 cmcostinit (); /* set up cursor motion costs */
1399 }
1400 \f
1401 struct fkey_table {
1402 char *cap, *name;
1403 };
1404
1405 /* Termcap capability names that correspond directly to X keysyms.
1406 Some of these (marked "terminfo") aren't supplied by old-style
1407 (Berkeley) termcap entries. They're listed in X keysym order;
1408 except we put the keypad keys first, so that if they clash with
1409 other keys (as on the IBM PC keyboard) they get overridden.
1410 */
1411
1412 static struct fkey_table keys[] =
1413 {
1414 {"kh", "home"}, /* termcap */
1415 {"kl", "left"}, /* termcap */
1416 {"ku", "up"}, /* termcap */
1417 {"kr", "right"}, /* termcap */
1418 {"kd", "down"}, /* termcap */
1419 {"%8", "prior"}, /* terminfo */
1420 {"%5", "next"}, /* terminfo */
1421 {"@7", "end"}, /* terminfo */
1422 {"@1", "begin"}, /* terminfo */
1423 {"*6", "select"}, /* terminfo */
1424 {"%9", "print"}, /* terminfo */
1425 {"@4", "execute"}, /* terminfo --- actually the `command' key */
1426 /*
1427 * "insert" --- see below
1428 */
1429 {"&8", "undo"}, /* terminfo */
1430 {"%0", "redo"}, /* terminfo */
1431 {"%7", "menu"}, /* terminfo --- actually the `options' key */
1432 {"@0", "find"}, /* terminfo */
1433 {"@2", "cancel"}, /* terminfo */
1434 {"%1", "help"}, /* terminfo */
1435 /*
1436 * "break" goes here, but can't be reliably intercepted with termcap
1437 */
1438 {"&4", "reset"}, /* terminfo --- actually `restart' */
1439 /*
1440 * "system" and "user" --- no termcaps
1441 */
1442 {"kE", "clearline"}, /* terminfo */
1443 {"kA", "insertline"}, /* terminfo */
1444 {"kL", "deleteline"}, /* terminfo */
1445 {"kI", "insertchar"}, /* terminfo */
1446 {"kD", "deletechar"}, /* terminfo */
1447 {"kB", "backtab"}, /* terminfo */
1448 /*
1449 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1450 */
1451 {"@8", "kp-enter"}, /* terminfo */
1452 /*
1453 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1454 * "kp-multiply", "kp-add", "kp-separator",
1455 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1456 * --- no termcaps for any of these.
1457 */
1458 {"K4", "kp-1"}, /* terminfo */
1459 /*
1460 * "kp-2" --- no termcap
1461 */
1462 {"K5", "kp-3"}, /* terminfo */
1463 /*
1464 * "kp-4" --- no termcap
1465 */
1466 {"K2", "kp-5"}, /* terminfo */
1467 /*
1468 * "kp-6" --- no termcap
1469 */
1470 {"K1", "kp-7"}, /* terminfo */
1471 /*
1472 * "kp-8" --- no termcap
1473 */
1474 {"K3", "kp-9"}, /* terminfo */
1475 /*
1476 * "kp-equal" --- no termcap
1477 */
1478 {"k1", "f1"},
1479 {"k2", "f2"},
1480 {"k3", "f3"},
1481 {"k4", "f4"},
1482 {"k5", "f5"},
1483 {"k6", "f6"},
1484 {"k7", "f7"},
1485 {"k8", "f8"},
1486 {"k9", "f9"}
1487 };
1488
1489 static char **term_get_fkeys_arg;
1490 static Lisp_Object term_get_fkeys_1 ();
1491
1492 /* Find the escape codes sent by the function keys for Vfunction_key_map.
1493 This function scans the termcap function key sequence entries, and
1494 adds entries to Vfunction_key_map for each function key it finds. */
1495
1496 void
1497 term_get_fkeys (address)
1498 char **address;
1499 {
1500 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1501 errors during the call. The only errors should be from Fdefine_key
1502 when given a key sequence containing an invalid prefix key. If the
1503 termcap defines function keys which use a prefix that is already bound
1504 to a command by the default bindings, we should silently ignore that
1505 function key specification, rather than giving the user an error and
1506 refusing to run at all on such a terminal. */
1507
1508 extern Lisp_Object Fidentity ();
1509 term_get_fkeys_arg = address;
1510 internal_condition_case (term_get_fkeys_1, Qerror, Fidentity);
1511 }
1512
1513 static Lisp_Object
1514 term_get_fkeys_1 ()
1515 {
1516 int i;
1517
1518 char **address = term_get_fkeys_arg;
1519
1520 /* This can happen if CANNOT_DUMP or with strange options. */
1521 if (!initialized)
1522 Vfunction_key_map = Fmake_sparse_keymap (Qnil);
1523
1524 for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++)
1525 {
1526 char *sequence = tgetstr (keys[i].cap, address);
1527 if (sequence)
1528 Fdefine_key (Vfunction_key_map, build_string (sequence),
1529 Fmake_vector (make_number (1),
1530 intern (keys[i].name)));
1531 }
1532
1533 /* The uses of the "k0" capability are inconsistent; sometimes it
1534 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1535 We will attempt to politely accommodate both systems by testing for
1536 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1537 */
1538 {
1539 char *k_semi = tgetstr ("k;", address);
1540 char *k0 = tgetstr ("k0", address);
1541 char *k0_name = "f10";
1542
1543 if (k_semi)
1544 {
1545 if (k0)
1546 /* Define f0 first, so that f10 takes precedence in case the
1547 key sequences happens to be the same. */
1548 Fdefine_key (Vfunction_key_map, build_string (k0),
1549 Fmake_vector (make_number (1), intern ("f0")));
1550 Fdefine_key (Vfunction_key_map, build_string (k_semi),
1551 Fmake_vector (make_number (1), intern ("f10")));
1552 }
1553 else if (k0)
1554 Fdefine_key (Vfunction_key_map, build_string (k0),
1555 Fmake_vector (make_number (1), intern (k0_name)));
1556 }
1557
1558 /* Set up cookies for numbered function keys above f10. */
1559 {
1560 char fcap[3], fkey[4];
1561
1562 fcap[0] = 'F'; fcap[2] = '\0';
1563 for (i = 11; i < 64; i++)
1564 {
1565 if (i <= 19)
1566 fcap[1] = '1' + i - 11;
1567 else if (i <= 45)
1568 fcap[1] = 'A' + i - 20;
1569 else
1570 fcap[1] = 'a' + i - 46;
1571
1572 {
1573 char *sequence = tgetstr (fcap, address);
1574 if (sequence)
1575 {
1576 sprintf (fkey, "f%d", i);
1577 Fdefine_key (Vfunction_key_map, build_string (sequence),
1578 Fmake_vector (make_number (1),
1579 intern (fkey)));
1580 }
1581 }
1582 }
1583 }
1584
1585 /*
1586 * Various mappings to try and get a better fit.
1587 */
1588 {
1589 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1590 if (!tgetstr (cap1, address)) \
1591 { \
1592 char *sequence = tgetstr (cap2, address); \
1593 if (sequence) \
1594 Fdefine_key (Vfunction_key_map, build_string (sequence), \
1595 Fmake_vector (make_number (1), \
1596 intern (sym))); \
1597 }
1598
1599 /* if there's no key_next keycap, map key_npage to `next' keysym */
1600 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1601 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1602 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1603 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1604 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1605 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1606 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1607
1608 /* IBM has their own non-standard dialect of terminfo.
1609 If the standard name isn't found, try the IBM name. */
1610 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1611 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1612 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1613 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1614 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1615 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1616 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1617 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1618 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1619 #undef CONDITIONAL_REASSIGN
1620 }
1621
1622 return Qnil;
1623 }
1624
1625 \f
1626 /***********************************************************************
1627 Character Display Information
1628 ***********************************************************************/
1629
1630 static void append_glyph P_ ((struct it *));
1631
1632
1633 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1634 terminal frames if IT->glyph_row != NULL. IT->c is the character
1635 for which to produce glyphs; IT->face_id contains the character's
1636 face. Padding glyphs are appended if IT->c has a IT->pixel_width >
1637 1. */
1638
1639 static void
1640 append_glyph (it)
1641 struct it *it;
1642 {
1643 struct glyph *glyph, *end;
1644 int i;
1645
1646 xassert (it->glyph_row);
1647 glyph = (it->glyph_row->glyphs[it->area]
1648 + it->glyph_row->used[it->area]);
1649 end = it->glyph_row->glyphs[1 + it->area];
1650
1651 for (i = 0;
1652 i < it->pixel_width && glyph < end;
1653 ++i)
1654 {
1655 glyph->type = CHAR_GLYPH;
1656 glyph->pixel_width = 1;
1657 glyph->u.ch = it->c;
1658 glyph->face_id = it->face_id;
1659 glyph->padding_p = i > 0;
1660 glyph->charpos = CHARPOS (it->position);
1661 glyph->object = it->object;
1662
1663 ++it->glyph_row->used[it->area];
1664 ++glyph;
1665 }
1666 }
1667
1668
1669 /* Produce glyphs for the display element described by IT. *IT
1670 specifies what we want to produce a glyph for (character, image, ...),
1671 and where in the glyph matrix we currently are (glyph row and hpos).
1672 produce_glyphs fills in output fields of *IT with information such as the
1673 pixel width and height of a character, and maybe output actual glyphs at
1674 the same time if IT->glyph_row is non-null. See the explanation of
1675 struct display_iterator in dispextern.h for an overview.
1676
1677 produce_glyphs also stores the result of glyph width, ascent
1678 etc. computations in *IT.
1679
1680 IT->glyph_row may be null, in which case produce_glyphs does not
1681 actually fill in the glyphs. This is used in the move_* functions
1682 in xdisp.c for text width and height computations.
1683
1684 Callers usually don't call produce_glyphs directly;
1685 instead they use the macro PRODUCE_GLYPHS. */
1686
1687 void
1688 produce_glyphs (it)
1689 struct it *it;
1690 {
1691 /* If a hook is installed, let it do the work. */
1692 xassert (it->what == IT_CHARACTER
1693 || it->what == IT_COMPOSITION
1694 || it->what == IT_IMAGE
1695 || it->what == IT_STRETCH);
1696
1697 /* Nothing but characters are supported on terminal frames. For a
1698 composition sequence, it->c is the first character of the
1699 sequence. */
1700 xassert (it->what == IT_CHARACTER
1701 || it->what == IT_COMPOSITION);
1702
1703 if (it->c >= 040 && it->c < 0177)
1704 {
1705 it->pixel_width = it->nglyphs = 1;
1706 if (it->glyph_row)
1707 append_glyph (it);
1708 }
1709 else if (it->c == '\n')
1710 it->pixel_width = it->nglyphs = 0;
1711 else if (it->c == '\t')
1712 {
1713 int absolute_x = (it->current_x
1714 + it->continuation_lines_width);
1715 int next_tab_x
1716 = (((1 + absolute_x + it->tab_width - 1)
1717 / it->tab_width)
1718 * it->tab_width);
1719 int nspaces;
1720
1721 /* If part of the TAB has been displayed on the previous line
1722 which is continued now, continuation_lines_width will have
1723 been incremented already by the part that fitted on the
1724 continued line. So, we will get the right number of spaces
1725 here. */
1726 nspaces = next_tab_x - absolute_x;
1727
1728 if (it->glyph_row)
1729 {
1730 int n = nspaces;
1731
1732 it->c = ' ';
1733 it->pixel_width = it->len = 1;
1734
1735 while (n--)
1736 append_glyph (it);
1737
1738 it->c = '\t';
1739 }
1740
1741 it->pixel_width = nspaces;
1742 it->nglyphs = nspaces;
1743 }
1744 else if (SINGLE_BYTE_CHAR_P (it->c))
1745 {
1746 /* Coming here means that it->c is from display table, thus we
1747 must send the code as is to the terminal. Although there's
1748 no way to know how many columns it occupies on a screen, it
1749 is a good assumption that a single byte code has 1-column
1750 width. */
1751 it->pixel_width = it->nglyphs = 1;
1752 if (it->glyph_row)
1753 append_glyph (it);
1754 }
1755 else
1756 {
1757 /* A multi-byte character. The display width is fixed for all
1758 characters of the set. Some of the glyphs may have to be
1759 ignored because they are already displayed in a continued
1760 line. */
1761 int charset = CHAR_CHARSET (it->c);
1762
1763 it->pixel_width = CHARSET_WIDTH (charset);
1764 it->nglyphs = it->pixel_width;
1765
1766 if (it->glyph_row)
1767 append_glyph (it);
1768 }
1769
1770 /* Advance current_x by the pixel width as a convenience for
1771 the caller. */
1772 if (it->area == TEXT_AREA)
1773 it->current_x += it->pixel_width;
1774 it->ascent = it->max_ascent = it->phys_ascent = it->max_phys_ascent = 0;
1775 it->descent = it->max_descent = it->phys_descent = it->max_phys_descent = 1;
1776 }
1777
1778
1779 /* Get information about special display element WHAT in an
1780 environment described by IT. WHAT is one of IT_TRUNCATION or
1781 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
1782 non-null glyph_row member. This function ensures that fields like
1783 face_id, c, len of IT are left untouched. */
1784
1785 void
1786 produce_special_glyphs (it, what)
1787 struct it *it;
1788 enum display_element_type what;
1789 {
1790 struct it temp_it;
1791
1792 temp_it = *it;
1793 temp_it.dp = NULL;
1794 temp_it.what = IT_CHARACTER;
1795 temp_it.len = 1;
1796 temp_it.object = make_number (0);
1797 bzero (&temp_it.current, sizeof temp_it.current);
1798
1799 if (what == IT_CONTINUATION)
1800 {
1801 /* Continuation glyph. */
1802 if (it->dp
1803 && INTEGERP (DISP_CONTINUE_GLYPH (it->dp))
1804 && GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (it->dp))))
1805 {
1806 temp_it.c = FAST_GLYPH_CHAR (XINT (DISP_CONTINUE_GLYPH (it->dp)));
1807 temp_it.len = CHAR_BYTES (temp_it.c);
1808 }
1809 else
1810 temp_it.c = '\\';
1811
1812 produce_glyphs (&temp_it);
1813 it->pixel_width = temp_it.pixel_width;
1814 it->nglyphs = temp_it.pixel_width;
1815 }
1816 else if (what == IT_TRUNCATION)
1817 {
1818 /* Truncation glyph. */
1819 if (it->dp
1820 && INTEGERP (DISP_TRUNC_GLYPH (it->dp))
1821 && GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (it->dp))))
1822 {
1823 temp_it.c = FAST_GLYPH_CHAR (XINT (DISP_TRUNC_GLYPH (it->dp)));
1824 temp_it.len = CHAR_BYTES (temp_it.c);
1825 }
1826 else
1827 temp_it.c = '$';
1828
1829 produce_glyphs (&temp_it);
1830 it->pixel_width = temp_it.pixel_width;
1831 it->nglyphs = temp_it.pixel_width;
1832 }
1833 else
1834 abort ();
1835 }
1836
1837
1838 \f
1839 /***********************************************************************
1840 Faces
1841 ***********************************************************************/
1842
1843 /* Value is non-zero if attribute ATTR may be used. ATTR should be
1844 one of the enumerators from enum no_color_bit, or a bit set built
1845 from them. Some display attributes may not be used together with
1846 color; the termcap capability `NC' specifies which ones. */
1847
1848 #define MAY_USE_WITH_COLORS_P(ATTR) \
1849 (TN_max_colors > 0 \
1850 ? (TN_no_color_video & (ATTR)) == 0 \
1851 : 1)
1852
1853 /* Turn appearances of face FACE_ID on tty frame F on. */
1854
1855 static void
1856 turn_on_face (f, face_id)
1857 struct frame *f;
1858 int face_id;
1859 {
1860 struct face *face = FACE_FROM_ID (f, face_id);
1861 long fg = face->foreground;
1862 long bg = face->background;
1863
1864 /* Do this first because TS_end_standout_mode may be the same
1865 as TS_exit_attribute_mode, which turns all appearances off. */
1866 if (MAY_USE_WITH_COLORS_P (NC_REVERSE))
1867 {
1868 if (TN_max_colors > 0)
1869 {
1870 if (fg >= 0 && bg >= 0)
1871 {
1872 /* If the terminal supports colors, we can set them
1873 below without using reverse video. The face's fg
1874 and bg colors are set as they should appear on
1875 the screen, i.e. they take the inverse-video'ness
1876 of the face already into account. */
1877 }
1878 else if (inverse_video)
1879 {
1880 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1881 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1882 toggle_highlight ();
1883 }
1884 else
1885 {
1886 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1887 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1888 toggle_highlight ();
1889 }
1890 }
1891 else
1892 {
1893 /* If we can't display colors, use reverse video
1894 if the face specifies that. */
1895 if (inverse_video)
1896 {
1897 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1898 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1899 toggle_highlight ();
1900 }
1901 else
1902 {
1903 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1904 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1905 toggle_highlight ();
1906 }
1907 }
1908 }
1909
1910 if (face->tty_bold_p)
1911 {
1912 if (MAY_USE_WITH_COLORS_P (NC_BOLD))
1913 OUTPUT1_IF (FRAME_TTY (f), TS_enter_bold_mode);
1914 }
1915 else if (face->tty_dim_p)
1916 if (MAY_USE_WITH_COLORS_P (NC_DIM))
1917 OUTPUT1_IF (FRAME_TTY (f), TS_enter_dim_mode);
1918
1919 /* Alternate charset and blinking not yet used. */
1920 if (face->tty_alt_charset_p
1921 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET))
1922 OUTPUT1_IF (FRAME_TTY (f), TS_enter_alt_charset_mode);
1923
1924 if (face->tty_blinking_p
1925 && MAY_USE_WITH_COLORS_P (NC_BLINK))
1926 OUTPUT1_IF (FRAME_TTY (f), TS_enter_blink_mode);
1927
1928 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (NC_UNDERLINE))
1929 OUTPUT1_IF (FRAME_TTY (f), TS_enter_underline_mode);
1930
1931 if (TN_max_colors > 0)
1932 {
1933 char *p;
1934
1935 if (fg >= 0 && TS_set_foreground)
1936 {
1937 p = tparam (TS_set_foreground, NULL, 0, (int) fg);
1938 OUTPUT (FRAME_TTY (f), p);
1939 xfree (p);
1940 }
1941
1942 if (bg >= 0 && TS_set_background)
1943 {
1944 p = tparam (TS_set_background, NULL, 0, (int) bg);
1945 OUTPUT (FRAME_TTY (f), p);
1946 xfree (p);
1947 }
1948 }
1949 }
1950
1951
1952 /* Turn off appearances of face FACE_ID on tty frame F. */
1953
1954 static void
1955 turn_off_face (f, face_id)
1956 struct frame *f;
1957 int face_id;
1958 {
1959 struct face *face = FACE_FROM_ID (f, face_id);
1960
1961 xassert (face != NULL);
1962
1963 if (TS_exit_attribute_mode)
1964 {
1965 /* Capability "me" will turn off appearance modes double-bright,
1966 half-bright, reverse-video, standout, underline. It may or
1967 may not turn off alt-char-mode. */
1968 if (face->tty_bold_p
1969 || face->tty_dim_p
1970 || face->tty_reverse_p
1971 || face->tty_alt_charset_p
1972 || face->tty_blinking_p
1973 || face->tty_underline_p)
1974 {
1975 OUTPUT1_IF (FRAME_TTY (f), TS_exit_attribute_mode);
1976 if (strcmp (TS_exit_attribute_mode, TS_end_standout_mode) == 0)
1977 standout_mode = 0;
1978 }
1979
1980 if (face->tty_alt_charset_p)
1981 OUTPUT_IF (FRAME_TTY (f), TS_exit_alt_charset_mode);
1982 }
1983 else
1984 {
1985 /* If we don't have "me" we can only have those appearances
1986 that have exit sequences defined. */
1987 if (face->tty_alt_charset_p)
1988 OUTPUT_IF (FRAME_TTY (f), TS_exit_alt_charset_mode);
1989
1990 if (face->tty_underline_p)
1991 OUTPUT_IF (FRAME_TTY (f), TS_exit_underline_mode);
1992 }
1993
1994 /* Switch back to default colors. */
1995 if (TN_max_colors > 0
1996 && ((face->foreground != FACE_TTY_DEFAULT_COLOR
1997 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR)
1998 || (face->background != FACE_TTY_DEFAULT_COLOR
1999 && face->background != FACE_TTY_DEFAULT_BG_COLOR)))
2000 OUTPUT1_IF (FRAME_TTY (f), TS_orig_pair);
2001 }
2002
2003
2004 /* Return non-zero if the terminal on frame F supports all of the
2005 capabilities in CAPS simultaneously, with foreground and background
2006 colors FG and BG. */
2007
2008 int
2009 tty_capable_p (f, caps, fg, bg)
2010 struct frame *f;
2011 unsigned caps;
2012 unsigned long fg, bg;
2013 {
2014 #define TTY_CAPABLE_P_TRY(cap, TS, NC_bit) \
2015 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(NC_bit))) \
2016 return 0;
2017
2018 TTY_CAPABLE_P_TRY (TTY_CAP_INVERSE, TS_standout_mode, NC_REVERSE);
2019 TTY_CAPABLE_P_TRY (TTY_CAP_UNDERLINE, TS_enter_underline_mode, NC_UNDERLINE);
2020 TTY_CAPABLE_P_TRY (TTY_CAP_BOLD, TS_enter_bold_mode, NC_BOLD);
2021 TTY_CAPABLE_P_TRY (TTY_CAP_DIM, TS_enter_dim_mode, NC_DIM);
2022 TTY_CAPABLE_P_TRY (TTY_CAP_BLINK, TS_enter_blink_mode, NC_BLINK);
2023 TTY_CAPABLE_P_TRY (TTY_CAP_ALT_CHARSET, TS_enter_alt_charset_mode, NC_ALT_CHARSET);
2024
2025 /* We can do it! */
2026 return 1;
2027 }
2028
2029
2030 /* Return non-zero if the terminal is capable to display colors. */
2031
2032 DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
2033 0, 1, 0,
2034 doc: /* Return non-nil if TTY can display colors on DISPLAY. */)
2035 (display)
2036 Lisp_Object display;
2037 {
2038 return TN_max_colors > 0 ? Qt : Qnil;
2039 }
2040
2041 /* Return the number of supported colors. */
2042 DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
2043 Stty_display_color_cells, 0, 1, 0,
2044 doc: /* Return the number of colors supported by TTY on DISPLAY. */)
2045 (display)
2046 Lisp_Object display;
2047 {
2048 return make_number (TN_max_colors);
2049 }
2050
2051 #ifndef WINDOWSNT
2052
2053 /* Save or restore the default color-related capabilities of this
2054 terminal. */
2055 static void
2056 tty_default_color_capabilities (save)
2057 int save;
2058 {
2059 static char
2060 *default_orig_pair, *default_set_foreground, *default_set_background;
2061 static int default_max_colors, default_max_pairs, default_no_color_video;
2062
2063 if (save)
2064 {
2065 if (default_orig_pair)
2066 xfree (default_orig_pair);
2067 default_orig_pair = TS_orig_pair ? xstrdup (TS_orig_pair) : NULL;
2068
2069 if (default_set_foreground)
2070 xfree (default_set_foreground);
2071 default_set_foreground = TS_set_foreground ? xstrdup (TS_set_foreground)
2072 : NULL;
2073
2074 if (default_set_background)
2075 xfree (default_set_background);
2076 default_set_background = TS_set_background ? xstrdup (TS_set_background)
2077 : NULL;
2078
2079 default_max_colors = TN_max_colors;
2080 default_max_pairs = TN_max_pairs;
2081 default_no_color_video = TN_no_color_video;
2082 }
2083 else
2084 {
2085 TS_orig_pair = default_orig_pair;
2086 TS_set_foreground = default_set_foreground;
2087 TS_set_background = default_set_background;
2088 TN_max_colors = default_max_colors;
2089 TN_max_pairs = default_max_pairs;
2090 TN_no_color_video = default_no_color_video;
2091 }
2092 }
2093
2094 /* Setup one of the standard tty color schemes according to MODE.
2095 MODE's value is generally the number of colors which we want to
2096 support; zero means set up for the default capabilities, the ones
2097 we saw at term_init time; -1 means turn off color support. */
2098 void
2099 tty_setup_colors (mode)
2100 int mode;
2101 {
2102 /* Canonicalize all negative values of MODE. */
2103 if (mode < -1)
2104 mode = -1;
2105
2106 switch (mode)
2107 {
2108 case -1: /* no colors at all */
2109 TN_max_colors = 0;
2110 TN_max_pairs = 0;
2111 TN_no_color_video = 0;
2112 TS_set_foreground = TS_set_background = TS_orig_pair = NULL;
2113 break;
2114 case 0: /* default colors, if any */
2115 default:
2116 tty_default_color_capabilities (0);
2117 break;
2118 case 8: /* 8 standard ANSI colors */
2119 TS_orig_pair = "\033[0m";
2120 #ifdef TERMINFO
2121 TS_set_foreground = "\033[3%p1%dm";
2122 TS_set_background = "\033[4%p1%dm";
2123 #else
2124 TS_set_foreground = "\033[3%dm";
2125 TS_set_background = "\033[4%dm";
2126 #endif
2127 TN_max_colors = 8;
2128 TN_max_pairs = 64;
2129 TN_no_color_video = 0;
2130 break;
2131 }
2132 }
2133
2134 void
2135 set_tty_color_mode (f, val)
2136 struct frame *f;
2137 Lisp_Object val;
2138 {
2139 Lisp_Object color_mode_spec, current_mode_spec;
2140 Lisp_Object color_mode, current_mode;
2141 int mode, old_mode;
2142 extern Lisp_Object Qtty_color_mode;
2143 Lisp_Object tty_color_mode_alist;
2144
2145 tty_color_mode_alist = Fintern_soft (build_string ("tty-color-mode-alist"),
2146 Qnil);
2147
2148 if (INTEGERP (val))
2149 color_mode = val;
2150 else
2151 {
2152 if (NILP (tty_color_mode_alist))
2153 color_mode_spec = Qnil;
2154 else
2155 color_mode_spec = Fassq (val, XSYMBOL (tty_color_mode_alist)->value);
2156
2157 if (CONSP (color_mode_spec))
2158 color_mode = XCDR (color_mode_spec);
2159 else
2160 color_mode = Qnil;
2161 }
2162
2163 current_mode_spec = assq_no_quit (Qtty_color_mode, f->param_alist);
2164
2165 if (CONSP (current_mode_spec))
2166 current_mode = XCDR (current_mode_spec);
2167 else
2168 current_mode = Qnil;
2169 if (INTEGERP (color_mode))
2170 mode = XINT (color_mode);
2171 else
2172 mode = 0; /* meaning default */
2173 if (INTEGERP (current_mode))
2174 old_mode = XINT (current_mode);
2175 else
2176 old_mode = 0;
2177
2178 if (mode != old_mode)
2179 {
2180 tty_setup_colors (mode);
2181 /* This recomputes all the faces given the new color
2182 definitions. */
2183 call0 (intern ("tty-set-up-initial-frame-faces"));
2184 redraw_frame (f);
2185 }
2186 }
2187
2188 #endif /* !WINDOWSNT */
2189
2190 \f
2191
2192 struct tty_output *
2193 get_named_tty (name)
2194 char *name;
2195 {
2196 struct tty_output *tty = tty_list;
2197
2198 while (tty) {
2199 if ((tty->name == 0 && name == 0)
2200 || (name && tty->name && !strcmp (tty->name, name)))
2201 return tty;
2202 tty = tty->next;
2203 };
2204
2205 return 0;
2206 }
2207
2208 \f
2209 /***********************************************************************
2210 Initialization
2211 ***********************************************************************/
2212
2213 struct tty_output *
2214 term_dummy_init (void)
2215 {
2216 if (initialized || tty_list)
2217 error ("tty already initialized");
2218
2219 tty_list = xmalloc (sizeof (struct tty_output));
2220 bzero (tty_list, sizeof (struct tty_output));
2221 TTY_NAME (tty_list) = 0;
2222 TTY_INPUT (tty_list) = stdin;
2223 TTY_OUTPUT (tty_list) = stdout;
2224 return tty_list;
2225 }
2226
2227
2228 struct tty_output *
2229 term_init (name, terminal_type)
2230 char *name;
2231 char *terminal_type;
2232 {
2233 char *area;
2234 char **address = &area;
2235 char *buffer = NULL;
2236 int buffer_size = 4096;
2237 register char *p;
2238 int status;
2239 struct frame *sf = XFRAME (selected_frame);
2240
2241 struct tty_output *tty;
2242
2243 tty = get_named_tty (name);
2244 if (tty)
2245 {
2246 /* Return the previously initialized terminal, except if it is the dummy
2247 terminal created for the initial frame. */
2248 if (tty->type)
2249 return tty;
2250 }
2251 else
2252 {
2253 if (!terminal_type)
2254 error ("Unknown terminal type");
2255
2256 tty = (struct tty_output *) xmalloc (sizeof (struct tty_output));
2257 bzero (tty, sizeof (struct tty_output));
2258 tty->next = tty_list;
2259 tty_list = tty;
2260 }
2261
2262 if (name)
2263 {
2264 int fd;
2265 FILE *f;
2266 fd = emacs_open (name, O_RDWR, 0);
2267 if (fd < 0)
2268 {
2269 tty_list = tty->next;
2270 xfree (tty);
2271 error ("could not open file: %s", name);
2272 }
2273 f = fdopen (fd, "w+");
2274 TTY_NAME (tty) = xstrdup (name);
2275 TTY_INPUT (tty) = f;
2276 TTY_OUTPUT (tty) = f;
2277 }
2278 else
2279 {
2280 TTY_NAME (tty) = 0;
2281 TTY_INPUT (tty) = stdin;
2282 TTY_OUTPUT (tty) = stdout;
2283 }
2284
2285 init_sys_modes (tty);
2286
2287 #ifdef WINDOWSNT
2288 initialize_w32_display ();
2289
2290 Wcm_clear ();
2291
2292 area = (char *) xmalloc (2044);
2293
2294 FrameRows = FRAME_LINES (sf);
2295 FrameCols = FRAME_COLS (sf);
2296 specified_window = FRAME_LINES (sf);
2297
2298 delete_in_insert_mode = 1;
2299
2300 UseTabs = 0;
2301 TTY_SCROLL_REGION_OK (tty) = 0;
2302
2303 /* Seems to insert lines when it's not supposed to, messing
2304 up the display. In doing a trace, it didn't seem to be
2305 called much, so I don't think we're losing anything by
2306 turning it off. */
2307 TTY_LINE_INS_DEL_OK (tty) = 0;
2308
2309 TTY_CHAR_INS_DEL_OK (tty) = 1;
2310
2311 baud_rate = 19200;
2312
2313 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0;
2314 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none;
2315 TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */
2316
2317 return tty;
2318 #else /* not WINDOWSNT */
2319
2320 Wcm_clear ();
2321
2322 TTY_TYPE (tty) = xstrdup (terminal_type);
2323
2324 buffer = (char *) xmalloc (buffer_size);
2325 status = tgetent (buffer, terminal_type);
2326 if (status < 0)
2327 {
2328 #ifdef TERMINFO
2329 fatal ("Cannot open terminfo database file");
2330 #else
2331 fatal ("Cannot open termcap database file");
2332 #endif
2333 }
2334 if (status == 0)
2335 {
2336 #ifdef TERMINFO
2337 fatal ("Terminal type %s is not defined.\n\
2338 If that is not the actual type of terminal you have,\n\
2339 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2340 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2341 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2342 terminal_type);
2343 #else
2344 fatal ("Terminal type %s is not defined.\n\
2345 If that is not the actual type of terminal you have,\n\
2346 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2347 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2348 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2349 terminal_type);
2350 #endif
2351 }
2352
2353 #ifndef TERMINFO
2354 if (strlen (buffer) >= buffer_size)
2355 abort ();
2356 buffer_size = strlen (buffer);
2357 #endif
2358 area = (char *) xmalloc (buffer_size);
2359
2360 TS_ins_line = tgetstr ("al", address);
2361 TS_ins_multi_lines = tgetstr ("AL", address);
2362 TS_bell = tgetstr ("bl", address);
2363 BackTab = tgetstr ("bt", address);
2364 TS_clr_to_bottom = tgetstr ("cd", address);
2365 TS_clr_line = tgetstr ("ce", address);
2366 TS_clr_frame = tgetstr ("cl", address);
2367 ColPosition = NULL; /* tgetstr ("ch", address); */
2368 AbsPosition = tgetstr ("cm", address);
2369 CR = tgetstr ("cr", address);
2370 TS_set_scroll_region = tgetstr ("cs", address);
2371 TS_set_scroll_region_1 = tgetstr ("cS", address);
2372 RowPosition = tgetstr ("cv", address);
2373 TS_del_char = tgetstr ("dc", address);
2374 TS_del_multi_chars = tgetstr ("DC", address);
2375 TS_del_line = tgetstr ("dl", address);
2376 TS_del_multi_lines = tgetstr ("DL", address);
2377 TS_delete_mode = tgetstr ("dm", address);
2378 TS_end_delete_mode = tgetstr ("ed", address);
2379 TS_end_insert_mode = tgetstr ("ei", address);
2380 Home = tgetstr ("ho", address);
2381 TS_ins_char = tgetstr ("ic", address);
2382 TS_ins_multi_chars = tgetstr ("IC", address);
2383 TS_insert_mode = tgetstr ("im", address);
2384 TS_pad_inserted_char = tgetstr ("ip", address);
2385 TS_end_keypad_mode = tgetstr ("ke", address);
2386 TS_keypad_mode = tgetstr ("ks", address);
2387 LastLine = tgetstr ("ll", address);
2388 Right = tgetstr ("nd", address);
2389 Down = tgetstr ("do", address);
2390 if (!Down)
2391 Down = tgetstr ("nl", address); /* Obsolete name for "do" */
2392 #ifdef VMS
2393 /* VMS puts a carriage return before each linefeed,
2394 so it is not safe to use linefeeds. */
2395 if (Down && Down[0] == '\n' && Down[1] == '\0')
2396 Down = 0;
2397 #endif /* VMS */
2398 if (tgetflag ("bs"))
2399 Left = "\b"; /* can't possibly be longer! */
2400 else /* (Actually, "bs" is obsolete...) */
2401 Left = tgetstr ("le", address);
2402 if (!Left)
2403 Left = tgetstr ("bc", address); /* Obsolete name for "le" */
2404 TS_pad_char = tgetstr ("pc", address);
2405 TS_repeat = tgetstr ("rp", address);
2406 TS_end_standout_mode = tgetstr ("se", address);
2407 TS_fwd_scroll = tgetstr ("sf", address);
2408 TS_standout_mode = tgetstr ("so", address);
2409 TS_rev_scroll = tgetstr ("sr", address);
2410 Wcm.cm_tab = tgetstr ("ta", address);
2411 TS_end_termcap_modes = tgetstr ("te", address);
2412 TS_termcap_modes = tgetstr ("ti", address);
2413 Up = tgetstr ("up", address);
2414 TS_visible_bell = tgetstr ("vb", address);
2415 TS_cursor_normal = tgetstr ("ve", address);
2416 TS_cursor_visible = tgetstr ("vs", address);
2417 TS_cursor_invisible = tgetstr ("vi", address);
2418 TS_set_window = tgetstr ("wi", address);
2419
2420 TS_enter_underline_mode = tgetstr ("us", address);
2421 TS_exit_underline_mode = tgetstr ("ue", address);
2422 TS_enter_bold_mode = tgetstr ("md", address);
2423 TS_enter_dim_mode = tgetstr ("mh", address);
2424 TS_enter_blink_mode = tgetstr ("mb", address);
2425 TS_enter_reverse_mode = tgetstr ("mr", address);
2426 TS_enter_alt_charset_mode = tgetstr ("as", address);
2427 TS_exit_alt_charset_mode = tgetstr ("ae", address);
2428 TS_exit_attribute_mode = tgetstr ("me", address);
2429
2430 MultiUp = tgetstr ("UP", address);
2431 MultiDown = tgetstr ("DO", address);
2432 MultiLeft = tgetstr ("LE", address);
2433 MultiRight = tgetstr ("RI", address);
2434
2435 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
2436 color because we can't switch back to the default foreground and
2437 background. */
2438 TS_orig_pair = tgetstr ("op", address);
2439 if (TS_orig_pair)
2440 {
2441 TS_set_foreground = tgetstr ("AF", address);
2442 TS_set_background = tgetstr ("AB", address);
2443 if (!TS_set_foreground)
2444 {
2445 /* SVr4. */
2446 TS_set_foreground = tgetstr ("Sf", address);
2447 TS_set_background = tgetstr ("Sb", address);
2448 }
2449
2450 TN_max_colors = tgetnum ("Co");
2451 TN_max_pairs = tgetnum ("pa");
2452
2453 TN_no_color_video = tgetnum ("NC");
2454 if (TN_no_color_video == -1)
2455 TN_no_color_video = 0;
2456 }
2457
2458 tty_default_color_capabilities (1);
2459
2460 MagicWrap = tgetflag ("xn");
2461 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2462 the former flag imply the latter. */
2463 AutoWrap = MagicWrap || tgetflag ("am");
2464 TTY_MEMORY_BELOW_FRAME (tty) = tgetflag ("db");
2465 TF_hazeltine = tgetflag ("hz");
2466 TTY_MUST_WRITE_SPACES (tty) = tgetflag ("in");
2467 meta_key = tgetflag ("km") || tgetflag ("MT");
2468 TF_insmode_motion = tgetflag ("mi");
2469 TF_standout_motion = tgetflag ("ms");
2470 TF_underscore = tgetflag ("ul");
2471 TF_teleray = tgetflag ("xt");
2472
2473 term_get_fkeys (address);
2474
2475 /* Get frame size from system, or else from termcap. */
2476 {
2477 int height, width;
2478 get_frame_size (&width, &height);
2479 FRAME_COLS (sf) = width;
2480 FRAME_LINES (sf) = height;
2481 }
2482
2483 if (FRAME_COLS (sf) <= 0)
2484 SET_FRAME_COLS (sf, tgetnum ("co"));
2485 else
2486 /* Keep width and external_width consistent */
2487 SET_FRAME_COLS (sf, FRAME_COLS (sf));
2488 if (FRAME_LINES (sf) <= 0)
2489 FRAME_LINES (sf) = tgetnum ("li");
2490
2491 if (FRAME_LINES (sf) < 3 || FRAME_COLS (sf) < 3)
2492 fatal ("Screen size %dx%d is too small",
2493 FRAME_LINES (sf), FRAME_COLS (sf));
2494
2495 #if 0 /* This is not used anywhere. */
2496 TTY_MIN_PADDING_SPEED (tty) = tgetnum ("pb");
2497 #endif
2498
2499 TabWidth = tgetnum ("tw");
2500
2501 #ifdef VMS
2502 /* These capabilities commonly use ^J.
2503 I don't know why, but sending them on VMS does not work;
2504 it causes following spaces to be lost, sometimes.
2505 For now, the simplest fix is to avoid using these capabilities ever. */
2506 if (Down && Down[0] == '\n')
2507 Down = 0;
2508 #endif /* VMS */
2509
2510 if (!TS_bell)
2511 TS_bell = "\07";
2512
2513 if (!TS_fwd_scroll)
2514 TS_fwd_scroll = Down;
2515
2516 PC = TS_pad_char ? *TS_pad_char : 0;
2517
2518 if (TabWidth < 0)
2519 TabWidth = 8;
2520
2521 /* Turned off since /etc/termcap seems to have :ta= for most terminals
2522 and newer termcap doc does not seem to say there is a default.
2523 if (!Wcm.cm_tab)
2524 Wcm.cm_tab = "\t";
2525 */
2526
2527 /* We don't support standout modes that use `magic cookies', so
2528 turn off any that do. */
2529 if (TS_standout_mode && tgetnum ("sg") >= 0)
2530 {
2531 TS_standout_mode = 0;
2532 TS_end_standout_mode = 0;
2533 }
2534 if (TS_enter_underline_mode && tgetnum ("ug") >= 0)
2535 {
2536 TS_enter_underline_mode = 0;
2537 TS_exit_underline_mode = 0;
2538 }
2539
2540 /* If there's no standout mode, try to use underlining instead. */
2541 if (TS_standout_mode == 0)
2542 {
2543 TS_standout_mode = TS_enter_underline_mode;
2544 TS_end_standout_mode = TS_exit_underline_mode;
2545 }
2546
2547 /* If no `se' string, try using a `me' string instead.
2548 If that fails, we can't use standout mode at all. */
2549 if (TS_end_standout_mode == 0)
2550 {
2551 char *s = tgetstr ("me", address);
2552 if (s != 0)
2553 TS_end_standout_mode = s;
2554 else
2555 TS_standout_mode = 0;
2556 }
2557
2558 if (TF_teleray)
2559 {
2560 Wcm.cm_tab = 0;
2561 /* We can't support standout mode, because it uses magic cookies. */
2562 TS_standout_mode = 0;
2563 /* But that means we cannot rely on ^M to go to column zero! */
2564 CR = 0;
2565 /* LF can't be trusted either -- can alter hpos */
2566 /* if move at column 0 thru a line with TS_standout_mode */
2567 Down = 0;
2568 }
2569
2570 /* Special handling for certain terminal types known to need it */
2571
2572 if (!strcmp (terminal_type, "supdup"))
2573 {
2574 TTY_MEMORY_BELOW_FRAME (tty) = 1;
2575 Wcm.cm_losewrap = 1;
2576 }
2577 if (!strncmp (terminal_type, "c10", 3)
2578 || !strcmp (terminal_type, "perq"))
2579 {
2580 /* Supply a makeshift :wi string.
2581 This string is not valid in general since it works only
2582 for windows starting at the upper left corner;
2583 but that is all Emacs uses.
2584
2585 This string works only if the frame is using
2586 the top of the video memory, because addressing is memory-relative.
2587 So first check the :ti string to see if that is true.
2588
2589 It would be simpler if the :wi string could go in the termcap
2590 entry, but it can't because it is not fully valid.
2591 If it were in the termcap entry, it would confuse other programs. */
2592 if (!TS_set_window)
2593 {
2594 p = TS_termcap_modes;
2595 while (*p && strcmp (p, "\033v "))
2596 p++;
2597 if (*p)
2598 TS_set_window = "\033v%C %C %C %C ";
2599 }
2600 /* Termcap entry often fails to have :in: flag */
2601 TTY_MUST_WRITE_SPACES (tty) = 1;
2602 /* :ti string typically fails to have \E^G! in it */
2603 /* This limits scope of insert-char to one line. */
2604 strcpy (area, TS_termcap_modes);
2605 strcat (area, "\033\007!");
2606 TS_termcap_modes = area;
2607 area += strlen (area) + 1;
2608 p = AbsPosition;
2609 /* Change all %+ parameters to %C, to handle
2610 values above 96 correctly for the C100. */
2611 while (*p)
2612 {
2613 if (p[0] == '%' && p[1] == '+')
2614 p[1] = 'C';
2615 p++;
2616 }
2617 }
2618
2619 FrameRows = FRAME_LINES (sf);
2620 FrameCols = FRAME_COLS (sf);
2621 specified_window = FRAME_LINES (sf);
2622
2623 if (Wcm_init () == -1) /* can't do cursor motion */
2624 #ifdef VMS
2625 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2626 It lacks the ability to position the cursor.\n\
2627 If that is not the actual type of terminal you have, use either the\n\
2628 DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
2629 or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2630 terminal_type);
2631 #else /* not VMS */
2632 # ifdef TERMINFO
2633 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2634 It lacks the ability to position the cursor.\n\
2635 If that is not the actual type of terminal you have,\n\
2636 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2637 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2638 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2639 terminal_type);
2640 # else /* TERMCAP */
2641 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2642 It lacks the ability to position the cursor.\n\
2643 If that is not the actual type of terminal you have,\n\
2644 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2645 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2646 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2647 terminal_type);
2648 # endif /* TERMINFO */
2649 #endif /*VMS */
2650 if (FRAME_LINES (sf) <= 0
2651 || FRAME_COLS (sf) <= 0)
2652 fatal ("The frame size has not been specified");
2653
2654 delete_in_insert_mode
2655 = TS_delete_mode && TS_insert_mode
2656 && !strcmp (TS_delete_mode, TS_insert_mode);
2657
2658 se_is_so = (TS_standout_mode
2659 && TS_end_standout_mode
2660 && !strcmp (TS_standout_mode, TS_end_standout_mode));
2661
2662 UseTabs = tabs_safe_p () && TabWidth == 8;
2663
2664 TTY_SCROLL_REGION_OK (tty)
2665 = (Wcm.cm_abs
2666 && (TS_set_window || TS_set_scroll_region || TS_set_scroll_region_1));
2667
2668 TTY_LINE_INS_DEL_OK (tty)
2669 = (((TS_ins_line || TS_ins_multi_lines)
2670 && (TS_del_line || TS_del_multi_lines))
2671 || (TTY_SCROLL_REGION_OK (tty)
2672 && TS_fwd_scroll && TS_rev_scroll));
2673
2674 TTY_CHAR_INS_DEL_OK (tty)
2675 = ((TS_ins_char || TS_insert_mode
2676 || TS_pad_inserted_char || TS_ins_multi_chars)
2677 && (TS_del_char || TS_del_multi_chars));
2678
2679 TTY_FAST_CLEAR_END_OF_LINE (tty) = TS_clr_line != 0;
2680
2681 init_baud_rate ();
2682 if (read_socket_hook) /* Baudrate is somewhat
2683 meaningless in this case */
2684 baud_rate = 9600;
2685
2686 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0;
2687 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none;
2688 #endif /* WINDOWSNT */
2689
2690 xfree (buffer);
2691
2692 return tty;
2693 }
2694
2695 /* VARARGS 1 */
2696 void
2697 fatal (str, arg1, arg2)
2698 char *str, *arg1, *arg2;
2699 {
2700 fprintf (stderr, "emacs: ");
2701 fprintf (stderr, str, arg1, arg2);
2702 fprintf (stderr, "\n");
2703 fflush (stderr);
2704 exit (1);
2705 }
2706
2707 void
2708 syms_of_term ()
2709 {
2710 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo,
2711 doc: /* Non-nil means the system uses terminfo rather than termcap.
2712 This variable can be used by terminal emulator packages. */);
2713 #ifdef TERMINFO
2714 system_uses_terminfo = 1;
2715 #else
2716 system_uses_terminfo = 0;
2717 #endif
2718
2719 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function,
2720 doc: /* Non-nil means call this function to ring the bell.
2721 The function should accept no arguments. */);
2722 Vring_bell_function = Qnil;
2723
2724 defsubr (&Stty_display_color_p);
2725 defsubr (&Stty_display_color_cells);
2726 }
2727
2728 struct tty_output *
2729 get_current_tty ()
2730 {
2731 return CURTTY();
2732 }
2733
2734
2735 /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
2736 (do not change this comment) */