lib-src/emacsclient.c: Implemented --here option (open a new Emacs tty). Needs...
[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 "lisp.h"
32 #include "systty.h" /* For emacs_tty in termchar.h */
33 #include "termchar.h"
34 #include "termopts.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_ ((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 turn_off_insert ();
796
797 /* Do not write in last row last col with Auto-wrap on. */
798 if (AutoWrap && curY == FRAME_LINES (f) - 1
799 && first_unused_hpos == FRAME_COLS (f))
800 first_unused_hpos--;
801
802 for (i = curX; i < first_unused_hpos; i++)
803 {
804 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
805 fputc (' ', TTY_TERMSCRIPT (FRAME_TTY (f)));
806 fputc (' ', TTY_OUTPUT (FRAME_TTY (f)));
807 }
808 cmplus (first_unused_hpos - curX);
809 }
810 }
811 \f
812 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes and
813 store them at DST. Do not write more than DST_LEN bytes. That may
814 require stopping before all SRC_LEN input glyphs have been
815 converted.
816
817 We store the number of glyphs actually converted in *CONSUMED. The
818 return value is the number of bytes store in DST. */
819
820 int
821 encode_terminal_code (src, dst, src_len, dst_len, consumed)
822 struct glyph *src;
823 int src_len;
824 unsigned char *dst;
825 int dst_len, *consumed;
826 {
827 struct glyph *src_start = src, *src_end = src + src_len;
828 unsigned char *dst_start = dst, *dst_end = dst + dst_len;
829 register GLYPH g;
830 unsigned char workbuf[MAX_MULTIBYTE_LENGTH];
831 const unsigned char *buf;
832 int len;
833 register int tlen = GLYPH_TABLE_LENGTH;
834 register Lisp_Object *tbase = GLYPH_TABLE_BASE;
835 int result;
836 struct coding_system *coding;
837
838 /* If terminal_coding does any conversion, use it, otherwise use
839 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
840 because it always return 1 if the member src_multibyte is 1. */
841 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK
842 ? &terminal_coding
843 : &safe_terminal_coding);
844
845 while (src < src_end)
846 {
847 /* We must skip glyphs to be padded for a wide character. */
848 if (! CHAR_GLYPH_PADDING_P (*src))
849 {
850 g = GLYPH_FROM_CHAR_GLYPH (src[0]);
851
852 if (g < 0 || g >= tlen)
853 {
854 /* This glyph doesn't has an entry in Vglyph_table. */
855 if (! CHAR_VALID_P (src->u.ch, 0))
856 {
857 len = 1;
858 buf = " ";
859 coding->src_multibyte = 0;
860 }
861 else
862 {
863 len = CHAR_STRING (src->u.ch, workbuf);
864 buf = workbuf;
865 coding->src_multibyte = 1;
866 }
867 }
868 else
869 {
870 /* This glyph has an entry in Vglyph_table,
871 so process any alias before testing for simpleness. */
872 GLYPH_FOLLOW_ALIASES (tbase, tlen, g);
873
874 if (GLYPH_SIMPLE_P (tbase, tlen, g))
875 {
876 /* We set the multi-byte form of a character in G
877 (that should be an ASCII character) at
878 WORKBUF. */
879 workbuf[0] = FAST_GLYPH_CHAR (g);
880 len = 1;
881 buf = workbuf;
882 coding->src_multibyte = 0;
883 }
884 else
885 {
886 /* We have a string in Vglyph_table. */
887 len = GLYPH_LENGTH (tbase, g);
888 buf = GLYPH_STRING (tbase, g);
889 coding->src_multibyte = STRING_MULTIBYTE (tbase[g]);
890 }
891 }
892
893 result = encode_coding (coding, buf, dst, len, dst_end - dst);
894 len -= coding->consumed;
895 dst += coding->produced;
896 if (result == CODING_FINISH_INSUFFICIENT_DST
897 || (result == CODING_FINISH_INSUFFICIENT_SRC
898 && len > dst_end - dst))
899 /* The remaining output buffer is too short. We must
900 break the loop here without increasing SRC so that the
901 next call of this function starts from the same glyph. */
902 break;
903
904 if (len > 0)
905 {
906 /* This is the case that a code of the range 0200..0237
907 exists in buf. We must just write out such a code. */
908 buf += coding->consumed;
909 while (len--)
910 *dst++ = *buf++;
911 }
912 }
913 src++;
914 }
915
916 *consumed = src - src_start;
917 return (dst - dst_start);
918 }
919
920
921 void
922 write_glyphs (string, len)
923 register struct glyph *string;
924 register int len;
925 {
926 int produced, consumed;
927 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame);
928 unsigned char conversion_buffer[1024];
929 int conversion_buffer_size = sizeof conversion_buffer;
930
931 if (write_glyphs_hook
932 && ! FRAME_TERMCAP_P (f))
933 {
934 (*write_glyphs_hook) (string, len);
935 return;
936 }
937
938 turn_off_insert ();
939 tty_hide_cursor ();
940
941 /* Don't dare write in last column of bottom line, if Auto-Wrap,
942 since that would scroll the whole frame on some terminals. */
943
944 if (AutoWrap
945 && curY + 1 == FRAME_LINES (f)
946 && (curX + len) == FRAME_COLS (f))
947 len --;
948 if (len <= 0)
949 return;
950
951 cmplus (len);
952
953 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
954 the tail. */
955 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK;
956
957 while (len > 0)
958 {
959 /* Identify a run of glyphs with the same face. */
960 int face_id = string->face_id;
961 int n;
962
963 for (n = 1; n < len; ++n)
964 if (string[n].face_id != face_id)
965 break;
966
967 /* Turn appearance modes of the face of the run on. */
968 highlight_if_desired ();
969 turn_on_face (f, face_id);
970
971 while (n > 0)
972 {
973 /* We use a fixed size (1024 bytes) of conversion buffer.
974 Usually it is sufficient, but if not, we just repeat the
975 loop. */
976 produced = encode_terminal_code (string, conversion_buffer,
977 n, conversion_buffer_size,
978 &consumed);
979 if (produced > 0)
980 {
981 fwrite (conversion_buffer, 1, produced,
982 TTY_OUTPUT (FRAME_TTY (f)));
983 if (ferror (TTY_OUTPUT (FRAME_TTY (f))))
984 clearerr (TTY_OUTPUT (FRAME_TTY (f)));
985 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
986 fwrite (conversion_buffer, 1, produced,
987 TTY_TERMSCRIPT (FRAME_TTY (f)));
988 }
989 len -= consumed;
990 n -= consumed;
991 string += consumed;
992 }
993
994 /* Turn appearance modes off. */
995 turn_off_face (f, face_id);
996 turn_off_highlight ();
997 }
998
999 /* We may have to output some codes to terminate the writing. */
1000 if (CODING_REQUIRE_FLUSHING (&terminal_coding))
1001 {
1002 terminal_coding.mode |= CODING_MODE_LAST_BLOCK;
1003 encode_coding (&terminal_coding, "", conversion_buffer,
1004 0, conversion_buffer_size);
1005 if (terminal_coding.produced > 0)
1006 {
1007 fwrite (conversion_buffer, 1, terminal_coding.produced,
1008 TTY_OUTPUT (FRAME_TTY (f)));
1009 if (ferror (TTY_OUTPUT (FRAME_TTY (f))))
1010 clearerr (TTY_OUTPUT (FRAME_TTY (f)));
1011 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
1012 fwrite (conversion_buffer, 1, terminal_coding.produced,
1013 TTY_TERMSCRIPT (FRAME_TTY (f)));
1014 }
1015 }
1016
1017 cmcheckmagic (FRAME_TTY (f));
1018 }
1019
1020 /* If start is zero, insert blanks instead of a string at start */
1021
1022 void
1023 insert_glyphs (start, len)
1024 register struct glyph *start;
1025 register int len;
1026 {
1027 char *buf;
1028 struct glyph *glyph = NULL;
1029 struct frame *f;
1030
1031 if (len <= 0)
1032 return;
1033
1034 if (insert_glyphs_hook)
1035 {
1036 (*insert_glyphs_hook) (start, len);
1037 return;
1038 }
1039
1040 f = updating_frame ? updating_frame : XFRAME (selected_frame);
1041
1042 if (TS_ins_multi_chars)
1043 {
1044 buf = tparam (TS_ins_multi_chars, 0, 0, len);
1045 OUTPUT1 (FRAME_TTY (f), buf);
1046 xfree (buf);
1047 if (start)
1048 write_glyphs (start, len);
1049 return;
1050 }
1051
1052 turn_on_insert ();
1053 cmplus (len);
1054 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */
1055 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK;
1056 while (len-- > 0)
1057 {
1058 int produced, consumed;
1059 unsigned char conversion_buffer[1024];
1060 int conversion_buffer_size = sizeof conversion_buffer;
1061
1062 OUTPUT1_IF (FRAME_TTY (f), TS_ins_char);
1063 if (!start)
1064 {
1065 conversion_buffer[0] = SPACEGLYPH;
1066 produced = 1;
1067 }
1068 else
1069 {
1070 highlight_if_desired ();
1071 turn_on_face (f, start->face_id);
1072 glyph = start;
1073 ++start;
1074 /* We must open sufficient space for a character which
1075 occupies more than one column. */
1076 while (len && CHAR_GLYPH_PADDING_P (*start))
1077 {
1078 OUTPUT1_IF (FRAME_TTY (f), TS_ins_char);
1079 start++, len--;
1080 }
1081
1082 if (len <= 0)
1083 /* This is the last glyph. */
1084 terminal_coding.mode |= CODING_MODE_LAST_BLOCK;
1085
1086 /* The size of conversion buffer (1024 bytes) is surely
1087 sufficient for just one glyph. */
1088 produced = encode_terminal_code (glyph, conversion_buffer, 1,
1089 conversion_buffer_size, &consumed);
1090 }
1091
1092 if (produced > 0)
1093 {
1094 fwrite (conversion_buffer, 1, produced,
1095 TTY_OUTPUT (FRAME_TTY (f)));
1096 if (ferror (TTY_OUTPUT (FRAME_TTY (f))))
1097 clearerr (TTY_OUTPUT (FRAME_TTY (f)));
1098 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
1099 fwrite (conversion_buffer, 1, produced,
1100 TTY_TERMSCRIPT (FRAME_TTY (f)));
1101 }
1102
1103 OUTPUT1_IF (FRAME_TTY (f), TS_pad_inserted_char);
1104 if (start)
1105 {
1106 turn_off_face (f, glyph->face_id);
1107 turn_off_highlight ();
1108 }
1109 }
1110
1111 cmcheckmagic (FRAME_TTY (f));
1112 }
1113
1114 void
1115 delete_glyphs (n)
1116 register int n;
1117 {
1118 char *buf;
1119 register int i;
1120
1121 if (delete_glyphs_hook && ! FRAME_TERMCAP_P (updating_frame))
1122 {
1123 (*delete_glyphs_hook) (n);
1124 return;
1125 }
1126
1127 if (delete_in_insert_mode)
1128 {
1129 turn_on_insert ();
1130 }
1131 else
1132 {
1133 turn_off_insert ();
1134 OUTPUT_IF (FRAME_TTY (updating_frame), TS_delete_mode);
1135 }
1136
1137 if (TS_del_multi_chars)
1138 {
1139 buf = tparam (TS_del_multi_chars, 0, 0, n);
1140 OUTPUT1 (FRAME_TTY (updating_frame), buf);
1141 xfree (buf);
1142 }
1143 else
1144 for (i = 0; i < n; i++)
1145 OUTPUT1 (FRAME_TTY (updating_frame), TS_del_char);
1146 if (!delete_in_insert_mode)
1147 OUTPUT_IF (FRAME_TTY (updating_frame), TS_end_delete_mode);
1148 }
1149 \f
1150 /* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
1151
1152 void
1153 ins_del_lines (vpos, n)
1154 int vpos, n;
1155 {
1156 char *multi = n > 0 ? TS_ins_multi_lines : TS_del_multi_lines;
1157 char *single = n > 0 ? TS_ins_line : TS_del_line;
1158 char *scroll = n > 0 ? TS_rev_scroll : TS_fwd_scroll;
1159 struct frame *f;
1160
1161 register int i = n > 0 ? n : -n;
1162 register char *buf;
1163
1164 if (ins_del_lines_hook && ! FRAME_TERMCAP_P (updating_frame))
1165 {
1166 (*ins_del_lines_hook) (vpos, n);
1167 return;
1168 }
1169
1170 f = (updating_frame ? updating_frame : XFRAME (selected_frame));
1171
1172 /* If the lines below the insertion are being pushed
1173 into the end of the window, this is the same as clearing;
1174 and we know the lines are already clear, since the matching
1175 deletion has already been done. So can ignore this. */
1176 /* If the lines below the deletion are blank lines coming
1177 out of the end of the window, don't bother,
1178 as there will be a matching inslines later that will flush them. */
1179 if (TTY_SCROLL_REGION_OK (FRAME_TTY (f))
1180 && vpos + i >= specified_window)
1181 return;
1182 if (!TTY_MEMORY_BELOW_FRAME (FRAME_TTY (f))
1183 && vpos + i >= FRAME_LINES (f))
1184 return;
1185
1186 if (multi)
1187 {
1188 raw_cursor_to (vpos, 0);
1189 background_highlight ();
1190 buf = tparam (multi, 0, 0, i);
1191 OUTPUT (FRAME_TTY (f), buf);
1192 xfree (buf);
1193 }
1194 else if (single)
1195 {
1196 raw_cursor_to (vpos, 0);
1197 background_highlight ();
1198 while (--i >= 0)
1199 OUTPUT (FRAME_TTY (f), single);
1200 if (TF_teleray)
1201 curX = 0;
1202 }
1203 else
1204 {
1205 set_scroll_region (vpos, specified_window);
1206 if (n < 0)
1207 raw_cursor_to (specified_window - 1, 0);
1208 else
1209 raw_cursor_to (vpos, 0);
1210 background_highlight ();
1211 while (--i >= 0)
1212 OUTPUTL (FRAME_TTY (f), scroll, specified_window - vpos);
1213 set_scroll_region (0, specified_window);
1214 }
1215
1216 if (!TTY_SCROLL_REGION_OK (FRAME_TTY (f))
1217 && TTY_MEMORY_BELOW_FRAME (FRAME_TTY (f))
1218 && n < 0)
1219 {
1220 cursor_to (FRAME_LINES (f) + n, 0);
1221 clear_to_end ();
1222 }
1223 }
1224 \f
1225 /* Compute cost of sending "str", in characters,
1226 not counting any line-dependent padding. */
1227
1228 int
1229 string_cost (str)
1230 char *str;
1231 {
1232 cost = 0;
1233 if (str)
1234 tputs (str, 0, evalcost);
1235 return cost;
1236 }
1237
1238 /* Compute cost of sending "str", in characters,
1239 counting any line-dependent padding at one line. */
1240
1241 static int
1242 string_cost_one_line (str)
1243 char *str;
1244 {
1245 cost = 0;
1246 if (str)
1247 tputs (str, 1, evalcost);
1248 return cost;
1249 }
1250
1251 /* Compute per line amount of line-dependent padding,
1252 in tenths of characters. */
1253
1254 int
1255 per_line_cost (str)
1256 register char *str;
1257 {
1258 cost = 0;
1259 if (str)
1260 tputs (str, 0, evalcost);
1261 cost = - cost;
1262 if (str)
1263 tputs (str, 10, evalcost);
1264 return cost;
1265 }
1266
1267 #ifndef old
1268 /* char_ins_del_cost[n] is cost of inserting N characters.
1269 char_ins_del_cost[-n] is cost of deleting N characters.
1270 The length of this vector is based on max_frame_cols. */
1271
1272 int *char_ins_del_vector;
1273
1274 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
1275 #endif
1276
1277 /* ARGSUSED */
1278 static void
1279 calculate_ins_del_char_costs (frame)
1280 FRAME_PTR frame;
1281 {
1282 int ins_startup_cost, del_startup_cost;
1283 int ins_cost_per_char, del_cost_per_char;
1284 register int i;
1285 register int *p;
1286
1287 if (TS_ins_multi_chars)
1288 {
1289 ins_cost_per_char = 0;
1290 ins_startup_cost = string_cost_one_line (TS_ins_multi_chars);
1291 }
1292 else if (TS_ins_char || TS_pad_inserted_char
1293 || (TS_insert_mode && TS_end_insert_mode))
1294 {
1295 ins_startup_cost = (30 * (string_cost (TS_insert_mode)
1296 + string_cost (TS_end_insert_mode))) / 100;
1297 ins_cost_per_char = (string_cost_one_line (TS_ins_char)
1298 + string_cost_one_line (TS_pad_inserted_char));
1299 }
1300 else
1301 {
1302 ins_startup_cost = 9999;
1303 ins_cost_per_char = 0;
1304 }
1305
1306 if (TS_del_multi_chars)
1307 {
1308 del_cost_per_char = 0;
1309 del_startup_cost = string_cost_one_line (TS_del_multi_chars);
1310 }
1311 else if (TS_del_char)
1312 {
1313 del_startup_cost = (string_cost (TS_delete_mode)
1314 + string_cost (TS_end_delete_mode));
1315 if (delete_in_insert_mode)
1316 del_startup_cost /= 2;
1317 del_cost_per_char = string_cost_one_line (TS_del_char);
1318 }
1319 else
1320 {
1321 del_startup_cost = 9999;
1322 del_cost_per_char = 0;
1323 }
1324
1325 /* Delete costs are at negative offsets */
1326 p = &char_ins_del_cost (frame)[0];
1327 for (i = FRAME_COLS (frame); --i >= 0;)
1328 *--p = (del_startup_cost += del_cost_per_char);
1329
1330 /* Doing nothing is free */
1331 p = &char_ins_del_cost (frame)[0];
1332 *p++ = 0;
1333
1334 /* Insert costs are at positive offsets */
1335 for (i = FRAME_COLS (frame); --i >= 0;)
1336 *p++ = (ins_startup_cost += ins_cost_per_char);
1337 }
1338
1339 void
1340 calculate_costs (frame)
1341 FRAME_PTR frame;
1342 {
1343 register char *f = (TS_set_scroll_region
1344 ? TS_set_scroll_region
1345 : TS_set_scroll_region_1);
1346
1347 FRAME_COST_BAUD_RATE (frame) = baud_rate;
1348
1349 if (FRAME_TERMCAP_P (frame))
1350 TTY_SCROLL_REGION_COST (frame->output_data.tty) = string_cost (f);
1351
1352 /* These variables are only used for terminal stuff. They are allocated
1353 once for the terminal frame of X-windows emacs, but not used afterwards.
1354
1355 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1356 X turns off char_ins_del_ok. */
1357
1358 max_frame_lines = max (max_frame_lines, FRAME_LINES (frame));
1359 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame));
1360
1361 costs_set = 1;
1362
1363 if (char_ins_del_vector != 0)
1364 char_ins_del_vector
1365 = (int *) xrealloc (char_ins_del_vector,
1366 (sizeof (int)
1367 + 2 * max_frame_cols * sizeof (int)));
1368 else
1369 char_ins_del_vector
1370 = (int *) xmalloc (sizeof (int)
1371 + 2 * max_frame_cols * sizeof (int));
1372
1373 bzero (char_ins_del_vector, (sizeof (int)
1374 + 2 * max_frame_cols * sizeof (int)));
1375
1376 if (f && (!TS_ins_line && !TS_del_line))
1377 do_line_insertion_deletion_costs (frame,
1378 TS_rev_scroll, TS_ins_multi_lines,
1379 TS_fwd_scroll, TS_del_multi_lines,
1380 f, f, 1);
1381 else
1382 do_line_insertion_deletion_costs (frame,
1383 TS_ins_line, TS_ins_multi_lines,
1384 TS_del_line, TS_del_multi_lines,
1385 0, 0, 1);
1386
1387 calculate_ins_del_char_costs (frame);
1388
1389 /* Don't use TS_repeat if its padding is worse than sending the chars */
1390 if (TS_repeat && per_line_cost (TS_repeat) * baud_rate < 9000)
1391 RPov = string_cost (TS_repeat);
1392 else
1393 RPov = FRAME_COLS (frame) * 2;
1394
1395 cmcostinit (); /* set up cursor motion costs */
1396 }
1397 \f
1398 struct fkey_table {
1399 char *cap, *name;
1400 };
1401
1402 /* Termcap capability names that correspond directly to X keysyms.
1403 Some of these (marked "terminfo") aren't supplied by old-style
1404 (Berkeley) termcap entries. They're listed in X keysym order;
1405 except we put the keypad keys first, so that if they clash with
1406 other keys (as on the IBM PC keyboard) they get overridden.
1407 */
1408
1409 static struct fkey_table keys[] =
1410 {
1411 {"kh", "home"}, /* termcap */
1412 {"kl", "left"}, /* termcap */
1413 {"ku", "up"}, /* termcap */
1414 {"kr", "right"}, /* termcap */
1415 {"kd", "down"}, /* termcap */
1416 {"%8", "prior"}, /* terminfo */
1417 {"%5", "next"}, /* terminfo */
1418 {"@7", "end"}, /* terminfo */
1419 {"@1", "begin"}, /* terminfo */
1420 {"*6", "select"}, /* terminfo */
1421 {"%9", "print"}, /* terminfo */
1422 {"@4", "execute"}, /* terminfo --- actually the `command' key */
1423 /*
1424 * "insert" --- see below
1425 */
1426 {"&8", "undo"}, /* terminfo */
1427 {"%0", "redo"}, /* terminfo */
1428 {"%7", "menu"}, /* terminfo --- actually the `options' key */
1429 {"@0", "find"}, /* terminfo */
1430 {"@2", "cancel"}, /* terminfo */
1431 {"%1", "help"}, /* terminfo */
1432 /*
1433 * "break" goes here, but can't be reliably intercepted with termcap
1434 */
1435 {"&4", "reset"}, /* terminfo --- actually `restart' */
1436 /*
1437 * "system" and "user" --- no termcaps
1438 */
1439 {"kE", "clearline"}, /* terminfo */
1440 {"kA", "insertline"}, /* terminfo */
1441 {"kL", "deleteline"}, /* terminfo */
1442 {"kI", "insertchar"}, /* terminfo */
1443 {"kD", "deletechar"}, /* terminfo */
1444 {"kB", "backtab"}, /* terminfo */
1445 /*
1446 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1447 */
1448 {"@8", "kp-enter"}, /* terminfo */
1449 /*
1450 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1451 * "kp-multiply", "kp-add", "kp-separator",
1452 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1453 * --- no termcaps for any of these.
1454 */
1455 {"K4", "kp-1"}, /* terminfo */
1456 /*
1457 * "kp-2" --- no termcap
1458 */
1459 {"K5", "kp-3"}, /* terminfo */
1460 /*
1461 * "kp-4" --- no termcap
1462 */
1463 {"K2", "kp-5"}, /* terminfo */
1464 /*
1465 * "kp-6" --- no termcap
1466 */
1467 {"K1", "kp-7"}, /* terminfo */
1468 /*
1469 * "kp-8" --- no termcap
1470 */
1471 {"K3", "kp-9"}, /* terminfo */
1472 /*
1473 * "kp-equal" --- no termcap
1474 */
1475 {"k1", "f1"},
1476 {"k2", "f2"},
1477 {"k3", "f3"},
1478 {"k4", "f4"},
1479 {"k5", "f5"},
1480 {"k6", "f6"},
1481 {"k7", "f7"},
1482 {"k8", "f8"},
1483 {"k9", "f9"}
1484 };
1485
1486 static char **term_get_fkeys_arg;
1487 static Lisp_Object term_get_fkeys_1 ();
1488
1489 /* Find the escape codes sent by the function keys for Vfunction_key_map.
1490 This function scans the termcap function key sequence entries, and
1491 adds entries to Vfunction_key_map for each function key it finds. */
1492
1493 void
1494 term_get_fkeys (address)
1495 char **address;
1496 {
1497 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1498 errors during the call. The only errors should be from Fdefine_key
1499 when given a key sequence containing an invalid prefix key. If the
1500 termcap defines function keys which use a prefix that is already bound
1501 to a command by the default bindings, we should silently ignore that
1502 function key specification, rather than giving the user an error and
1503 refusing to run at all on such a terminal. */
1504
1505 extern Lisp_Object Fidentity ();
1506 term_get_fkeys_arg = address;
1507 internal_condition_case (term_get_fkeys_1, Qerror, Fidentity);
1508 }
1509
1510 static Lisp_Object
1511 term_get_fkeys_1 ()
1512 {
1513 int i;
1514
1515 char **address = term_get_fkeys_arg;
1516
1517 /* This can happen if CANNOT_DUMP or with strange options. */
1518 if (!initialized)
1519 Vfunction_key_map = Fmake_sparse_keymap (Qnil);
1520
1521 for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++)
1522 {
1523 char *sequence = tgetstr (keys[i].cap, address);
1524 if (sequence)
1525 Fdefine_key (Vfunction_key_map, build_string (sequence),
1526 Fmake_vector (make_number (1),
1527 intern (keys[i].name)));
1528 }
1529
1530 /* The uses of the "k0" capability are inconsistent; sometimes it
1531 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1532 We will attempt to politely accommodate both systems by testing for
1533 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1534 */
1535 {
1536 char *k_semi = tgetstr ("k;", address);
1537 char *k0 = tgetstr ("k0", address);
1538 char *k0_name = "f10";
1539
1540 if (k_semi)
1541 {
1542 if (k0)
1543 /* Define f0 first, so that f10 takes precedence in case the
1544 key sequences happens to be the same. */
1545 Fdefine_key (Vfunction_key_map, build_string (k0),
1546 Fmake_vector (make_number (1), intern ("f0")));
1547 Fdefine_key (Vfunction_key_map, build_string (k_semi),
1548 Fmake_vector (make_number (1), intern ("f10")));
1549 }
1550 else if (k0)
1551 Fdefine_key (Vfunction_key_map, build_string (k0),
1552 Fmake_vector (make_number (1), intern (k0_name)));
1553 }
1554
1555 /* Set up cookies for numbered function keys above f10. */
1556 {
1557 char fcap[3], fkey[4];
1558
1559 fcap[0] = 'F'; fcap[2] = '\0';
1560 for (i = 11; i < 64; i++)
1561 {
1562 if (i <= 19)
1563 fcap[1] = '1' + i - 11;
1564 else if (i <= 45)
1565 fcap[1] = 'A' + i - 20;
1566 else
1567 fcap[1] = 'a' + i - 46;
1568
1569 {
1570 char *sequence = tgetstr (fcap, address);
1571 if (sequence)
1572 {
1573 sprintf (fkey, "f%d", i);
1574 Fdefine_key (Vfunction_key_map, build_string (sequence),
1575 Fmake_vector (make_number (1),
1576 intern (fkey)));
1577 }
1578 }
1579 }
1580 }
1581
1582 /*
1583 * Various mappings to try and get a better fit.
1584 */
1585 {
1586 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1587 if (!tgetstr (cap1, address)) \
1588 { \
1589 char *sequence = tgetstr (cap2, address); \
1590 if (sequence) \
1591 Fdefine_key (Vfunction_key_map, build_string (sequence), \
1592 Fmake_vector (make_number (1), \
1593 intern (sym))); \
1594 }
1595
1596 /* if there's no key_next keycap, map key_npage to `next' keysym */
1597 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1598 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1599 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1600 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1601 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1602 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1603 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1604
1605 /* IBM has their own non-standard dialect of terminfo.
1606 If the standard name isn't found, try the IBM name. */
1607 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1608 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1609 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1610 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1611 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1612 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1613 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1614 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1615 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1616 #undef CONDITIONAL_REASSIGN
1617 }
1618
1619 return Qnil;
1620 }
1621
1622 \f
1623 /***********************************************************************
1624 Character Display Information
1625 ***********************************************************************/
1626
1627 static void append_glyph P_ ((struct it *));
1628
1629
1630 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1631 terminal frames if IT->glyph_row != NULL. IT->c is the character
1632 for which to produce glyphs; IT->face_id contains the character's
1633 face. Padding glyphs are appended if IT->c has a IT->pixel_width >
1634 1. */
1635
1636 static void
1637 append_glyph (it)
1638 struct it *it;
1639 {
1640 struct glyph *glyph, *end;
1641 int i;
1642
1643 xassert (it->glyph_row);
1644 glyph = (it->glyph_row->glyphs[it->area]
1645 + it->glyph_row->used[it->area]);
1646 end = it->glyph_row->glyphs[1 + it->area];
1647
1648 for (i = 0;
1649 i < it->pixel_width && glyph < end;
1650 ++i)
1651 {
1652 glyph->type = CHAR_GLYPH;
1653 glyph->pixel_width = 1;
1654 glyph->u.ch = it->c;
1655 glyph->face_id = it->face_id;
1656 glyph->padding_p = i > 0;
1657 glyph->charpos = CHARPOS (it->position);
1658 glyph->object = it->object;
1659
1660 ++it->glyph_row->used[it->area];
1661 ++glyph;
1662 }
1663 }
1664
1665
1666 /* Produce glyphs for the display element described by IT. *IT
1667 specifies what we want to produce a glyph for (character, image, ...),
1668 and where in the glyph matrix we currently are (glyph row and hpos).
1669 produce_glyphs fills in output fields of *IT with information such as the
1670 pixel width and height of a character, and maybe output actual glyphs at
1671 the same time if IT->glyph_row is non-null. See the explanation of
1672 struct display_iterator in dispextern.h for an overview.
1673
1674 produce_glyphs also stores the result of glyph width, ascent
1675 etc. computations in *IT.
1676
1677 IT->glyph_row may be null, in which case produce_glyphs does not
1678 actually fill in the glyphs. This is used in the move_* functions
1679 in xdisp.c for text width and height computations.
1680
1681 Callers usually don't call produce_glyphs directly;
1682 instead they use the macro PRODUCE_GLYPHS. */
1683
1684 void
1685 produce_glyphs (it)
1686 struct it *it;
1687 {
1688 /* If a hook is installed, let it do the work. */
1689 xassert (it->what == IT_CHARACTER
1690 || it->what == IT_COMPOSITION
1691 || it->what == IT_IMAGE
1692 || it->what == IT_STRETCH);
1693
1694 /* Nothing but characters are supported on terminal frames. For a
1695 composition sequence, it->c is the first character of the
1696 sequence. */
1697 xassert (it->what == IT_CHARACTER
1698 || it->what == IT_COMPOSITION);
1699
1700 if (it->c >= 040 && it->c < 0177)
1701 {
1702 it->pixel_width = it->nglyphs = 1;
1703 if (it->glyph_row)
1704 append_glyph (it);
1705 }
1706 else if (it->c == '\n')
1707 it->pixel_width = it->nglyphs = 0;
1708 else if (it->c == '\t')
1709 {
1710 int absolute_x = (it->current_x
1711 + it->continuation_lines_width);
1712 int next_tab_x
1713 = (((1 + absolute_x + it->tab_width - 1)
1714 / it->tab_width)
1715 * it->tab_width);
1716 int nspaces;
1717
1718 /* If part of the TAB has been displayed on the previous line
1719 which is continued now, continuation_lines_width will have
1720 been incremented already by the part that fitted on the
1721 continued line. So, we will get the right number of spaces
1722 here. */
1723 nspaces = next_tab_x - absolute_x;
1724
1725 if (it->glyph_row)
1726 {
1727 int n = nspaces;
1728
1729 it->c = ' ';
1730 it->pixel_width = it->len = 1;
1731
1732 while (n--)
1733 append_glyph (it);
1734
1735 it->c = '\t';
1736 }
1737
1738 it->pixel_width = nspaces;
1739 it->nglyphs = nspaces;
1740 }
1741 else if (SINGLE_BYTE_CHAR_P (it->c))
1742 {
1743 /* Coming here means that it->c is from display table, thus we
1744 must send the code as is to the terminal. Although there's
1745 no way to know how many columns it occupies on a screen, it
1746 is a good assumption that a single byte code has 1-column
1747 width. */
1748 it->pixel_width = it->nglyphs = 1;
1749 if (it->glyph_row)
1750 append_glyph (it);
1751 }
1752 else
1753 {
1754 /* A multi-byte character. The display width is fixed for all
1755 characters of the set. Some of the glyphs may have to be
1756 ignored because they are already displayed in a continued
1757 line. */
1758 int charset = CHAR_CHARSET (it->c);
1759
1760 it->pixel_width = CHARSET_WIDTH (charset);
1761 it->nglyphs = it->pixel_width;
1762
1763 if (it->glyph_row)
1764 append_glyph (it);
1765 }
1766
1767 /* Advance current_x by the pixel width as a convenience for
1768 the caller. */
1769 if (it->area == TEXT_AREA)
1770 it->current_x += it->pixel_width;
1771 it->ascent = it->max_ascent = it->phys_ascent = it->max_phys_ascent = 0;
1772 it->descent = it->max_descent = it->phys_descent = it->max_phys_descent = 1;
1773 }
1774
1775
1776 /* Get information about special display element WHAT in an
1777 environment described by IT. WHAT is one of IT_TRUNCATION or
1778 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
1779 non-null glyph_row member. This function ensures that fields like
1780 face_id, c, len of IT are left untouched. */
1781
1782 void
1783 produce_special_glyphs (it, what)
1784 struct it *it;
1785 enum display_element_type what;
1786 {
1787 struct it temp_it;
1788
1789 temp_it = *it;
1790 temp_it.dp = NULL;
1791 temp_it.what = IT_CHARACTER;
1792 temp_it.len = 1;
1793 temp_it.object = make_number (0);
1794 bzero (&temp_it.current, sizeof temp_it.current);
1795
1796 if (what == IT_CONTINUATION)
1797 {
1798 /* Continuation glyph. */
1799 if (it->dp
1800 && INTEGERP (DISP_CONTINUE_GLYPH (it->dp))
1801 && GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (it->dp))))
1802 {
1803 temp_it.c = FAST_GLYPH_CHAR (XINT (DISP_CONTINUE_GLYPH (it->dp)));
1804 temp_it.len = CHAR_BYTES (temp_it.c);
1805 }
1806 else
1807 temp_it.c = '\\';
1808
1809 produce_glyphs (&temp_it);
1810 it->pixel_width = temp_it.pixel_width;
1811 it->nglyphs = temp_it.pixel_width;
1812 }
1813 else if (what == IT_TRUNCATION)
1814 {
1815 /* Truncation glyph. */
1816 if (it->dp
1817 && INTEGERP (DISP_TRUNC_GLYPH (it->dp))
1818 && GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (it->dp))))
1819 {
1820 temp_it.c = FAST_GLYPH_CHAR (XINT (DISP_TRUNC_GLYPH (it->dp)));
1821 temp_it.len = CHAR_BYTES (temp_it.c);
1822 }
1823 else
1824 temp_it.c = '$';
1825
1826 produce_glyphs (&temp_it);
1827 it->pixel_width = temp_it.pixel_width;
1828 it->nglyphs = temp_it.pixel_width;
1829 }
1830 else
1831 abort ();
1832 }
1833
1834
1835 \f
1836 /***********************************************************************
1837 Faces
1838 ***********************************************************************/
1839
1840 /* Value is non-zero if attribute ATTR may be used. ATTR should be
1841 one of the enumerators from enum no_color_bit, or a bit set built
1842 from them. Some display attributes may not be used together with
1843 color; the termcap capability `NC' specifies which ones. */
1844
1845 #define MAY_USE_WITH_COLORS_P(ATTR) \
1846 (TN_max_colors > 0 \
1847 ? (TN_no_color_video & (ATTR)) == 0 \
1848 : 1)
1849
1850 /* Turn appearances of face FACE_ID on tty frame F on. */
1851
1852 static void
1853 turn_on_face (f, face_id)
1854 struct frame *f;
1855 int face_id;
1856 {
1857 struct face *face = FACE_FROM_ID (f, face_id);
1858 long fg = face->foreground;
1859 long bg = face->background;
1860
1861 /* Do this first because TS_end_standout_mode may be the same
1862 as TS_exit_attribute_mode, which turns all appearances off. */
1863 if (MAY_USE_WITH_COLORS_P (NC_REVERSE))
1864 {
1865 if (TN_max_colors > 0)
1866 {
1867 if (fg >= 0 && bg >= 0)
1868 {
1869 /* If the terminal supports colors, we can set them
1870 below without using reverse video. The face's fg
1871 and bg colors are set as they should appear on
1872 the screen, i.e. they take the inverse-video'ness
1873 of the face already into account. */
1874 }
1875 else if (inverse_video)
1876 {
1877 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1878 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1879 toggle_highlight ();
1880 }
1881 else
1882 {
1883 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1884 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1885 toggle_highlight ();
1886 }
1887 }
1888 else
1889 {
1890 /* If we can't display colors, use reverse video
1891 if the face specifies that. */
1892 if (inverse_video)
1893 {
1894 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1895 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1896 toggle_highlight ();
1897 }
1898 else
1899 {
1900 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1901 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1902 toggle_highlight ();
1903 }
1904 }
1905 }
1906
1907 if (face->tty_bold_p)
1908 {
1909 if (MAY_USE_WITH_COLORS_P (NC_BOLD))
1910 OUTPUT1_IF (FRAME_TTY (f), TS_enter_bold_mode);
1911 }
1912 else if (face->tty_dim_p)
1913 if (MAY_USE_WITH_COLORS_P (NC_DIM))
1914 OUTPUT1_IF (FRAME_TTY (f), TS_enter_dim_mode);
1915
1916 /* Alternate charset and blinking not yet used. */
1917 if (face->tty_alt_charset_p
1918 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET))
1919 OUTPUT1_IF (FRAME_TTY (f), TS_enter_alt_charset_mode);
1920
1921 if (face->tty_blinking_p
1922 && MAY_USE_WITH_COLORS_P (NC_BLINK))
1923 OUTPUT1_IF (FRAME_TTY (f), TS_enter_blink_mode);
1924
1925 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (NC_UNDERLINE))
1926 OUTPUT1_IF (FRAME_TTY (f), TS_enter_underline_mode);
1927
1928 if (TN_max_colors > 0)
1929 {
1930 char *p;
1931
1932 if (fg >= 0 && TS_set_foreground)
1933 {
1934 p = tparam (TS_set_foreground, NULL, 0, (int) fg);
1935 OUTPUT (FRAME_TTY (f), p);
1936 xfree (p);
1937 }
1938
1939 if (bg >= 0 && TS_set_background)
1940 {
1941 p = tparam (TS_set_background, NULL, 0, (int) bg);
1942 OUTPUT (FRAME_TTY (f), p);
1943 xfree (p);
1944 }
1945 }
1946 }
1947
1948
1949 /* Turn off appearances of face FACE_ID on tty frame F. */
1950
1951 static void
1952 turn_off_face (f, face_id)
1953 struct frame *f;
1954 int face_id;
1955 {
1956 struct face *face = FACE_FROM_ID (f, face_id);
1957
1958 xassert (face != NULL);
1959
1960 if (TS_exit_attribute_mode)
1961 {
1962 /* Capability "me" will turn off appearance modes double-bright,
1963 half-bright, reverse-video, standout, underline. It may or
1964 may not turn off alt-char-mode. */
1965 if (face->tty_bold_p
1966 || face->tty_dim_p
1967 || face->tty_reverse_p
1968 || face->tty_alt_charset_p
1969 || face->tty_blinking_p
1970 || face->tty_underline_p)
1971 {
1972 OUTPUT1_IF (FRAME_TTY (f), TS_exit_attribute_mode);
1973 if (strcmp (TS_exit_attribute_mode, TS_end_standout_mode) == 0)
1974 standout_mode = 0;
1975 }
1976
1977 if (face->tty_alt_charset_p)
1978 OUTPUT_IF (FRAME_TTY (f), TS_exit_alt_charset_mode);
1979 }
1980 else
1981 {
1982 /* If we don't have "me" we can only have those appearances
1983 that have exit sequences defined. */
1984 if (face->tty_alt_charset_p)
1985 OUTPUT_IF (FRAME_TTY (f), TS_exit_alt_charset_mode);
1986
1987 if (face->tty_underline_p)
1988 OUTPUT_IF (FRAME_TTY (f), TS_exit_underline_mode);
1989 }
1990
1991 /* Switch back to default colors. */
1992 if (TN_max_colors > 0
1993 && ((face->foreground != FACE_TTY_DEFAULT_COLOR
1994 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR)
1995 || (face->background != FACE_TTY_DEFAULT_COLOR
1996 && face->background != FACE_TTY_DEFAULT_BG_COLOR)))
1997 OUTPUT1_IF (FRAME_TTY (f), TS_orig_pair);
1998 }
1999
2000
2001 /* Return non-zero if the terminal on frame F supports all of the
2002 capabilities in CAPS simultaneously, with foreground and background
2003 colors FG and BG. */
2004
2005 int
2006 tty_capable_p (f, caps, fg, bg)
2007 struct frame *f;
2008 unsigned caps;
2009 unsigned long fg, bg;
2010 {
2011 #define TTY_CAPABLE_P_TRY(cap, TS, NC_bit) \
2012 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(NC_bit))) \
2013 return 0;
2014
2015 TTY_CAPABLE_P_TRY (TTY_CAP_INVERSE, TS_standout_mode, NC_REVERSE);
2016 TTY_CAPABLE_P_TRY (TTY_CAP_UNDERLINE, TS_enter_underline_mode, NC_UNDERLINE);
2017 TTY_CAPABLE_P_TRY (TTY_CAP_BOLD, TS_enter_bold_mode, NC_BOLD);
2018 TTY_CAPABLE_P_TRY (TTY_CAP_DIM, TS_enter_dim_mode, NC_DIM);
2019 TTY_CAPABLE_P_TRY (TTY_CAP_BLINK, TS_enter_blink_mode, NC_BLINK);
2020 TTY_CAPABLE_P_TRY (TTY_CAP_ALT_CHARSET, TS_enter_alt_charset_mode, NC_ALT_CHARSET);
2021
2022 /* We can do it! */
2023 return 1;
2024 }
2025
2026
2027 /* Return non-zero if the terminal is capable to display colors. */
2028
2029 DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
2030 0, 1, 0,
2031 doc: /* Return non-nil if TTY can display colors on DISPLAY. */)
2032 (display)
2033 Lisp_Object display;
2034 {
2035 return TN_max_colors > 0 ? Qt : Qnil;
2036 }
2037
2038 /* Return the number of supported colors. */
2039 DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
2040 Stty_display_color_cells, 0, 1, 0,
2041 doc: /* Return the number of colors supported by TTY on DISPLAY. */)
2042 (display)
2043 Lisp_Object display;
2044 {
2045 return make_number (TN_max_colors);
2046 }
2047
2048 #ifndef WINDOWSNT
2049
2050 /* Save or restore the default color-related capabilities of this
2051 terminal. */
2052 static void
2053 tty_default_color_capabilities (save)
2054 int save;
2055 {
2056 static char
2057 *default_orig_pair, *default_set_foreground, *default_set_background;
2058 static int default_max_colors, default_max_pairs, default_no_color_video;
2059
2060 if (save)
2061 {
2062 if (default_orig_pair)
2063 xfree (default_orig_pair);
2064 default_orig_pair = TS_orig_pair ? xstrdup (TS_orig_pair) : NULL;
2065
2066 if (default_set_foreground)
2067 xfree (default_set_foreground);
2068 default_set_foreground = TS_set_foreground ? xstrdup (TS_set_foreground)
2069 : NULL;
2070
2071 if (default_set_background)
2072 xfree (default_set_background);
2073 default_set_background = TS_set_background ? xstrdup (TS_set_background)
2074 : NULL;
2075
2076 default_max_colors = TN_max_colors;
2077 default_max_pairs = TN_max_pairs;
2078 default_no_color_video = TN_no_color_video;
2079 }
2080 else
2081 {
2082 TS_orig_pair = default_orig_pair;
2083 TS_set_foreground = default_set_foreground;
2084 TS_set_background = default_set_background;
2085 TN_max_colors = default_max_colors;
2086 TN_max_pairs = default_max_pairs;
2087 TN_no_color_video = default_no_color_video;
2088 }
2089 }
2090
2091 /* Setup one of the standard tty color schemes according to MODE.
2092 MODE's value is generally the number of colors which we want to
2093 support; zero means set up for the default capabilities, the ones
2094 we saw at term_init time; -1 means turn off color support. */
2095 void
2096 tty_setup_colors (mode)
2097 int mode;
2098 {
2099 /* Canonicalize all negative values of MODE. */
2100 if (mode < -1)
2101 mode = -1;
2102
2103 switch (mode)
2104 {
2105 case -1: /* no colors at all */
2106 TN_max_colors = 0;
2107 TN_max_pairs = 0;
2108 TN_no_color_video = 0;
2109 TS_set_foreground = TS_set_background = TS_orig_pair = NULL;
2110 break;
2111 case 0: /* default colors, if any */
2112 default:
2113 tty_default_color_capabilities (0);
2114 break;
2115 case 8: /* 8 standard ANSI colors */
2116 TS_orig_pair = "\033[0m";
2117 #ifdef TERMINFO
2118 TS_set_foreground = "\033[3%p1%dm";
2119 TS_set_background = "\033[4%p1%dm";
2120 #else
2121 TS_set_foreground = "\033[3%dm";
2122 TS_set_background = "\033[4%dm";
2123 #endif
2124 TN_max_colors = 8;
2125 TN_max_pairs = 64;
2126 TN_no_color_video = 0;
2127 break;
2128 }
2129 }
2130
2131 void
2132 set_tty_color_mode (f, val)
2133 struct frame *f;
2134 Lisp_Object val;
2135 {
2136 Lisp_Object color_mode_spec, current_mode_spec;
2137 Lisp_Object color_mode, current_mode;
2138 int mode, old_mode;
2139 extern Lisp_Object Qtty_color_mode;
2140 Lisp_Object tty_color_mode_alist;
2141
2142 tty_color_mode_alist = Fintern_soft (build_string ("tty-color-mode-alist"),
2143 Qnil);
2144
2145 if (INTEGERP (val))
2146 color_mode = val;
2147 else
2148 {
2149 if (NILP (tty_color_mode_alist))
2150 color_mode_spec = Qnil;
2151 else
2152 color_mode_spec = Fassq (val, XSYMBOL (tty_color_mode_alist)->value);
2153
2154 if (CONSP (color_mode_spec))
2155 color_mode = XCDR (color_mode_spec);
2156 else
2157 color_mode = Qnil;
2158 }
2159
2160 current_mode_spec = assq_no_quit (Qtty_color_mode, f->param_alist);
2161
2162 if (CONSP (current_mode_spec))
2163 current_mode = XCDR (current_mode_spec);
2164 else
2165 current_mode = Qnil;
2166 if (INTEGERP (color_mode))
2167 mode = XINT (color_mode);
2168 else
2169 mode = 0; /* meaning default */
2170 if (INTEGERP (current_mode))
2171 old_mode = XINT (current_mode);
2172 else
2173 old_mode = 0;
2174
2175 if (mode != old_mode)
2176 {
2177 tty_setup_colors (mode);
2178 /* This recomputes all the faces given the new color
2179 definitions. */
2180 call0 (intern ("tty-set-up-initial-frame-faces"));
2181 redraw_frame (f);
2182 }
2183 }
2184
2185 #endif /* !WINDOWSNT */
2186
2187 \f
2188
2189 struct tty_output *
2190 get_named_tty (name)
2191 char *name;
2192 {
2193 struct tty_output *tty = tty_list;
2194
2195 while (tty) {
2196 if ((tty->name == 0 && name == 0)
2197 || (name && tty->name && !strcmp (tty->name, name)))
2198 return tty;
2199 tty = tty->next;
2200 };
2201
2202 return 0;
2203 }
2204
2205 \f
2206 /***********************************************************************
2207 Initialization
2208 ***********************************************************************/
2209
2210 struct tty_output *
2211 term_dummy_init (void)
2212 {
2213 if (initialized || tty_list)
2214 error ("tty already initialized");
2215
2216 tty_list = xmalloc (sizeof (struct tty_output));
2217 bzero (tty_list, sizeof (struct tty_output));
2218 TTY_NAME (tty_list) = 0;
2219 TTY_INPUT (tty_list) = stdin;
2220 TTY_OUTPUT (tty_list) = stdout;
2221 return tty_list;
2222 }
2223
2224
2225 struct tty_output *
2226 term_init (name, terminal_type)
2227 char *name;
2228 char *terminal_type;
2229 {
2230 char *area;
2231 char **address = &area;
2232 char *buffer = NULL;
2233 int buffer_size = 4096;
2234 register char *p;
2235 int status;
2236 struct frame *sf = XFRAME (selected_frame);
2237
2238 struct tty_output *tty;
2239
2240 tty = get_named_tty (name);
2241 if (tty)
2242 {
2243 /* Return the previously initialized terminal, except if it is the dummy
2244 terminal created for the initial frame. */
2245 if (tty->type)
2246 return tty;
2247 }
2248 else
2249 {
2250 if (!terminal_type)
2251 error ("Unknown terminal type");
2252
2253 tty = (struct tty_output *) xmalloc (sizeof (struct tty_output));
2254 bzero (tty, sizeof (struct tty_output));
2255 tty->next = tty_list;
2256 tty_list = tty;
2257 }
2258
2259 if (name)
2260 {
2261 int fd;
2262 FILE *f;
2263 fd = emacs_open (name, O_RDWR, 0);
2264 if (fd < 0)
2265 {
2266 tty_list = tty->next;
2267 xfree (tty);
2268 error ("could not open file: %s", name);
2269 }
2270 f = fdopen (fd, "w+");
2271 TTY_NAME (tty) = xstrdup (name);
2272 TTY_INPUT (tty) = f;
2273 TTY_OUTPUT (tty) = f;
2274 }
2275 else
2276 {
2277 TTY_NAME (tty) = 0;
2278 TTY_INPUT (tty) = stdin;
2279 TTY_OUTPUT (tty) = stdout;
2280 }
2281
2282 init_sys_modes (tty);
2283
2284 #ifdef WINDOWSNT
2285 initialize_w32_display ();
2286
2287 Wcm_clear ();
2288
2289 area = (char *) xmalloc (2044);
2290
2291 FrameRows = FRAME_LINES (sf);
2292 FrameCols = FRAME_COLS (sf);
2293 specified_window = FRAME_LINES (sf);
2294
2295 delete_in_insert_mode = 1;
2296
2297 UseTabs = 0;
2298 TTY_SCROLL_REGION_OK (tty) = 0;
2299
2300 /* Seems to insert lines when it's not supposed to, messing
2301 up the display. In doing a trace, it didn't seem to be
2302 called much, so I don't think we're losing anything by
2303 turning it off. */
2304 TTY_LINE_INS_DEL_OK (tty) = 0;
2305
2306 TTY_CHAR_INS_DEL_OK (tty) = 1;
2307
2308 baud_rate = 19200;
2309
2310 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0;
2311 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none;
2312 TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */
2313
2314 return tty;
2315 #else /* not WINDOWSNT */
2316
2317 Wcm_clear ();
2318
2319 TTY_TYPE (tty) = xstrdup (terminal_type);
2320
2321 buffer = (char *) xmalloc (buffer_size);
2322 status = tgetent (buffer, terminal_type);
2323 if (status < 0)
2324 {
2325 #ifdef TERMINFO
2326 fatal ("Cannot open terminfo database file");
2327 #else
2328 fatal ("Cannot open termcap database file");
2329 #endif
2330 }
2331 if (status == 0)
2332 {
2333 #ifdef TERMINFO
2334 fatal ("Terminal type %s is not defined.\n\
2335 If that is not the actual type of terminal you have,\n\
2336 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2337 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2338 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2339 terminal_type);
2340 #else
2341 fatal ("Terminal type %s is not defined.\n\
2342 If that is not the actual type of terminal you have,\n\
2343 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2344 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2345 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2346 terminal_type);
2347 #endif
2348 }
2349
2350 #ifndef TERMINFO
2351 if (strlen (buffer) >= buffer_size)
2352 abort ();
2353 buffer_size = strlen (buffer);
2354 #endif
2355 area = (char *) xmalloc (buffer_size);
2356
2357 TS_ins_line = tgetstr ("al", address);
2358 TS_ins_multi_lines = tgetstr ("AL", address);
2359 TS_bell = tgetstr ("bl", address);
2360 BackTab = tgetstr ("bt", address);
2361 TS_clr_to_bottom = tgetstr ("cd", address);
2362 TS_clr_line = tgetstr ("ce", address);
2363 TS_clr_frame = tgetstr ("cl", address);
2364 ColPosition = NULL; /* tgetstr ("ch", address); */
2365 AbsPosition = tgetstr ("cm", address);
2366 CR = tgetstr ("cr", address);
2367 TS_set_scroll_region = tgetstr ("cs", address);
2368 TS_set_scroll_region_1 = tgetstr ("cS", address);
2369 RowPosition = tgetstr ("cv", address);
2370 TS_del_char = tgetstr ("dc", address);
2371 TS_del_multi_chars = tgetstr ("DC", address);
2372 TS_del_line = tgetstr ("dl", address);
2373 TS_del_multi_lines = tgetstr ("DL", address);
2374 TS_delete_mode = tgetstr ("dm", address);
2375 TS_end_delete_mode = tgetstr ("ed", address);
2376 TS_end_insert_mode = tgetstr ("ei", address);
2377 Home = tgetstr ("ho", address);
2378 TS_ins_char = tgetstr ("ic", address);
2379 TS_ins_multi_chars = tgetstr ("IC", address);
2380 TS_insert_mode = tgetstr ("im", address);
2381 TS_pad_inserted_char = tgetstr ("ip", address);
2382 TS_end_keypad_mode = tgetstr ("ke", address);
2383 TS_keypad_mode = tgetstr ("ks", address);
2384 LastLine = tgetstr ("ll", address);
2385 Right = tgetstr ("nd", address);
2386 Down = tgetstr ("do", address);
2387 if (!Down)
2388 Down = tgetstr ("nl", address); /* Obsolete name for "do" */
2389 #ifdef VMS
2390 /* VMS puts a carriage return before each linefeed,
2391 so it is not safe to use linefeeds. */
2392 if (Down && Down[0] == '\n' && Down[1] == '\0')
2393 Down = 0;
2394 #endif /* VMS */
2395 if (tgetflag ("bs"))
2396 Left = "\b"; /* can't possibly be longer! */
2397 else /* (Actually, "bs" is obsolete...) */
2398 Left = tgetstr ("le", address);
2399 if (!Left)
2400 Left = tgetstr ("bc", address); /* Obsolete name for "le" */
2401 TS_pad_char = tgetstr ("pc", address);
2402 TS_repeat = tgetstr ("rp", address);
2403 TS_end_standout_mode = tgetstr ("se", address);
2404 TS_fwd_scroll = tgetstr ("sf", address);
2405 TS_standout_mode = tgetstr ("so", address);
2406 TS_rev_scroll = tgetstr ("sr", address);
2407 Wcm.cm_tab = tgetstr ("ta", address);
2408 TS_end_termcap_modes = tgetstr ("te", address);
2409 TS_termcap_modes = tgetstr ("ti", address);
2410 Up = tgetstr ("up", address);
2411 TS_visible_bell = tgetstr ("vb", address);
2412 TS_cursor_normal = tgetstr ("ve", address);
2413 TS_cursor_visible = tgetstr ("vs", address);
2414 TS_cursor_invisible = tgetstr ("vi", address);
2415 TS_set_window = tgetstr ("wi", address);
2416
2417 TS_enter_underline_mode = tgetstr ("us", address);
2418 TS_exit_underline_mode = tgetstr ("ue", address);
2419 TS_enter_bold_mode = tgetstr ("md", address);
2420 TS_enter_dim_mode = tgetstr ("mh", address);
2421 TS_enter_blink_mode = tgetstr ("mb", address);
2422 TS_enter_reverse_mode = tgetstr ("mr", address);
2423 TS_enter_alt_charset_mode = tgetstr ("as", address);
2424 TS_exit_alt_charset_mode = tgetstr ("ae", address);
2425 TS_exit_attribute_mode = tgetstr ("me", address);
2426
2427 MultiUp = tgetstr ("UP", address);
2428 MultiDown = tgetstr ("DO", address);
2429 MultiLeft = tgetstr ("LE", address);
2430 MultiRight = tgetstr ("RI", address);
2431
2432 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
2433 color because we can't switch back to the default foreground and
2434 background. */
2435 TS_orig_pair = tgetstr ("op", address);
2436 if (TS_orig_pair)
2437 {
2438 TS_set_foreground = tgetstr ("AF", address);
2439 TS_set_background = tgetstr ("AB", address);
2440 if (!TS_set_foreground)
2441 {
2442 /* SVr4. */
2443 TS_set_foreground = tgetstr ("Sf", address);
2444 TS_set_background = tgetstr ("Sb", address);
2445 }
2446
2447 TN_max_colors = tgetnum ("Co");
2448 TN_max_pairs = tgetnum ("pa");
2449
2450 TN_no_color_video = tgetnum ("NC");
2451 if (TN_no_color_video == -1)
2452 TN_no_color_video = 0;
2453 }
2454
2455 tty_default_color_capabilities (1);
2456
2457 MagicWrap = tgetflag ("xn");
2458 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2459 the former flag imply the latter. */
2460 AutoWrap = MagicWrap || tgetflag ("am");
2461 TTY_MEMORY_BELOW_FRAME (tty) = tgetflag ("db");
2462 TF_hazeltine = tgetflag ("hz");
2463 TTY_MUST_WRITE_SPACES (tty) = tgetflag ("in");
2464 meta_key = tgetflag ("km") || tgetflag ("MT");
2465 TF_insmode_motion = tgetflag ("mi");
2466 TF_standout_motion = tgetflag ("ms");
2467 TF_underscore = tgetflag ("ul");
2468 TF_teleray = tgetflag ("xt");
2469
2470 term_get_fkeys (address);
2471
2472 /* Get frame size from system, or else from termcap. */
2473 {
2474 int height, width;
2475 get_tty_size (tty, &width, &height);
2476 FRAME_COLS (sf) = width;
2477 FRAME_LINES (sf) = height;
2478 }
2479
2480 if (FRAME_COLS (sf) <= 0)
2481 SET_FRAME_COLS (sf, tgetnum ("co"));
2482 else
2483 /* Keep width and external_width consistent */
2484 SET_FRAME_COLS (sf, FRAME_COLS (sf));
2485 if (FRAME_LINES (sf) <= 0)
2486 FRAME_LINES (sf) = tgetnum ("li");
2487
2488 if (FRAME_LINES (sf) < 3 || FRAME_COLS (sf) < 3)
2489 fatal ("Screen size %dx%d is too small",
2490 FRAME_LINES (sf), FRAME_COLS (sf));
2491
2492 #if 0 /* This is not used anywhere. */
2493 TTY_MIN_PADDING_SPEED (tty) = tgetnum ("pb");
2494 #endif
2495
2496 TabWidth = tgetnum ("tw");
2497
2498 #ifdef VMS
2499 /* These capabilities commonly use ^J.
2500 I don't know why, but sending them on VMS does not work;
2501 it causes following spaces to be lost, sometimes.
2502 For now, the simplest fix is to avoid using these capabilities ever. */
2503 if (Down && Down[0] == '\n')
2504 Down = 0;
2505 #endif /* VMS */
2506
2507 if (!TS_bell)
2508 TS_bell = "\07";
2509
2510 if (!TS_fwd_scroll)
2511 TS_fwd_scroll = Down;
2512
2513 PC = TS_pad_char ? *TS_pad_char : 0;
2514
2515 if (TabWidth < 0)
2516 TabWidth = 8;
2517
2518 /* Turned off since /etc/termcap seems to have :ta= for most terminals
2519 and newer termcap doc does not seem to say there is a default.
2520 if (!Wcm.cm_tab)
2521 Wcm.cm_tab = "\t";
2522 */
2523
2524 /* We don't support standout modes that use `magic cookies', so
2525 turn off any that do. */
2526 if (TS_standout_mode && tgetnum ("sg") >= 0)
2527 {
2528 TS_standout_mode = 0;
2529 TS_end_standout_mode = 0;
2530 }
2531 if (TS_enter_underline_mode && tgetnum ("ug") >= 0)
2532 {
2533 TS_enter_underline_mode = 0;
2534 TS_exit_underline_mode = 0;
2535 }
2536
2537 /* If there's no standout mode, try to use underlining instead. */
2538 if (TS_standout_mode == 0)
2539 {
2540 TS_standout_mode = TS_enter_underline_mode;
2541 TS_end_standout_mode = TS_exit_underline_mode;
2542 }
2543
2544 /* If no `se' string, try using a `me' string instead.
2545 If that fails, we can't use standout mode at all. */
2546 if (TS_end_standout_mode == 0)
2547 {
2548 char *s = tgetstr ("me", address);
2549 if (s != 0)
2550 TS_end_standout_mode = s;
2551 else
2552 TS_standout_mode = 0;
2553 }
2554
2555 if (TF_teleray)
2556 {
2557 Wcm.cm_tab = 0;
2558 /* We can't support standout mode, because it uses magic cookies. */
2559 TS_standout_mode = 0;
2560 /* But that means we cannot rely on ^M to go to column zero! */
2561 CR = 0;
2562 /* LF can't be trusted either -- can alter hpos */
2563 /* if move at column 0 thru a line with TS_standout_mode */
2564 Down = 0;
2565 }
2566
2567 /* Special handling for certain terminal types known to need it */
2568
2569 if (!strcmp (terminal_type, "supdup"))
2570 {
2571 TTY_MEMORY_BELOW_FRAME (tty) = 1;
2572 Wcm.cm_losewrap = 1;
2573 }
2574 if (!strncmp (terminal_type, "c10", 3)
2575 || !strcmp (terminal_type, "perq"))
2576 {
2577 /* Supply a makeshift :wi string.
2578 This string is not valid in general since it works only
2579 for windows starting at the upper left corner;
2580 but that is all Emacs uses.
2581
2582 This string works only if the frame is using
2583 the top of the video memory, because addressing is memory-relative.
2584 So first check the :ti string to see if that is true.
2585
2586 It would be simpler if the :wi string could go in the termcap
2587 entry, but it can't because it is not fully valid.
2588 If it were in the termcap entry, it would confuse other programs. */
2589 if (!TS_set_window)
2590 {
2591 p = TS_termcap_modes;
2592 while (*p && strcmp (p, "\033v "))
2593 p++;
2594 if (*p)
2595 TS_set_window = "\033v%C %C %C %C ";
2596 }
2597 /* Termcap entry often fails to have :in: flag */
2598 TTY_MUST_WRITE_SPACES (tty) = 1;
2599 /* :ti string typically fails to have \E^G! in it */
2600 /* This limits scope of insert-char to one line. */
2601 strcpy (area, TS_termcap_modes);
2602 strcat (area, "\033\007!");
2603 TS_termcap_modes = area;
2604 area += strlen (area) + 1;
2605 p = AbsPosition;
2606 /* Change all %+ parameters to %C, to handle
2607 values above 96 correctly for the C100. */
2608 while (*p)
2609 {
2610 if (p[0] == '%' && p[1] == '+')
2611 p[1] = 'C';
2612 p++;
2613 }
2614 }
2615
2616 FrameRows = FRAME_LINES (sf);
2617 FrameCols = FRAME_COLS (sf);
2618 specified_window = FRAME_LINES (sf);
2619
2620 if (Wcm_init () == -1) /* can't do cursor motion */
2621 #ifdef VMS
2622 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2623 It lacks the ability to position the cursor.\n\
2624 If that is not the actual type of terminal you have, use either the\n\
2625 DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
2626 or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2627 terminal_type);
2628 #else /* not VMS */
2629 # ifdef TERMINFO
2630 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2631 It lacks the ability to position the cursor.\n\
2632 If that is not the actual type of terminal you have,\n\
2633 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2634 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2635 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2636 terminal_type);
2637 # else /* TERMCAP */
2638 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2639 It lacks the ability to position the cursor.\n\
2640 If that is not the actual type of terminal you have,\n\
2641 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2642 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2643 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2644 terminal_type);
2645 # endif /* TERMINFO */
2646 #endif /*VMS */
2647 if (FRAME_LINES (sf) <= 0
2648 || FRAME_COLS (sf) <= 0)
2649 fatal ("The frame size has not been specified");
2650
2651 delete_in_insert_mode
2652 = TS_delete_mode && TS_insert_mode
2653 && !strcmp (TS_delete_mode, TS_insert_mode);
2654
2655 se_is_so = (TS_standout_mode
2656 && TS_end_standout_mode
2657 && !strcmp (TS_standout_mode, TS_end_standout_mode));
2658
2659 UseTabs = tabs_safe_p () && TabWidth == 8;
2660
2661 TTY_SCROLL_REGION_OK (tty)
2662 = (Wcm.cm_abs
2663 && (TS_set_window || TS_set_scroll_region || TS_set_scroll_region_1));
2664
2665 TTY_LINE_INS_DEL_OK (tty)
2666 = (((TS_ins_line || TS_ins_multi_lines)
2667 && (TS_del_line || TS_del_multi_lines))
2668 || (TTY_SCROLL_REGION_OK (tty)
2669 && TS_fwd_scroll && TS_rev_scroll));
2670
2671 TTY_CHAR_INS_DEL_OK (tty)
2672 = ((TS_ins_char || TS_insert_mode
2673 || TS_pad_inserted_char || TS_ins_multi_chars)
2674 && (TS_del_char || TS_del_multi_chars));
2675
2676 TTY_FAST_CLEAR_END_OF_LINE (tty) = TS_clr_line != 0;
2677
2678 init_baud_rate ();
2679 if (read_socket_hook) /* Baudrate is somewhat
2680 meaningless in this case */
2681 baud_rate = 9600;
2682
2683 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0;
2684 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none;
2685 #endif /* WINDOWSNT */
2686
2687 xfree (buffer);
2688
2689 return tty;
2690 }
2691
2692 /* VARARGS 1 */
2693 void
2694 fatal (str, arg1, arg2)
2695 char *str, *arg1, *arg2;
2696 {
2697 fprintf (stderr, "emacs: ");
2698 fprintf (stderr, str, arg1, arg2);
2699 fprintf (stderr, "\n");
2700 fflush (stderr);
2701 exit (1);
2702 }
2703
2704 void
2705 syms_of_term ()
2706 {
2707 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo,
2708 doc: /* Non-nil means the system uses terminfo rather than termcap.
2709 This variable can be used by terminal emulator packages. */);
2710 #ifdef TERMINFO
2711 system_uses_terminfo = 1;
2712 #else
2713 system_uses_terminfo = 0;
2714 #endif
2715
2716 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function,
2717 doc: /* Non-nil means call this function to ring the bell.
2718 The function should accept no arguments. */);
2719 Vring_bell_function = Qnil;
2720
2721 defsubr (&Stty_display_color_p);
2722 defsubr (&Stty_display_color_cells);
2723 }
2724
2725 struct tty_output *
2726 get_current_tty ()
2727 {
2728 return CURTTY();
2729 }
2730
2731
2732 /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
2733 (do not change this comment) */