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