aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.c
diff options
context:
space:
mode:
authorKaroly Lorentey2005-12-25 20:06:58 +0000
committerKaroly Lorentey2005-12-25 20:06:58 +0000
commited8dad6b616204b4dd4e853801f41da6f4c3b0a7 (patch)
treed260111171143cc889b7c801b911a07cf05da67c /src/term.c
parent4beb2d71ea5cbd7f451b8958c3cd21b3cd4d6edc (diff)
downloademacs-ed8dad6b616204b4dd4e853801f41da6f4c3b0a7.tar.gz
emacs-ed8dad6b616204b4dd4e853801f41da6f4c3b0a7.zip
Reimplement terminal parameters in C; clean up term.c, create terminal.c.
* lisp/termdev.el (terminal-parameter-alist, terminal-parameters, terminal-parameter-p) (terminal-parameter, set-terminal-parameter, terminal-handle-delete-frame): Remove. * src/term.c (Vring_bell_function, device_list, initial_device) (next_device_id, ring_bell, update_begin, update_end) (set_terminal_window, cursor_to, raw_cursor_to) (clear_to_end, clear_frame, clear_end_of_line) (write_glyphs, insert_glyphs, delete_glyphs, ins_del_lines) (get_device, Fdisplay_name, create_device, delete_device) (Fdelete_display, Fdisplay_live_p, Fdisplay_list) Move to terminal.c. (syms_of_term): Move their initialization to terminal.c. * src/terminal.c: New file. (device_list, next_device_id, initial_device, Vring_bell_function) (ring_bell, update_begin, update_end, set_terminal_window) (cursor_to, raw_cursor_to, clear_to_end, clear_frame) (clear_end_of_line, write_glyphs, insert_glyphs, delete_glyphs) (ins_del_lines, get_device, create_device, delete_device) (Fdelete_display, Fdisplay_live_p, Fdisplay_list, Fdisplay_name): Move here. (mark_devices, get_terminal_param, store_terminal_param) (Fterminal_parameters, Fterminal_parameter) (Fmodify_terminal_parameters, Fset_terminal_parameter) (init_initial_device, delete_initial_device) (syms_of_terminal): New functions. * lisp/simple.el (normal-erase-is-backspace-setup-frame) (normal-erase-is-backspace-mode): Rephrase things without terminal-parameter-p. * lisp/termdev.el (terminal-getenv, terminal-setenv) (with-terminal-environment): Ditto. * mac/makefile.MPW (EmacsObjects): Add terminal.c.x. ({Src}terminal.c.x): Add dependencies. * src/Makefile.in (obj): Add terminal.o. (terminal.o): Add dependencies. [HAVE_CARBON]: Make terminal.o depend on macgui.h. * src/alloc.c (mark_devices): Declare. (Fgarbage_collect): Call `mark_devices'. * src/dispextern.h (set_scroll_region, turn_off_insert) (turn_off_highlight, background_highlight, clear_end_of_line_raw) (tty_clear_end_of_line, tty_setup_colors, delete_tty): Remove. (raw_cursor_to, clear_to_end, tty_turn_off_insert) (tty_turn_off_highlight): Add declaration. * src/emacs.c (main): Call `syms_of_terminal'. * src/frame.c (get_future_frame_param): New function. (Fmake_terminal_frame): Use it. * src/keyboard.c (pop_kboard): Remove unused variable. (Fset_output_flow_control): Return nil. * src/keymap.h (Fset_keymap_parent): Add EXFUN. * src/lisp.h (syms_of_terminal): Declare it. * src/sysdep.c (reset_sys_modes): Update for renames. * src/term.c (set_scroll_region): Rename to `tty_set_scroll_region'. (turn_on_insert): Rename to `tty_turn_on_insert'. (turn_off_insert): Rename to `tty_turn_off_insert'. (turn_off_highlight): Rename to `tty_turn_off_highlight'. (turn_on_highlight): Rename to `tty_turn_on_highlight'. (toggle_highligh): Rename to `tty_toggle_highlight'. (background_highlight): Rename to `tty_background_highlight'. (highlight_if_desired): Rename to `tty_highlight_if_desired'. (tty_ring_bell, tty_update_end, tty_set_terminal_window) (tty_set_scroll_region, tty_background_highlight) (tty_cursor_to, tty_raw_cursor_to, tty_clear_to_end) (tty_clear_frame, tty_clear_end_of_line, tty_write_glyphs) (tty_insert_glyphs, tty_delete_glyphs, tty_ins_del_lines) (term_get_fkeys, tty_setup_colors, dissociate_if_controlling_tty) (delete_tty): Add static modifier. (tty_reset_terminal_modes, tty_set_terminal_window) (tty_set_scroll_region, tty_background_highlight) (tty_highlight_if_desired, tty_cursor_to) (tty_raw_cursor_to, tty_clear_to_end, tty_clear_frame) (tty_clear_end_of_line, tty_write_glyphs, tty_insert_glyphs) (tty_delete_glyphs, tty_ins_del_lines, turn_on_face): Update for renames. * src/termhooks.h (param_alist): New member to struct device. * src/xterm.h (x_delete_device): Declare. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-460
Diffstat (limited to 'src/term.c')
-rw-r--r--src/term.c814
1 files changed, 205 insertions, 609 deletions
diff --git a/src/term.c b/src/term.c
index 679def93c72..b599e1b97fe 100644
--- a/src/term.c
+++ b/src/term.c
@@ -80,14 +80,14 @@ extern int tgetnum P_ ((char *id));
80#define O_NOCTTY 0 80#define O_NOCTTY 0
81#endif 81#endif
82 82
83static void tty_set_scroll_region P_ ((struct frame *f, int start, int stop));
83static void turn_on_face P_ ((struct frame *, int face_id)); 84static void turn_on_face P_ ((struct frame *, int face_id));
84static void turn_off_face P_ ((struct frame *, int face_id)); 85static void turn_off_face P_ ((struct frame *, int face_id));
85static void tty_show_cursor P_ ((struct tty_display_info *)); 86static void tty_show_cursor P_ ((struct tty_display_info *));
86static void tty_hide_cursor P_ ((struct tty_display_info *)); 87static void tty_hide_cursor P_ ((struct tty_display_info *));
87 88static void tty_background_highlight P_ ((struct tty_display_info *tty));
88void delete_initial_device P_ ((struct device *)); 89static void dissociate_if_controlling_tty P_ ((int fd));
89void create_tty_output P_ ((struct frame *)); 90static void delete_tty P_ ((struct device *));
90void delete_tty_output P_ ((struct frame *));
91 91
92#define OUTPUT(tty, a) \ 92#define OUTPUT(tty, a) \
93 emacs_tputs ((tty), a, \ 93 emacs_tputs ((tty), a, \
@@ -113,22 +113,12 @@ void delete_tty_output P_ ((struct frame *));
113 113
114extern Lisp_Object Qspace, QCalign_to, QCwidth; 114extern Lisp_Object Qspace, QCalign_to, QCwidth;
115 115
116/* Function to use to ring the bell. */
117
118Lisp_Object Vring_bell_function;
119
120/* Functions to call after suspending a tty. */ 116/* Functions to call after suspending a tty. */
121Lisp_Object Vsuspend_tty_functions; 117Lisp_Object Vsuspend_tty_functions;
122 118
123/* Functions to call after resuming a tty. */ 119/* Functions to call after resuming a tty. */
124Lisp_Object Vresume_tty_functions; 120Lisp_Object Vresume_tty_functions;
125 121
126/* Chain of all displays currently in use. */
127struct device *device_list;
128
129/* The initial display device, created by initial_term_init. */
130struct device *initial_device;
131
132/* Chain of all tty device parameters. */ 122/* Chain of all tty device parameters. */
133struct tty_display_info *tty_list; 123struct tty_display_info *tty_list;
134 124
@@ -138,7 +128,6 @@ struct tty_display_info *tty_list;
138 else. */ 128 else. */
139int no_redraw_on_reenter; 129int no_redraw_on_reenter;
140 130
141
142/* Meaning of bits in no_color_video. Each bit set means that the 131/* Meaning of bits in no_color_video. Each bit set means that the
143 corresponding attribute cannot be combined with colors. */ 132 corresponding attribute cannot be combined with colors. */
144 133
@@ -169,9 +158,6 @@ int max_frame_lines;
169 should not open a frame on stdout. */ 158 should not open a frame on stdout. */
170static int no_controlling_tty; 159static int no_controlling_tty;
171 160
172/* The first unallocated display id. */
173static int next_device_id;
174
175/* Provided for lisp packages. */ 161/* Provided for lisp packages. */
176 162
177static int system_uses_terminfo; 163static int system_uses_terminfo;
@@ -192,35 +178,10 @@ extern char *tgetstr ();
192#define FRAME_TERMCAP_P(_f_) 0 178#define FRAME_TERMCAP_P(_f_) 0
193#endif /* WINDOWSNT */ 179#endif /* WINDOWSNT */
194 180
195void
196ring_bell (struct frame *f)
197{
198 if (!NILP (Vring_bell_function))
199 {
200 Lisp_Object function;
201
202 /* Temporarily set the global variable to nil
203 so that if we get an error, it stays nil
204 and we don't call it over and over.
205
206 We don't specbind it, because that would carefully
207 restore the bad value if there's an error
208 and make the loop of errors happen anyway. */
209
210 function = Vring_bell_function;
211 Vring_bell_function = Qnil;
212
213 call0 (function);
214
215 Vring_bell_function = function;
216 }
217 else if (FRAME_DEVICE (f)->ring_bell_hook)
218 (*FRAME_DEVICE (f)->ring_bell_hook) (f);
219}
220 181
221/* Ring the bell on a tty. */ 182/* Ring the bell on a tty. */
222 183
223void 184static void
224tty_ring_bell (struct frame *f) 185tty_ring_bell (struct frame *f)
225{ 186{
226 struct tty_display_info *tty = FRAME_TTY (f); 187 struct tty_display_info *tty = FRAME_TTY (f);
@@ -272,8 +233,8 @@ tty_reset_terminal_modes (struct device *display)
272 233
273 if (tty->output) 234 if (tty->output)
274 { 235 {
275 turn_off_highlight (tty); 236 tty_turn_off_highlight (tty);
276 turn_off_insert (tty); 237 tty_turn_off_insert (tty);
277 OUTPUT_IF (tty, tty->TS_end_keypad_mode); 238 OUTPUT_IF (tty, tty->TS_end_keypad_mode);
278 OUTPUT_IF (tty, tty->TS_cursor_normal); 239 OUTPUT_IF (tty, tty->TS_cursor_normal);
279 OUTPUT_IF (tty, tty->TS_end_termcap_modes); 240 OUTPUT_IF (tty, tty->TS_end_termcap_modes);
@@ -285,59 +246,33 @@ tty_reset_terminal_modes (struct device *display)
285 } 246 }
286} 247}
287 248
288void
289update_begin (struct frame *f)
290{
291 if (FRAME_DEVICE (f)->update_begin_hook)
292 (*FRAME_DEVICE (f)->update_begin_hook) (f);
293}
294
295void
296update_end (struct frame *f)
297{
298 if (FRAME_DEVICE (f)->update_end_hook)
299 (*FRAME_DEVICE (f)->update_end_hook) (f);
300}
301
302/* Flag the end of a display update on a termcap display. */ 249/* Flag the end of a display update on a termcap display. */
303 250
304void 251static void
305tty_update_end (struct frame *f) 252tty_update_end (struct frame *f)
306{ 253{
307 struct tty_display_info *tty = FRAME_TTY (f); 254 struct tty_display_info *tty = FRAME_TTY (f);
308 255
309 if (!XWINDOW (selected_window)->cursor_off_p) 256 if (!XWINDOW (selected_window)->cursor_off_p)
310 tty_show_cursor (tty); 257 tty_show_cursor (tty);
311 turn_off_insert (tty); 258 tty_turn_off_insert (tty);
312 background_highlight (tty); 259 tty_background_highlight (tty);
313}
314
315/* Specify how many text lines, from the top of the window,
316 should be affected by insert-lines and delete-lines operations.
317 This, and those operations, are used only within an update
318 that is bounded by calls to update_begin and update_end. */
319
320void
321set_terminal_window (struct frame *f, int size)
322{
323 if (FRAME_DEVICE (f)->set_terminal_window_hook)
324 (*FRAME_DEVICE (f)->set_terminal_window_hook) (f, size);
325} 260}
326 261
327/* The implementation of set_terminal_window for termcap frames. */ 262/* The implementation of set_terminal_window for termcap frames. */
328 263
329void 264static void
330tty_set_terminal_window (struct frame *f, int size) 265tty_set_terminal_window (struct frame *f, int size)
331{ 266{
332 struct tty_display_info *tty = FRAME_TTY (f); 267 struct tty_display_info *tty = FRAME_TTY (f);
333 268
334 tty->specified_window = size ? size : FRAME_LINES (f); 269 tty->specified_window = size ? size : FRAME_LINES (f);
335 if (FRAME_SCROLL_REGION_OK (f)) 270 if (FRAME_SCROLL_REGION_OK (f))
336 set_scroll_region (f, 0, tty->specified_window); 271 tty_set_scroll_region (f, 0, tty->specified_window);
337} 272}
338 273
339void 274static void
340set_scroll_region (struct frame *f, int start, int stop) 275tty_set_scroll_region (struct frame *f, int start, int stop)
341{ 276{
342 char *buf; 277 char *buf;
343 struct tty_display_info *tty = FRAME_TTY (f); 278 struct tty_display_info *tty = FRAME_TTY (f);
@@ -359,7 +294,7 @@ set_scroll_region (struct frame *f, int start, int stop)
359 294
360 295
361static void 296static void
362turn_on_insert (struct tty_display_info *tty) 297tty_turn_on_insert (struct tty_display_info *tty)
363{ 298{
364 if (!tty->insert_mode) 299 if (!tty->insert_mode)
365 OUTPUT (tty, tty->TS_insert_mode); 300 OUTPUT (tty, tty->TS_insert_mode);
@@ -367,7 +302,7 @@ turn_on_insert (struct tty_display_info *tty)
367} 302}
368 303
369void 304void
370turn_off_insert (struct tty_display_info *tty) 305tty_turn_off_insert (struct tty_display_info *tty)
371{ 306{
372 if (tty->insert_mode) 307 if (tty->insert_mode)
373 OUTPUT (tty, tty->TS_end_insert_mode); 308 OUTPUT (tty, tty->TS_end_insert_mode);
@@ -377,7 +312,7 @@ turn_off_insert (struct tty_display_info *tty)
377/* Handle highlighting. */ 312/* Handle highlighting. */
378 313
379void 314void
380turn_off_highlight (struct tty_display_info *tty) 315tty_turn_off_highlight (struct tty_display_info *tty)
381{ 316{
382 if (tty->standout_mode) 317 if (tty->standout_mode)
383 OUTPUT_IF (tty, tty->TS_end_standout_mode); 318 OUTPUT_IF (tty, tty->TS_end_standout_mode);
@@ -385,7 +320,7 @@ turn_off_highlight (struct tty_display_info *tty)
385} 320}
386 321
387static void 322static void
388turn_on_highlight (struct tty_display_info *tty) 323tty_turn_on_highlight (struct tty_display_info *tty)
389{ 324{
390 if (!tty->standout_mode) 325 if (!tty->standout_mode)
391 OUTPUT_IF (tty, tty->TS_standout_mode); 326 OUTPUT_IF (tty, tty->TS_standout_mode);
@@ -393,12 +328,12 @@ turn_on_highlight (struct tty_display_info *tty)
393} 328}
394 329
395static void 330static void
396toggle_highlight (struct tty_display_info *tty) 331tty_toggle_highlight (struct tty_display_info *tty)
397{ 332{
398 if (tty->standout_mode) 333 if (tty->standout_mode)
399 turn_off_highlight (tty); 334 tty_turn_off_highlight (tty);
400 else 335 else
401 turn_on_highlight (tty); 336 tty_turn_on_highlight (tty);
402} 337}
403 338
404 339
@@ -433,38 +368,31 @@ tty_show_cursor (struct tty_display_info *tty)
433 empty space inside windows. What this is, 368 empty space inside windows. What this is,
434 depends on the user option inverse-video. */ 369 depends on the user option inverse-video. */
435 370
436void 371static void
437background_highlight (struct tty_display_info *tty) 372tty_background_highlight (struct tty_display_info *tty)
438{ 373{
439 if (inverse_video) 374 if (inverse_video)
440 turn_on_highlight (tty); 375 tty_turn_on_highlight (tty);
441 else 376 else
442 turn_off_highlight (tty); 377 tty_turn_off_highlight (tty);
443} 378}
444 379
445/* Set standout mode to the mode specified for the text to be output. */ 380/* Set standout mode to the mode specified for the text to be output. */
446 381
447static void 382static void
448highlight_if_desired (struct tty_display_info *tty) 383tty_highlight_if_desired (struct tty_display_info *tty)
449{ 384{
450 if (inverse_video) 385 if (inverse_video)
451 turn_on_highlight (tty); 386 tty_turn_on_highlight (tty);
452 else 387 else
453 turn_off_highlight (tty); 388 tty_turn_off_highlight (tty);
454} 389}
455 390
456 391
457/* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are 392/* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
458 frame-relative coordinates. */ 393 frame-relative coordinates. */
459 394
460void 395static void
461cursor_to (struct frame *f, int vpos, int hpos)
462{
463 if (FRAME_DEVICE (f)->cursor_to_hook)
464 (*FRAME_DEVICE (f)->cursor_to_hook) (f, vpos, hpos);
465}
466
467void
468tty_cursor_to (struct frame *f, int vpos, int hpos) 396tty_cursor_to (struct frame *f, int vpos, int hpos)
469{ 397{
470 struct tty_display_info *tty = FRAME_TTY (f); 398 struct tty_display_info *tty = FRAME_TTY (f);
@@ -478,22 +406,15 @@ tty_cursor_to (struct frame *f, int vpos, int hpos)
478 && curX (tty) == hpos) 406 && curX (tty) == hpos)
479 return; 407 return;
480 if (!tty->TF_standout_motion) 408 if (!tty->TF_standout_motion)
481 background_highlight (tty); 409 tty_background_highlight (tty);
482 if (!tty->TF_insmode_motion) 410 if (!tty->TF_insmode_motion)
483 turn_off_insert (tty); 411 tty_turn_off_insert (tty);
484 cmgoto (tty, vpos, hpos); 412 cmgoto (tty, vpos, hpos);
485} 413}
486 414
487/* Similar but don't take any account of the wasted characters. */ 415/* Similar but don't take any account of the wasted characters. */
488 416
489void 417static void
490raw_cursor_to (struct frame *f, int row, int col)
491{
492 if (FRAME_DEVICE (f)->raw_cursor_to_hook)
493 (*FRAME_DEVICE (f)->raw_cursor_to_hook) (f, row, col);
494}
495
496void
497tty_raw_cursor_to (struct frame *f, int row, int col) 418tty_raw_cursor_to (struct frame *f, int row, int col)
498{ 419{
499 struct tty_display_info *tty = FRAME_TTY (f); 420 struct tty_display_info *tty = FRAME_TTY (f);
@@ -502,25 +423,17 @@ tty_raw_cursor_to (struct frame *f, int row, int col)
502 && curX (tty) == col) 423 && curX (tty) == col)
503 return; 424 return;
504 if (!tty->TF_standout_motion) 425 if (!tty->TF_standout_motion)
505 background_highlight (tty); 426 tty_background_highlight (tty);
506 if (!tty->TF_insmode_motion) 427 if (!tty->TF_insmode_motion)
507 turn_off_insert (tty); 428 tty_turn_off_insert (tty);
508 cmgoto (tty, row, col); 429 cmgoto (tty, row, col);
509} 430}
510 431
511/* Erase operations */ 432/* Erase operations */
512 433
513/* Clear from cursor to end of frame. */
514void
515clear_to_end (struct frame *f)
516{
517 if (FRAME_DEVICE (f)->clear_to_end_hook)
518 (*FRAME_DEVICE (f)->clear_to_end_hook) (f);
519}
520
521/* Clear from cursor to end of frame on a termcap device. */ 434/* Clear from cursor to end of frame on a termcap device. */
522 435
523void 436static void
524tty_clear_to_end (struct frame *f) 437tty_clear_to_end (struct frame *f)
525{ 438{
526 register int i; 439 register int i;
@@ -528,7 +441,7 @@ tty_clear_to_end (struct frame *f)
528 441
529 if (tty->TS_clr_to_bottom) 442 if (tty->TS_clr_to_bottom)
530 { 443 {
531 background_highlight (tty); 444 tty_background_highlight (tty);
532 OUTPUT (tty, tty->TS_clr_to_bottom); 445 OUTPUT (tty, tty->TS_clr_to_bottom);
533 } 446 }
534 else 447 else
@@ -541,25 +454,16 @@ tty_clear_to_end (struct frame *f)
541 } 454 }
542} 455}
543 456
544/* Clear entire frame */
545
546void
547clear_frame (struct frame *f)
548{
549 if (FRAME_DEVICE (f)->clear_frame_hook)
550 (*FRAME_DEVICE (f)->clear_frame_hook) (f);
551}
552
553/* Clear an entire termcap frame. */ 457/* Clear an entire termcap frame. */
554 458
555void 459static void
556tty_clear_frame (struct frame *f) 460tty_clear_frame (struct frame *f)
557{ 461{
558 struct tty_display_info *tty = FRAME_TTY (f); 462 struct tty_display_info *tty = FRAME_TTY (f);
559 463
560 if (tty->TS_clr_frame) 464 if (tty->TS_clr_frame)
561 { 465 {
562 background_highlight (tty); 466 tty_background_highlight (tty);
563 OUTPUT (tty, tty->TS_clr_frame); 467 OUTPUT (tty, tty->TS_clr_frame);
564 cmat (tty, 0, 0); 468 cmat (tty, 0, 0);
565 } 469 }
@@ -570,23 +474,11 @@ tty_clear_frame (struct frame *f)
570 } 474 }
571} 475}
572 476
573/* Clear from cursor to end of line.
574 Assume that the line is already clear starting at column first_unused_hpos.
575
576 Note that the cursor may be moved, on terminals lacking a `ce' string. */
577
578void
579clear_end_of_line (struct frame *f, int first_unused_hpos)
580{
581 if (FRAME_DEVICE (f)->clear_end_of_line_hook)
582 (*FRAME_DEVICE (f)->clear_end_of_line_hook) (f, first_unused_hpos);
583}
584
585/* An implementation of clear_end_of_line for termcap frames. 477/* An implementation of clear_end_of_line for termcap frames.
586 478
587 Note that the cursor may be moved, on terminals lacking a `ce' string. */ 479 Note that the cursor may be moved, on terminals lacking a `ce' string. */
588 480
589void 481static void
590tty_clear_end_of_line (struct frame *f, int first_unused_hpos) 482tty_clear_end_of_line (struct frame *f, int first_unused_hpos)
591{ 483{
592 register int i; 484 register int i;
@@ -599,14 +491,14 @@ tty_clear_end_of_line (struct frame *f, int first_unused_hpos)
599 491
600 if (curX (tty) >= first_unused_hpos) 492 if (curX (tty) >= first_unused_hpos)
601 return; 493 return;
602 background_highlight (tty); 494 tty_background_highlight (tty);
603 if (tty->TS_clr_line) 495 if (tty->TS_clr_line)
604 { 496 {
605 OUTPUT1 (tty, tty->TS_clr_line); 497 OUTPUT1 (tty, tty->TS_clr_line);
606 } 498 }
607 else 499 else
608 { /* have to do it the hard way */ 500 { /* have to do it the hard way */
609 turn_off_insert (tty); 501 tty_turn_off_insert (tty);
610 502
611 /* Do not write in last row last col with Auto-wrap on. */ 503 /* Do not write in last row last col with Auto-wrap on. */
612 if (AutoWrap (tty) 504 if (AutoWrap (tty)
@@ -743,19 +635,9 @@ encode_terminal_code (src, src_len, coding)
743} 635}
744 636
745 637
746/* Output LEN glyphs starting at STRING at the nominal cursor position.
747 Advance the nominal cursor over the text. */
748
749void
750write_glyphs (struct frame *f, struct glyph *string, int len)
751{
752 if (FRAME_DEVICE (f)->write_glyphs_hook)
753 (*FRAME_DEVICE (f)->write_glyphs_hook) (f, string, len);
754}
755
756/* An implementation of write_glyphs for termcap frames. */ 638/* An implementation of write_glyphs for termcap frames. */
757 639
758void 640static void
759tty_write_glyphs (struct frame *f, struct glyph *string, int len) 641tty_write_glyphs (struct frame *f, struct glyph *string, int len)
760{ 642{
761 unsigned char *conversion_buffer; 643 unsigned char *conversion_buffer;
@@ -763,7 +645,7 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len)
763 645
764 struct tty_display_info *tty = FRAME_TTY (f); 646 struct tty_display_info *tty = FRAME_TTY (f);
765 647
766 turn_off_insert (tty); 648 tty_turn_off_insert (tty);
767 tty_hide_cursor (tty); 649 tty_hide_cursor (tty);
768 650
769 /* Don't dare write in last column of bottom line, if Auto-Wrap, 651 /* Don't dare write in last column of bottom line, if Auto-Wrap,
@@ -798,7 +680,7 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len)
798 break; 680 break;
799 681
800 /* Turn appearance modes of the face of the run on. */ 682 /* Turn appearance modes of the face of the run on. */
801 highlight_if_desired (tty); 683 tty_highlight_if_desired (tty);
802 turn_on_face (f, face_id); 684 turn_on_face (f, face_id);
803 685
804 if (n == len) 686 if (n == len)
@@ -818,29 +700,15 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len)
818 700
819 /* Turn appearance modes off. */ 701 /* Turn appearance modes off. */
820 turn_off_face (f, face_id); 702 turn_off_face (f, face_id);
821 turn_off_highlight (tty); 703 tty_turn_off_highlight (tty);
822 } 704 }
823 705
824 cmcheckmagic (tty); 706 cmcheckmagic (tty);
825} 707}
826 708
827/* Insert LEN glyphs from START at the nominal cursor position.
828
829 If start is zero, insert blanks instead of a string at start */
830
831void
832insert_glyphs (struct frame *f, struct glyph *start, int len)
833{
834 if (len <= 0)
835 return;
836
837 if (FRAME_DEVICE (f)->insert_glyphs_hook)
838 (*FRAME_DEVICE (f)->insert_glyphs_hook) (f, start, len);
839}
840
841/* An implementation of insert_glyphs for termcap frames. */ 709/* An implementation of insert_glyphs for termcap frames. */
842 710
843void 711static void
844tty_insert_glyphs (struct frame *f, struct glyph *start, int len) 712tty_insert_glyphs (struct frame *f, struct glyph *start, int len)
845{ 713{
846 char *buf; 714 char *buf;
@@ -861,7 +729,7 @@ tty_insert_glyphs (struct frame *f, struct glyph *start, int len)
861 return; 729 return;
862 } 730 }
863 731
864 turn_on_insert (tty); 732 tty_turn_on_insert (tty);
865 cmplus (tty, len); 733 cmplus (tty, len);
866 734
867 if (! start) 735 if (! start)
@@ -886,7 +754,7 @@ tty_insert_glyphs (struct frame *f, struct glyph *start, int len)
886 } 754 }
887 else 755 else
888 { 756 {
889 highlight_if_desired (tty); 757 tty_highlight_if_desired (tty);
890 turn_on_face (f, start->face_id); 758 turn_on_face (f, start->face_id);
891 glyph = start; 759 glyph = start;
892 ++start; 760 ++start;
@@ -918,25 +786,16 @@ tty_insert_glyphs (struct frame *f, struct glyph *start, int len)
918 if (start) 786 if (start)
919 { 787 {
920 turn_off_face (f, glyph->face_id); 788 turn_off_face (f, glyph->face_id);
921 turn_off_highlight (tty); 789 tty_turn_off_highlight (tty);
922 } 790 }
923 } 791 }
924 792
925 cmcheckmagic (tty); 793 cmcheckmagic (tty);
926} 794}
927 795
928/* Delete N glyphs at the nominal cursor position. */
929
930void
931delete_glyphs (struct frame *f, int n)
932{
933 if (FRAME_DEVICE (f)->delete_glyphs_hook)
934 (*FRAME_DEVICE (f)->delete_glyphs_hook) (f, n);
935}
936
937/* An implementation of delete_glyphs for termcap frames. */ 796/* An implementation of delete_glyphs for termcap frames. */
938 797
939void 798static void
940tty_delete_glyphs (struct frame *f, int n) 799tty_delete_glyphs (struct frame *f, int n)
941{ 800{
942 char *buf; 801 char *buf;
@@ -946,11 +805,11 @@ tty_delete_glyphs (struct frame *f, int n)
946 805
947 if (tty->delete_in_insert_mode) 806 if (tty->delete_in_insert_mode)
948 { 807 {
949 turn_on_insert (tty); 808 tty_turn_on_insert (tty);
950 } 809 }
951 else 810 else
952 { 811 {
953 turn_off_insert (tty); 812 tty_turn_off_insert (tty);
954 OUTPUT_IF (tty, tty->TS_delete_mode); 813 OUTPUT_IF (tty, tty->TS_delete_mode);
955 } 814 }
956 815
@@ -967,18 +826,9 @@ tty_delete_glyphs (struct frame *f, int n)
967 OUTPUT_IF (tty, tty->TS_end_delete_mode); 826 OUTPUT_IF (tty, tty->TS_end_delete_mode);
968} 827}
969 828
970/* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
971
972void
973ins_del_lines (struct frame *f, int vpos, int n)
974{
975 if (FRAME_DEVICE (f)->ins_del_lines_hook)
976 (*FRAME_DEVICE (f)->ins_del_lines_hook) (f, vpos, n);
977}
978
979/* An implementation of ins_del_lines for termcap frames. */ 829/* An implementation of ins_del_lines for termcap frames. */
980 830
981void 831static void
982tty_ins_del_lines (struct frame *f, int vpos, int n) 832tty_ins_del_lines (struct frame *f, int vpos, int n)
983{ 833{
984 struct tty_display_info *tty = FRAME_TTY (f); 834 struct tty_display_info *tty = FRAME_TTY (f);
@@ -1006,7 +856,7 @@ tty_ins_del_lines (struct frame *f, int vpos, int n)
1006 if (multi) 856 if (multi)
1007 { 857 {
1008 raw_cursor_to (f, vpos, 0); 858 raw_cursor_to (f, vpos, 0);
1009 background_highlight (tty); 859 tty_background_highlight (tty);
1010 buf = tparam (multi, 0, 0, i); 860 buf = tparam (multi, 0, 0, i);
1011 OUTPUT (tty, buf); 861 OUTPUT (tty, buf);
1012 xfree (buf); 862 xfree (buf);
@@ -1014,7 +864,7 @@ tty_ins_del_lines (struct frame *f, int vpos, int n)
1014 else if (single) 864 else if (single)
1015 { 865 {
1016 raw_cursor_to (f, vpos, 0); 866 raw_cursor_to (f, vpos, 0);
1017 background_highlight (tty); 867 tty_background_highlight (tty);
1018 while (--i >= 0) 868 while (--i >= 0)
1019 OUTPUT (tty, single); 869 OUTPUT (tty, single);
1020 if (tty->TF_teleray) 870 if (tty->TF_teleray)
@@ -1022,15 +872,15 @@ tty_ins_del_lines (struct frame *f, int vpos, int n)
1022 } 872 }
1023 else 873 else
1024 { 874 {
1025 set_scroll_region (f, vpos, tty->specified_window); 875 tty_set_scroll_region (f, vpos, tty->specified_window);
1026 if (n < 0) 876 if (n < 0)
1027 raw_cursor_to (f, tty->specified_window - 1, 0); 877 raw_cursor_to (f, tty->specified_window - 1, 0);
1028 else 878 else
1029 raw_cursor_to (f, vpos, 0); 879 raw_cursor_to (f, vpos, 0);
1030 background_highlight (tty); 880 tty_background_highlight (tty);
1031 while (--i >= 0) 881 while (--i >= 0)
1032 OUTPUTL (tty, scroll, tty->specified_window - vpos); 882 OUTPUTL (tty, scroll, tty->specified_window - vpos);
1033 set_scroll_region (f, 0, tty->specified_window); 883 tty_set_scroll_region (f, 0, tty->specified_window);
1034 } 884 }
1035 885
1036 if (!FRAME_SCROLL_REGION_OK (f) 886 if (!FRAME_SCROLL_REGION_OK (f)
@@ -1331,7 +1181,7 @@ static Lisp_Object term_get_fkeys_1 ();
1331 This function scans the termcap function key sequence entries, and 1181 This function scans the termcap function key sequence entries, and
1332 adds entries to Vfunction_key_map for each function key it finds. */ 1182 adds entries to Vfunction_key_map for each function key it finds. */
1333 1183
1334void 1184static void
1335term_get_fkeys (address, kboard) 1185term_get_fkeys (address, kboard)
1336 char **address; 1186 char **address;
1337 KBOARD *kboard; 1187 KBOARD *kboard;
@@ -1805,13 +1655,13 @@ turn_on_face (f, face_id)
1805 { 1655 {
1806 if (fg == FACE_TTY_DEFAULT_FG_COLOR 1656 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1807 || bg == FACE_TTY_DEFAULT_BG_COLOR) 1657 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1808 toggle_highlight (tty); 1658 tty_toggle_highlight (tty);
1809 } 1659 }
1810 else 1660 else
1811 { 1661 {
1812 if (fg == FACE_TTY_DEFAULT_BG_COLOR 1662 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1813 || bg == FACE_TTY_DEFAULT_FG_COLOR) 1663 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1814 toggle_highlight (tty); 1664 tty_toggle_highlight (tty);
1815 } 1665 }
1816 } 1666 }
1817 else 1667 else
@@ -1822,13 +1672,13 @@ turn_on_face (f, face_id)
1822 { 1672 {
1823 if (fg == FACE_TTY_DEFAULT_FG_COLOR 1673 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1824 || bg == FACE_TTY_DEFAULT_BG_COLOR) 1674 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1825 toggle_highlight (tty); 1675 tty_toggle_highlight (tty);
1826 } 1676 }
1827 else 1677 else
1828 { 1678 {
1829 if (fg == FACE_TTY_DEFAULT_BG_COLOR 1679 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1830 || bg == FACE_TTY_DEFAULT_FG_COLOR) 1680 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1831 toggle_highlight (tty); 1681 tty_toggle_highlight (tty);
1832 } 1682 }
1833 } 1683 }
1834 } 1684 }
@@ -2031,7 +1881,7 @@ tty_default_color_capabilities (struct tty_display_info *tty, int save)
2031 MODE's value is generally the number of colors which we want to 1881 MODE's value is generally the number of colors which we want to
2032 support; zero means set up for the default capabilities, the ones 1882 support; zero means set up for the default capabilities, the ones
2033 we saw at init_tty time; -1 means turn off color support. */ 1883 we saw at init_tty time; -1 means turn off color support. */
2034void 1884static void
2035tty_setup_colors (struct tty_display_info *tty, int mode) 1885tty_setup_colors (struct tty_display_info *tty, int mode)
2036{ 1886{
2037 /* Canonicalize all negative values of MODE. */ 1887 /* Canonicalize all negative values of MODE. */
@@ -2124,43 +1974,6 @@ set_tty_color_mode (f, val)
2124 1974
2125 1975
2126 1976
2127/* Return the display object specified by DEVICE. DEVICE may be a
2128 display id, a frame, or nil for the display device of the current
2129 frame. If THROW is zero, return NULL for failure, otherwise throw
2130 an error. */
2131
2132struct device *
2133get_device (Lisp_Object device, int throw)
2134{
2135 struct device *result = NULL;
2136
2137 if (NILP (device))
2138 device = selected_frame;
2139
2140 if (INTEGERP (device))
2141 {
2142 struct device *d;
2143
2144 for (d = device_list; d; d = d->next_device)
2145 {
2146 if (d->id == XINT (device))
2147 {
2148 result = d;
2149 break;
2150 }
2151 }
2152 }
2153 else if (FRAMEP (device))
2154 {
2155 result = FRAME_DEVICE (XFRAME (device));
2156 }
2157
2158 if (result == NULL && throw)
2159 wrong_type_argument (Qdisplay_live_p, device);
2160
2161 return result;
2162}
2163
2164/* Return the tty display object specified by DEVICE. */ 1977/* Return the tty display object specified by DEVICE. */
2165 1978
2166struct device * 1979struct device *
@@ -2204,24 +2017,6 @@ get_named_tty (name)
2204} 2017}
2205 2018
2206 2019
2207
2208DEFUN ("display-name", Fdisplay_name, Sdisplay_name, 0, 1, 0,
2209 doc: /* Return the name of the display device DEVICE.
2210It is not guaranteed that the returned value is unique among opened devices.
2211
2212DEVICE may be a display device id, a frame, or nil (meaning the
2213selected frame's display device). */)
2214 (device)
2215 Lisp_Object device;
2216{
2217 struct device *d = get_device (device, 1);
2218
2219 if (d->name)
2220 return build_string (d->name);
2221 else
2222 return Qnil;
2223}
2224
2225DEFUN ("display-tty-type", Fdisplay_tty_type, Sdisplay_tty_type, 0, 1, 0, 2020DEFUN ("display-tty-type", Fdisplay_tty_type, Sdisplay_tty_type, 0, 1, 0,
2226 doc: /* Return the type of the tty device that DEVICE uses. 2021 doc: /* Return the type of the tty device that DEVICE uses.
2227 2022
@@ -2275,47 +2070,166 @@ selected frame's display device). */)
2275 return Qnil; 2070 return Qnil;
2276} 2071}
2277 2072
2073
2074
2075DEFUN ("suspend-tty", Fsuspend_tty, Ssuspend_tty, 0, 1, 0,
2076 doc: /* Suspend the terminal device TTY.
2077
2078The device is restored to its default state, and Emacs ceases all
2079access to the tty device. Frames that use the device are not deleted,
2080but input is not read from them and if they change, their display is
2081not updated.
2082
2083TTY may be a terminal id, a frame, or nil for the terminal device of
2084the currently selected frame.
2085
2086This function runs `suspend-tty-functions' after suspending the
2087device. The functions are run with one arg, the id of the suspended
2088terminal device.
2089
2090`suspend-tty' does nothing if it is called on a device that is already
2091suspended.
2092
2093A suspended tty may be resumed by calling `resume-tty' on it. */)
2094 (tty)
2095 Lisp_Object tty;
2096{
2097 struct device *d = get_tty_device (tty);
2098 FILE *f;
2099
2100 if (!d)
2101 error ("Unknown tty device");
2102
2103 f = d->display_info.tty->input;
2104
2105 if (f)
2106 {
2107 reset_sys_modes (d->display_info.tty);
2108
2109 delete_keyboard_wait_descriptor (fileno (f));
2110
2111 fclose (f);
2112 if (f != d->display_info.tty->output)
2113 fclose (d->display_info.tty->output);
2114
2115 d->display_info.tty->input = 0;
2116 d->display_info.tty->output = 0;
2117
2118 if (FRAMEP (d->display_info.tty->top_frame))
2119 FRAME_SET_VISIBLE (XFRAME (d->display_info.tty->top_frame), 0);
2120
2121 /* Run `suspend-tty-functions'. */
2122 if (!NILP (Vrun_hooks))
2123 {
2124 Lisp_Object args[2];
2125 args[0] = intern ("suspend-tty-functions");
2126 args[1] = make_number (d->id);
2127 Frun_hook_with_args (2, args);
2128 }
2129 }
2130
2131 return Qnil;
2132}
2133
2134DEFUN ("resume-tty", Fresume_tty, Sresume_tty, 0, 1, 0,
2135 doc: /* Resume the previously suspended terminal device TTY.
2136The terminal is opened and reinitialized. Frames that are on the
2137suspended display are revived.
2138
2139It is an error to resume a display while another display is active on
2140the same device.
2141
2142This function runs `resume-tty-functions' after resuming the device.
2143The functions are run with one arg, the id of the resumed display
2144device.
2145
2146`resume-tty' does nothing if it is called on a device that is not
2147suspended.
2148
2149TTY may be a display device id, a frame, or nil for the display device
2150of the currently selected frame. */)
2151 (tty)
2152 Lisp_Object tty;
2153{
2154 struct device *d = get_tty_device (tty);
2155 int fd;
2156
2157 if (!d)
2158 error ("Unknown tty device");
2159
2160 if (!d->display_info.tty->input)
2161 {
2162 if (get_named_tty (d->display_info.tty->name))
2163 error ("Cannot resume display while another display is active on the same device");
2164
2165 fd = emacs_open (d->display_info.tty->name, O_RDWR | O_NOCTTY, 0);
2166
2167 /* XXX What if open fails? */
2168
2169 dissociate_if_controlling_tty (fd);
2170
2171 d->display_info.tty->output = fdopen (fd, "w+");
2172 d->display_info.tty->input = d->display_info.tty->output;
2173
2174 add_keyboard_wait_descriptor (fd);
2175
2176 if (FRAMEP (d->display_info.tty->top_frame))
2177 FRAME_SET_VISIBLE (XFRAME (d->display_info.tty->top_frame), 1);
2178
2179 init_sys_modes (d->display_info.tty);
2180
2181 /* Run `suspend-tty-functions'. */
2182 if (!NILP (Vrun_hooks))
2183 {
2184 Lisp_Object args[2];
2185 args[0] = intern ("resume-tty-functions");
2186 args[1] = make_number (d->id);
2187 Frun_hook_with_args (2, args);
2188 }
2189 }
2190
2191 return Qnil;
2192}
2278 2193
2279 2194
2280/*********************************************************************** 2195/***********************************************************************
2281 Initialization 2196 Initialization
2282 ***********************************************************************/ 2197 ***********************************************************************/
2283 2198
2284/* Create the bootstrap display device for the initial frame. 2199/* Initialize the tty-dependent part of frame F. The frame must
2285 Returns a device of type output_initial. */ 2200 already have its device initialized. */
2286 2201
2287struct device * 2202void
2288init_initial_device (void) 2203create_tty_output (struct frame *f)
2289{ 2204{
2290 if (initialized || device_list || tty_list) 2205 struct tty_output *t;
2206
2207 if (! FRAME_TERMCAP_P (f))
2291 abort (); 2208 abort ();
2292 2209
2293 initial_device = create_device (); 2210 t = xmalloc (sizeof (struct tty_output));
2294 initial_device->type = output_initial; 2211 bzero (t, sizeof (struct tty_output));
2295 initial_device->name = xstrdup ("initial_device");
2296 initial_device->kboard = initial_kboard;
2297 2212
2298 initial_device->delete_device_hook = &delete_initial_device; 2213 t->display_info = FRAME_DEVICE (f)->display_info.tty;
2299 /* All other hooks are NULL. */
2300 2214
2301 return initial_device; 2215 f->output_data.tty = t;
2302} 2216}
2303 2217
2304/* Deletes the bootstrap display device. 2218/* Delete the tty-dependent part of frame F. */
2305 Called through delete_device_hook. */
2306 2219
2307void 2220static void
2308delete_initial_device (struct device *device) 2221delete_tty_output (struct frame *f)
2309{ 2222{
2310 if (device != initial_device) 2223 if (! FRAME_TERMCAP_P (f))
2311 abort (); 2224 abort ();
2312 2225
2313 delete_device (device); 2226 xfree (f->output_data.tty);
2314 initial_device = NULL;
2315} 2227}
2316 2228
2229
2230
2317/* Drop the controlling terminal if fd is the same device. */ 2231/* Drop the controlling terminal if fd is the same device. */
2318void 2232static void
2319dissociate_if_controlling_tty (int fd) 2233dissociate_if_controlling_tty (int fd)
2320{ 2234{
2321 int pgid; 2235 int pgid;
@@ -2974,7 +2888,7 @@ static int deleting_tty = 0;
2974 2888
2975/* Delete the given terminal device, closing all frames on it. */ 2889/* Delete the given terminal device, closing all frames on it. */
2976 2890
2977void 2891static void
2978delete_tty (struct device *device) 2892delete_tty (struct device *device)
2979{ 2893{
2980 struct tty_display_info *tty; 2894 struct tty_display_info *tty;
@@ -3066,44 +2980,11 @@ delete_tty (struct device *device)
3066 2980
3067 2981
3068 2982
3069/* Initialize the tty-dependent part of frame F. The frame must
3070 already have its device initialized. */
3071
3072void
3073create_tty_output (struct frame *f)
3074{
3075 struct tty_output *t;
3076
3077 if (! FRAME_TERMCAP_P (f))
3078 abort ();
3079
3080 t = xmalloc (sizeof (struct tty_output));
3081 bzero (t, sizeof (struct tty_output));
3082
3083 t->display_info = FRAME_DEVICE (f)->display_info.tty;
3084
3085 f->output_data.tty = t;
3086}
3087
3088/* Delete the tty-dependent part of frame F. */
3089
3090void
3091delete_tty_output (struct frame *f)
3092{
3093 if (! FRAME_TERMCAP_P (f))
3094 abort ();
3095
3096 xfree (f->output_data.tty);
3097}
3098
3099
3100
3101
3102/* Mark the pointers in the tty_display_info objects. 2983/* Mark the pointers in the tty_display_info objects.
3103 Called by the Fgarbage_collector. */ 2984 Called by the Fgarbage_collector. */
3104 2985
3105void 2986void
3106mark_ttys () 2987mark_ttys (void)
3107{ 2988{
3108 struct tty_display_info *tty; 2989 struct tty_display_info *tty;
3109 2990
@@ -3116,279 +2997,6 @@ mark_ttys ()
3116 2997
3117 2998
3118 2999
3119/* Create a new device object and add it to the device list. */
3120
3121struct device *
3122create_device (void)
3123{
3124 struct device *device = (struct device *) xmalloc (sizeof (struct device));
3125
3126 bzero (device, sizeof (struct device));
3127 device->next_device = device_list;
3128 device_list = device;
3129
3130 device->id = next_device_id++;
3131
3132 device->keyboard_coding =
3133 (struct coding_system *) xmalloc (sizeof (struct coding_system));
3134 device->terminal_coding =
3135 (struct coding_system *) xmalloc (sizeof (struct coding_system));
3136
3137 setup_coding_system (Qnil, device->keyboard_coding);
3138 setup_coding_system (Qnil, device->terminal_coding);
3139
3140 return device;
3141}
3142
3143/* Remove a device from the device list and free its memory. */
3144
3145void
3146delete_device (struct device *device)
3147{
3148 struct device **dp;
3149 Lisp_Object tail, frame;
3150
3151 /* Check for and close live frames that are still on this
3152 device. */
3153 FOR_EACH_FRAME (tail, frame)
3154 {
3155 struct frame *f = XFRAME (frame);
3156 if (FRAME_LIVE_P (f) && f->device == device)
3157 {
3158 Fdelete_frame (frame, Qt);
3159 }
3160 }
3161
3162 for (dp = &device_list; *dp != device; dp = &(*dp)->next_device)
3163 if (! *dp)
3164 abort ();
3165 *dp = device->next_device;
3166
3167 if (device->keyboard_coding)
3168 xfree (device->keyboard_coding);
3169 if (device->terminal_coding)
3170 xfree (device->terminal_coding);
3171 if (device->name)
3172 xfree (device->name);
3173
3174#ifdef MULTI_KBOARD
3175 if (device->kboard && --device->kboard->reference_count == 0)
3176 delete_kboard (device->kboard);
3177#endif
3178
3179 bzero (device, sizeof (struct device));
3180 xfree (device);
3181}
3182
3183DEFUN ("delete-display", Fdelete_display, Sdelete_display, 0, 2, 0,
3184 doc: /* Delete DEVICE by deleting all frames on it and closing the device.
3185DEVICE may be a display device id, a frame, or nil (meaning the
3186selected frame's display device).
3187
3188Normally, you may not delete a display if all other displays are suspended,
3189but if the second argument FORCE is non-nil, you may do so. */)
3190 (device, force)
3191 Lisp_Object device, force;
3192{
3193 struct device *d, *p;
3194
3195 d = get_device (device, 0);
3196
3197 if (!d)
3198 return Qnil;
3199
3200 p = device_list;
3201 while (p && (p == d || !DEVICE_ACTIVE_P (p)))
3202 p = p->next_device;
3203
3204 if (NILP (force) && !p)
3205 error ("Attempt to delete the sole active display device");
3206
3207 if (d->delete_device_hook)
3208 (*d->delete_device_hook) (d);
3209 else
3210 delete_device (d);
3211
3212 return Qnil;
3213}
3214
3215DEFUN ("display-live-p", Fdisplay_live_p, Sdisplay_live_p, 1, 1, 0,
3216 doc: /* Return non-nil if OBJECT is a device which has not been deleted.
3217Value is nil if OBJECT is not a live display device.
3218If object is a live display device, the return value indicates what
3219sort of output device it uses. See the documentation of `framep' for
3220possible return values.
3221
3222Display devices are represented by their integer identifiers. */)
3223 (object)
3224 Lisp_Object object;
3225{
3226 struct device *d;
3227
3228 if (!INTEGERP (object))
3229 return Qnil;
3230
3231 d = get_device (object, 0);
3232
3233 if (!d)
3234 return Qnil;
3235
3236 switch (d->type)
3237 {
3238 case output_initial: /* The initial frame is like a termcap frame. */
3239 case output_termcap:
3240 return Qt;
3241 case output_x_window:
3242 return Qx;
3243 case output_w32:
3244 return Qw32;
3245 case output_msdos_raw:
3246 return Qpc;
3247 case output_mac:
3248 return Qmac;
3249 default:
3250 abort ();
3251 }
3252}
3253
3254DEFUN ("display-list", Fdisplay_list, Sdisplay_list, 0, 0, 0,
3255 doc: /* Return a list of all display devices.
3256Display devices are represented by their integer identifiers. */)
3257 ()
3258{
3259 Lisp_Object devices = Qnil;
3260 struct device *d;
3261
3262 for (d = device_list; d; d = d->next_device)
3263 devices = Fcons (make_number (d->id), devices);
3264
3265 return devices;
3266}
3267
3268
3269
3270
3271DEFUN ("suspend-tty", Fsuspend_tty, Ssuspend_tty, 0, 1, 0,
3272 doc: /* Suspend the terminal device TTY.
3273
3274The device is restored to its default state, and Emacs ceases all
3275access to the tty device. Frames that use the device are not deleted,
3276but input is not read from them and if they change, their display is
3277not updated.
3278
3279TTY may be a terminal id, a frame, or nil for the terminal device of
3280the currently selected frame.
3281
3282This function runs `suspend-tty-functions' after suspending the
3283device. The functions are run with one arg, the id of the suspended
3284terminal device.
3285
3286`suspend-tty' does nothing if it is called on a device that is already
3287suspended.
3288
3289A suspended tty may be resumed by calling `resume-tty' on it. */)
3290 (tty)
3291 Lisp_Object tty;
3292{
3293 struct device *d = get_tty_device (tty);
3294 FILE *f;
3295
3296 if (!d)
3297 error ("Unknown tty device");
3298
3299 f = d->display_info.tty->input;
3300
3301 if (f)
3302 {
3303 reset_sys_modes (d->display_info.tty);
3304
3305 delete_keyboard_wait_descriptor (fileno (f));
3306
3307 fclose (f);
3308 if (f != d->display_info.tty->output)
3309 fclose (d->display_info.tty->output);
3310
3311 d->display_info.tty->input = 0;
3312 d->display_info.tty->output = 0;
3313
3314 if (FRAMEP (d->display_info.tty->top_frame))
3315 FRAME_SET_VISIBLE (XFRAME (d->display_info.tty->top_frame), 0);
3316
3317 /* Run `suspend-tty-functions'. */
3318 if (!NILP (Vrun_hooks))
3319 {
3320 Lisp_Object args[2];
3321 args[0] = intern ("suspend-tty-functions");
3322 args[1] = make_number (d->id);
3323 Frun_hook_with_args (2, args);
3324 }
3325 }
3326
3327 return Qnil;
3328}
3329
3330
3331DEFUN ("resume-tty", Fresume_tty, Sresume_tty, 0, 1, 0,
3332 doc: /* Resume the previously suspended terminal device TTY.
3333The terminal is opened and reinitialized. Frames that are on the
3334suspended display are revived.
3335
3336It is an error to resume a display while another display is active on
3337the same device.
3338
3339This function runs `resume-tty-functions' after resuming the device.
3340The functions are run with one arg, the id of the resumed display
3341device.
3342
3343`resume-tty' does nothing if it is called on a device that is not
3344suspended.
3345
3346TTY may be a display device id, a frame, or nil for the display device
3347of the currently selected frame. */)
3348 (tty)
3349 Lisp_Object tty;
3350{
3351 struct device *d = get_tty_device (tty);
3352 int fd;
3353
3354 if (!d)
3355 error ("Unknown tty device");
3356
3357 if (!d->display_info.tty->input)
3358 {
3359 if (get_named_tty (d->display_info.tty->name))
3360 error ("Cannot resume display while another display is active on the same device");
3361
3362 fd = emacs_open (d->display_info.tty->name, O_RDWR | O_NOCTTY, 0);
3363
3364 /* XXX What if open fails? */
3365
3366 dissociate_if_controlling_tty (fd);
3367
3368 d->display_info.tty->output = fdopen (fd, "w+");
3369 d->display_info.tty->input = d->display_info.tty->output;
3370
3371 add_keyboard_wait_descriptor (fd);
3372
3373 if (FRAMEP (d->display_info.tty->top_frame))
3374 FRAME_SET_VISIBLE (XFRAME (d->display_info.tty->top_frame), 1);
3375
3376 init_sys_modes (d->display_info.tty);
3377
3378 /* Run `suspend-tty-functions'. */
3379 if (!NILP (Vrun_hooks))
3380 {
3381 Lisp_Object args[2];
3382 args[0] = intern ("resume-tty-functions");
3383 args[1] = make_number (d->id);
3384 Frun_hook_with_args (2, args);
3385 }
3386 }
3387
3388 return Qnil;
3389}
3390
3391
3392void 3000void
3393syms_of_term () 3001syms_of_term ()
3394{ 3002{
@@ -3401,11 +3009,6 @@ This variable can be used by terminal emulator packages. */);
3401 system_uses_terminfo = 0; 3009 system_uses_terminfo = 0;
3402#endif 3010#endif
3403 3011
3404 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function,
3405 doc: /* Non-nil means call this function to ring the bell.
3406The function should accept no arguments. */);
3407 Vring_bell_function = Qnil;
3408
3409 DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions, 3012 DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions,
3410 doc: /* Functions to be run after suspending a tty. 3013 doc: /* Functions to be run after suspending a tty.
3411The functions are run with one argument, the name of the tty to be suspended. 3014The functions are run with one argument, the name of the tty to be suspended.
@@ -3422,17 +3025,10 @@ See `resume-tty'. */);
3422 defsubr (&Stty_display_color_p); 3025 defsubr (&Stty_display_color_p);
3423 defsubr (&Stty_display_color_cells); 3026 defsubr (&Stty_display_color_cells);
3424 defsubr (&Stty_no_underline); 3027 defsubr (&Stty_no_underline);
3425 defsubr (&Sdisplay_name);
3426 defsubr (&Sdisplay_tty_type); 3028 defsubr (&Sdisplay_tty_type);
3427 defsubr (&Sdisplay_controlling_tty_p); 3029 defsubr (&Sdisplay_controlling_tty_p);
3428 defsubr (&Sdelete_display);
3429 defsubr (&Sdisplay_live_p);
3430 defsubr (&Sdisplay_list);
3431 defsubr (&Ssuspend_tty); 3030 defsubr (&Ssuspend_tty);
3432 defsubr (&Sresume_tty); 3031 defsubr (&Sresume_tty);
3433
3434 Fprovide (intern ("multi-tty"), Qnil);
3435
3436} 3032}
3437 3033
3438 3034