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