Mercurial > hg > xemacs-beta
annotate src/console.c @ 5125:b5df3737028a ben-lisp-object
merge
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Feb 2010 01:58:04 -0600 |
parents | 623d57b7fbe8 ae48681c47fa |
children | 2a462149bd6a |
rev | line source |
---|---|
428 | 1 /* The console object. |
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. | |
800 | 3 Copyright (C) 1996, 2002 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Not in FSF. */ | |
23 | |
853 | 24 /* Written by Ben Wing, late 1995?. |
25 suspend-console, set-input-mode, and related stuff largely based on | |
26 existing code. | |
27 */ | |
428 | 28 |
29 #include <config.h> | |
30 #include "lisp.h" | |
31 | |
32 #include "buffer.h" | |
872 | 33 #include "console-impl.h" |
34 #include "device-impl.h" | |
428 | 35 #include "events.h" |
872 | 36 #include "frame-impl.h" |
428 | 37 #include "redisplay.h" |
38 #include "sysdep.h" | |
39 #include "window.h" | |
40 | |
1204 | 41 #include "console-stream-impl.h" |
872 | 42 #ifdef HAVE_TTY |
43 #include "console-tty-impl.h" | |
44 #endif | |
800 | 45 |
2340 | 46 #ifdef HAVE_TTY |
47 #define USED_IF_TTY(decl) decl | |
48 #else | |
49 #define USED_IF_TTY(decl) UNUSED (decl) | |
50 #endif | |
51 | |
428 | 52 Lisp_Object Vconsole_list, Vselected_console; |
53 | |
54 Lisp_Object Vcreate_console_hook, Vdelete_console_hook; | |
55 | |
56 Lisp_Object Qconsolep, Qconsole_live_p; | |
57 Lisp_Object Qcreate_console_hook; | |
58 Lisp_Object Qdelete_console_hook; | |
59 | |
60 Lisp_Object Qsuspend_hook; | |
61 Lisp_Object Qsuspend_resume_hook; | |
62 | |
63 /* This structure holds the default values of the console-local | |
64 variables defined with DEFVAR_CONSOLE_LOCAL, that have special | |
65 slots in each console. The default value occupies the same slot | |
66 in this structure as an individual console's value occupies in | |
67 that console. Setting the default value also goes through the | |
68 list of consoles and stores into each console that does not say | |
69 it has a local value. */ | |
70 Lisp_Object Vconsole_defaults; | |
71 static void *console_defaults_saved_slots; | |
72 | |
73 /* This structure marks which slots in a console have corresponding | |
74 default values in console_defaults. | |
75 Each such slot has a nonzero value in this structure. | |
76 The value has only one nonzero bit. | |
77 | |
78 When a console has its own local value for a slot, | |
79 the bit for that slot (found in the same slot in this structure) | |
80 is turned on in the console's local_var_flags slot. | |
81 | |
82 If a slot in this structure is 0, then there is a DEFVAR_CONSOLE_LOCAL | |
83 for the slot, but there is no default value for it; the corresponding | |
84 slot in console_defaults is not used except to initialize newly-created | |
85 consoles. | |
86 | |
87 If a slot is -1, then there is a DEFVAR_CONSOLE_LOCAL for it | |
88 as well as a default value which is used to initialize newly-created | |
89 consoles and as a reset-value when local-vars are killed. | |
90 | |
91 If a slot is -2, there is no DEFVAR_CONSOLE_LOCAL for it. | |
92 (The slot is always local, but there's no lisp variable for it.) | |
93 The default value is only used to initialize newly-creation consoles. | |
94 | |
95 If a slot is -3, then there is no DEFVAR_CONSOLE_LOCAL for it but | |
96 there is a default which is used to initialize newly-creation | |
97 consoles and as a reset-value when local-vars are killed. | |
98 | |
99 | |
100 */ | |
101 struct console console_local_flags; | |
102 | |
103 /* This structure holds the names of symbols whose values may be | |
104 console-local. It is indexed and accessed in the same way as the above. */ | |
105 static Lisp_Object Vconsole_local_symbols; | |
106 static void *console_local_symbols_saved_slots; | |
107 | |
108 DEFINE_CONSOLE_TYPE (dead); | |
109 | |
110 Lisp_Object Vconsole_type_list; | |
111 | |
112 console_type_entry_dynarr *the_console_type_entry_dynarr; | |
113 | |
114 | |
934 | 115 |
1204 | 116 static const struct memory_description console_data_description_1 []= { |
117 #ifdef HAVE_TTY | |
3092 | 118 #ifdef NEW_GC |
119 { XD_LISP_OBJECT, tty_console }, | |
120 #else /* not NEW_GC */ | |
2551 | 121 { XD_BLOCK_PTR, tty_console, 1, { &tty_console_data_description} }, |
3092 | 122 #endif /* not NEW_GC */ |
1204 | 123 #endif |
3092 | 124 #ifdef NEW_GC |
125 { XD_LISP_OBJECT, stream_console }, | |
126 #else /* not NEW_GC */ | |
2551 | 127 { XD_BLOCK_PTR, stream_console, 1, { &stream_console_data_description} }, |
3092 | 128 #endif /* not NEW_GC */ |
934 | 129 { XD_END } |
130 }; | |
131 | |
1204 | 132 static const struct sized_memory_description console_data_description = { |
133 sizeof (void *), console_data_description_1 | |
934 | 134 }; |
135 | |
1204 | 136 static const struct memory_description console_description [] = { |
934 | 137 { XD_INT, offsetof (struct console, contype) }, |
1204 | 138 #define MARKED_SLOT(x) { XD_LISP_OBJECT, offsetof (struct console, x) }, |
139 #include "conslots.h" | |
2367 | 140 { XD_BLOCK_PTR, offsetof (struct console, conmeths), 1, |
2551 | 141 { &console_methods_description } }, |
934 | 142 { XD_UNION, offsetof (struct console, console_data), |
2551 | 143 XD_INDIRECT (0, 0), { &console_data_description } }, |
934 | 144 { XD_END } |
145 }; | |
146 | |
428 | 147 static Lisp_Object |
148 mark_console (Lisp_Object obj) | |
149 { | |
150 struct console *con = XCONSOLE (obj); | |
151 | |
1204 | 152 #define MARKED_SLOT(x) mark_object (con->x); |
428 | 153 #include "conslots.h" |
154 | |
155 /* Can be zero for Vconsole_defaults, Vconsole_local_symbols */ | |
156 if (con->conmeths) | |
157 { | |
158 mark_object (con->conmeths->symbol); | |
159 MAYBE_CONMETH (con, mark_console, (con)); | |
160 } | |
161 | |
162 return Qnil; | |
163 } | |
164 | |
165 static void | |
2286 | 166 print_console (Lisp_Object obj, Lisp_Object printcharfun, |
167 int UNUSED (escapeflag)) | |
428 | 168 { |
169 struct console *con = XCONSOLE (obj); | |
170 | |
171 if (print_readably) | |
4846 | 172 printing_unreadable_lcrecord (obj, XSTRING_DATA (con->name)); |
428 | 173 |
800 | 174 write_fmt_string (printcharfun, "#<%s-console", |
175 !CONSOLE_LIVE_P (con) ? "dead" : CONSOLE_TYPE_NAME (con)); | |
440 | 176 if (CONSOLE_LIVE_P (con) && !NILP (CONSOLE_CONNECTION (con))) |
800 | 177 write_fmt_string_lisp (printcharfun, " on %S", 1, |
178 CONSOLE_CONNECTION (con)); | |
179 write_fmt_string (printcharfun, " 0x%x>", con->header.uid); | |
428 | 180 } |
181 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
182 DEFINE_NODUMP_LISP_OBJECT ("console", console, mark_console, |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
183 print_console, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
184 console_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
185 struct console); |
428 | 186 |
1204 | 187 |
188 static void | |
189 set_quit_events (struct console *con, Lisp_Object key) | |
190 { | |
191 /* Make sure to run Fcharacter_to_event() *BEFORE* setting QUIT_CHAR, | |
192 so that nothing is changed when invalid values trigger an error! */ | |
193 con->quit_event = Fcharacter_to_event (key, Qnil, wrap_console (con), Qnil); | |
194 con->quit_char = key; | |
195 con->critical_quit_event = Fcopy_event (con->quit_event, Qnil); | |
196 upshift_event (con->critical_quit_event); | |
197 } | |
198 | |
428 | 199 static struct console * |
1204 | 200 allocate_console (Lisp_Object type) |
428 | 201 { |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
202 Lisp_Object console = ALLOC_LISP_OBJECT (console); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
203 struct console *con = XCONSOLE (console); |
428 | 204 struct gcpro gcpro1; |
205 | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
206 COPY_LISP_OBJECT (con, XCONSOLE (Vconsole_defaults)); |
428 | 207 |
208 GCPRO1 (console); | |
209 | |
1204 | 210 con->conmeths = decode_console_type (type, ERROR_ME); |
211 con->contype = get_console_variant (type); | |
771 | 212 con->command_builder = allocate_command_builder (console, 1); |
428 | 213 con->function_key_map = Fmake_sparse_keymap (Qnil); |
1204 | 214 set_quit_events (con, make_char (7)); /* C-g */ |
428 | 215 |
216 UNGCPRO; | |
217 return con; | |
218 } | |
219 | |
220 struct console * | |
221 decode_console (Lisp_Object console) | |
222 { | |
223 if (NILP (console)) | |
224 console = Fselected_console (); | |
225 /* quietly accept devices and frames for the console arg */ | |
226 if (DEVICEP (console) || FRAMEP (console)) | |
227 console = DEVICE_CONSOLE (decode_device (console)); | |
228 CHECK_LIVE_CONSOLE (console); | |
229 return XCONSOLE (console); | |
230 } | |
231 | |
232 | |
233 struct console_methods * | |
578 | 234 decode_console_type (Lisp_Object type, Error_Behavior errb) |
428 | 235 { |
236 int i; | |
237 | |
238 for (i = 0; i < Dynarr_length (the_console_type_entry_dynarr); i++) | |
239 if (EQ (type, Dynarr_at (the_console_type_entry_dynarr, i).symbol)) | |
240 return Dynarr_at (the_console_type_entry_dynarr, i).meths; | |
241 | |
563 | 242 maybe_invalid_constant ("Invalid console type", type, Qconsole, errb); |
428 | 243 |
244 return 0; | |
245 } | |
246 | |
934 | 247 enum console_variant |
248 get_console_variant (Lisp_Object type) | |
249 { | |
250 if (EQ (type, Qtty)) | |
1204 | 251 return tty_console; |
934 | 252 |
253 if (EQ (type, Qgtk)) | |
1204 | 254 return gtk_console; |
934 | 255 |
256 if (EQ (type, Qx)) | |
1204 | 257 return x_console; |
934 | 258 |
259 if (EQ (type, Qmswindows)) | |
1204 | 260 return mswindows_console; |
934 | 261 |
1346 | 262 if (EQ (type, Qmsprinter)) |
263 return msprinter_console; | |
264 | |
934 | 265 if (EQ (type, Qstream)) |
1204 | 266 return stream_console; |
934 | 267 |
2500 | 268 ABORT (); /* should never happen */ |
934 | 269 return dead_console; |
270 } | |
271 | |
428 | 272 int |
273 valid_console_type_p (Lisp_Object type) | |
274 { | |
275 return decode_console_type (type, ERROR_ME_NOT) != 0; | |
276 } | |
277 | |
278 DEFUN ("valid-console-type-p", Fvalid_console_type_p, 1, 1, 0, /* | |
444 | 279 Return t if CONSOLE-TYPE is a valid console type. |
3025 | 280 Valid types are `x', `tty', `mswindows', `msprinter', `gtk', and `stream'. |
428 | 281 */ |
282 (console_type)) | |
283 { | |
284 return valid_console_type_p (console_type) ? Qt : Qnil; | |
285 } | |
286 | |
287 DEFUN ("console-type-list", Fconsole_type_list, 0, 0, 0, /* | |
288 Return a list of valid console types. | |
289 */ | |
290 ()) | |
291 { | |
292 return Fcopy_sequence (Vconsole_type_list); | |
293 } | |
294 | |
295 DEFUN ("cdfw-console", Fcdfw_console, 1, 1, 0, /* | |
296 Given a console, device, frame, or window, return the associated console. | |
297 Return nil otherwise. | |
298 */ | |
444 | 299 (object)) |
428 | 300 { |
444 | 301 return CDFW_CONSOLE (object); |
428 | 302 } |
303 | |
872 | 304 int |
305 console_live_p (struct console *c) | |
306 { | |
307 return CONSOLE_LIVE_P (c); | |
308 } | |
309 | |
310 Lisp_Object | |
311 console_device_list (struct console *c) | |
312 { | |
313 return CONSOLE_DEVICE_LIST (c); | |
314 } | |
315 | |
428 | 316 |
317 DEFUN ("selected-console", Fselected_console, 0, 0, 0, /* | |
318 Return the console which is currently active. | |
319 */ | |
320 ()) | |
321 { | |
322 return Vselected_console; | |
323 } | |
324 | |
325 /* Called from selected_device_1(), called from selected_frame_1(), | |
326 called from Fselect_window() */ | |
327 void | |
328 select_console_1 (Lisp_Object console) | |
329 { | |
330 /* perhaps this should do something more complicated */ | |
331 Vselected_console = console; | |
332 | |
333 /* #### Schedule this to be removed in 19.14 */ | |
334 #ifdef HAVE_X_WINDOWS | |
335 if (CONSOLE_X_P (XCONSOLE (console))) | |
336 Vwindow_system = Qx; | |
337 else | |
338 #endif | |
462 | 339 #ifdef HAVE_GTK |
340 if (CONSOLE_GTK_P (XCONSOLE (console))) | |
341 Vwindow_system = Qgtk; | |
342 else | |
343 #endif | |
428 | 344 #ifdef HAVE_MS_WINDOWS |
345 if (CONSOLE_MSWINDOWS_P (XCONSOLE (console))) | |
346 Vwindow_system = Qmswindows; | |
347 else | |
348 #endif | |
349 Vwindow_system = Qnil; | |
350 } | |
351 | |
352 DEFUN ("select-console", Fselect_console, 1, 1, 0, /* | |
353 Select the console CONSOLE. | |
354 Subsequent editing commands apply to its selected device, selected frame, | |
355 and selected window. The selection of CONSOLE lasts until the next time | |
356 the user does something to select a different console, or until the next | |
357 time this function is called. | |
358 */ | |
359 (console)) | |
360 { | |
361 Lisp_Object device; | |
362 | |
363 CHECK_LIVE_CONSOLE (console); | |
364 | |
365 device = CONSOLE_SELECTED_DEVICE (XCONSOLE (console)); | |
366 if (!NILP (device)) | |
367 { | |
368 struct device *d = XDEVICE (device); | |
369 Lisp_Object frame = DEVICE_SELECTED_FRAME (d); | |
370 if (!NILP (frame)) | |
371 { | |
372 struct frame *f = XFRAME(frame); | |
373 Fselect_window (FRAME_SELECTED_WINDOW (f), Qnil); | |
374 } | |
375 else | |
563 | 376 invalid_operation ("Can't select console with no frames", Qunbound); |
428 | 377 } |
378 else | |
563 | 379 invalid_operation ("Can't select a console with no devices", Qunbound); |
428 | 380 return Qnil; |
381 } | |
382 | |
383 void | |
384 set_console_last_nonminibuf_frame (struct console *con, | |
385 Lisp_Object frame) | |
386 { | |
387 con->last_nonminibuf_frame = frame; | |
388 } | |
389 | |
390 DEFUN ("consolep", Fconsolep, 1, 1, 0, /* | |
391 Return non-nil if OBJECT is a console. | |
392 */ | |
393 (object)) | |
394 { | |
395 return CONSOLEP (object) ? Qt : Qnil; | |
396 } | |
397 | |
398 DEFUN ("console-live-p", Fconsole_live_p, 1, 1, 0, /* | |
399 Return non-nil if OBJECT is a console that has not been deleted. | |
400 */ | |
401 (object)) | |
402 { | |
403 return CONSOLEP (object) && CONSOLE_LIVE_P (XCONSOLE (object)) ? Qt : Qnil; | |
404 } | |
405 | |
406 DEFUN ("console-type", Fconsole_type, 0, 1, 0, /* | |
444 | 407 Return the console type (e.g. `x' or `tty') of CONSOLE. |
1346 | 408 Value is |
409 `tty' for a tty console (a character-only terminal), | |
428 | 410 `x' for a console that is an X display, |
1346 | 411 `mswindows' for a console that is an MS Windows connection, |
412 `msprinter' for a console that is an MS Windows printer connection, | |
413 `gtk' for a console that is a GTK connection, | |
428 | 414 `stream' for a stream console (which acts like a stdio stream), and |
415 `dead' for a deleted console. | |
416 */ | |
417 (console)) | |
418 { | |
419 /* don't call decode_console() because we want to allow for dead | |
420 consoles. */ | |
421 if (NILP (console)) | |
422 console = Fselected_console (); | |
423 CHECK_CONSOLE (console); | |
424 return CONSOLE_TYPE (XCONSOLE (console)); | |
425 } | |
426 | |
427 DEFUN ("console-name", Fconsole_name, 0, 1, 0, /* | |
444 | 428 Return the name of CONSOLE. |
428 | 429 */ |
430 (console)) | |
431 { | |
432 return CONSOLE_NAME (decode_console (console)); | |
433 } | |
434 | |
435 DEFUN ("console-connection", Fconsole_connection, 0, 1, 0, /* | |
436 Return the connection of the specified console. | |
437 CONSOLE defaults to the selected console if omitted. | |
438 */ | |
439 (console)) | |
440 { | |
441 return CONSOLE_CONNECTION (decode_console (console)); | |
442 } | |
443 | |
444 static Lisp_Object | |
445 semi_canonicalize_console_connection (struct console_methods *meths, | |
578 | 446 Lisp_Object name, Error_Behavior errb) |
428 | 447 { |
440 | 448 if (HAS_CONTYPE_METH_P (meths, semi_canonicalize_console_connection)) |
449 return CONTYPE_METH (meths, semi_canonicalize_console_connection, | |
450 (name, errb)); | |
451 else | |
452 return CONTYPE_METH_OR_GIVEN (meths, canonicalize_console_connection, | |
453 (name, errb), name); | |
428 | 454 } |
455 | |
456 static Lisp_Object | |
457 canonicalize_console_connection (struct console_methods *meths, | |
578 | 458 Lisp_Object name, Error_Behavior errb) |
428 | 459 { |
440 | 460 if (HAS_CONTYPE_METH_P (meths, canonicalize_console_connection)) |
461 return CONTYPE_METH (meths, canonicalize_console_connection, | |
462 (name, errb)); | |
463 else | |
464 return CONTYPE_METH_OR_GIVEN (meths, semi_canonicalize_console_connection, | |
465 (name, errb), name); | |
428 | 466 } |
467 | |
468 static Lisp_Object | |
469 find_console_of_type (struct console_methods *meths, Lisp_Object canon) | |
470 { | |
471 Lisp_Object concons; | |
472 | |
473 CONSOLE_LOOP (concons) | |
474 { | |
475 Lisp_Object console = XCAR (concons); | |
476 | |
477 if (EQ (CONMETH_TYPE (meths), CONSOLE_TYPE (XCONSOLE (console))) | |
478 && internal_equal (CONSOLE_CANON_CONNECTION (XCONSOLE (console)), | |
479 canon, 0)) | |
480 return console; | |
481 } | |
482 | |
483 return Qnil; | |
484 } | |
485 | |
486 DEFUN ("find-console", Ffind_console, 1, 2, 0, /* | |
487 Look for an existing console attached to connection CONNECTION. | |
488 Return the console if found; otherwise, return nil. | |
489 | |
490 If TYPE is specified, only return consoles of that type; otherwise, | |
491 return consoles of any type. (It is possible, although unlikely, | |
492 that two consoles of different types could have the same connection | |
493 name; in such a case, the first console found is returned.) | |
494 */ | |
495 (connection, type)) | |
496 { | |
497 Lisp_Object canon = Qnil; | |
498 struct gcpro gcpro1; | |
499 | |
500 GCPRO1 (canon); | |
501 | |
502 if (!NILP (type)) | |
503 { | |
504 struct console_methods *conmeths = decode_console_type (type, ERROR_ME); | |
505 canon = canonicalize_console_connection (conmeths, connection, | |
506 ERROR_ME_NOT); | |
507 if (UNBOUNDP (canon)) | |
508 RETURN_UNGCPRO (Qnil); | |
509 | |
510 RETURN_UNGCPRO (find_console_of_type (conmeths, canon)); | |
511 } | |
512 else | |
513 { | |
514 int i; | |
515 | |
516 for (i = 0; i < Dynarr_length (the_console_type_entry_dynarr); i++) | |
517 { | |
518 struct console_methods *conmeths = | |
519 Dynarr_at (the_console_type_entry_dynarr, i).meths; | |
520 canon = canonicalize_console_connection (conmeths, connection, | |
521 ERROR_ME_NOT); | |
522 if (!UNBOUNDP (canon)) | |
523 { | |
524 Lisp_Object console = find_console_of_type (conmeths, canon); | |
525 if (!NILP (console)) | |
526 RETURN_UNGCPRO (console); | |
527 } | |
528 } | |
529 | |
530 RETURN_UNGCPRO (Qnil); | |
531 } | |
532 } | |
533 | |
534 DEFUN ("get-console", Fget_console, 1, 2, 0, /* | |
535 Look for an existing console attached to connection CONNECTION. | |
536 Return the console if found; otherwise, signal an error. | |
537 | |
538 If TYPE is specified, only return consoles of that type; otherwise, | |
539 return consoles of any type. (It is possible, although unlikely, | |
540 that two consoles of different types could have the same connection | |
541 name; in such a case, the first console found is returned.) | |
542 */ | |
543 (connection, type)) | |
544 { | |
545 Lisp_Object console = Ffind_console (connection, type); | |
546 if (NILP (console)) | |
547 { | |
548 if (NILP (type)) | |
563 | 549 invalid_argument ("No such console", connection); |
428 | 550 else |
563 | 551 invalid_argument_2 ("No such console", type, connection); |
428 | 552 } |
553 return console; | |
554 } | |
555 | |
556 Lisp_Object | |
557 create_console (Lisp_Object name, Lisp_Object type, Lisp_Object connection, | |
558 Lisp_Object props) | |
559 { | |
560 /* This function can GC */ | |
561 struct console *con; | |
562 Lisp_Object console; | |
563 struct gcpro gcpro1; | |
564 | |
565 console = Ffind_console (connection, type); | |
566 if (!NILP (console)) | |
567 return console; | |
568 | |
1204 | 569 con = allocate_console (type); |
793 | 570 console = wrap_console (con); |
428 | 571 |
572 GCPRO1 (console); | |
573 | |
574 CONSOLE_NAME (con) = name; | |
575 CONSOLE_CONNECTION (con) = | |
576 semi_canonicalize_console_connection (con->conmeths, connection, | |
577 ERROR_ME); | |
578 CONSOLE_CANON_CONNECTION (con) = | |
579 canonicalize_console_connection (con->conmeths, connection, | |
580 ERROR_ME); | |
581 | |
582 MAYBE_CONMETH (con, init_console, (con, props)); | |
583 | |
584 /* Do it this way so that the console list is in order of creation */ | |
585 Vconsole_list = nconc2 (Vconsole_list, Fcons (console, Qnil)); | |
853 | 586 note_object_created (console); |
428 | 587 |
440 | 588 if (CONMETH_OR_GIVEN (con, initially_selected_for_input, (con), 0)) |
428 | 589 event_stream_select_console (con); |
590 | |
591 UNGCPRO; | |
592 return console; | |
593 } | |
594 | |
595 void | |
596 add_entry_to_console_type_list (Lisp_Object symbol, | |
597 struct console_methods *meths) | |
598 { | |
599 struct console_type_entry entry; | |
600 | |
601 entry.symbol = symbol; | |
602 entry.meths = meths; | |
603 Dynarr_add (the_console_type_entry_dynarr, entry); | |
604 Vconsole_type_list = Fcons (symbol, Vconsole_type_list); | |
605 } | |
606 | |
607 /* find a console other than the selected one. Prefer non-stream | |
608 consoles over stream consoles. */ | |
609 | |
610 static Lisp_Object | |
611 find_other_console (Lisp_Object console) | |
612 { | |
613 Lisp_Object concons; | |
614 | |
615 /* look for a non-stream console */ | |
616 CONSOLE_LOOP (concons) | |
617 { | |
618 Lisp_Object con = XCAR (concons); | |
619 if (!CONSOLE_STREAM_P (XCONSOLE (con)) | |
620 && !EQ (con, console) | |
621 && !NILP (CONSOLE_SELECTED_DEVICE (XCONSOLE (con))) | |
622 && !NILP (DEVICE_SELECTED_FRAME | |
623 (XDEVICE (CONSOLE_SELECTED_DEVICE (XCONSOLE (con)))))) | |
624 break; | |
625 } | |
626 if (!NILP (concons)) | |
627 return XCAR (concons); | |
628 | |
629 /* OK, now look for a stream console */ | |
630 CONSOLE_LOOP (concons) | |
631 { | |
632 Lisp_Object con = XCAR (concons); | |
633 if (!EQ (con, console) | |
634 && !NILP (CONSOLE_SELECTED_DEVICE (XCONSOLE (con))) | |
635 && !NILP (DEVICE_SELECTED_FRAME | |
636 (XDEVICE (CONSOLE_SELECTED_DEVICE (XCONSOLE (con)))))) | |
637 break; | |
638 } | |
639 if (!NILP (concons)) | |
640 return XCAR (concons); | |
641 | |
642 /* Sorry, there ain't none */ | |
643 return Qnil; | |
644 } | |
645 | |
646 static int | |
647 find_nonminibuffer_frame_not_on_console_predicate (Lisp_Object frame, | |
648 void *closure) | |
649 { | |
650 Lisp_Object console; | |
651 | |
5013 | 652 console = GET_LISP_FROM_VOID (closure); |
428 | 653 if (FRAME_MINIBUF_ONLY_P (XFRAME (frame))) |
654 return 0; | |
655 if (EQ (console, FRAME_CONSOLE (XFRAME (frame)))) | |
656 return 0; | |
657 return 1; | |
658 } | |
659 | |
660 static Lisp_Object | |
661 find_nonminibuffer_frame_not_on_console (Lisp_Object console) | |
662 { | |
663 return find_some_frame (find_nonminibuffer_frame_not_on_console_predicate, | |
5013 | 664 STORE_LISP_IN_VOID (console)); |
428 | 665 } |
666 | |
617 | 667 static void |
668 nuke_all_console_slots (struct console *con, Lisp_Object zap) | |
669 { | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
670 ZERO_LISP_OBJECT (con); |
617 | 671 |
1204 | 672 #define MARKED_SLOT(x) con->x = zap; |
617 | 673 #include "conslots.h" |
674 } | |
675 | |
428 | 676 /* Delete console CON. |
677 | |
678 If FORCE is non-zero, allow deletion of the only frame. | |
679 | |
680 If CALLED_FROM_KILL_EMACS is non-zero, then, if | |
681 deleting the last console, just delete it, | |
682 instead of calling `save-buffers-kill-emacs'. | |
683 | |
684 If FROM_IO_ERROR is non-zero, then the console is gone due | |
685 to an I/O error. This affects what happens if we exit | |
686 (we do an emergency exit instead of `save-buffers-kill-emacs'.) | |
687 */ | |
688 | |
689 void | |
690 delete_console_internal (struct console *con, int force, | |
691 int called_from_kill_emacs, int from_io_error) | |
692 { | |
693 /* This function can GC */ | |
694 Lisp_Object console; | |
695 struct gcpro gcpro1; | |
696 | |
697 /* OK to delete an already-deleted console. */ | |
698 if (!CONSOLE_LIVE_P (con)) | |
699 return; | |
700 | |
793 | 701 console = wrap_console (con); |
853 | 702 |
703 if (!force) | |
704 check_allowed_operation (OPERATION_DELETE_OBJECT, console, Qnil); | |
705 | |
428 | 706 GCPRO1 (console); |
707 | |
708 if (!called_from_kill_emacs) | |
709 { | |
710 int down_we_go = 0; | |
711 | |
712 if ((XINT (Flength (Vconsole_list)) == 1) | |
713 /* if we just created the console, it might not be listed, | |
714 or something ... */ | |
715 && !NILP (memq_no_quit (console, Vconsole_list))) | |
716 down_we_go = 1; | |
717 /* If there aren't any nonminibuffer frames that would | |
718 be left, then exit. */ | |
719 else if (NILP (find_nonminibuffer_frame_not_on_console (console))) | |
720 down_we_go = 1; | |
721 | |
722 if (down_we_go) | |
723 { | |
724 if (!force) | |
563 | 725 invalid_operation ("Attempt to delete the only frame", Qunbound); |
428 | 726 else if (from_io_error) |
727 { | |
728 /* Mayday mayday! We're going down! */ | |
729 stderr_out (" Autosaving and exiting...\n"); | |
730 Vwindow_system = Qnil; /* let it lie! */ | |
731 preparing_for_armageddon = 1; | |
732 Fkill_emacs (make_int (70)); | |
733 } | |
734 else | |
735 { | |
736 call0 (Qsave_buffers_kill_emacs); | |
737 UNGCPRO; | |
738 /* If we get here, the user said they didn't want | |
739 to exit, so don't. */ | |
740 return; | |
741 } | |
742 } | |
743 } | |
744 | |
745 /* Breathe a sigh of relief. We're still alive. */ | |
746 | |
747 { | |
748 Lisp_Object frmcons, devcons; | |
749 | |
750 /* First delete all frames without their own minibuffers, | |
751 to avoid errors coming from attempting to delete a frame | |
752 that is a surrogate for another frame. | |
753 | |
754 We don't set "called_from_delete_console" because we want the | |
755 device to go ahead and get deleted if we delete the last frame | |
756 on a device. We won't run into trouble here because for any | |
757 frame without a minibuffer, there has to be another one on | |
758 the same console with a minibuffer, and we're not deleting that, | |
759 so delete_console_internal() won't get recursively called. | |
760 | |
761 WRONG! With surrogate minibuffers this isn't true. Frames | |
762 with only a minibuffer are not enough to prevent | |
763 delete_frame_internal from triggering a device deletion. */ | |
764 CONSOLE_FRAME_LOOP_NO_BREAK (frmcons, devcons, con) | |
765 { | |
766 struct frame *f = XFRAME (XCAR (frmcons)); | |
767 /* delete_frame_internal() might do anything such as run hooks, | |
768 so be defensive. */ | |
769 if (FRAME_LIVE_P (f) && !FRAME_HAS_MINIBUF_P (f)) | |
770 delete_frame_internal (f, 1, 1, from_io_error); | |
771 | |
772 if (!CONSOLE_LIVE_P (con)) /* make sure the delete-*-hook didn't | |
773 go ahead and delete anything */ | |
774 { | |
775 UNGCPRO; | |
776 return; | |
777 } | |
778 } | |
779 | |
780 CONSOLE_DEVICE_LOOP (devcons, con) | |
781 { | |
782 struct device *d = XDEVICE (XCAR (devcons)); | |
783 /* delete_device_internal() might do anything such as run hooks, | |
784 so be defensive. */ | |
785 if (DEVICE_LIVE_P (d)) | |
786 delete_device_internal (d, 1, 1, from_io_error); | |
787 if (!CONSOLE_LIVE_P (con)) /* make sure the delete-*-hook didn't | |
788 go ahead and delete anything */ | |
789 { | |
790 UNGCPRO; | |
791 return; | |
792 } | |
793 } | |
794 } | |
795 | |
796 CONSOLE_SELECTED_DEVICE (con) = Qnil; | |
797 | |
798 /* try to select another console */ | |
799 | |
800 if (EQ (console, Fselected_console ())) | |
801 { | |
802 Lisp_Object other_dev = find_other_console (console); | |
803 if (!NILP (other_dev)) | |
804 Fselect_console (other_dev); | |
805 else | |
806 { | |
807 /* necessary? */ | |
808 Vselected_console = Qnil; | |
809 Vwindow_system = Qnil; | |
810 } | |
811 } | |
812 | |
813 if (con->input_enabled) | |
814 event_stream_unselect_console (con); | |
815 | |
816 MAYBE_CONMETH (con, delete_console, (con)); | |
817 | |
818 Vconsole_list = delq_no_quit (console, Vconsole_list); | |
617 | 819 |
428 | 820 RESET_CHANGED_SET_FLAGS; |
617 | 821 |
822 /* Nobody should be accessing anything in this object any more, and | |
823 making all Lisp_Objects Qnil allows for better GC'ing in case a | |
824 pointer to the dead console continues to hang around. Zero all | |
825 other structs in case someone tries to access something through | |
826 them. */ | |
827 nuke_all_console_slots (con, Qnil); | |
428 | 828 con->conmeths = dead_console_methods; |
1204 | 829 con->contype = dead_console; |
853 | 830 note_object_deleted (console); |
428 | 831 |
832 UNGCPRO; | |
833 } | |
834 | |
835 void | |
836 io_error_delete_console (Lisp_Object console) | |
837 { | |
838 delete_console_internal (XCONSOLE (console), 1, 0, 1); | |
839 } | |
840 | |
841 DEFUN ("delete-console", Fdelete_console, 1, 2, 0, /* | |
842 Delete CONSOLE, permanently eliminating it from use. | |
843 Normally, you cannot delete the last non-minibuffer-only frame (you must | |
844 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional | |
845 second argument FORCE is non-nil, you can delete the last frame. (This | |
846 will automatically call `save-buffers-kill-emacs'.) | |
847 */ | |
848 (console, force)) | |
849 { | |
850 CHECK_CONSOLE (console); | |
851 delete_console_internal (XCONSOLE (console), !NILP (force), 0, 0); | |
852 return Qnil; | |
853 } | |
854 | |
855 DEFUN ("console-list", Fconsole_list, 0, 0, 0, /* | |
856 Return a list of all consoles. | |
857 */ | |
858 ()) | |
859 { | |
860 return Fcopy_sequence (Vconsole_list); | |
861 } | |
862 | |
863 DEFUN ("console-device-list", Fconsole_device_list, 0, 1, 0, /* | |
864 Return a list of all devices on CONSOLE. | |
444 | 865 If CONSOLE is nil, the selected console is used. |
428 | 866 */ |
867 (console)) | |
868 { | |
869 return Fcopy_sequence (CONSOLE_DEVICE_LIST (decode_console (console))); | |
870 } | |
871 | |
872 DEFUN ("console-enable-input", Fconsole_enable_input, 1, 1, 0, /* | |
873 Enable input on console CONSOLE. | |
874 */ | |
875 (console)) | |
876 { | |
877 struct console *con = decode_console (console); | |
878 if (!con->input_enabled) | |
879 event_stream_select_console (con); | |
880 return Qnil; | |
881 } | |
882 | |
883 DEFUN ("console-disable-input", Fconsole_disable_input, 1, 1, 0, /* | |
884 Disable input on console CONSOLE. | |
885 */ | |
886 (console)) | |
887 { | |
888 struct console *con = decode_console (console); | |
889 if (con->input_enabled) | |
890 event_stream_unselect_console (con); | |
891 return Qnil; | |
892 } | |
893 | |
894 DEFUN ("console-on-window-system-p", Fconsole_on_window_system_p, 0, 1, 0, /* | |
444 | 895 Return t if CONSOLE is on a window system. |
896 If CONSOLE is nil, the selected console is used. | |
428 | 897 This generally means that there is support for the mouse, the menubar, |
898 the toolbar, glyphs, etc. | |
899 */ | |
900 (console)) | |
901 { | |
902 Lisp_Object type = CONSOLE_TYPE (decode_console (console)); | |
903 | |
904 return !EQ (type, Qtty) && !EQ (type, Qstream) ? Qt : Qnil; | |
905 } | |
906 | |
907 | |
908 | |
909 /**********************************************************************/ | |
910 /* Miscellaneous low-level functions */ | |
911 /**********************************************************************/ | |
912 | |
913 static Lisp_Object | |
914 unwind_init_sys_modes (Lisp_Object console) | |
915 { | |
916 reinit_initial_console (); | |
917 | |
918 if (!no_redraw_on_reenter && | |
919 CONSOLEP (console) && | |
920 CONSOLE_LIVE_P (XCONSOLE (console))) | |
921 { | |
922 struct frame *f = | |
923 XFRAME (DEVICE_SELECTED_FRAME | |
924 (XDEVICE (CONSOLE_SELECTED_DEVICE (XCONSOLE (console))))); | |
925 MARK_FRAME_CHANGED (f); | |
926 } | |
927 return Qnil; | |
928 } | |
929 | |
930 DEFUN ("suspend-emacs", Fsuspend_emacs, 0, 1, "", /* | |
931 Stop Emacs and return to superior process. You can resume later. | |
932 On systems that don't have job control, run a subshell instead. | |
933 | |
934 If optional arg STUFFSTRING is non-nil, its characters are stuffed | |
935 to be read as terminal input by Emacs's superior shell. | |
936 | |
937 Before suspending, run the normal hook `suspend-hook'. | |
938 After resumption run the normal hook `suspend-resume-hook'. | |
939 | |
940 Some operating systems cannot stop the Emacs process and resume it later. | |
941 On such systems, Emacs will start a subshell and wait for it to exit. | |
942 */ | |
943 (stuffstring)) | |
944 { | |
945 int speccount = specpdl_depth (); | |
946 struct gcpro gcpro1; | |
947 | |
948 if (!NILP (stuffstring)) | |
949 CHECK_STRING (stuffstring); | |
950 GCPRO1 (stuffstring); | |
951 | |
952 /* There used to be a check that the initial console is TTY. | |
953 This is bogus. Even checking to see whether any console | |
954 is a controlling terminal is not correct -- maybe | |
955 the user used the -t option or something. If we want to | |
956 suspend, then we suspend. Period. */ | |
957 | |
958 /* Call value of suspend-hook. */ | |
959 run_hook (Qsuspend_hook); | |
960 | |
961 reset_initial_console (); | |
962 /* sys_suspend can get an error if it tries to fork a subshell | |
963 and the system resources aren't available for that. */ | |
964 record_unwind_protect (unwind_init_sys_modes, Vcontrolling_terminal); | |
965 stuff_buffered_input (stuffstring); | |
966 sys_suspend (); | |
967 /* the console is un-reset inside of the unwind-protect. */ | |
771 | 968 unbind_to (speccount); |
428 | 969 |
970 #ifdef SIGWINCH | |
971 /* It is possible that a size change occurred while we were | |
972 suspended. Assume one did just to be safe. It won't hurt | |
973 anything if one didn't. */ | |
974 asynch_device_change_pending++; | |
975 #endif | |
976 | |
977 /* Call value of suspend-resume-hook | |
978 if it is bound and value is non-nil. */ | |
979 run_hook (Qsuspend_resume_hook); | |
980 | |
981 UNGCPRO; | |
982 return Qnil; | |
983 } | |
984 | |
985 /* If STUFFSTRING is a string, stuff its contents as pending terminal input. | |
986 Then in any case stuff anything Emacs has read ahead and not used. */ | |
987 | |
988 void | |
2286 | 989 stuff_buffered_input ( |
3146 | 990 #if defined(BSD) && defined(HAVE_TTY) |
2286 | 991 Lisp_Object stuffstring |
992 #else | |
993 Lisp_Object UNUSED (stuffstring) | |
994 #endif | |
995 ) | |
428 | 996 { |
997 /* stuff_char works only in BSD, versions 4.2 and up. */ | |
3146 | 998 #if defined(BSD) && defined(HAVE_TTY) |
428 | 999 if (!CONSOLEP (Vcontrolling_terminal) || |
1000 !CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal))) | |
1001 return; | |
1002 | |
1003 if (STRINGP (stuffstring)) | |
1004 { | |
665 | 1005 Bytecount count; |
428 | 1006 Extbyte *p; |
1007 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1008 LISP_STRING_TO_SIZED_EXTERNAL (stuffstring, p, count, Qkeyboard); |
428 | 1009 while (count-- > 0) |
1010 stuff_char (XCONSOLE (Vcontrolling_terminal), *p++); | |
1011 stuff_char (XCONSOLE (Vcontrolling_terminal), '\n'); | |
1012 } | |
1013 /* Anything we have read ahead, put back for the shell to read. */ | |
1014 # if 0 /* oh, who cares about this silliness */ | |
1015 while (kbd_fetch_ptr != kbd_store_ptr) | |
1016 { | |
1017 if (kbd_fetch_ptr == kbd_buffer + KBD_BUFFER_SIZE) | |
1018 kbd_fetch_ptr = kbd_buffer; | |
1019 stuff_char (XCONSOLE (Vcontrolling_terminal), *kbd_fetch_ptr++); | |
1020 } | |
1021 # endif | |
3146 | 1022 #endif /* BSD && HAVE_TTY */ |
428 | 1023 } |
1024 | |
1025 DEFUN ("suspend-console", Fsuspend_console, 0, 1, "", /* | |
1026 Suspend a console. For tty consoles, it sends a signal to suspend | |
1027 the process in charge of the tty, and removes the devices and | |
1028 frames of that console from the display. | |
1029 | |
1030 If optional arg CONSOLE is non-nil, it is the console to be suspended. | |
1031 Otherwise it is assumed to be the selected console. | |
1032 | |
1033 Some operating systems cannot stop processes and resume them later. | |
1034 On such systems, who knows what will happen. | |
1035 */ | |
2340 | 1036 (USED_IF_TTY (console))) |
428 | 1037 { |
1038 #ifdef HAVE_TTY | |
1039 struct console *con = decode_console (console); | |
1040 | |
1041 if (CONSOLE_TTY_P (con)) | |
1042 { | |
1043 /* | |
1044 * hide all the unhidden frames so the display code won't update | |
1045 * them while the console is suspended. | |
1046 */ | |
1047 Lisp_Object device = CONSOLE_SELECTED_DEVICE (con); | |
1048 if (!NILP (device)) | |
1049 { | |
1050 struct device *d = XDEVICE (device); | |
1051 Lisp_Object frame_list = DEVICE_FRAME_LIST (d); | |
1052 while (CONSP (frame_list)) | |
1053 { | |
1054 struct frame *f = XFRAME (XCAR (frame_list)); | |
1055 if (FRAME_REPAINT_P (f)) | |
1056 f->visible = -1; | |
1057 frame_list = XCDR (frame_list); | |
1058 } | |
1059 } | |
1060 reset_one_console (con); | |
1061 event_stream_unselect_console (con); | |
1062 sys_suspend_process (XINT (Fconsole_tty_controlling_process (console))); | |
1063 } | |
1064 #endif /* HAVE_TTY */ | |
1065 | |
1066 return Qnil; | |
1067 } | |
1068 | |
1069 DEFUN ("resume-console", Fresume_console, 1, 1, "", /* | |
1070 Re-initialize a previously suspended console. | |
1071 For tty consoles, do stuff to the tty to make it sane again. | |
1072 */ | |
2340 | 1073 (USED_IF_TTY (console))) |
428 | 1074 { |
1075 #ifdef HAVE_TTY | |
1076 struct console *con = decode_console (console); | |
1077 | |
1078 if (CONSOLE_TTY_P (con)) | |
1079 { | |
1080 /* raise the selected frame */ | |
1081 Lisp_Object device = CONSOLE_SELECTED_DEVICE (con); | |
1082 if (!NILP (device)) | |
1083 { | |
1084 struct device *d = XDEVICE (device); | |
1085 Lisp_Object frame = DEVICE_SELECTED_FRAME (d); | |
1086 if (!NILP (frame)) | |
1087 { | |
1088 /* force the frame to be cleared */ | |
1089 SET_FRAME_CLEAR (XFRAME (frame)); | |
1090 Fraise_frame (frame); | |
1091 } | |
1092 } | |
1093 init_one_console (con); | |
1094 event_stream_select_console (con); | |
1095 #ifdef SIGWINCH | |
1096 /* The same as in Fsuspend_emacs: it is possible that a size | |
1097 change occurred while we were suspended. Assume one did just | |
1098 to be safe. It won't hurt anything if one didn't. */ | |
1099 asynch_device_change_pending++; | |
1100 #endif | |
1101 } | |
1102 #endif /* HAVE_TTY */ | |
1103 | |
1104 return Qnil; | |
1105 } | |
1106 | |
1107 DEFUN ("set-input-mode", Fset_input_mode, 3, 5, 0, /* | |
1108 Set mode of reading keyboard input. | |
1204 | 1109 First arg (formerly INTERRUPT-INPUT) is ignored, for backward compatibility. |
428 | 1110 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal |
1111 (no effect except in CBREAK mode). | |
1112 Third arg META t means accept 8-bit input (for a Meta key). | |
1113 META nil means ignore the top bit, on the assumption it is parity. | |
1114 Otherwise, accept 8-bit input and don't use the top bit for Meta. | |
1115 First three arguments only apply to TTY consoles. | |
1116 Optional fourth arg QUIT if non-nil specifies character to use for quitting. | |
1117 Optional fifth arg CONSOLE specifies console to make changes to; nil means | |
1118 the selected console. | |
1119 See also `current-input-mode'. | |
1120 */ | |
2340 | 1121 (UNUSED (ignored), USED_IF_TTY (flow), meta, quit, console)) |
428 | 1122 { |
1123 struct console *con = decode_console (console); | |
1124 int meta_key = (!CONSOLE_TTY_P (con) ? 1 : | |
1125 EQ (meta, Qnil) ? 0 : | |
1126 EQ (meta, Qt) ? 1 : | |
1127 2); | |
1128 | |
1129 if (!NILP (quit)) | |
1130 { | |
1204 | 1131 if (CHAR_OR_CHAR_INTP (quit) && !meta_key) |
1132 set_quit_events (con, make_char (XCHAR_OR_CHAR_INT (quit) & 0177)); | |
1133 else | |
1134 set_quit_events (con, quit); | |
428 | 1135 } |
1136 | |
1137 #ifdef HAVE_TTY | |
1138 if (CONSOLE_TTY_P (con)) | |
1139 { | |
1140 reset_one_console (con); | |
1141 TTY_FLAGS (con).flow_control = !NILP (flow); | |
1142 TTY_FLAGS (con).meta_key = meta_key; | |
1143 init_one_console (con); | |
444 | 1144 MARK_FRAME_CHANGED (XFRAME (CONSOLE_SELECTED_FRAME (con))); |
428 | 1145 } |
1146 #endif | |
1147 | |
1148 return Qnil; | |
1149 } | |
1150 | |
1151 DEFUN ("current-input-mode", Fcurrent_input_mode, 0, 1, 0, /* | |
1152 Return information about the way Emacs currently reads keyboard input. | |
1153 Optional arg CONSOLE specifies console to return information about; nil means | |
1154 the selected console. | |
1155 The value is a list of the form (nil FLOW META QUIT), where | |
1156 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the | |
1157 terminal; this does not apply if Emacs uses interrupt-driven input. | |
1158 META is t if accepting 8-bit input with 8th bit as Meta flag. | |
1159 META nil means ignoring the top bit, on the assumption it is parity. | |
1160 META is neither t nor nil if accepting 8-bit input and using | |
1161 all 8 bits as the character code. | |
1162 QUIT is the character Emacs currently uses to quit. | |
1163 FLOW, and META are only meaningful for TTY consoles. | |
1164 The elements of this list correspond to the arguments of | |
1165 `set-input-mode'. | |
1166 */ | |
1167 (console)) | |
1168 { | |
1169 struct console *con = decode_console (console); | |
1204 | 1170 Lisp_Object flow, meta; |
428 | 1171 |
1172 #ifdef HAVE_TTY | |
1173 flow = CONSOLE_TTY_P (con) && TTY_FLAGS (con).flow_control ? Qt : Qnil; | |
1174 meta = (!CONSOLE_TTY_P (con) ? Qt : | |
1175 TTY_FLAGS (con).meta_key == 1 ? Qt : | |
1176 TTY_FLAGS (con).meta_key == 2 ? Qzero : | |
1177 Qnil); | |
1178 #else | |
1179 flow = Qnil; | |
1180 meta = Qt; | |
1181 #endif | |
1182 | |
1204 | 1183 return list4 (Qnil, flow, meta, CONSOLE_QUIT_CHAR (con)); |
428 | 1184 } |
1185 | |
1186 | |
1187 /************************************************************************/ | |
1188 /* initialization */ | |
1189 /************************************************************************/ | |
1190 | |
1191 void | |
1192 syms_of_console (void) | |
1193 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1194 INIT_LISP_OBJECT (console); |
3092 | 1195 #ifdef NEW_GC |
1196 #ifdef HAVE_TTY | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1197 INIT_LISP_OBJECT (tty_console); |
3092 | 1198 #endif |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1199 INIT_LISP_OBJECT (stream_console); |
3263 | 1200 #endif /* NEW_GC */ |
442 | 1201 |
428 | 1202 DEFSUBR (Fvalid_console_type_p); |
1203 DEFSUBR (Fconsole_type_list); | |
1204 DEFSUBR (Fcdfw_console); | |
1205 DEFSUBR (Fselected_console); | |
1206 DEFSUBR (Fselect_console); | |
1207 DEFSUBR (Fconsolep); | |
1208 DEFSUBR (Fconsole_live_p); | |
1209 DEFSUBR (Fconsole_type); | |
1210 DEFSUBR (Fconsole_name); | |
1211 DEFSUBR (Fconsole_connection); | |
1212 DEFSUBR (Ffind_console); | |
1213 DEFSUBR (Fget_console); | |
1214 DEFSUBR (Fdelete_console); | |
1215 DEFSUBR (Fconsole_list); | |
1216 DEFSUBR (Fconsole_device_list); | |
1217 DEFSUBR (Fconsole_enable_input); | |
1218 DEFSUBR (Fconsole_disable_input); | |
1219 DEFSUBR (Fconsole_on_window_system_p); | |
1220 DEFSUBR (Fsuspend_console); | |
1221 DEFSUBR (Fresume_console); | |
1222 | |
1223 DEFSUBR (Fsuspend_emacs); | |
1224 DEFSUBR (Fset_input_mode); | |
1225 DEFSUBR (Fcurrent_input_mode); | |
1226 | |
563 | 1227 DEFSYMBOL (Qconsolep); |
1228 DEFSYMBOL (Qconsole_live_p); | |
428 | 1229 |
563 | 1230 DEFSYMBOL (Qcreate_console_hook); |
1231 DEFSYMBOL (Qdelete_console_hook); | |
428 | 1232 |
563 | 1233 DEFSYMBOL (Qsuspend_hook); |
1234 DEFSYMBOL (Qsuspend_resume_hook); | |
428 | 1235 } |
1236 | |
1204 | 1237 static const struct memory_description cte_description_1[] = { |
440 | 1238 { XD_LISP_OBJECT, offsetof (console_type_entry, symbol) }, |
2551 | 1239 { XD_BLOCK_PTR, offsetof (console_type_entry, meths), 1, |
1240 { &console_methods_description } }, | |
428 | 1241 { XD_END } |
1242 }; | |
1243 | |
1204 | 1244 static const struct sized_memory_description cte_description = { |
440 | 1245 sizeof (console_type_entry), |
428 | 1246 cte_description_1 |
1247 }; | |
1248 | |
1204 | 1249 static const struct memory_description cted_description_1[] = { |
440 | 1250 XD_DYNARR_DESC (console_type_entry_dynarr, &cte_description), |
428 | 1251 { XD_END } |
1252 }; | |
1253 | |
1204 | 1254 const struct sized_memory_description cted_description = { |
440 | 1255 sizeof (console_type_entry_dynarr), |
428 | 1256 cted_description_1 |
1257 }; | |
1258 | |
1204 | 1259 static const struct memory_description console_methods_description_1[] = { |
440 | 1260 { XD_LISP_OBJECT, offsetof (struct console_methods, symbol) }, |
1261 { XD_LISP_OBJECT, offsetof (struct console_methods, predicate_symbol) }, | |
1262 { XD_LISP_OBJECT, offsetof (struct console_methods, image_conversion_list) }, | |
428 | 1263 { XD_END } |
1264 }; | |
1265 | |
1204 | 1266 const struct sized_memory_description console_methods_description = { |
440 | 1267 sizeof (struct console_methods), |
428 | 1268 console_methods_description_1 |
1269 }; | |
1270 | |
1271 | |
1272 void | |
1273 console_type_create (void) | |
1274 { | |
1275 the_console_type_entry_dynarr = Dynarr_new (console_type_entry); | |
2367 | 1276 dump_add_root_block_ptr (&the_console_type_entry_dynarr, &cted_description); |
428 | 1277 |
1278 Vconsole_type_list = Qnil; | |
1279 staticpro (&Vconsole_type_list); | |
1280 | |
1281 /* Initialize the dead console type */ | |
1282 INITIALIZE_CONSOLE_TYPE (dead, "dead", "console-dead-p"); | |
1283 | |
1284 /* then reset the console-type lists, because `dead' is not really | |
1285 a valid console type */ | |
1286 Dynarr_reset (the_console_type_entry_dynarr); | |
1287 Vconsole_type_list = Qnil; | |
1288 } | |
1289 | |
1290 void | |
1291 reinit_vars_of_console (void) | |
1292 { | |
1293 staticpro_nodump (&Vconsole_list); | |
1294 Vconsole_list = Qnil; | |
1295 staticpro_nodump (&Vselected_console); | |
1296 Vselected_console = Qnil; | |
1297 } | |
1298 | |
1299 void | |
1300 vars_of_console (void) | |
1301 { | |
1302 DEFVAR_LISP ("create-console-hook", &Vcreate_console_hook /* | |
1303 Function or functions to call when a console is created. | |
1304 One argument, the newly-created console. | |
1305 This is called after the first frame has been created, but before | |
1306 calling the `create-device-hook' or `create-frame-hook'. | |
1307 Note that in general the console will not be selected. | |
1308 */ ); | |
1309 Vcreate_console_hook = Qnil; | |
1310 | |
1311 DEFVAR_LISP ("delete-console-hook", &Vdelete_console_hook /* | |
1312 Function or functions to call when a console is deleted. | |
1313 One argument, the to-be-deleted console. | |
1314 */ ); | |
1315 Vdelete_console_hook = Qnil; | |
1316 | |
1317 #ifdef HAVE_WINDOW_SYSTEM | |
1318 Fprovide (intern ("window-system")); | |
1319 #endif | |
1320 } | |
1321 | |
643 | 1322 /* The docstrings for DEFVAR_* are recorded externally by make-docfile. */ |
3263 | 1323 #ifdef NEW_GC |
2720 | 1324 #define DEFVAR_CONSOLE_LOCAL_1(lname, field_name, forward_type, magic_fun) \ |
1325 do { \ | |
1326 struct symbol_value_forward *I_hate_C = \ | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1327 XSYMBOL_VALUE_FORWARD (ALLOC_LISP_OBJECT (symbol_value_forward)); \ |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1328 /*mcpro ((Lisp_Object) I_hate_C);*/ \ |
2720 | 1329 \ |
1330 I_hate_C->magic.value = &(console_local_flags.field_name); \ | |
1331 I_hate_C->magic.type = forward_type; \ | |
1332 I_hate_C->magicfun = magic_fun; \ | |
1333 \ | |
1334 MARK_LRECORD_AS_LISP_READONLY (I_hate_C); \ | |
1335 \ | |
1336 { \ | |
1337 int offset = ((char *)symbol_value_forward_forward (I_hate_C) \ | |
1338 - (char *)&console_local_flags); \ | |
1339 \ | |
1340 defvar_magic (lname, I_hate_C); \ | |
1341 \ | |
1342 *((Lisp_Object *)(offset + (char *)XCONSOLE (Vconsole_local_symbols))) \ | |
1343 = intern (lname); \ | |
1344 } \ | |
1345 } while (0) | |
3263 | 1346 #else /* not NEW_GC */ |
617 | 1347 #define DEFVAR_CONSOLE_LOCAL_1(lname, field_name, forward_type, magicfun) \ |
1348 do { \ | |
1349 static const struct symbol_value_forward I_hate_C = \ | |
1350 { /* struct symbol_value_forward */ \ | |
1351 { /* struct symbol_value_magic */ \ | |
3024 | 1352 { /* struct old_lcrecord_header */ \ |
617 | 1353 { /* struct lrecord_header */ \ |
1354 lrecord_type_symbol_value_forward, /* lrecord_type_index */ \ | |
1355 1, /* mark bit */ \ | |
1356 1, /* c_readonly bit */ \ | |
1357 1 /* lisp_readonly bit */ \ | |
1358 }, \ | |
1359 0, /* next */ \ | |
1360 0, /* uid */ \ | |
1361 0 /* free */ \ | |
1362 }, \ | |
1363 &(console_local_flags.field_name), \ | |
1364 forward_type \ | |
1365 }, \ | |
1366 magicfun \ | |
1367 }; \ | |
1368 \ | |
1369 { \ | |
1370 int offset = ((char *)symbol_value_forward_forward (&I_hate_C) \ | |
1371 - (char *)&console_local_flags); \ | |
1372 \ | |
1373 defvar_magic (lname, &I_hate_C); \ | |
1374 \ | |
1375 *((Lisp_Object *)(offset + (char *)XCONSOLE (Vconsole_local_symbols))) \ | |
1376 = intern (lname); \ | |
1377 } \ | |
428 | 1378 } while (0) |
3263 | 1379 #endif /* not NEW_GC */ |
428 | 1380 |
1381 #define DEFVAR_CONSOLE_LOCAL_MAGIC(lname, field_name, magicfun) \ | |
1382 DEFVAR_CONSOLE_LOCAL_1 (lname, field_name, \ | |
1383 SYMVAL_SELECTED_CONSOLE_FORWARD, magicfun) | |
1384 #define DEFVAR_CONSOLE_LOCAL(lname, field_name) \ | |
1385 DEFVAR_CONSOLE_LOCAL_MAGIC (lname, field_name, 0) | |
1386 #define DEFVAR_CONST_CONSOLE_LOCAL_MAGIC(lname, field_name, magicfun) \ | |
1387 DEFVAR_CONSOLE_LOCAL_1 (lname, field_name, \ | |
1388 SYMVAL_CONST_SELECTED_CONSOLE_FORWARD, magicfun) | |
1389 #define DEFVAR_CONST_CONSOLE_LOCAL(lname, field_name) \ | |
1390 DEFVAR_CONST_CONSOLE_LOCAL_MAGIC (lname, field_name, 0) | |
1391 | |
1392 #define DEFVAR_CONSOLE_DEFAULTS_MAGIC(lname, field_name, magicfun) \ | |
1393 DEFVAR_SYMVAL_FWD(lname, &(console_local_flags.field_name), \ | |
1394 SYMVAL_DEFAULT_CONSOLE_FORWARD, magicfun) | |
1395 #define DEFVAR_CONSOLE_DEFAULTS(lname, field_name) \ | |
1396 DEFVAR_CONSOLE_DEFAULTS_MAGIC (lname, field_name, 0) | |
1397 | |
1398 static void | |
1399 common_init_complex_vars_of_console (void) | |
1400 { | |
1401 /* Make sure all markable slots in console_defaults | |
1402 are initialized reasonably, so mark_console won't choke. | |
1403 */ | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1404 Lisp_Object defobj = ALLOC_LISP_OBJECT (console); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1405 struct console *defs = XCONSOLE (defobj); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1406 Lisp_Object symobj = ALLOC_LISP_OBJECT (console); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1407 struct console *syms = XCONSOLE (symobj); |
428 | 1408 |
1409 staticpro_nodump (&Vconsole_defaults); | |
1410 staticpro_nodump (&Vconsole_local_symbols); | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1411 Vconsole_defaults = defobj; |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1412 Vconsole_local_symbols = symobj; |
428 | 1413 |
1414 nuke_all_console_slots (syms, Qnil); | |
1415 nuke_all_console_slots (defs, Qnil); | |
1416 | |
1417 /* Set up the non-nil default values of various console slots. | |
1418 Must do these before making the first console. | |
1419 */ | |
1204 | 1420 |
1421 /* ... Nothing here for the moment. | |
1422 #### Console-local variables should probably be eliminated.*/ | |
428 | 1423 |
1424 { | |
1425 /* 0 means var is always local. Default used only at creation. | |
1426 * -1 means var is always local. Default used only at reset and | |
1427 * creation. | |
1428 * -2 means there's no lisp variable corresponding to this slot | |
1429 * and the default is only used at creation. | |
1430 * -3 means no Lisp variable. Default used only at reset and creation. | |
1431 * >0 is mask. Var is local if ((console->local_var_flags & mask) != 0) | |
1432 * Otherwise default is used. | |
1433 * | |
1434 * #### We don't currently ever reset console variables, so there | |
1435 * is no current distinction between 0 and -1, and between -2 and -3. | |
1436 */ | |
1437 Lisp_Object always_local_resettable = make_int (-1); | |
1438 | |
1439 #if 0 /* not used */ | |
1440 Lisp_Object always_local_no_default = make_int (0); | |
1441 Lisp_Object resettable = make_int (-3); | |
1442 #endif | |
1443 | |
1444 /* Assign the local-flags to the slots that have default values. | |
1445 The local flag is a bit that is used in the console | |
1446 to say that it has its own local value for the slot. | |
1447 The local flag bits are in the local_var_flags slot of the | |
1448 console. */ | |
1449 | |
1450 nuke_all_console_slots (&console_local_flags, make_int (-2)); | |
1451 console_local_flags.defining_kbd_macro = always_local_resettable; | |
1452 console_local_flags.last_kbd_macro = always_local_resettable; | |
1453 console_local_flags.prefix_arg = always_local_resettable; | |
1454 console_local_flags.default_minibuffer_frame = always_local_resettable; | |
1455 console_local_flags.overriding_terminal_local_map = | |
1456 always_local_resettable; | |
1457 #ifdef HAVE_TTY | |
1458 console_local_flags.tty_erase_char = always_local_resettable; | |
1459 #endif | |
1460 | |
1461 console_local_flags.function_key_map = make_int (1); | |
1462 | |
1463 /* #### Warning, 0x4000000 (that's six zeroes) is the largest number | |
1464 currently allowable due to the XINT() handling of this value. | |
1465 With some rearrangement you can get 4 more bits. */ | |
1466 } | |
1467 } | |
1468 | |
1469 | |
1470 #define CONSOLE_SLOTS_SIZE (offsetof (struct console, CONSOLE_SLOTS_LAST_NAME) - offsetof (struct console, CONSOLE_SLOTS_FIRST_NAME) + sizeof (Lisp_Object)) | |
1471 #define CONSOLE_SLOTS_COUNT (CONSOLE_SLOTS_SIZE / sizeof (Lisp_Object)) | |
1472 | |
1473 void | |
771 | 1474 reinit_complex_vars_of_console_runtime_only (void) |
428 | 1475 { |
1476 struct console *defs, *syms; | |
1477 | |
1478 common_init_complex_vars_of_console (); | |
1479 | |
1480 defs = XCONSOLE (Vconsole_defaults); | |
1481 syms = XCONSOLE (Vconsole_local_symbols); | |
1482 memcpy (&defs->CONSOLE_SLOTS_FIRST_NAME, | |
1483 console_defaults_saved_slots, | |
1484 CONSOLE_SLOTS_SIZE); | |
1485 memcpy (&syms->CONSOLE_SLOTS_FIRST_NAME, | |
1486 console_local_symbols_saved_slots, | |
1487 CONSOLE_SLOTS_SIZE); | |
1488 } | |
1489 | |
1490 | |
1204 | 1491 static const struct memory_description console_slots_description_1[] = { |
440 | 1492 { XD_LISP_OBJECT_ARRAY, 0, CONSOLE_SLOTS_COUNT }, |
428 | 1493 { XD_END } |
1494 }; | |
1495 | |
1204 | 1496 static const struct sized_memory_description console_slots_description = { |
428 | 1497 CONSOLE_SLOTS_SIZE, |
1498 console_slots_description_1 | |
1499 }; | |
1500 | |
1501 void | |
1502 complex_vars_of_console (void) | |
1503 { | |
1504 struct console *defs, *syms; | |
1505 | |
1506 common_init_complex_vars_of_console (); | |
1507 | |
1508 defs = XCONSOLE (Vconsole_defaults); | |
1509 syms = XCONSOLE (Vconsole_local_symbols); | |
1510 console_defaults_saved_slots = &defs->CONSOLE_SLOTS_FIRST_NAME; | |
1511 console_local_symbols_saved_slots = &syms->CONSOLE_SLOTS_FIRST_NAME; | |
2367 | 1512 dump_add_root_block_ptr (&console_defaults_saved_slots, &console_slots_description); |
1513 dump_add_root_block_ptr (&console_local_symbols_saved_slots, &console_slots_description); | |
428 | 1514 |
1515 DEFVAR_CONSOLE_DEFAULTS ("default-function-key-map", function_key_map /* | |
1516 Default value of `function-key-map' for consoles that don't override it. | |
1517 This is the same as (default-value 'function-key-map). | |
1518 */ ); | |
1519 | |
1520 DEFVAR_CONSOLE_LOCAL ("function-key-map", function_key_map /* | |
1521 Keymap mapping ASCII function key sequences onto their preferred forms. | |
1522 This allows Emacs to recognize function keys sent from ASCII | |
1523 terminals at any point in a key sequence. | |
1524 | |
1525 The `read-key-sequence' function replaces any subsequence bound by | |
1526 `function-key-map' with its binding. More precisely, when the active | |
1527 keymaps have no binding for the current key sequence but | |
1528 `function-key-map' binds a suffix of the sequence to a vector or string, | |
1529 `read-key-sequence' replaces the matching suffix with its binding, and | |
2027 | 1530 continues with the new sequence. See `key-binding'. |
428 | 1531 |
1532 The events that come from bindings in `function-key-map' are not | |
1533 themselves looked up in `function-key-map'. | |
1534 | |
1535 For example, suppose `function-key-map' binds `ESC O P' to [f1]. | |
1536 Typing `ESC O P' to `read-key-sequence' would return | |
1537 \[#<keypress-event f1>]. Typing `C-x ESC O P' would return | |
1538 \[#<keypress-event control-X> #<keypress-event f1>]. If [f1] | |
1539 were a prefix key, typing `ESC O P x' would return | |
1540 \[#<keypress-event f1> #<keypress-event x>]. | |
1541 */ ); | |
1542 | |
1543 #ifdef HAVE_TTY | |
440 | 1544 /* #### Should this somehow go to TTY data? How do we make it |
428 | 1545 accessible from Lisp, then? */ |
1546 DEFVAR_CONSOLE_LOCAL ("tty-erase-char", tty_erase_char /* | |
1547 The ERASE character as set by the user with stty. | |
1548 When this value cannot be determined or would be meaningless (on non-TTY | |
1549 consoles, for example), it is set to nil. | |
1550 */ ); | |
1551 #endif | |
1552 | |
442 | 1553 /* While this should be const it can't be because some things |
428 | 1554 (i.e. edebug) do manipulate it. */ |
1555 DEFVAR_CONSOLE_LOCAL ("defining-kbd-macro", defining_kbd_macro /* | |
442 | 1556 Non-nil while a keyboard macro is being defined. Don't set this! |
428 | 1557 */ ); |
1558 | |
1559 DEFVAR_CONSOLE_LOCAL ("last-kbd-macro", last_kbd_macro /* | |
442 | 1560 Last keyboard macro defined, as a vector of events; nil if none defined. |
428 | 1561 */ ); |
1562 | |
1563 DEFVAR_CONSOLE_LOCAL ("prefix-arg", prefix_arg /* | |
1564 The value of the prefix argument for the next editing command. | |
1565 It may be a number, or the symbol `-' for just a minus sign as arg, | |
1566 or a list whose car is a number for just one or more C-U's | |
1567 or nil if no argument has been specified. | |
1568 | |
1569 You cannot examine this variable to find the argument for this command | |
1570 since it has been set to nil by the time you can look. | |
1571 Instead, you should use the variable `current-prefix-arg', although | |
1572 normally commands can get this prefix argument with (interactive "P"). | |
1573 */ ); | |
1574 | |
1575 DEFVAR_CONSOLE_LOCAL ("default-minibuffer-frame", | |
1576 default_minibuffer_frame /* | |
1577 Minibufferless frames use this frame's minibuffer. | |
1578 | |
1579 Emacs cannot create minibufferless frames unless this is set to an | |
1580 appropriate surrogate. | |
1581 | |
1582 XEmacs consults this variable only when creating minibufferless | |
1583 frames; once the frame is created, it sticks with its assigned | |
1584 minibuffer, no matter what this variable is set to. This means that | |
1585 this variable doesn't necessarily say anything meaningful about the | |
1586 current set of frames, or where the minibuffer is currently being | |
1587 displayed. | |
1588 */ ); | |
1589 | |
1590 DEFVAR_CONSOLE_LOCAL ("overriding-terminal-local-map", | |
1591 overriding_terminal_local_map /* | |
1592 Keymap that overrides all other local keymaps, for the selected console only. | |
1593 If this variable is non-nil, it is used as a keymap instead of the | |
1594 buffer's local map, and the minor mode keymaps and text property keymaps. | |
1595 */ ); | |
1596 | |
1597 /* Check for DEFVAR_CONSOLE_LOCAL without initializing the corresponding | |
1598 slot of console_local_flags and vice-versa. Must be done after all | |
1599 DEFVAR_CONSOLE_LOCAL() calls. */ | |
1600 #define MARKED_SLOT(slot) \ | |
1601 if ((XINT (console_local_flags.slot) != -2 && \ | |
1602 XINT (console_local_flags.slot) != -3) \ | |
1603 != !(NILP (XCONSOLE (Vconsole_local_symbols)->slot))) \ | |
2500 | 1604 ABORT (); |
428 | 1605 #include "conslots.h" |
1606 } |