1 /* Terminal control module for terminals described by TERMCAP
2 Copyright (C) 1985, 86, 87, 93, 94, 95, 98, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
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)
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.
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. */
22 /* New redisplay, TTY faces by Gerd Moellmann <gerd@gnu.org>. */
36 #include "termhooks.h"
37 #include "dispextern.h"
40 /* For now, don't try to include termcap.h. On some systems,
41 configure finds a non-standard termcap.h that the main build
44 #if defined HAVE_TERMCAP_H && 0
47 extern void tputs
P_ ((const char *, int, int (*)(int)));
48 extern int tgetent
P_ ((char *, const char *));
49 extern int tgetflag
P_ ((char *id
));
50 extern int tgetnum
P_ ((char *id
));
61 static void turn_on_face
P_ ((struct frame
*, int face_id
));
62 static void turn_off_face
P_ ((struct frame
*, int face_id
));
63 static void tty_show_cursor
P_ ((void));
64 static void tty_hide_cursor
P_ ((void));
67 tputs (a, (int) (FRAME_HEIGHT (XFRAME (selected_frame)) - curY), cmputc)
68 #define OUTPUT1(a) tputs (a, 1, cmputc)
69 #define OUTPUTL(a, lines) tputs (a, lines, cmputc)
71 #define OUTPUT_IF(a) \
74 tputs (a, (int) (FRAME_HEIGHT (XFRAME (selected_frame)) \
78 #define OUTPUT1_IF(a) do { if (a) tputs (a, 1, cmputc); } while (0)
80 /* Function to use to ring the bell. */
82 Lisp_Object Vring_bell_function
;
84 /* Terminal characteristics that higher levels want to look at.
85 These are all extern'd in termchar.h */
87 int must_write_spaces
; /* Nonzero means spaces in the text
88 must actually be output; can't just skip
89 over some columns to leave them blank. */
90 int min_padding_speed
; /* Speed below which no padding necessary */
92 int line_ins_del_ok
; /* Terminal can insert and delete lines */
93 int char_ins_del_ok
; /* Terminal can insert and delete chars */
94 int scroll_region_ok
; /* Terminal supports setting the
96 int scroll_region_cost
; /* Cost of setting a scroll window,
97 measured in characters */
98 int memory_below_frame
; /* Terminal remembers lines
99 scrolled off bottom */
100 int fast_clear_end_of_line
; /* Terminal has a `ce' string */
102 /* Nonzero means no need to redraw the entire frame on resuming
103 a suspended Emacs. This is useful on terminals with multiple pages,
104 where one page is used for Emacs and another for all else. */
106 int no_redraw_on_reenter
;
108 /* Hook functions that you can set to snap out the functions in this file.
109 These are all extern'd in termhooks.h */
111 void (*cursor_to_hook
) P_ ((int, int));
112 void (*raw_cursor_to_hook
) P_ ((int, int));
113 void (*clear_to_end_hook
) P_ ((void));
114 void (*clear_frame_hook
) P_ ((void));
115 void (*clear_end_of_line_hook
) P_ ((int));
117 void (*ins_del_lines_hook
) P_ ((int, int));
119 void (*change_line_highlight_hook
) P_ ((int, int, int, int));
120 void (*reassert_line_highlight_hook
) P_ ((int, int));
122 void (*delete_glyphs_hook
) P_ ((int));
124 void (*ring_bell_hook
) P_ ((void));
126 void (*reset_terminal_modes_hook
) P_ ((void));
127 void (*set_terminal_modes_hook
) P_ ((void));
128 void (*update_begin_hook
) P_ ((struct frame
*));
129 void (*update_end_hook
) P_ ((struct frame
*));
130 void (*set_terminal_window_hook
) P_ ((int));
131 void (*insert_glyphs_hook
) P_ ((struct glyph
*, int));
132 void (*write_glyphs_hook
) P_ ((struct glyph
*, int));
133 void (*delete_glyphs_hook
) P_ ((int));
135 int (*read_socket_hook
) P_ ((int, struct input_event
*, int, int));
137 void (*frame_up_to_date_hook
) P_ ((struct frame
*));
139 /* Return the current position of the mouse.
141 Set *f to the frame the mouse is in, or zero if the mouse is in no
142 Emacs frame. If it is set to zero, all the other arguments are
145 If the motion started in a scroll bar, set *bar_window to the
146 scroll bar's window, *part to the part the mouse is currently over,
147 *x to the position of the mouse along the scroll bar, and *y to the
148 overall length of the scroll bar.
150 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
151 row of the character cell the mouse is over.
153 Set *time to the time the mouse was at the returned position.
155 This should clear mouse_moved until the next motion
158 void (*mouse_position_hook
) P_ ((FRAME_PTR
*f
, int insist
,
159 Lisp_Object
*bar_window
,
160 enum scroll_bar_part
*part
,
163 unsigned long *time
));
165 /* When reading from a minibuffer in a different frame, Emacs wants
166 to shift the highlight from the selected frame to the mini-buffer's
167 frame; under X, this means it lies about where the focus is.
168 This hook tells the window system code to re-decide where to put
171 void (*frame_rehighlight_hook
) P_ ((FRAME_PTR f
));
173 /* If we're displaying frames using a window system that can stack
174 frames on top of each other, this hook allows you to bring a frame
175 to the front, or bury it behind all the other windows. If this
176 hook is zero, that means the device we're displaying on doesn't
177 support overlapping frames, so there's no need to raise or lower
180 If RAISE is non-zero, F is brought to the front, before all other
181 windows. If RAISE is zero, F is sent to the back, behind all other
184 void (*frame_raise_lower_hook
) P_ ((FRAME_PTR f
, int raise
));
186 /* Set the vertical scroll bar for WINDOW to have its upper left corner
187 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
188 indicate that we are displaying PORTION characters out of a total
189 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
190 have a scroll bar, create one for it. */
192 void (*set_vertical_scroll_bar_hook
)
193 P_ ((struct window
*window
,
194 int portion
, int whole
, int position
));
197 /* The following three hooks are used when we're doing a thorough
198 redisplay of the frame. We don't explicitly know which scroll bars
199 are going to be deleted, because keeping track of when windows go
200 away is a real pain - can you say set-window-configuration?
201 Instead, we just assert at the beginning of redisplay that *all*
202 scroll bars are to be removed, and then save scroll bars from the
203 fiery pit when we actually redisplay their window. */
205 /* Arrange for all scroll bars on FRAME to be removed at the next call
206 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
207 `*redeem_scroll_bar_hook' is applied to its window before the judgment.
209 This should be applied to each frame each time its window tree is
210 redisplayed, even if it is not displaying scroll bars at the moment;
211 if the HAS_SCROLL_BARS flag has just been turned off, only calling
212 this and the judge_scroll_bars_hook will get rid of them.
214 If non-zero, this hook should be safe to apply to any frame,
215 whether or not it can support scroll bars, and whether or not it is
216 currently displaying them. */
218 void (*condemn_scroll_bars_hook
) P_ ((FRAME_PTR frame
));
220 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
221 Note that it's okay to redeem a scroll bar that is not condemned. */
223 void (*redeem_scroll_bar_hook
) P_ ((struct window
*window
));
225 /* Remove all scroll bars on FRAME that haven't been saved since the
226 last call to `*condemn_scroll_bars_hook'.
228 This should be applied to each frame after each time its window
229 tree is redisplayed, even if it is not displaying scroll bars at the
230 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
231 calling this and condemn_scroll_bars_hook will get rid of them.
233 If non-zero, this hook should be safe to apply to any frame,
234 whether or not it can support scroll bars, and whether or not it is
235 currently displaying them. */
237 void (*judge_scroll_bars_hook
) P_ ((FRAME_PTR FRAME
));
239 /* Hook to call in estimate_mode_line_height, if any. */
241 int (* estimate_mode_line_height_hook
) P_ ((struct frame
*f
, enum face_id
));
244 /* Strings, numbers and flags taken from the termcap entry. */
246 char *TS_ins_line
; /* "al" */
247 char *TS_ins_multi_lines
; /* "AL" (one parameter, # lines to insert) */
248 char *TS_bell
; /* "bl" */
249 char *TS_clr_to_bottom
; /* "cd" */
250 char *TS_clr_line
; /* "ce", clear to end of line */
251 char *TS_clr_frame
; /* "cl" */
252 char *TS_set_scroll_region
; /* "cs" (2 params, first line and last line) */
253 char *TS_set_scroll_region_1
; /* "cS" (4 params: total lines,
254 lines above scroll region, lines below it,
255 total lines again) */
256 char *TS_del_char
; /* "dc" */
257 char *TS_del_multi_chars
; /* "DC" (one parameter, # chars to delete) */
258 char *TS_del_line
; /* "dl" */
259 char *TS_del_multi_lines
; /* "DL" (one parameter, # lines to delete) */
260 char *TS_delete_mode
; /* "dm", enter character-delete mode */
261 char *TS_end_delete_mode
; /* "ed", leave character-delete mode */
262 char *TS_end_insert_mode
; /* "ei", leave character-insert mode */
263 char *TS_ins_char
; /* "ic" */
264 char *TS_ins_multi_chars
; /* "IC" (one parameter, # chars to insert) */
265 char *TS_insert_mode
; /* "im", enter character-insert mode */
266 char *TS_pad_inserted_char
; /* "ip". Just padding, no commands. */
267 char *TS_end_keypad_mode
; /* "ke" */
268 char *TS_keypad_mode
; /* "ks" */
269 char *TS_pad_char
; /* "pc", char to use as padding */
270 char *TS_repeat
; /* "rp" (2 params, # times to repeat
271 and character to be repeated) */
272 char *TS_end_standout_mode
; /* "se" */
273 char *TS_fwd_scroll
; /* "sf" */
274 char *TS_standout_mode
; /* "so" */
275 char *TS_rev_scroll
; /* "sr" */
276 char *TS_end_termcap_modes
; /* "te" */
277 char *TS_termcap_modes
; /* "ti" */
278 char *TS_visible_bell
; /* "vb" */
279 char *TS_cursor_normal
; /* "ve" */
280 char *TS_cursor_visible
; /* "vs" */
281 char *TS_cursor_invisible
; /* "vi" */
282 char *TS_set_window
; /* "wi" (4 params, start and end of window,
283 each as vpos and hpos) */
285 /* Value of the "NC" (no_color_video) capability, or 0 if not
288 static int TN_no_color_video
;
290 /* Meaning of bits in no_color_video. Each bit set means that the
291 corresponding attribute cannot be combined with colors. */
295 NC_STANDOUT
= 1 << 0,
296 NC_UNDERLINE
= 1 << 1,
303 NC_ALT_CHARSET
= 1 << 8
306 /* "md" -- turn on bold (extra bright mode). */
308 char *TS_enter_bold_mode
;
310 /* "mh" -- turn on half-bright mode. */
312 char *TS_enter_dim_mode
;
314 /* "mb" -- enter blinking mode. */
316 char *TS_enter_blink_mode
;
318 /* "mr" -- enter reverse video mode. */
320 char *TS_enter_reverse_mode
;
322 /* "us"/"ue" -- start/end underlining. */
324 char *TS_exit_underline_mode
, *TS_enter_underline_mode
;
326 /* "ug" -- number of blanks left by underline. */
328 int TN_magic_cookie_glitch_ul
;
330 /* "as"/"ae" -- start/end alternate character set. Not really
333 char *TS_enter_alt_charset_mode
, *TS_exit_alt_charset_mode
;
335 /* "me" -- switch appearances off. */
337 char *TS_exit_attribute_mode
;
339 /* "Co" -- number of colors. */
343 /* "pa" -- max. number of color pairs on screen. Not handled yet.
344 Could be a problem if not equal to TN_max_colors * TN_max_colors. */
348 /* "op" -- SVr4 set default pair to its original value. */
352 /* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color.
353 1 param, the color index. */
355 char *TS_set_foreground
, *TS_set_background
;
357 int TF_hazeltine
; /* termcap hz flag. */
358 int TF_insmode_motion
; /* termcap mi flag: can move while in insert mode. */
359 int TF_standout_motion
; /* termcap mi flag: can move while in standout mode. */
360 int TF_underscore
; /* termcap ul flag: _ underlines if over-struck on
361 non-blank position. Must clear before writing _. */
362 int TF_teleray
; /* termcap xt flag: many weird consequences.
365 int TF_xs
; /* Nonzero for "xs". If set together with
366 TN_standout_width == 0, it means don't bother
367 to write any end-standout cookies. */
369 int TN_standout_width
; /* termcap sg number: width occupied by standout
372 static int RPov
; /* # chars to start a TS_repeat */
374 static int delete_in_insert_mode
; /* delete mode == insert mode */
376 static int se_is_so
; /* 1 if same string both enters and leaves
381 /* The largest frame width in any call to calculate_costs. */
385 /* The largest frame height in any call to calculate_costs. */
387 int max_frame_height
;
389 /* Number of chars of space used for standout marker at beginning of line,
390 or'd with 0100. Zero if no standout marker at all.
391 The length of these vectors is max_frame_height.
393 Used IFF TN_standout_width >= 0. */
395 static char *chars_wasted
;
396 static char *copybuf
;
398 /* nonzero means supposed to write text in standout mode. */
400 int standout_requested
;
402 int insert_mode
; /* Nonzero when in insert mode. */
403 int standout_mode
; /* Nonzero when in standout mode. */
405 /* Size of window specified by higher levels.
406 This is the number of lines, from the top of frame downwards,
407 which can participate in insert-line/delete-line operations.
409 Effectively it excludes the bottom frame_height - specified_window_size
410 lines from those operations. */
412 int specified_window
;
414 /* Frame currently being redisplayed; 0 if not currently redisplaying.
415 (Direct output does not count). */
417 FRAME_PTR updating_frame
;
419 /* Provided for lisp packages. */
421 static int system_uses_terminfo
;
423 /* Flag used in tty_show/hide_cursor. */
425 static int tty_cursor_hidden
;
429 extern char *tgetstr ();
433 /* We aren't X windows, but we aren't termcap either. This makes me
434 uncertain as to what value to use for frame.output_method. For
435 this file, we'll define FRAME_TERMCAP_P to be zero so that our
436 output hooks get called instead of the termcap functions. Probably
437 the best long-term solution is to define an output_windows_nt... */
439 #undef FRAME_TERMCAP_P
440 #define FRAME_TERMCAP_P(_f_) 0
441 #endif /* WINDOWSNT */
446 if (!NILP (Vring_bell_function
))
448 Lisp_Object function
;
450 /* Temporarily set the global variable to nil
451 so that if we get an error, it stays nil
452 and we don't call it over and over.
454 We don't specbind it, because that would carefully
455 restore the bad value if there's an error
456 and make the loop of errors happen anyway. */
458 function
= Vring_bell_function
;
459 Vring_bell_function
= Qnil
;
463 Vring_bell_function
= function
;
465 else if (!FRAME_TERMCAP_P (XFRAME (selected_frame
)))
466 (*ring_bell_hook
) ();
468 OUTPUT (TS_visible_bell
&& visible_bell
? TS_visible_bell
: TS_bell
);
472 set_terminal_modes ()
474 if (FRAME_TERMCAP_P (XFRAME (selected_frame
)))
476 OUTPUT_IF (TS_termcap_modes
);
477 OUTPUT_IF (TS_cursor_visible
);
478 OUTPUT_IF (TS_keypad_mode
);
482 (*set_terminal_modes_hook
) ();
486 reset_terminal_modes ()
488 if (FRAME_TERMCAP_P (XFRAME (selected_frame
)))
490 if (TN_standout_width
< 0)
491 turn_off_highlight ();
493 OUTPUT_IF (TS_end_keypad_mode
);
494 OUTPUT_IF (TS_cursor_normal
);
495 OUTPUT_IF (TS_end_termcap_modes
);
496 OUTPUT_IF (TS_orig_pair
);
497 /* Output raw CR so kernel can track the cursor hpos. */
498 /* But on magic-cookie terminals this can erase an end-standout
499 marker and cause the rest of the frame to be in standout, so
501 if (TN_standout_width
>= 0)
505 else if (reset_terminal_modes_hook
)
506 (*reset_terminal_modes_hook
) ();
514 if (!FRAME_TERMCAP_P (f
))
515 update_begin_hook (f
);
522 if (FRAME_TERMCAP_P (f
))
524 if (!XWINDOW (selected_window
)->cursor_off_p
)
527 background_highlight ();
528 standout_requested
= 0;
533 updating_frame
= NULL
;
537 set_terminal_window (size
)
540 if (FRAME_TERMCAP_P (updating_frame
))
542 specified_window
= size
? size
: FRAME_HEIGHT (updating_frame
);
543 if (scroll_region_ok
)
544 set_scroll_region (0, specified_window
);
547 set_terminal_window_hook (size
);
551 set_scroll_region (start
, stop
)
555 struct frame
*sf
= XFRAME (selected_frame
);
557 if (TS_set_scroll_region
)
558 buf
= tparam (TS_set_scroll_region
, 0, 0, start
, stop
- 1);
559 else if (TS_set_scroll_region_1
)
560 buf
= tparam (TS_set_scroll_region_1
, 0, 0,
561 FRAME_HEIGHT (sf
), start
,
562 FRAME_HEIGHT (sf
) - stop
,
565 buf
= tparam (TS_set_window
, 0, 0, start
, 0, stop
, FRAME_WIDTH (sf
));
577 OUTPUT (TS_insert_mode
);
585 OUTPUT (TS_end_insert_mode
);
589 /* Handle highlighting when TN_standout_width (termcap sg) is not specified.
590 In these terminals, output is affected by the value of standout
591 mode when the output is written.
593 These functions are called on all terminals, but do nothing
594 on terminals whose standout mode does not work that way. */
597 turn_off_highlight ()
599 if (TN_standout_width
< 0)
602 OUTPUT_IF (TS_end_standout_mode
);
610 if (TN_standout_width
< 0)
613 OUTPUT_IF (TS_standout_mode
);
622 turn_off_highlight ();
624 turn_on_highlight ();
628 /* Make cursor invisible. */
633 if (tty_cursor_hidden
== 0)
635 tty_cursor_hidden
= 1;
636 OUTPUT_IF (TS_cursor_invisible
);
641 /* Ensure that cursor is visible. */
646 if (tty_cursor_hidden
)
648 tty_cursor_hidden
= 0;
649 OUTPUT_IF (TS_cursor_normal
);
650 OUTPUT_IF (TS_cursor_visible
);
655 /* Set standout mode to the state it should be in for
656 empty space inside windows. What this is,
657 depends on the user option inverse-video. */
660 background_highlight ()
662 if (TN_standout_width
>= 0)
665 turn_on_highlight ();
667 turn_off_highlight ();
670 /* Set standout mode to the mode specified for the text to be output. */
673 highlight_if_desired ()
675 if (TN_standout_width
>= 0)
677 if (!inverse_video
== !standout_requested
)
678 turn_off_highlight ();
680 turn_on_highlight ();
683 /* Handle standout mode for terminals in which TN_standout_width >= 0.
684 On these terminals, standout is controlled by markers that
685 live inside the terminal's memory. TN_standout_width is the width
686 that the marker occupies in memory. Standout runs from the marker
687 to the end of the line on some terminals, or to the next
688 turn-off-standout marker (TS_end_standout_mode) string
689 on other terminals. */
691 /* Write a standout marker or end-standout marker at the front of the line
692 at vertical position vpos. */
695 write_standout_marker (flag
, vpos
)
699 || (TS_end_standout_mode
&& !TF_teleray
&& !se_is_so
700 && !(TF_xs
&& TN_standout_width
== 0)))
703 cmplus (TN_standout_width
);
704 OUTPUT (flag
? TS_standout_mode
: TS_end_standout_mode
);
705 chars_wasted
[curY
] = TN_standout_width
| 0100;
709 /* External interface to control of standout mode.
710 Call this when about to modify line at position VPOS
711 and not change whether it is highlighted. */
714 reassert_line_highlight (highlight
, vpos
)
718 struct frame
*f
= updating_frame
? updating_frame
: XFRAME (selected_frame
);
719 if (! FRAME_TERMCAP_P (f
))
721 (*reassert_line_highlight_hook
) (highlight
, vpos
);
724 if (TN_standout_width
< 0)
725 /* Handle terminals where standout takes affect at output time */
726 standout_requested
= highlight
;
727 else if (chars_wasted
&& chars_wasted
[vpos
] == 0)
728 /* For terminals with standout markers, write one on this line
729 if there isn't one already. */
730 write_standout_marker (inverse_video
? !highlight
: highlight
, vpos
);
733 /* Call this when about to modify line at position VPOS
734 and change whether it is highlighted. */
737 change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
738 int new_highlight
, vpos
, y
, first_unused_hpos
;
740 standout_requested
= new_highlight
;
741 if (! FRAME_TERMCAP_P (updating_frame
))
743 (*change_line_highlight_hook
) (new_highlight
, vpos
, y
, first_unused_hpos
);
749 if (TN_standout_width
< 0)
750 background_highlight ();
751 /* If line starts with a marker, delete the marker */
752 else if (TS_clr_line
&& chars_wasted
[curY
])
755 /* On Teleray, make sure to erase the SO marker. */
758 cmgoto (curY
- 1, FRAME_WIDTH (XFRAME (selected_frame
)) - 4);
760 curY
++; /* ESC S moves to next line where the TS_standout_mode was */
764 cmgoto (curY
, 0); /* reposition to kill standout marker */
766 clear_end_of_line_raw (first_unused_hpos
);
767 reassert_line_highlight (new_highlight
, curY
);
771 /* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
772 frame-relative coordinates. */
775 cursor_to (vpos
, hpos
)
778 struct frame
*f
= updating_frame
? updating_frame
: XFRAME (selected_frame
);
780 if (! FRAME_TERMCAP_P (f
) && cursor_to_hook
)
782 (*cursor_to_hook
) (vpos
, hpos
);
786 /* Detect the case where we are called from reset_sys_modes
787 and the costs have never been calculated. Do nothing. */
788 if (chars_wasted
== 0)
791 hpos
+= chars_wasted
[vpos
] & 077;
792 if (curY
== vpos
&& curX
== hpos
)
794 if (!TF_standout_motion
)
795 background_highlight ();
796 if (!TF_insmode_motion
)
801 /* Similar but don't take any account of the wasted characters. */
804 raw_cursor_to (row
, col
)
807 struct frame
*f
= updating_frame
? updating_frame
: XFRAME (selected_frame
);
808 if (! FRAME_TERMCAP_P (f
))
810 (*raw_cursor_to_hook
) (row
, col
);
813 if (curY
== row
&& curX
== col
)
815 if (!TF_standout_motion
)
816 background_highlight ();
817 if (!TF_insmode_motion
)
822 /* Erase operations */
824 /* clear from cursor to end of frame */
830 if (clear_to_end_hook
&& ! FRAME_TERMCAP_P (updating_frame
))
832 (*clear_to_end_hook
) ();
835 if (TS_clr_to_bottom
)
837 background_highlight ();
838 OUTPUT (TS_clr_to_bottom
);
839 bzero (chars_wasted
+ curY
,
840 FRAME_HEIGHT (XFRAME (selected_frame
)) - curY
);
844 for (i
= curY
; i
< FRAME_HEIGHT (XFRAME (selected_frame
)); i
++)
847 clear_end_of_line_raw (FRAME_WIDTH (XFRAME (selected_frame
)));
852 /* Clear entire frame */
857 struct frame
*sf
= XFRAME (selected_frame
);
860 && ! FRAME_TERMCAP_P ((updating_frame
? updating_frame
: sf
)))
862 (*clear_frame_hook
) ();
867 background_highlight ();
868 OUTPUT (TS_clr_frame
);
869 bzero (chars_wasted
, FRAME_HEIGHT (sf
));
879 /* Clear to end of line, but do not clear any standout marker.
880 Assumes that the cursor is positioned at a character of real text,
881 which implies it cannot be before a standout marker
882 unless the marker has zero width.
884 Note that the cursor may be moved. */
887 clear_end_of_line (first_unused_hpos
)
888 int first_unused_hpos
;
890 if (FRAME_TERMCAP_P (XFRAME (selected_frame
))
892 && TN_standout_width
== 0 && curX
== 0 && chars_wasted
[curY
] != 0)
893 write_glyphs (&space_glyph
, 1);
894 clear_end_of_line_raw (first_unused_hpos
);
897 /* Clear from cursor to end of line.
898 Assume that the line is already clear starting at column first_unused_hpos.
899 If the cursor is at a standout marker, erase the marker.
901 Note that the cursor may be moved, on terminals lacking a `ce' string. */
904 clear_end_of_line_raw (first_unused_hpos
)
905 int first_unused_hpos
;
909 if (clear_end_of_line_hook
910 && ! FRAME_TERMCAP_P ((updating_frame
912 : XFRAME (selected_frame
))))
914 (*clear_end_of_line_hook
) (first_unused_hpos
);
918 /* Detect the case where we are called from reset_sys_modes
919 and the costs have never been calculated. Do nothing. */
920 if (chars_wasted
== 0)
923 first_unused_hpos
+= chars_wasted
[curY
] & 077;
924 if (curX
>= first_unused_hpos
)
926 /* Notice if we are erasing a magic cookie */
928 chars_wasted
[curY
] = 0;
929 background_highlight ();
932 OUTPUT1 (TS_clr_line
);
935 { /* have to do it the hard way */
936 struct frame
*sf
= XFRAME (selected_frame
);
939 /* Do not write in last row last col with Auto-wrap on. */
940 if (AutoWrap
&& curY
== FRAME_HEIGHT (sf
) - 1
941 && first_unused_hpos
== FRAME_WIDTH (sf
))
944 for (i
= curX
; i
< first_unused_hpos
; i
++)
947 fputc (' ', termscript
);
950 cmplus (first_unused_hpos
- curX
);
954 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes and
955 store them at DST. Do not write more than DST_LEN bytes. That may
956 require stopping before all SRC_LEN input glyphs have been
959 We store the number of glyphs actually converted in *CONSUMED. The
960 return value is the number of bytes store in DST. */
963 encode_terminal_code (src
, dst
, src_len
, dst_len
, consumed
)
967 int dst_len
, *consumed
;
969 struct glyph
*src_start
= src
, *src_end
= src
+ src_len
;
970 unsigned char *dst_start
= dst
, *dst_end
= dst
+ dst_len
;
972 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *buf
;
974 register int tlen
= GLYPH_TABLE_LENGTH
;
975 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
977 struct coding_system
*coding
;
979 /* If terminal_coding does any conversion, use it, otherwise use
980 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
981 because it always return 1 if the member src_multibyte is 1. */
982 coding
= (terminal_coding
.common_flags
& CODING_REQUIRE_ENCODING_MASK
984 : &safe_terminal_coding
);
986 while (src
< src_end
)
988 /* We must skip glyphs to be padded for a wide character. */
989 if (! CHAR_GLYPH_PADDING_P (*src
))
991 g
= GLYPH_FROM_CHAR_GLYPH (src
[0]);
993 if (g
< 0 || g
>= tlen
)
995 /* This glyph doesn't has an entry in Vglyph_table. */
996 if (! CHAR_VALID_P (src
->u
.ch
, 0))
1000 coding
->src_multibyte
= 0;
1004 len
= CHAR_STRING (src
->u
.ch
, workbuf
);
1006 coding
->src_multibyte
= 1;
1011 /* This glyph has an entry in Vglyph_table,
1012 so process any alias before testing for simpleness. */
1013 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
1015 if (GLYPH_SIMPLE_P (tbase
, tlen
, g
))
1017 /* We set the multi-byte form of a character in G
1018 (that should be an ASCII character) at
1020 workbuf
[0] = FAST_GLYPH_CHAR (g
);
1023 coding
->src_multibyte
= 0;
1027 /* We have a string in Vglyph_table. */
1028 len
= GLYPH_LENGTH (tbase
, g
);
1029 buf
= GLYPH_STRING (tbase
, g
);
1030 coding
->src_multibyte
= STRING_MULTIBYTE (tbase
[g
]);
1034 result
= encode_coding (coding
, buf
, dst
, len
, dst_end
- dst
);
1035 len
-= coding
->consumed
;
1036 dst
+= coding
->produced
;
1037 if (result
== CODING_FINISH_INSUFFICIENT_DST
1038 || (result
== CODING_FINISH_INSUFFICIENT_SRC
1039 && len
> dst_end
- dst
))
1040 /* The remaining output buffer is too short. We must
1041 break the loop here without increasing SRC so that the
1042 next call of this function starts from the same glyph. */
1047 /* This is the case that a code of the range 0200..0237
1048 exists in buf. We must just write out such a code. */
1049 buf
+= coding
->consumed
;
1057 *consumed
= src
- src_start
;
1058 return (dst
- dst_start
);
1063 write_glyphs (string
, len
)
1064 register struct glyph
*string
;
1067 int produced
, consumed
;
1068 struct frame
*sf
= XFRAME (selected_frame
);
1069 struct frame
*f
= updating_frame
? updating_frame
: sf
;
1070 unsigned char conversion_buffer
[1024];
1071 int conversion_buffer_size
= sizeof conversion_buffer
;
1073 if (write_glyphs_hook
1074 && ! FRAME_TERMCAP_P (f
))
1076 (*write_glyphs_hook
) (string
, len
);
1083 /* Don't dare write in last column of bottom line, if Auto-Wrap,
1084 since that would scroll the whole frame on some terminals. */
1087 && curY
+ 1 == FRAME_HEIGHT (sf
)
1088 && (curX
+ len
- (chars_wasted
[curY
] & 077) == FRAME_WIDTH (sf
)))
1095 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
1097 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
1101 /* Identify a run of glyphs with the same face. */
1102 int face_id
= string
->face_id
;
1105 for (n
= 1; n
< len
; ++n
)
1106 if (string
[n
].face_id
!= face_id
)
1109 /* Turn appearance modes of the face of the run on. */
1110 highlight_if_desired ();
1111 turn_on_face (f
, face_id
);
1115 /* We use a fixed size (1024 bytes) of conversion buffer.
1116 Usually it is sufficient, but if not, we just repeat the
1118 produced
= encode_terminal_code (string
, conversion_buffer
,
1119 n
, conversion_buffer_size
,
1123 fwrite (conversion_buffer
, 1, produced
, stdout
);
1124 if (ferror (stdout
))
1127 fwrite (conversion_buffer
, 1, produced
, termscript
);
1134 /* Turn appearance modes off. */
1135 turn_off_face (f
, face_id
);
1136 turn_off_highlight ();
1139 /* We may have to output some codes to terminate the writing. */
1140 if (CODING_REQUIRE_FLUSHING (&terminal_coding
))
1142 terminal_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1143 encode_coding (&terminal_coding
, "", conversion_buffer
,
1144 0, conversion_buffer_size
);
1145 if (terminal_coding
.produced
> 0)
1147 fwrite (conversion_buffer
, 1, terminal_coding
.produced
, stdout
);
1148 if (ferror (stdout
))
1151 fwrite (conversion_buffer
, 1, terminal_coding
.produced
,
1159 /* If start is zero, insert blanks instead of a string at start */
1162 insert_glyphs (start
, len
)
1163 register struct glyph
*start
;
1167 struct glyph
*glyph
= NULL
;
1168 struct frame
*f
, *sf
;
1173 if (insert_glyphs_hook
)
1175 (*insert_glyphs_hook
) (start
, len
);
1179 sf
= XFRAME (selected_frame
);
1180 f
= updating_frame
? updating_frame
: sf
;
1182 if (TS_ins_multi_chars
)
1184 buf
= tparam (TS_ins_multi_chars
, 0, 0, len
);
1188 write_glyphs (start
, len
);
1194 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */
1195 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
1198 int produced
, consumed
;
1199 unsigned char conversion_buffer
[1024];
1200 int conversion_buffer_size
= sizeof conversion_buffer
;
1202 OUTPUT1_IF (TS_ins_char
);
1205 conversion_buffer
[0] = SPACEGLYPH
;
1210 highlight_if_desired ();
1211 turn_on_face (f
, start
->face_id
);
1214 /* We must open sufficient space for a character which
1215 occupies more than one column. */
1216 while (len
&& CHAR_GLYPH_PADDING_P (*start
))
1218 OUTPUT1_IF (TS_ins_char
);
1223 /* This is the last glyph. */
1224 terminal_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1226 /* The size of conversion buffer (1024 bytes) is surely
1227 sufficient for just one glyph. */
1228 produced
= encode_terminal_code (glyph
, conversion_buffer
, 1,
1229 conversion_buffer_size
, &consumed
);
1234 fwrite (conversion_buffer
, 1, produced
, stdout
);
1235 if (ferror (stdout
))
1238 fwrite (conversion_buffer
, 1, produced
, termscript
);
1241 OUTPUT1_IF (TS_pad_inserted_char
);
1244 turn_off_face (f
, glyph
->face_id
);
1245 turn_off_highlight ();
1259 if (delete_glyphs_hook
&& ! FRAME_TERMCAP_P (updating_frame
))
1261 (*delete_glyphs_hook
) (n
);
1265 if (delete_in_insert_mode
)
1272 OUTPUT_IF (TS_delete_mode
);
1275 if (TS_del_multi_chars
)
1277 buf
= tparam (TS_del_multi_chars
, 0, 0, n
);
1282 for (i
= 0; i
< n
; i
++)
1283 OUTPUT1 (TS_del_char
);
1284 if (!delete_in_insert_mode
)
1285 OUTPUT_IF (TS_end_delete_mode
);
1288 /* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
1291 ins_del_lines (vpos
, n
)
1294 char *multi
= n
> 0 ? TS_ins_multi_lines
: TS_del_multi_lines
;
1295 char *single
= n
> 0 ? TS_ins_line
: TS_del_line
;
1296 char *scroll
= n
> 0 ? TS_rev_scroll
: TS_fwd_scroll
;
1299 register int i
= n
> 0 ? n
: -n
;
1302 if (ins_del_lines_hook
&& ! FRAME_TERMCAP_P (updating_frame
))
1304 (*ins_del_lines_hook
) (vpos
, n
);
1308 sf
= XFRAME (selected_frame
);
1310 /* If the lines below the insertion are being pushed
1311 into the end of the window, this is the same as clearing;
1312 and we know the lines are already clear, since the matching
1313 deletion has already been done. So can ignore this. */
1314 /* If the lines below the deletion are blank lines coming
1315 out of the end of the window, don't bother,
1316 as there will be a matching inslines later that will flush them. */
1317 if (scroll_region_ok
&& vpos
+ i
>= specified_window
)
1319 if (!memory_below_frame
&& vpos
+ i
>= FRAME_HEIGHT (sf
))
1324 raw_cursor_to (vpos
, 0);
1325 background_highlight ();
1326 buf
= tparam (multi
, 0, 0, i
);
1332 raw_cursor_to (vpos
, 0);
1333 background_highlight ();
1341 set_scroll_region (vpos
, specified_window
);
1343 raw_cursor_to (specified_window
- 1, 0);
1345 raw_cursor_to (vpos
, 0);
1346 background_highlight ();
1348 OUTPUTL (scroll
, specified_window
- vpos
);
1349 set_scroll_region (0, specified_window
);
1352 if (TN_standout_width
>= 0)
1354 register int lower_limit
1357 : FRAME_HEIGHT (sf
));
1361 bcopy (&chars_wasted
[vpos
- n
], &chars_wasted
[vpos
],
1362 lower_limit
- vpos
+ n
);
1363 bzero (&chars_wasted
[lower_limit
+ n
], - n
);
1367 bcopy (&chars_wasted
[vpos
], ©buf
[vpos
], lower_limit
- vpos
- n
);
1368 bcopy (©buf
[vpos
], &chars_wasted
[vpos
+ n
],
1369 lower_limit
- vpos
- n
);
1370 bzero (&chars_wasted
[vpos
], n
);
1373 if (!scroll_region_ok
&& memory_below_frame
&& n
< 0)
1375 cursor_to (FRAME_HEIGHT (sf
) + n
, 0);
1380 /* Compute cost of sending "str", in characters,
1381 not counting any line-dependent padding. */
1389 tputs (str
, 0, evalcost
);
1393 /* Compute cost of sending "str", in characters,
1394 counting any line-dependent padding at one line. */
1397 string_cost_one_line (str
)
1402 tputs (str
, 1, evalcost
);
1406 /* Compute per line amount of line-dependent padding,
1407 in tenths of characters. */
1415 tputs (str
, 0, evalcost
);
1418 tputs (str
, 10, evalcost
);
1423 /* char_ins_del_cost[n] is cost of inserting N characters.
1424 char_ins_del_cost[-n] is cost of deleting N characters.
1425 The length of this vector is based on max_frame_width. */
1427 int *char_ins_del_vector
;
1429 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_WIDTH ((f))])
1434 calculate_ins_del_char_costs (frame
)
1437 int ins_startup_cost
, del_startup_cost
;
1438 int ins_cost_per_char
, del_cost_per_char
;
1442 if (TS_ins_multi_chars
)
1444 ins_cost_per_char
= 0;
1445 ins_startup_cost
= string_cost_one_line (TS_ins_multi_chars
);
1447 else if (TS_ins_char
|| TS_pad_inserted_char
1448 || (TS_insert_mode
&& TS_end_insert_mode
))
1450 ins_startup_cost
= (30 * (string_cost (TS_insert_mode
)
1451 + string_cost (TS_end_insert_mode
))) / 100;
1452 ins_cost_per_char
= (string_cost_one_line (TS_ins_char
)
1453 + string_cost_one_line (TS_pad_inserted_char
));
1457 ins_startup_cost
= 9999;
1458 ins_cost_per_char
= 0;
1461 if (TS_del_multi_chars
)
1463 del_cost_per_char
= 0;
1464 del_startup_cost
= string_cost_one_line (TS_del_multi_chars
);
1466 else if (TS_del_char
)
1468 del_startup_cost
= (string_cost (TS_delete_mode
)
1469 + string_cost (TS_end_delete_mode
));
1470 if (delete_in_insert_mode
)
1471 del_startup_cost
/= 2;
1472 del_cost_per_char
= string_cost_one_line (TS_del_char
);
1476 del_startup_cost
= 9999;
1477 del_cost_per_char
= 0;
1480 /* Delete costs are at negative offsets */
1481 p
= &char_ins_del_cost (frame
)[0];
1482 for (i
= FRAME_WIDTH (frame
); --i
>= 0;)
1483 *--p
= (del_startup_cost
+= del_cost_per_char
);
1485 /* Doing nothing is free */
1486 p
= &char_ins_del_cost (frame
)[0];
1489 /* Insert costs are at positive offsets */
1490 for (i
= FRAME_WIDTH (frame
); --i
>= 0;)
1491 *p
++ = (ins_startup_cost
+= ins_cost_per_char
);
1495 calculate_costs (frame
)
1498 register char *f
= (TS_set_scroll_region
1499 ? TS_set_scroll_region
1500 : TS_set_scroll_region_1
);
1502 FRAME_COST_BAUD_RATE (frame
) = baud_rate
;
1504 scroll_region_cost
= string_cost (f
);
1506 /* These variables are only used for terminal stuff. They are allocated
1507 once for the terminal frame of X-windows emacs, but not used afterwards.
1509 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1510 X turns off char_ins_del_ok.
1512 chars_wasted and copybuf are only used here in term.c in cases where
1513 the term hook isn't called. */
1515 max_frame_height
= max (max_frame_height
, FRAME_HEIGHT (frame
));
1516 max_frame_width
= max (max_frame_width
, FRAME_WIDTH (frame
));
1518 if (chars_wasted
!= 0)
1519 chars_wasted
= (char *) xrealloc (chars_wasted
, max_frame_height
);
1521 chars_wasted
= (char *) xmalloc (max_frame_height
);
1524 copybuf
= (char *) xrealloc (copybuf
, max_frame_height
);
1526 copybuf
= (char *) xmalloc (max_frame_height
);
1528 if (char_ins_del_vector
!= 0)
1530 = (int *) xrealloc (char_ins_del_vector
,
1532 + 2 * max_frame_width
* sizeof (int)));
1535 = (int *) xmalloc (sizeof (int)
1536 + 2 * max_frame_width
* sizeof (int));
1538 bzero (chars_wasted
, max_frame_height
);
1539 bzero (copybuf
, max_frame_height
);
1540 bzero (char_ins_del_vector
, (sizeof (int)
1541 + 2 * max_frame_width
* sizeof (int)));
1543 if (f
&& (!TS_ins_line
&& !TS_del_line
))
1544 do_line_insertion_deletion_costs (frame
,
1545 TS_rev_scroll
, TS_ins_multi_lines
,
1546 TS_fwd_scroll
, TS_del_multi_lines
,
1549 do_line_insertion_deletion_costs (frame
,
1550 TS_ins_line
, TS_ins_multi_lines
,
1551 TS_del_line
, TS_del_multi_lines
,
1554 calculate_ins_del_char_costs (frame
);
1556 /* Don't use TS_repeat if its padding is worse than sending the chars */
1557 if (TS_repeat
&& per_line_cost (TS_repeat
) * baud_rate
< 9000)
1558 RPov
= string_cost (TS_repeat
);
1560 RPov
= FRAME_WIDTH (frame
) * 2;
1562 cmcostinit (); /* set up cursor motion costs */
1569 /* Termcap capability names that correspond directly to X keysyms.
1570 Some of these (marked "terminfo") aren't supplied by old-style
1571 (Berkeley) termcap entries. They're listed in X keysym order;
1572 except we put the keypad keys first, so that if they clash with
1573 other keys (as on the IBM PC keyboard) they get overridden.
1576 static struct fkey_table keys
[] =
1578 "kh", "home", /* termcap */
1579 "kl", "left", /* termcap */
1580 "ku", "up", /* termcap */
1581 "kr", "right", /* termcap */
1582 "kd", "down", /* termcap */
1583 "%8", "prior", /* terminfo */
1584 "%5", "next", /* terminfo */
1585 "@7", "end", /* terminfo */
1586 "@1", "begin", /* terminfo */
1587 "*6", "select", /* terminfo */
1588 "%9", "print", /* terminfo */
1589 "@4", "execute", /* terminfo --- actually the `command' key */
1591 * "insert" --- see below
1593 "&8", "undo", /* terminfo */
1594 "%0", "redo", /* terminfo */
1595 "%7", "menu", /* terminfo --- actually the `options' key */
1596 "@0", "find", /* terminfo */
1597 "@2", "cancel", /* terminfo */
1598 "%1", "help", /* terminfo */
1600 * "break" goes here, but can't be reliably intercepted with termcap
1602 "&4", "reset", /* terminfo --- actually `restart' */
1604 * "system" and "user" --- no termcaps
1606 "kE", "clearline", /* terminfo */
1607 "kA", "insertline", /* terminfo */
1608 "kL", "deleteline", /* terminfo */
1609 "kI", "insertchar", /* terminfo */
1610 "kD", "deletechar", /* terminfo */
1611 "kB", "backtab", /* terminfo */
1613 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1615 "@8", "kp-enter", /* terminfo */
1617 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1618 * "kp-multiply", "kp-add", "kp-separator",
1619 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1620 * --- no termcaps for any of these.
1622 "K4", "kp-1", /* terminfo */
1624 * "kp-2" --- no termcap
1626 "K5", "kp-3", /* terminfo */
1628 * "kp-4" --- no termcap
1630 "K2", "kp-5", /* terminfo */
1632 * "kp-6" --- no termcap
1634 "K1", "kp-7", /* terminfo */
1636 * "kp-8" --- no termcap
1638 "K3", "kp-9", /* terminfo */
1640 * "kp-equal" --- no termcap
1653 static char **term_get_fkeys_arg
;
1654 static Lisp_Object
term_get_fkeys_1 ();
1656 /* Find the escape codes sent by the function keys for Vfunction_key_map.
1657 This function scans the termcap function key sequence entries, and
1658 adds entries to Vfunction_key_map for each function key it finds. */
1661 term_get_fkeys (address
)
1664 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1665 errors during the call. The only errors should be from Fdefine_key
1666 when given a key sequence containing an invalid prefix key. If the
1667 termcap defines function keys which use a prefix that is already bound
1668 to a command by the default bindings, we should silently ignore that
1669 function key specification, rather than giving the user an error and
1670 refusing to run at all on such a terminal. */
1672 extern Lisp_Object
Fidentity ();
1673 term_get_fkeys_arg
= address
;
1674 internal_condition_case (term_get_fkeys_1
, Qerror
, Fidentity
);
1682 char **address
= term_get_fkeys_arg
;
1684 /* This can happen if CANNOT_DUMP or with strange options. */
1686 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
1688 for (i
= 0; i
< (sizeof (keys
)/sizeof (keys
[0])); i
++)
1690 char *sequence
= tgetstr (keys
[i
].cap
, address
);
1692 Fdefine_key (Vfunction_key_map
, build_string (sequence
),
1693 Fmake_vector (make_number (1),
1694 intern (keys
[i
].name
)));
1697 /* The uses of the "k0" capability are inconsistent; sometimes it
1698 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1699 We will attempt to politely accommodate both systems by testing for
1700 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1703 char *k_semi
= tgetstr ("k;", address
);
1704 char *k0
= tgetstr ("k0", address
);
1705 char *k0_name
= "f10";
1709 Fdefine_key (Vfunction_key_map
, build_string (k_semi
),
1710 Fmake_vector (make_number (1), intern ("f10")));
1715 Fdefine_key (Vfunction_key_map
, build_string (k0
),
1716 Fmake_vector (make_number (1), intern (k0_name
)));
1719 /* Set up cookies for numbered function keys above f10. */
1721 char fcap
[3], fkey
[4];
1723 fcap
[0] = 'F'; fcap
[2] = '\0';
1724 for (i
= 11; i
< 64; i
++)
1727 fcap
[1] = '1' + i
- 11;
1729 fcap
[1] = 'A' + i
- 20;
1731 fcap
[1] = 'a' + i
- 46;
1734 char *sequence
= tgetstr (fcap
, address
);
1737 sprintf (fkey
, "f%d", i
);
1738 Fdefine_key (Vfunction_key_map
, build_string (sequence
),
1739 Fmake_vector (make_number (1),
1747 * Various mappings to try and get a better fit.
1750 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1751 if (!tgetstr (cap1, address)) \
1753 char *sequence = tgetstr (cap2, address); \
1755 Fdefine_key (Vfunction_key_map, build_string (sequence), \
1756 Fmake_vector (make_number (1), \
1760 /* if there's no key_next keycap, map key_npage to `next' keysym */
1761 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1762 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1763 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1764 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1765 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1766 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1767 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1769 /* IBM has their own non-standard dialect of terminfo.
1770 If the standard name isn't found, try the IBM name. */
1771 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1772 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1773 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1774 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1775 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1776 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1777 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1778 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1779 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1780 #undef CONDITIONAL_REASSIGN
1787 /***********************************************************************
1788 Character Display Information
1789 ***********************************************************************/
1791 static void append_glyph
P_ ((struct it
*));
1794 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1795 terminal frames if IT->glyph_row != NULL. IT->c is the character
1796 for which to produce glyphs; IT->face_id contains the character's
1797 face. Padding glyphs are appended if IT->c has a IT->pixel_width >
1804 struct glyph
*glyph
, *end
;
1807 xassert (it
->glyph_row
);
1808 glyph
= (it
->glyph_row
->glyphs
[it
->area
]
1809 + it
->glyph_row
->used
[it
->area
]);
1810 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1813 i
< it
->pixel_width
&& glyph
< end
;
1816 glyph
->type
= CHAR_GLYPH
;
1817 glyph
->pixel_width
= 1;
1818 glyph
->u
.ch
= it
->c
;
1819 glyph
->face_id
= it
->face_id
;
1820 glyph
->padding_p
= i
> 0;
1821 glyph
->charpos
= CHARPOS (it
->position
);
1822 glyph
->object
= it
->object
;
1824 ++it
->glyph_row
->used
[it
->area
];
1830 /* Produce glyphs for the display element described by IT. The
1831 function fills output fields of IT with pixel information like the
1832 pixel width and height of a character, and maybe produces glyphs at
1833 the same time if IT->glyph_row is non-null. See the explanation of
1834 struct display_iterator in dispextern.h for an overview. */
1840 /* If a hook is installed, let it do the work. */
1841 xassert (it
->what
== IT_CHARACTER
1842 || it
->what
== IT_COMPOSITION
1843 || it
->what
== IT_IMAGE
1844 || it
->what
== IT_STRETCH
);
1846 /* Nothing but characters are supported on terminal frames. For a
1847 composition sequence, it->c is the first character of the
1849 xassert (it
->what
== IT_CHARACTER
1850 || it
->what
== IT_COMPOSITION
);
1852 if (it
->c
>= 040 && it
->c
< 0177)
1854 it
->pixel_width
= it
->nglyphs
= 1;
1858 else if (it
->c
== '\n')
1859 it
->pixel_width
= it
->nglyphs
= 0;
1860 else if (it
->c
== '\t')
1862 int absolute_x
= (it
->current_x
1863 + it
->continuation_lines_width
);
1865 = (((1 + absolute_x
+ it
->tab_width
- 1)
1870 /* If part of the TAB has been displayed on the previous line
1871 which is continued now, continuation_lines_width will have
1872 been incremented already by the part that fitted on the
1873 continued line. So, we will get the right number of spaces
1875 nspaces
= next_tab_x
- absolute_x
;
1882 it
->pixel_width
= it
->len
= 1;
1890 it
->pixel_width
= nspaces
;
1891 it
->nglyphs
= nspaces
;
1893 else if (SINGLE_BYTE_CHAR_P (it
->c
))
1895 /* Coming here means that it->c is from display table, thus we
1896 must send the code as is to the terminal. Although there's
1897 no way to know how many columns it occupies on a screen, it
1898 is a good assumption that a single byte code has 1-column
1900 it
->pixel_width
= it
->nglyphs
= 1;
1906 /* A multi-byte character. The display width is fixed for all
1907 characters of the set. Some of the glyphs may have to be
1908 ignored because they are already displayed in a continued
1910 int charset
= CHAR_CHARSET (it
->c
);
1912 it
->pixel_width
= CHARSET_WIDTH (charset
);
1913 it
->nglyphs
= it
->pixel_width
;
1919 /* Advance current_x by the pixel width as a convenience for
1921 if (it
->area
== TEXT_AREA
)
1922 it
->current_x
+= it
->pixel_width
;
1923 it
->ascent
= it
->max_ascent
= it
->phys_ascent
= it
->max_phys_ascent
= 0;
1924 it
->descent
= it
->max_descent
= it
->phys_descent
= it
->max_phys_descent
= 1;
1928 /* Get information about special display element WHAT in an
1929 environment described by IT. WHAT is one of IT_TRUNCATION or
1930 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
1931 non-null glyph_row member. This function ensures that fields like
1932 face_id, c, len of IT are left untouched. */
1935 produce_special_glyphs (it
, what
)
1937 enum display_element_type what
;
1943 temp_it
.what
= IT_CHARACTER
;
1945 temp_it
.object
= make_number (0);
1946 bzero (&temp_it
.current
, sizeof temp_it
.current
);
1948 if (what
== IT_CONTINUATION
)
1950 /* Continuation glyph. */
1952 && INTEGERP (DISP_CONTINUE_GLYPH (it
->dp
))
1953 && GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (it
->dp
))))
1955 temp_it
.c
= FAST_GLYPH_CHAR (XINT (DISP_CONTINUE_GLYPH (it
->dp
)));
1956 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
1961 produce_glyphs (&temp_it
);
1962 it
->pixel_width
= temp_it
.pixel_width
;
1963 it
->nglyphs
= temp_it
.pixel_width
;
1965 else if (what
== IT_TRUNCATION
)
1967 /* Truncation glyph. */
1969 && INTEGERP (DISP_TRUNC_GLYPH (it
->dp
))
1970 && GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (it
->dp
))))
1972 temp_it
.c
= FAST_GLYPH_CHAR (XINT (DISP_TRUNC_GLYPH (it
->dp
)));
1973 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
1978 produce_glyphs (&temp_it
);
1979 it
->pixel_width
= temp_it
.pixel_width
;
1980 it
->nglyphs
= temp_it
.pixel_width
;
1987 /* Return an estimation of the pixel height of mode or top lines on
1988 frame F. FACE_ID specifies what line's height to estimate. */
1991 estimate_mode_line_height (f
, face_id
)
1993 enum face_id face_id
;
1995 if (estimate_mode_line_height_hook
)
1996 return estimate_mode_line_height_hook (f
, face_id
);
2003 /***********************************************************************
2005 ***********************************************************************/
2007 /* Value is non-zero if attribute ATTR may be used. ATTR should be
2008 one of the enumerators from enum no_color_bit, or a bit set built
2009 from them. Some display attributes may not be used together with
2010 color; the termcap capability `NC' specifies which ones. */
2012 #define MAY_USE_WITH_COLORS_P(ATTR) \
2013 (TN_max_colors > 0 \
2014 ? (TN_no_color_video & (ATTR)) == 0 \
2017 /* Turn appearances of face FACE_ID on tty frame F on. */
2020 turn_on_face (f
, face_id
)
2024 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2025 long fg
= face
->foreground
;
2026 long bg
= face
->background
;
2028 /* Do this first because TS_end_standout_mode may be the same
2029 as TS_exit_attribute_mode, which turns all appearances off. */
2030 if (MAY_USE_WITH_COLORS_P (NC_REVERSE
))
2032 if (TN_max_colors
> 0)
2034 if (fg
>= 0 && bg
>= 0)
2036 /* If the terminal supports colors, we can set them
2037 below without using reverse video. The face's fg
2038 and bg colors are set as they should appear on
2039 the screen, i.e. they take the inverse-video'ness
2040 of the face already into account. */
2042 else if (inverse_video
)
2044 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
2045 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
2046 toggle_highlight ();
2050 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
2051 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
2052 toggle_highlight ();
2057 /* If we can't display colors, use reverse video
2058 if the face specifies that. */
2061 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
2062 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
2063 toggle_highlight ();
2067 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
2068 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
2069 toggle_highlight ();
2074 if (face
->tty_bold_p
)
2076 if (MAY_USE_WITH_COLORS_P (NC_BOLD
))
2077 OUTPUT1_IF (TS_enter_bold_mode
);
2079 else if (face
->tty_dim_p
)
2080 if (MAY_USE_WITH_COLORS_P (NC_DIM
))
2081 OUTPUT1_IF (TS_enter_dim_mode
);
2083 /* Alternate charset and blinking not yet used. */
2084 if (face
->tty_alt_charset_p
2085 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET
))
2086 OUTPUT1_IF (TS_enter_alt_charset_mode
);
2088 if (face
->tty_blinking_p
2089 && MAY_USE_WITH_COLORS_P (NC_BLINK
))
2090 OUTPUT1_IF (TS_enter_blink_mode
);
2092 if (face
->tty_underline_p
2093 /* Don't underline if that's difficult. */
2094 && TN_magic_cookie_glitch_ul
<= 0
2095 && MAY_USE_WITH_COLORS_P (NC_UNDERLINE
))
2096 OUTPUT1_IF (TS_enter_underline_mode
);
2098 if (TN_max_colors
> 0)
2102 if (fg
>= 0 && TS_set_foreground
)
2104 p
= tparam (TS_set_foreground
, NULL
, 0, (int) fg
);
2109 if (bg
>= 0 && TS_set_background
)
2111 p
= tparam (TS_set_background
, NULL
, 0, (int) bg
);
2119 /* Turn off appearances of face FACE_ID on tty frame F. */
2122 turn_off_face (f
, face_id
)
2126 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2128 xassert (face
!= NULL
);
2130 if (TS_exit_attribute_mode
)
2132 /* Capability "me" will turn off appearance modes double-bright,
2133 half-bright, reverse-video, standout, underline. It may or
2134 may not turn off alt-char-mode. */
2135 if (face
->tty_bold_p
2137 || face
->tty_reverse_p
2138 || face
->tty_alt_charset_p
2139 || face
->tty_blinking_p
2140 || face
->tty_underline_p
)
2142 OUTPUT1_IF (TS_exit_attribute_mode
);
2143 if (strcmp (TS_exit_attribute_mode
, TS_end_standout_mode
) == 0)
2147 if (face
->tty_alt_charset_p
)
2148 OUTPUT_IF (TS_exit_alt_charset_mode
);
2152 /* If we don't have "me" we can only have those appearances
2153 that have exit sequences defined. */
2154 if (face
->tty_alt_charset_p
)
2155 OUTPUT_IF (TS_exit_alt_charset_mode
);
2157 if (face
->tty_underline_p
2158 /* We don't underline if that's difficult. */
2159 && TN_magic_cookie_glitch_ul
<= 0)
2160 OUTPUT_IF (TS_exit_underline_mode
);
2163 /* Switch back to default colors. */
2164 if (TN_max_colors
> 0
2165 && ((face
->foreground
!= FACE_TTY_DEFAULT_COLOR
2166 && face
->foreground
!= FACE_TTY_DEFAULT_FG_COLOR
)
2167 || (face
->background
!= FACE_TTY_DEFAULT_COLOR
2168 && face
->background
!= FACE_TTY_DEFAULT_BG_COLOR
)))
2169 OUTPUT1_IF (TS_orig_pair
);
2173 /* Return non-zero if the terminal is capable to display colors. */
2175 DEFUN ("tty-display-color-p", Ftty_display_color_p
, Stty_display_color_p
,
2177 "Return non-nil if TTY can display colors on FRAME.")
2181 return TN_max_colors
> 0 ? Qt
: Qnil
;
2187 /***********************************************************************
2189 ***********************************************************************/
2192 term_init (terminal_type
)
2193 char *terminal_type
;
2196 char **address
= &area
;
2200 struct frame
*sf
= XFRAME (selected_frame
);
2203 initialize_w32_display ();
2207 area
= (char *) xmalloc (2044);
2212 FrameRows
= FRAME_HEIGHT (sf
);
2213 FrameCols
= FRAME_WIDTH (sf
);
2214 specified_window
= FRAME_HEIGHT (sf
);
2216 delete_in_insert_mode
= 1;
2219 scroll_region_ok
= 0;
2221 /* Seems to insert lines when it's not supposed to, messing
2222 up the display. In doing a trace, it didn't seem to be
2223 called much, so I don't think we're losing anything by
2226 line_ins_del_ok
= 0;
2227 char_ins_del_ok
= 1;
2231 FRAME_CAN_HAVE_SCROLL_BARS (sf
) = 0;
2232 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf
) = vertical_scroll_bar_none
;
2233 TN_max_colors
= 16; /* Required to be non-zero for tty-display-color-p */
2236 #else /* not WINDOWSNT */
2240 status
= tgetent (buffer
, terminal_type
);
2244 fatal ("Cannot open terminfo database file");
2246 fatal ("Cannot open termcap database file");
2252 fatal ("Terminal type %s is not defined.\n\
2253 If that is not the actual type of terminal you have,\n\
2254 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2255 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2256 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2259 fatal ("Terminal type %s is not defined.\n\
2260 If that is not the actual type of terminal you have,\n\
2261 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2262 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2263 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2268 area
= (char *) xmalloc (2044);
2270 area
= (char *) xmalloc (strlen (buffer
));
2271 #endif /* not TERMINFO */
2275 TS_ins_line
= tgetstr ("al", address
);
2276 TS_ins_multi_lines
= tgetstr ("AL", address
);
2277 TS_bell
= tgetstr ("bl", address
);
2278 BackTab
= tgetstr ("bt", address
);
2279 TS_clr_to_bottom
= tgetstr ("cd", address
);
2280 TS_clr_line
= tgetstr ("ce", address
);
2281 TS_clr_frame
= tgetstr ("cl", address
);
2282 ColPosition
= NULL
; /* tgetstr ("ch", address); */
2283 AbsPosition
= tgetstr ("cm", address
);
2284 CR
= tgetstr ("cr", address
);
2285 TS_set_scroll_region
= tgetstr ("cs", address
);
2286 TS_set_scroll_region_1
= tgetstr ("cS", address
);
2287 RowPosition
= tgetstr ("cv", address
);
2288 TS_del_char
= tgetstr ("dc", address
);
2289 TS_del_multi_chars
= tgetstr ("DC", address
);
2290 TS_del_line
= tgetstr ("dl", address
);
2291 TS_del_multi_lines
= tgetstr ("DL", address
);
2292 TS_delete_mode
= tgetstr ("dm", address
);
2293 TS_end_delete_mode
= tgetstr ("ed", address
);
2294 TS_end_insert_mode
= tgetstr ("ei", address
);
2295 Home
= tgetstr ("ho", address
);
2296 TS_ins_char
= tgetstr ("ic", address
);
2297 TS_ins_multi_chars
= tgetstr ("IC", address
);
2298 TS_insert_mode
= tgetstr ("im", address
);
2299 TS_pad_inserted_char
= tgetstr ("ip", address
);
2300 TS_end_keypad_mode
= tgetstr ("ke", address
);
2301 TS_keypad_mode
= tgetstr ("ks", address
);
2302 LastLine
= tgetstr ("ll", address
);
2303 Right
= tgetstr ("nd", address
);
2304 Down
= tgetstr ("do", address
);
2306 Down
= tgetstr ("nl", address
); /* Obsolete name for "do" */
2308 /* VMS puts a carriage return before each linefeed,
2309 so it is not safe to use linefeeds. */
2310 if (Down
&& Down
[0] == '\n' && Down
[1] == '\0')
2313 if (tgetflag ("bs"))
2314 Left
= "\b"; /* can't possibly be longer! */
2315 else /* (Actually, "bs" is obsolete...) */
2316 Left
= tgetstr ("le", address
);
2318 Left
= tgetstr ("bc", address
); /* Obsolete name for "le" */
2319 TS_pad_char
= tgetstr ("pc", address
);
2320 TS_repeat
= tgetstr ("rp", address
);
2321 TS_end_standout_mode
= tgetstr ("se", address
);
2322 TS_fwd_scroll
= tgetstr ("sf", address
);
2323 TS_standout_mode
= tgetstr ("so", address
);
2324 TS_rev_scroll
= tgetstr ("sr", address
);
2325 Wcm
.cm_tab
= tgetstr ("ta", address
);
2326 TS_end_termcap_modes
= tgetstr ("te", address
);
2327 TS_termcap_modes
= tgetstr ("ti", address
);
2328 Up
= tgetstr ("up", address
);
2329 TS_visible_bell
= tgetstr ("vb", address
);
2330 TS_cursor_normal
= tgetstr ("ve", address
);
2331 TS_cursor_visible
= tgetstr ("vs", address
);
2332 TS_cursor_invisible
= tgetstr ("vi", address
);
2333 TS_set_window
= tgetstr ("wi", address
);
2335 TS_enter_underline_mode
= tgetstr ("us", address
);
2336 TS_exit_underline_mode
= tgetstr ("ue", address
);
2337 TN_magic_cookie_glitch_ul
= tgetnum ("ug");
2338 TS_enter_bold_mode
= tgetstr ("md", address
);
2339 TS_enter_dim_mode
= tgetstr ("mh", address
);
2340 TS_enter_blink_mode
= tgetstr ("mb", address
);
2341 TS_enter_reverse_mode
= tgetstr ("mr", address
);
2342 TS_enter_alt_charset_mode
= tgetstr ("as", address
);
2343 TS_exit_alt_charset_mode
= tgetstr ("ae", address
);
2344 TS_exit_attribute_mode
= tgetstr ("me", address
);
2346 MultiUp
= tgetstr ("UP", address
);
2347 MultiDown
= tgetstr ("DO", address
);
2348 MultiLeft
= tgetstr ("LE", address
);
2349 MultiRight
= tgetstr ("RI", address
);
2351 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
2352 color because we can't switch back to the default foreground and
2354 TS_orig_pair
= tgetstr ("op", address
);
2357 TS_set_foreground
= tgetstr ("AF", address
);
2358 TS_set_background
= tgetstr ("AB", address
);
2359 if (!TS_set_foreground
)
2362 TS_set_foreground
= tgetstr ("Sf", address
);
2363 TS_set_background
= tgetstr ("Sb", address
);
2366 TN_max_colors
= tgetnum ("Co");
2367 TN_max_pairs
= tgetnum ("pa");
2369 TN_no_color_video
= tgetnum ("NC");
2370 if (TN_no_color_video
== -1)
2371 TN_no_color_video
= 0;
2374 MagicWrap
= tgetflag ("xn");
2375 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2376 the former flag imply the latter. */
2377 AutoWrap
= MagicWrap
|| tgetflag ("am");
2378 memory_below_frame
= tgetflag ("db");
2379 TF_hazeltine
= tgetflag ("hz");
2380 must_write_spaces
= tgetflag ("in");
2381 meta_key
= tgetflag ("km") || tgetflag ("MT");
2382 TF_insmode_motion
= tgetflag ("mi");
2383 TF_standout_motion
= tgetflag ("ms");
2384 TF_underscore
= tgetflag ("ul");
2385 TF_xs
= tgetflag ("xs");
2386 TF_teleray
= tgetflag ("xt");
2388 term_get_fkeys (address
);
2390 /* Get frame size from system, or else from termcap. */
2393 get_frame_size (&width
, &height
);
2394 FRAME_WIDTH (sf
) = width
;
2395 FRAME_HEIGHT (sf
) = height
;
2398 if (FRAME_WIDTH (sf
) <= 0)
2399 SET_FRAME_WIDTH (sf
, tgetnum ("co"));
2401 /* Keep width and external_width consistent */
2402 SET_FRAME_WIDTH (sf
, FRAME_WIDTH (sf
));
2403 if (FRAME_HEIGHT (sf
) <= 0)
2404 FRAME_HEIGHT (sf
) = tgetnum ("li");
2406 if (FRAME_HEIGHT (sf
) < 3 || FRAME_WIDTH (sf
) < 3)
2407 fatal ("Screen size %dx%d is too small",
2408 FRAME_HEIGHT (sf
), FRAME_WIDTH (sf
));
2410 min_padding_speed
= tgetnum ("pb");
2411 TN_standout_width
= tgetnum ("sg");
2412 TabWidth
= tgetnum ("tw");
2415 /* These capabilities commonly use ^J.
2416 I don't know why, but sending them on VMS does not work;
2417 it causes following spaces to be lost, sometimes.
2418 For now, the simplest fix is to avoid using these capabilities ever. */
2419 if (Down
&& Down
[0] == '\n')
2427 TS_fwd_scroll
= Down
;
2429 PC
= TS_pad_char
? *TS_pad_char
: 0;
2434 /* Turned off since /etc/termcap seems to have :ta= for most terminals
2435 and newer termcap doc does not seem to say there is a default.
2440 if (TS_standout_mode
== 0)
2442 TN_standout_width
= tgetnum ("ug");
2443 TS_end_standout_mode
= tgetstr ("ue", address
);
2444 TS_standout_mode
= tgetstr ("us", address
);
2447 /* If no `se' string, try using a `me' string instead.
2448 If that fails, we can't use standout mode at all. */
2449 if (TS_end_standout_mode
== 0)
2451 char *s
= tgetstr ("me", address
);
2453 TS_end_standout_mode
= s
;
2455 TS_standout_mode
= 0;
2461 /* Teleray: most programs want a space in front of TS_standout_mode,
2462 but Emacs can do without it (and give one extra column). */
2463 TS_standout_mode
= "\033RD";
2464 TN_standout_width
= 1;
2465 /* But that means we cannot rely on ^M to go to column zero! */
2467 /* LF can't be trusted either -- can alter hpos */
2468 /* if move at column 0 thru a line with TS_standout_mode */
2472 /* Special handling for certain terminal types known to need it */
2474 if (!strcmp (terminal_type
, "supdup"))
2476 memory_below_frame
= 1;
2477 Wcm
.cm_losewrap
= 1;
2479 if (!strncmp (terminal_type
, "c10", 3)
2480 || !strcmp (terminal_type
, "perq"))
2482 /* Supply a makeshift :wi string.
2483 This string is not valid in general since it works only
2484 for windows starting at the upper left corner;
2485 but that is all Emacs uses.
2487 This string works only if the frame is using
2488 the top of the video memory, because addressing is memory-relative.
2489 So first check the :ti string to see if that is true.
2491 It would be simpler if the :wi string could go in the termcap
2492 entry, but it can't because it is not fully valid.
2493 If it were in the termcap entry, it would confuse other programs. */
2496 p
= TS_termcap_modes
;
2497 while (*p
&& strcmp (p
, "\033v "))
2500 TS_set_window
= "\033v%C %C %C %C ";
2502 /* Termcap entry often fails to have :in: flag */
2503 must_write_spaces
= 1;
2504 /* :ti string typically fails to have \E^G! in it */
2505 /* This limits scope of insert-char to one line. */
2506 strcpy (area
, TS_termcap_modes
);
2507 strcat (area
, "\033\007!");
2508 TS_termcap_modes
= area
;
2509 area
+= strlen (area
) + 1;
2511 /* Change all %+ parameters to %C, to handle
2512 values above 96 correctly for the C100. */
2515 if (p
[0] == '%' && p
[1] == '+')
2521 FrameRows
= FRAME_HEIGHT (sf
);
2522 FrameCols
= FRAME_WIDTH (sf
);
2523 specified_window
= FRAME_HEIGHT (sf
);
2525 if (Wcm_init () == -1) /* can't do cursor motion */
2527 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2528 It lacks the ability to position the cursor.\n\
2529 If that is not the actual type of terminal you have, use either the\n\
2530 DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
2531 or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2535 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2536 It lacks the ability to position the cursor.\n\
2537 If that is not the actual type of terminal you have,\n\
2538 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2539 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2540 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2542 # else /* TERMCAP */
2543 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2544 It lacks the ability to position the cursor.\n\
2545 If that is not the actual type of terminal you have,\n\
2546 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2547 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2548 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2550 # endif /* TERMINFO */
2552 if (FRAME_HEIGHT (sf
) <= 0
2553 || FRAME_WIDTH (sf
) <= 0)
2554 fatal ("The frame size has not been specified");
2556 delete_in_insert_mode
2557 = TS_delete_mode
&& TS_insert_mode
2558 && !strcmp (TS_delete_mode
, TS_insert_mode
);
2560 se_is_so
= (TS_standout_mode
2561 && TS_end_standout_mode
2562 && !strcmp (TS_standout_mode
, TS_end_standout_mode
));
2564 /* Remove width of standout marker from usable width of line */
2565 if (TN_standout_width
> 0)
2566 SET_FRAME_WIDTH (sf
, FRAME_WIDTH (sf
) - TN_standout_width
);
2568 UseTabs
= tabs_safe_p () && TabWidth
== 8;
2572 && (TS_set_window
|| TS_set_scroll_region
|| TS_set_scroll_region_1
));
2574 line_ins_del_ok
= (((TS_ins_line
|| TS_ins_multi_lines
)
2575 && (TS_del_line
|| TS_del_multi_lines
))
2576 || (scroll_region_ok
&& TS_fwd_scroll
&& TS_rev_scroll
));
2578 char_ins_del_ok
= ((TS_ins_char
|| TS_insert_mode
2579 || TS_pad_inserted_char
|| TS_ins_multi_chars
)
2580 && (TS_del_char
|| TS_del_multi_chars
));
2582 fast_clear_end_of_line
= TS_clr_line
!= 0;
2585 if (read_socket_hook
) /* Baudrate is somewhat */
2586 /* meaningless in this case */
2589 FRAME_CAN_HAVE_SCROLL_BARS (sf
) = 0;
2590 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf
) = vertical_scroll_bar_none
;
2591 #endif /* WINDOWSNT */
2596 fatal (str
, arg1
, arg2
)
2597 char *str
, *arg1
, *arg2
;
2599 fprintf (stderr
, "emacs: ");
2600 fprintf (stderr
, str
, arg1
, arg2
);
2601 fprintf (stderr
, "\n");
2609 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo
,
2610 "Non-nil means the system uses terminfo rather than termcap.\n\
2611 This variable can be used by terminal emulator packages.");
2613 system_uses_terminfo
= 1;
2615 system_uses_terminfo
= 0;
2618 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function
,
2619 "Non-nil means call this function to ring the bell.\n\
2620 The function should accept no arguments.");
2621 Vring_bell_function
= Qnil
;
2623 defsubr (&Stty_display_color_p
);