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