0
|
1 /****************************************************************************
|
|
2 ***
|
|
3 *** Copyright (c) 1990 by Sun/Lucid, All Rights Reserved.
|
|
4 *** Copyright (c) 1991-1993 by Lucid, Inc. All Rights Reserved.
|
|
5 ***
|
|
6 *****************************************************************************/
|
|
7
|
|
8 /* Synched up with: Not in FSF. */
|
|
9
|
|
10 #include <config.h>
|
|
11
|
|
12 #ifdef ENERGIZE /* whole file */
|
|
13
|
|
14 #include "lisp.h"
|
|
15
|
|
16 /* Display Context for the icons */
|
|
17 #include "console-x.h"
|
|
18 #include <Xm/DialogS.h>
|
157
|
19 #include "../lwlib/lwlib.h"
|
0
|
20 #include "objects-x.h"
|
|
21
|
|
22 #include "events.h"
|
|
23 #include "opaque.h"
|
|
24 #include "buffer.h"
|
|
25 #include "extents.h"
|
|
26 #include "process.h"
|
|
27 #include "insdel.h"
|
|
28 #include "window.h"
|
|
29 #include "faces.h"
|
|
30
|
|
31 /* Energize editor requests and I/O operations */
|
|
32 #include "energize.h"
|
|
33
|
|
34 #include "systime.h"
|
|
35 #include "sysfile.h"
|
|
36 #include "syssignal.h"
|
|
37
|
|
38 #ifndef CBFileYourself
|
|
39 /* This means that emacs is being compiled against the connection library
|
|
40 and headers that go with an Energize protocol less than 0.10. We need
|
|
41 to do some slightly different things in this file because of that.
|
|
42
|
|
43 Note that if Emacs is compiled against the 3.0 version of the connection
|
|
44 library and associated headers, it can still talk to 2.1- or 2.5-level
|
|
45 servers. But the opposite is not true.
|
|
46 */
|
|
47 # define ENERGIZE_V2_HEADERS
|
|
48 #endif
|
|
49
|
|
50 /* The Connection library
|
|
51 */
|
|
52 extern void CWriteQueryChoicesRequest ();
|
|
53 extern void CWriteExecuteChoicesRequest ();
|
|
54 extern void CWriteSheetRequest ();
|
|
55 extern void CWriteSetControlRequest ();
|
|
56 extern void CWriteChoice ();
|
|
57 extern void CWriteProtocol ();
|
|
58 extern int CGetPortNumber ();
|
|
59
|
|
60
|
|
61 /************** Typedefs and Structs ***********************/
|
|
62
|
|
63 /* structure argument used by the next mapping function */
|
|
64 typedef struct
|
|
65 {
|
|
66 BufferInfo *binfo;
|
|
67 int n_extents;
|
|
68 } binfo_and_n_extents;
|
|
69
|
|
70 typedef struct
|
|
71 {
|
|
72 BufferInfo* binfo;
|
|
73 int state;
|
|
74 int tell_energize;
|
|
75 } binfo_and_state;
|
|
76
|
|
77 struct reply_wait
|
|
78 {
|
|
79 int serial;
|
|
80 EId objectId;
|
|
81 EId genericId;
|
|
82 EId itemId;
|
|
83 char answered_p;
|
|
84 char status;
|
|
85 char* message;
|
|
86 Lisp_Object menu_result;
|
|
87 Lisp_Object only_name;
|
|
88 struct reply_wait* next;
|
|
89 };
|
|
90
|
|
91 static struct reply_wait *global_reply_wait;
|
|
92
|
|
93 Lisp_Object Venergize_kernel_busy;
|
|
94 Lisp_Object Qenergize_kernel_busy;
|
|
95 Lisp_Object Venergize_attributes_mapping;
|
|
96 int energize_extent_gc_threshold;
|
|
97 Lisp_Object Venergize_kernel_busy_hook;
|
|
98 Lisp_Object Qenergize_kernel_busy_hook;
|
|
99 Lisp_Object Venergize_menu_update_hook;
|
|
100 Lisp_Object Qenergize_menu_update_hook;
|
|
101 Lisp_Object Qenergize;
|
|
102 Lisp_Object Qenergize_auto_revert_buffer;
|
|
103
|
|
104
|
|
105 static void set_energize_extent_data (EXTENT extent, void *data);
|
|
106
|
|
107 static char *kernel_buffer_type_to_elisp_type (char *kernel_type);
|
|
108
|
|
109 static CONST void *get_object (EId id, BufferInfo *binfo);
|
|
110 static void put_object (EId id, BufferInfo *binfo, void *object);
|
|
111 static void remove_object (EId id, BufferInfo *binfo);
|
|
112 static void free_GDataclass (GDataClass *cl, BufferInfo *binfo);
|
|
113
|
|
114 static void free_GenericData (GenericData *gen, BufferInfo *binfo);
|
|
115
|
|
116 static void free_Energize_Extent_Data (Energize_Extent_Data *, BufferInfo *,
|
|
117 enum Energize_Object_Free_Type);
|
|
118
|
|
119 static BufferInfo *get_buffer_info_for_emacs_buffer (Lisp_Object emacs_buf,
|
|
120 Editor *editor);
|
|
121 static void put_buffer_info (EId id, Lisp_Object emacs_buf,
|
|
122 BufferInfo *binfo, Editor *editor);
|
|
123
|
|
124 static void handle_sheet_control_change (Widget, EId sheet_id, void* arg);
|
|
125 static Connection *make_energize_connection (Editor *editor,
|
|
126 int fdin, int fdout);
|
|
127 static void close_energize_connection (void);
|
|
128 Lisp_Object Fclose_connection_to_energize (void);
|
|
129 static void mark_all_extents_as_unmodified (BufferInfo *binfo);
|
|
130 Lisp_Object Fenergize_barf_if_buffer_locked (void);
|
|
131 Lisp_Object Fconnected_to_energize_p (void);
|
|
132 static int get_energize_connection_and_buffer_id (Lisp_Object buffer,
|
|
133 void **conn_ptr,
|
|
134 long *buffer_id_ptr);
|
|
135
|
|
136 void restore_energize_extent_state (EXTENT);
|
|
137
|
|
138
|
|
139 /**************************** Variables *****************************/
|
|
140
|
|
141 /* debugging variable */
|
|
142 int ignore_kernel;
|
|
143
|
|
144 Lisp_Object Venergize_kernel_modification_hook;
|
|
145 Lisp_Object Venergize_create_buffer_hook;
|
|
146 Lisp_Object Qenergize_create_buffer_hook;
|
|
147
|
|
148 Lisp_Object Qenergize_buffer_modified_hook;
|
|
149 Lisp_Object Qbuffer_locked_by_energize;
|
|
150 Lisp_Object Qenergize_user_input_buffer_mark;
|
|
151 Lisp_Object Qenergize_make_many_buffers_visible;
|
|
152
|
|
153 int inside_parse_buffer;
|
|
154
|
|
155 /* List of all buffers currently managed by Energize. This is
|
|
156 Staticpro'ed so that they don't get GC'ed from under us. */
|
|
157 static Lisp_Object Venergize_buffers_list;
|
|
158
|
|
159 static Editor *energize_connection;
|
|
160 static protocol_edit_options *peo;
|
|
161
|
|
162 static int request_serial_number;
|
|
163
|
|
164 extern int current_debuggerpanel_exposed_p;
|
|
165 extern int desired_debuggerpanel_exposed_p;
|
|
166 extern int debuggerpanel_sheet;
|
|
167
|
|
168 /**************************** Macros *****************************/
|
|
169
|
|
170 #define BUFFER_NOTIFY_BACKGROUND_BIT_SET_P(buffer) 1
|
|
171
|
|
172 #define get_extent_data(id,binfo) (Energize_Extent_Data*)get_object(id, binfo)
|
|
173 #define get_class(id,binfo) (GDataClass*)get_object(id, binfo)
|
|
174 #define get_generic(id,binfo) (GenericData*)get_object(id, binfo)
|
|
175
|
|
176 #define put_extent_data(id,binfo,obj) put_object(id, binfo, obj)
|
|
177 #define put_class(id,binfo,obj) put_object(id, binfo, obj)
|
|
178 #define put_generic(id,binfo,obj) put_object(id, binfo, obj)
|
|
179
|
|
180 #define remove_extent_data(id,binfo) remove_object(id, binfo)
|
|
181 #define remove_class(id,binfo) remove_object(id, binfo)
|
|
182 #define remove_generic(id,binfo) remove_object(id, binfo)
|
|
183
|
|
184 #define DEBUGGER_PSHEET_NAME "DEBUGGER_P_SHEET"
|
|
185
|
|
186 /* special graphics attribute meaning "use what anyone else's attributes" */
|
|
187 #define GA_NO_CHANGE 0
|
|
188 /* this number should be bigger than any of the "real" GA's */
|
|
189 #define GA_MAX 0x1000
|
|
190
|
|
191 /**************************** Utilities *****************************/
|
|
192
|
|
193 static int
|
|
194 emacs_CWriteRequestBuffer (Connection* conn)
|
|
195 {
|
|
196 int result;
|
|
197 /* don't kill emacs with SIGPIPE */
|
|
198 SIGTYPE (*old_sigpipe)() =
|
|
199 (SIGTYPE (*) ()) signal (SIGPIPE, SIG_IGN);
|
|
200
|
|
201 result = CWriteRequestBuffer (conn); /* the real one; macroized later */
|
|
202 signal (SIGPIPE, old_sigpipe);
|
|
203 return result;
|
|
204 }
|
|
205
|
|
206 #define CWriteRequestBuffer emacs_CWriteRequestBuffer
|
|
207
|
|
208
|
|
209 static Energize_Extent_Data *
|
|
210 extent_to_data (Lisp_Object extent_obj)
|
|
211 {
|
|
212 Energize_Extent_Data *ext = 0;
|
|
213
|
|
214 if (!EXTENTP (extent_obj))
|
|
215 return 0;
|
|
216 else
|
|
217 ext = energize_extent_data (XEXTENT (extent_obj));
|
|
218
|
|
219 if (ext)
|
|
220 {
|
|
221 if (EQ (ext->extent, extent_obj))
|
|
222 return ext;
|
|
223 else
|
|
224 abort ();
|
|
225 }
|
|
226 else
|
|
227 return 0;
|
|
228 }
|
|
229
|
|
230
|
|
231 static Lisp_Object
|
|
232 data_to_extent (Energize_Extent_Data *ext)
|
|
233 {
|
|
234 Lisp_Object extent = ext->extent;
|
|
235 assert (EXTENTP (extent));
|
|
236 return extent;
|
|
237 }
|
|
238
|
|
239 /* duplicate a string */
|
|
240 static char*
|
|
241 copy_string (char *s)
|
|
242 {
|
|
243 if (!s)
|
|
244 return 0;
|
|
245 else
|
|
246 {
|
|
247 int len = strlen (s);
|
|
248 char *res = (char *) xmalloc (len + 1);
|
|
249 return strcpy (res, s);
|
|
250 }
|
|
251 }
|
|
252
|
|
253 /* Get objects from the hashtables */
|
|
254 static CONST void *
|
|
255 get_object_internal (EId id, c_hashtable table)
|
|
256 {
|
|
257 void *res;
|
|
258 CONST void *found = gethash ((void*)id, table, &res);
|
|
259
|
|
260 if (found) CHECK_OBJECT (res);
|
|
261
|
|
262 return found ? res : 0;
|
|
263 }
|
|
264
|
|
265 static CONST void *
|
|
266 get_object (EId id, BufferInfo *binfo)
|
|
267 {
|
|
268 return get_object_internal (id, binfo->id_to_object);
|
|
269 }
|
|
270
|
|
271 static void
|
|
272 put_object_internal (EId id, c_hashtable table, void *object)
|
|
273 {
|
|
274 if (!PUT_ABLE_OBJECT (object))
|
|
275 error ("Can't put 0x%x in table", object);
|
|
276 CHECK_OBJECT (object);
|
|
277 puthash ((void*)id, object, table);
|
|
278 }
|
|
279
|
|
280 static void
|
|
281 put_object (EId id, BufferInfo *binfo, void *object)
|
|
282 {
|
|
283 put_object_internal (id, binfo->id_to_object, object);
|
|
284 return;
|
|
285 }
|
|
286
|
|
287 static void
|
|
288 remove_object_internal (EId id, c_hashtable table)
|
|
289 {
|
|
290 void *res;
|
|
291
|
|
292 if (gethash ((void*)id, table, &res))
|
|
293 {
|
|
294 if (OBJECT_FREE (res))
|
|
295 error ("Free'd object 0x%x still in table!", res);
|
|
296 remhash ((void*)id, table);
|
|
297 }
|
|
298 else if (id)
|
|
299 /* #### If this happens for Energize_Extent_Data as a result of extent
|
|
300 finalization, this aborts (because gc_in_progress). These errors are
|
|
301 awfully bad, so probably they should just be abort()s anyway... */
|
|
302 error ("EId %d not in table!", id);
|
|
303 }
|
|
304
|
|
305 static void
|
|
306 remove_object (EId id, BufferInfo *binfo)
|
|
307 {
|
|
308 remove_object_internal (id, binfo->id_to_object);
|
|
309 return;
|
|
310 }
|
|
311
|
|
312 /* maphash_function called by free_buffer_info */
|
|
313 static void
|
|
314 free_object (void *key, void *contents, void *arg)
|
|
315 {
|
|
316 BufferInfo *binfo = arg;
|
|
317
|
|
318 if (contents)
|
|
319 {
|
|
320 switch (OBJECT_SEAL (contents))
|
|
321 {
|
|
322 case BUF_INFO_SEAL:
|
|
323 break;
|
|
324 case EXTENT_SEAL:
|
|
325 free_Energize_Extent_Data ((Energize_Extent_Data *) contents,
|
|
326 binfo, OFT_MAPHASH);
|
|
327 break;
|
|
328 case GDATA_CLASS_SEAL:
|
|
329 free_GDataclass ((GDataClass *) contents, binfo);
|
|
330 break;
|
|
331 case GDATA_SEAL:
|
|
332 free_GenericData ((GenericData *) contents, binfo);
|
|
333 break;
|
|
334 default:
|
|
335 error ("Bad argument 0x%x to free_object()", contents);
|
|
336 return;
|
|
337 }
|
|
338 }
|
|
339 }
|
|
340
|
|
341 static GDataClass *
|
|
342 alloc_GDataclass (EId id, BufferInfo *binfo)
|
|
343 {
|
185
|
344 GDataClass *cl = xnew_and_zero (GDataClass);
|
0
|
345 cl->seal = GDATA_CLASS_SEAL;
|
|
346 cl->id = id;
|
|
347 put_class (cl->id, binfo, cl);
|
|
348 return cl;
|
|
349 }
|
|
350
|
|
351 static void
|
|
352 free_GDataclass (GDataClass *cl, BufferInfo *binfo)
|
|
353 {
|
|
354 if (cl)
|
|
355 {
|
|
356 remove_class (cl->id, binfo);
|
|
357 SET_OBJECT_FREE (cl);
|
|
358 }
|
|
359 return;
|
|
360 }
|
|
361
|
|
362
|
|
363 static GenericData *
|
|
364 alloc_GenericData (EId id, GDataClass *cl, BufferInfo *binfo)
|
|
365 {
|
|
366 GenericData *gen = xnew (GenericData);
|
|
367 gen->seal = GDATA_SEAL;
|
|
368 gen->id = id;
|
|
369 gen->cl = cl;
|
|
370 /* gen->image = 0;*/
|
|
371 gen->flags = 0;
|
|
372 gen->modified_state = 0;
|
|
373 put_generic (gen->id, binfo, gen);
|
|
374 return gen;
|
|
375 }
|
|
376
|
|
377 static void
|
|
378 free_GenericData (GenericData *gen, BufferInfo *binfo)
|
|
379 {
|
|
380 if (gen)
|
|
381 {
|
|
382 remove_generic (gen->id, binfo);
|
|
383 gen->cl = 0;
|
|
384 SET_OBJECT_FREE (gen);
|
|
385 }
|
|
386 return;
|
|
387 }
|
|
388
|
|
389 /* Called to flush the extent from the hash table when Energize tells us to
|
|
390 lose the extent. This is NOT called from the extent GC finalization method,
|
|
391 because there would be a period before the next GC when we still had an
|
|
392 Energize ID that the server thought was dead, and could concievably reuse.
|
|
393
|
|
394 Since we protect extents from GC until Energize says they're done, if an
|
|
395 extent still has Energize data by the time it gets collected, something is
|
|
396 fucked.
|
|
397 */
|
|
398 static void
|
|
399 free_Energize_Extent_Data (Energize_Extent_Data *ext, BufferInfo *binfo,
|
|
400 enum Energize_Object_Free_Type free_type)
|
|
401 {
|
|
402 if (ext)
|
|
403 {
|
|
404 Lisp_Object extent_obj = data_to_extent (ext);
|
|
405
|
|
406 /* Remove the extent, remove the extent's pointer to the data,
|
|
407 and the data's pointer to the extent. */
|
|
408 Fdetach_extent (extent_obj);
|
|
409 set_energize_extent_data (XEXTENT (extent_obj), 0);
|
|
410 ext->extent = Qnil; /* at this point, refs will abort */
|
|
411
|
|
412 /* Remove the data from the hash table, and mark it as dead. */
|
|
413 remove_extent_data (ext->id, binfo);
|
|
414 ext->id = 0;
|
|
415
|
|
416 /* don't free this "sub-guy" via maphash, as it will get taken care
|
|
417 of during the course of the maphash without our doing anything */
|
|
418 if (free_type != OFT_MAPHASH)
|
|
419 {
|
|
420 if (ext->extentType == CEGeneric)
|
|
421 free_GenericData (ext->u.generic.gData, binfo);
|
|
422 }
|
|
423
|
|
424 SET_OBJECT_FREE (ext);
|
|
425 }
|
|
426 return;
|
|
427 }
|
|
428
|
|
429 static BufferInfo *
|
|
430 alloc_BufferInfo (EId id, Lisp_Object name, Lisp_Object filename,
|
|
431 char *class_str, Editor *editor, Window win, int nobjects)
|
|
432 {
|
|
433 BufferInfo *binfo = xnew (BufferInfo);
|
|
434 Widget nw = 0;
|
|
435 Lisp_Object buffer = Qnil;
|
|
436
|
|
437 if (win)
|
|
438 {
|
|
439 char win_as_string [16];
|
|
440 nw = XtWindowToWidget (get_x_display (Qnil), win);
|
|
441 if (nw)
|
|
442 nw = XtParent (nw);
|
185
|
443
|
0
|
444 if (nw)
|
|
445 sprintf (win_as_string, "w%x", nw);
|
|
446 else
|
|
447 sprintf (win_as_string, "0x%x", win);
|
|
448 binfo->frame =
|
|
449 Fx_create_frame (Qnil, Qnil, build_string (win_as_string));
|
|
450 }
|
|
451 else
|
|
452 binfo->frame = Qnil;
|
|
453
|
|
454 /* try to re-use a buffer with the same file name if one already exists.
|
|
455 * If a buffer already exists but is modified we should do a dialog and
|
|
456 * ask the user what to do. For now I'll just use a new buffer in that case.
|
|
457 * ParseBuffer will erase the buffer.
|
|
458 */
|
|
459 if (!NILP (filename))
|
|
460 {
|
|
461 int offct = find_file_compare_truenames;
|
|
462 find_file_compare_truenames = 1;
|
|
463 buffer = Fget_file_buffer (filename);
|
|
464 find_file_compare_truenames = offct;
|
|
465
|
|
466 if (!NILP (buffer) && !NILP (Fbuffer_modified_p (buffer)))
|
|
467 buffer = Qnil;
|
|
468 }
|
|
469
|
|
470 if (NILP (buffer))
|
|
471 buffer = Fget_buffer_create (Fgenerate_new_buffer_name (name, Qnil));
|
|
472
|
|
473 binfo->seal = BUF_INFO_SEAL;
|
|
474 binfo->id = id;
|
|
475 binfo->flags = 0;
|
|
476 binfo->editor = editor;
|
|
477 binfo->id_to_object = make_hashtable (nobjects);
|
|
478 binfo->emacs_buffer = buffer;
|
|
479 binfo->modified_state = 0;
|
|
480 binfo->editable = 0;
|
|
481 binfo->output_mark = Qnil;
|
|
482 binfo->buffer_type = kernel_buffer_type_to_elisp_type (class_str);
|
|
483 binfo->p_sheet_ids = 0;
|
|
484 binfo->n_p_sheets = 0;
|
|
485 binfo->note_ids = 0;
|
|
486 binfo->n_notes = 0;
|
|
487 #ifdef I18N4
|
|
488 binfo->wcmap.valid = 0;
|
|
489 binfo->wcmap.modiff_stamp = -1;
|
|
490 binfo->wcmap.map = NULL;
|
185
|
491 #endif
|
0
|
492 put_buffer_info (id, binfo->emacs_buffer, binfo, editor);
|
|
493
|
|
494 Venergize_buffers_list = Fcons (buffer, Venergize_buffers_list);
|
|
495
|
|
496 #if 0
|
|
497 * if (nw){
|
|
498 * Lisp_Object window = Fframe_selected_window (binfo->frame);
|
|
499 * Fset_window_buffer (window, binfo->emacs_buffer);
|
|
500 * set_text_widget ((NoteWidget)nw,
|
|
501 * FRAME_X_SHELL_WIDGET (XFRAME (binfo->frame)));
|
|
502 * }
|
|
503 #endif
|
|
504
|
|
505 return binfo;
|
|
506 }
|
|
507
|
|
508 /* free a buffer_info */
|
|
509 static void
|
|
510 free_buffer_info (BufferInfo *binfo)
|
|
511 {
|
|
512 maphash (free_object, binfo->id_to_object, (void *)binfo);
|
|
513 free_hashtable (binfo->id_to_object);
|
|
514 if (energize_connection && energize_connection->binfo_hash)
|
|
515 {
|
|
516 if (binfo->id)
|
|
517 remhash ((void *)binfo->id, energize_connection->binfo_hash);
|
|
518 if (!NILP (binfo->emacs_buffer))
|
|
519 {
|
|
520 remhash (LISP_TO_VOID (binfo->emacs_buffer),
|
|
521 energize_connection->binfo_hash);
|
|
522 }
|
|
523 }
|
|
524 binfo->id = 0;
|
|
525 binfo->emacs_buffer = Qnil;
|
|
526 #ifdef I18N4
|
|
527 if (binfo->wcmap.valid) {
|
|
528 binfo->wcmap.valid= 0;
|
|
529 xfree(binfo->wcmap.map);
|
|
530 }
|
185
|
531 #endif
|
0
|
532 SET_OBJECT_FREE (binfo);
|
|
533 }
|
|
534
|
|
535 /* hash for BufferInfo structures */
|
|
536 static BufferInfo*
|
|
537 get_buffer_info_for_emacs_buffer (Lisp_Object emacs_buf, Editor *editor)
|
|
538 {
|
|
539 BufferInfo *res;
|
|
540 if (!editor || !editor->binfo_hash)
|
|
541 return 0;
|
|
542 else
|
|
543 {
|
|
544 void *vbuf;
|
|
545 /* #### Probably should use a Lisp hash table for this; what if the last
|
|
546 pointer to the buffer was in the editor struct? */
|
|
547 return (gethash (LISP_TO_VOID (emacs_buf),
|
|
548 editor->binfo_hash,
|
|
549 (void *) &res)
|
|
550 ? res : 0);
|
|
551 }
|
|
552 }
|
|
553
|
|
554
|
|
555
|
|
556 /* Called by mark_buffer. It is possible for the last remaining pointer to
|
|
557 an extent object to be in an Energize_Extent_Data structure that is pointed
|
|
558 at by the binfo->id_to_object table. Since Energize may still reference
|
|
559 this object by its id (in fact, I think it may even "ressurect" a detached
|
185
|
560 extent) we must prevent the extent from being garbage collected. Aside
|
0
|
561 from the obvious lossage (that the extent itself would be trashed) this
|
|
562 would also cause us to free the Energize_Extent_Data which the server still
|
|
563 believes we have. The buffers all get marked because they're on the
|
|
564 `Venergize_buffers_list'.
|
|
565
|
|
566 So, an Energize extent or buffer only ever gets collected when the server
|
|
567 has claimed that it is done with it (or when the connection is closed).
|
|
568
|
|
569 Of course, by keeping pointers to lisp objects in C structs under non-lisp
|
|
570 hash tables, we again build in the assumption that GC never relocates.
|
|
571 */
|
|
572
|
|
573 /* FUCK!! It's not standard-conforming to cast pointers to functions
|
|
574 to or from void*. Give me a fucking break! */
|
185
|
575 struct markobj_kludge_fmh
|
0
|
576 {
|
|
577 void (*markobj) (Lisp_Object);
|
|
578 };
|
|
579
|
|
580 static void
|
|
581 mark_energize_buffer_data_extent_mapper (void *key, void *val, void *arg)
|
|
582 {
|
|
583 if (OBJECT_SEAL (val) == EXTENT_SEAL)
|
|
584 {
|
|
585 struct markobj_kludge_fmh *fmh = arg;
|
|
586 struct Energize_Extent_Data *ext = (Energize_Extent_Data *) val;
|
|
587 /* Lisp_Object extent = data_to_extent (ext); (will abort if marked) */
|
|
588 Lisp_Object extent = ext->extent;
|
|
589 assert (GC_EXTENTP (extent));
|
|
590 ((*fmh->markobj) (extent));
|
|
591 }
|
|
592 }
|
|
593
|
|
594 void
|
|
595 mark_energize_buffer_data (struct buffer *b,
|
|
596 void (*markobj) (Lisp_Object))
|
|
597 {
|
|
598 struct markobj_kludge_fmh fmh;
|
|
599 Lisp_Object buffer;
|
|
600 BufferInfo *binfo;
|
|
601 if (!energize_connection || !energize_connection->binfo_hash)
|
|
602 return;
|
|
603 XSETBUFFER (buffer, b);
|
|
604 binfo = get_buffer_info_for_emacs_buffer (buffer, energize_connection);
|
|
605 if (! binfo)
|
|
606 return;
|
|
607 fmh.markobj = markobj;
|
|
608 maphash (mark_energize_buffer_data_extent_mapper, binfo->id_to_object, &fmh);
|
|
609 }
|
|
610
|
|
611
|
|
612
|
|
613 struct buffer_and_sheet_ids
|
|
614 {
|
|
615 EId buffer_id;
|
|
616 EId sheet_id;
|
|
617 };
|
|
618
|
|
619 static void
|
|
620 find_sheet_id (void* key, void* contents, void* arg)
|
|
621 {
|
|
622 BufferInfo* binfo = (BufferInfo*)contents;
|
|
623 EId buffer_id = (EId)key;
|
|
624 struct buffer_and_sheet_ids* result = (struct buffer_and_sheet_ids*)arg;
|
|
625 int i;
|
|
626
|
|
627 if (!result->buffer_id)
|
|
628 for (i = 0; i < binfo->n_p_sheets; i++)
|
|
629 if (binfo->p_sheet_ids [i] == result->sheet_id)
|
|
630 {
|
|
631 result->buffer_id = buffer_id;
|
|
632 return;
|
|
633 }
|
|
634 }
|
|
635
|
|
636 static EId
|
|
637 buffer_id_of_sheet (EId id)
|
|
638 {
|
|
639 Editor *editor = energize_connection;
|
|
640 struct buffer_and_sheet_ids basi;
|
|
641 if (!energize_connection)
|
|
642 return 0;
|
|
643
|
|
644 basi.buffer_id = 0;
|
|
645 basi.sheet_id = id;
|
|
646 maphash (find_sheet_id, editor->binfo_hash, (void*)&basi);
|
|
647 return basi.buffer_id;
|
|
648 }
|
|
649
|
|
650 static long
|
|
651 get_energize_buffer_id (Lisp_Object emacs_buf)
|
|
652 {
|
|
653 Editor *editor = energize_connection;
|
|
654 BufferInfo *res;
|
|
655
|
|
656 if (!editor || !editor->binfo_hash)
|
|
657 return -1;
|
|
658 else if (!gethash (LISP_TO_VOID (emacs_buf), editor->binfo_hash, (void *)&res))
|
|
659 return -1;
|
|
660 else
|
|
661 return (long) res->id;
|
|
662 }
|
|
663
|
|
664 static char *
|
|
665 kernel_buffer_type_to_elisp_type (char *kernel_type)
|
|
666 {
|
|
667 struct buffer_type_struct *bts =
|
|
668 kernel_buffer_types_to_elisp_buffer_types_vector;
|
|
669 char *elisp_type = 0;
|
|
670
|
|
671 if (!kernel_type)
|
|
672 return UNINITIALIZED_BUFFER_TYPE;
|
|
673
|
|
674 while (bts->kernel_name)
|
|
675 {
|
|
676 if (!strcmp (bts->kernel_name, kernel_type))
|
|
677 {
|
|
678 elisp_type = bts->elisp_name;
|
|
679 break;
|
|
680 }
|
|
681 bts++;
|
|
682 }
|
|
683
|
|
684 if (!elisp_type)
|
|
685 return kernel_type;
|
|
686 else
|
|
687 return elisp_type;
|
|
688 }
|
|
689
|
|
690 static Lisp_Object
|
|
691 get_buffer_type_for_emacs_buffer (Lisp_Object emacs_buf, Editor *editor)
|
|
692 {
|
|
693 BufferInfo *binfo;
|
|
694 if (!(binfo = get_buffer_info_for_emacs_buffer (emacs_buf, editor)))
|
|
695 return Qnil;
|
|
696 else
|
|
697 {
|
|
698 if (!binfo->buffer_type) binfo->buffer_type =
|
|
699 UNINITIALIZED_BUFFER_TYPE;
|
|
700
|
|
701 return intern (binfo->buffer_type);
|
|
702 }
|
|
703 }
|
|
704
|
|
705 static Lisp_Object
|
|
706 set_buffer_type_for_emacs_buffer (Lisp_Object emacs_buf, Editor *editor,
|
|
707 Lisp_Object type)
|
|
708 {
|
|
709 BufferInfo *binfo;
|
|
710 if (!(binfo = get_buffer_info_for_emacs_buffer (emacs_buf, editor)))
|
|
711 return Qnil;
|
|
712 else
|
|
713 {
|
|
714 char *type_string;
|
|
715
|
|
716 if (NILP (type)) return Qnil;
|
|
717
|
|
718 if (SYMBOLP (type))
|
|
719 XSETSTRING (type, XSYMBOL (type)->name);
|
|
720
|
|
721 if (STRINGP (type))
|
80
|
722 type_string = (char *) XSTRING_DATA (type);
|
0
|
723
|
|
724 type_string = copy_string (type_string);
|
|
725
|
|
726 if (!type_string) return Qnil;
|
|
727
|
|
728 binfo->buffer_type = type_string;
|
|
729
|
|
730 return intern (binfo->buffer_type);
|
|
731 }
|
|
732 }
|
|
733
|
|
734 static BufferInfo*
|
|
735 get_buffer_info_for_id (EId id, Editor *editor)
|
|
736 {
|
|
737 BufferInfo *res;
|
|
738 return (gethash ((void *)id, editor->binfo_hash, (void *)&res))?res:0;
|
|
739 }
|
|
740
|
|
741 static void
|
|
742 put_buffer_info (EId id, Lisp_Object emacs_buf, BufferInfo *binfo,
|
|
743 Editor *editor)
|
|
744 {
|
|
745 puthash ((void *)id, binfo, editor->binfo_hash);
|
|
746 puthash (LISP_TO_VOID (emacs_buf), binfo, editor->binfo_hash);
|
|
747 }
|
|
748
|
|
749 static void
|
|
750 remove_buffer_info (EId id, Lisp_Object emacs_buf, Editor *editor)
|
|
751 {
|
|
752 void *vbuf;
|
|
753 remhash ((void *)id, editor->binfo_hash);
|
|
754 remhash (LISP_TO_VOID (emacs_buf), editor->binfo_hash);
|
|
755 }
|
|
756
|
|
757
|
|
758 /* Conversion between Energize and Emacs buffer positions */
|
|
759
|
|
760 #if defined(I18N4)
|
|
761
|
|
762 /* An emacs position is an index into the buffer... In I18N, foreign
|
|
763 characters take up the same amount of space as ASCII characters. Emacs
|
|
764 is using wide characters. The first position is 1.
|
|
765
|
|
766 An energize position is a straight byte offset into the file when it's
|
|
767 saved onto disk. Foreign characters take up more than one byte. The
|
|
768 first position is 0. */
|
|
769
|
|
770 #define WCMAP_SETSIZE(wcmap,n) { \
|
|
771 (wcmap).mapsize = (n); \
|
|
772 (wcmap).map = (WCharMapRec *) xrealloc((wcmap).map, \
|
|
773 (n) * sizeof(WCharMapRec)); \
|
|
774 }
|
|
775 #define WCMAP_ENLARGE(wcmap) WCMAP_SETSIZE(wcmap, 2*(wcmap.mapsize))
|
|
776
|
|
777 #ifndef MB_LEN_MAX
|
|
778 #define MB_LEN_MAX 10 /* arbitrarily large enough */
|
185
|
779 #endif
|
0
|
780
|
|
781 static char wcsize_buf[MB_LEN_MAX];
|
|
782 #define WCSIZE(wc) (isascii(wc) ? 1 : wctomb(wcsize_buf,wc))
|
|
783
|
|
784 #define SANITY_CHECK_NOT
|
|
785 #ifdef SANITY_CHECK
|
|
786 static int sanity=0;
|
185
|
787 #endif
|
0
|
788
|
|
789 static void
|
|
790 sync_buffer_widechar_map (BufferInfo *binfo)
|
|
791 {
|
|
792 /* #### - check this: */
|
|
793 assert (XBUFFER (binfo->emacs_buffer) == current_buffer);
|
|
794
|
|
795 if (!binfo->wcmap.valid)
|
|
796 {
|
|
797 binfo->wcmap.valid= 1;
|
|
798 binfo->wcmap.modiff_stamp= -1;
|
|
799 binfo->wcmap.map= NULL;
|
|
800 WCMAP_SETSIZE (binfo->wcmap, 1);
|
|
801 }
|
|
802
|
|
803 if (binfo->wcmap.modiff_stamp == BUF_MODIFF (current_buffer))
|
|
804 {
|
|
805 return;
|
|
806 }
|
|
807 else
|
|
808 {
|
|
809 int nbytes, maxpos,
|
|
810 pos = 0, /* start at zero instead of 1 */
|
|
811 adjustment = 0,
|
|
812 mapindex= 0;
|
|
813 wchar_t *buf, t;
|
|
814
|
|
815 #ifdef SANITY_CHECK
|
14
|
816 stderr_out ("rebuilding widechar map for %s\n", XSTRING_DATA (current_buffer->name));
|
0
|
817 #endif
|
185
|
818
|
0
|
819 /* #### this is not gonna compile. move_gap() is now a private function
|
|
820 inside of insdel.c and it should stay that way. */
|
|
821 if (BUF_BEGV (current_buffer) < GPT && BUF_ZV (current_buffer) > GPT)
|
|
822 move_gap (current_buffer, BUF_BEGV (current_buffer));
|
|
823 binfo->wcmap.modiff_stamp = BUF_MODIFF (current_buffer);
|
185
|
824
|
0
|
825 buf = BUF_BEG_ADDR (current_buffer);
|
|
826 maxpos= (BUF_Z (current_buffer) - 1);
|
|
827 wctomb (NULL, 0); /* reset shift state of wctomb() */
|
|
828 binfo->wcmap.map[mapindex].pos= pos;
|
|
829 binfo->wcmap.map[mapindex].eucsize=
|
|
830 ((pos<maxpos) ? (nbytes= WCSIZE(buf[pos])) : 1);
|
|
831 do {
|
|
832 while ((pos < maxpos) && (nbytes == WCSIZE(t = buf[pos])))
|
|
833 ++pos;
|
|
834 binfo->wcmap.map[mapindex++].endpos= pos;
|
|
835 if (mapindex == binfo->wcmap.mapsize)
|
|
836 WCMAP_ENLARGE(binfo->wcmap);
|
|
837 if (pos < maxpos)
|
|
838 {
|
|
839 binfo->wcmap.map[mapindex].pos= pos;
|
|
840 binfo->wcmap.map[mapindex].eucsize= nbytes= WCSIZE(t);
|
|
841 }
|
|
842 } while (pos < maxpos);
|
|
843 WCMAP_SETSIZE(binfo->wcmap, mapindex);
|
|
844 }
|
|
845 }
|
|
846
|
|
847 static EnergizePos
|
|
848 EnergizePosForBufpos (Bufpos char_pos, BufferInfo *binfo)
|
|
849 {
|
|
850 int mapindex;
|
|
851 WCharMapRec map;
|
|
852 EnergizePos byte_pos;
|
|
853
|
|
854 sync_buffer_widechar_map (binfo);
|
|
855
|
|
856 --char_pos; /* preadjust emacs position */
|
|
857
|
|
858 mapindex=0, byte_pos=0;
|
|
859 while ((mapindex < binfo->wcmap.mapsize) &&
|
|
860 (char_pos > (map= binfo->wcmap.map[mapindex++]).pos)) {
|
|
861 if (char_pos > map.endpos) {
|
|
862 byte_pos += ((map.endpos - map.pos) * map.eucsize);
|
|
863 } else {
|
|
864 byte_pos += ((char_pos - map.pos) * map.eucsize);
|
|
865 }
|
|
866 }
|
|
867 /* there should be a sanity check here */
|
|
868 #ifdef CHECK_SANITY
|
|
869 if (!sanity) {
|
|
870 Bufpos check_pos;
|
|
871 sanity=1;
|
|
872 check_pos= BufposForEnergizePos(byte_pos, binfo);
|
|
873 sanity=0;
|
|
874
|
|
875 if (check_pos != char_pos) {
|
|
876 stderr_out ("ezpos(%d) = %d, Bufpos(%d) = %d\n",
|
|
877 char_pos, byte_pos, byte_pos, check_pos);
|
|
878 }
|
|
879 }
|
185
|
880 #endif
|
0
|
881 return byte_pos;
|
|
882 }
|
|
883
|
|
884 static Bufpos
|
|
885 BufposForEnergizePos (EnergizePos ez_pos, BufferInfo *binfo)
|
|
886 {
|
|
887 int mapindex, x;
|
|
888 WCharMapRec map;
|
|
889 Bufpos char_pos;
|
|
890 EnergizePos byte_pos;
|
|
891
|
|
892 sync_buffer_widechar_map(binfo);
|
|
893
|
|
894 mapindex=0, byte_pos=0;
|
|
895 while ((mapindex < binfo->wcmap.mapsize) &&
|
|
896 (byte_pos <= ez_pos)) {
|
|
897 map= binfo->wcmap.map[mapindex++];
|
|
898 x= (map.eucsize*(map.endpos-map.pos));
|
|
899 if (ez_pos > (byte_pos + x)) {
|
|
900 byte_pos += x;
|
|
901 char_pos = map.endpos;
|
|
902 } else {
|
|
903 char_pos = (map.pos + ((ez_pos - byte_pos)/map.eucsize));
|
|
904 break;
|
|
905 }
|
|
906 }
|
|
907 char_pos= (char_pos >= (1 << VALBITS)) ? BUF_Z (current_buffer) :
|
|
908 (char_pos + 1);
|
|
909 #ifdef CHECK_SANITY
|
|
910 if (!sanity) {
|
|
911 EnergizePos check_pos;
|
|
912 sanity=1;
|
|
913 check_pos= EnergizePosForBufpos(char_pos);
|
|
914 sanity=0;
|
185
|
915
|
0
|
916 if (check_pos != ez_pos) {
|
|
917 stderr_out ("Bufpos(%d) = %d, EnergizePosForBufpos(%d) = %d\n",
|
|
918 ez_pos, char_pos, char_pos, check_pos);
|
|
919 }
|
|
920 }
|
185
|
921 #endif
|
173
|
922 return char_pos;
|
0
|
923 }
|
|
924
|
|
925 #else /* !I18N4 */
|
|
926
|
|
927 static Bufpos
|
|
928 BufposForEnergizePos (EnergizePos energizePos, BufferInfo *binfo)
|
|
929 {
|
185
|
930 return ((energizePos >= (1 << VALBITS)) ? BUF_Z (current_buffer) :
|
0
|
931 (energizePos + 1));
|
|
932 }
|
|
933
|
|
934 static EnergizePos
|
|
935 EnergizePosForBufpos (Bufpos emacs_pos, BufferInfo *binfo)
|
|
936 {
|
|
937 return (emacs_pos - 1);
|
|
938 }
|
|
939
|
|
940 #endif /* !I18N4 */
|
|
941
|
|
942
|
20
|
943 DEFUN ("energize-update-menubar", Fenergize_update_menubar, 0, 1, 0, /*
|
0
|
944 obsolete
|
20
|
945 */
|
|
946 (frame))
|
0
|
947 {
|
|
948 return Qnil;
|
|
949 }
|
|
950
|
|
951
|
20
|
952 DEFUN ("energize-extent-menu-p", Fenergize_extent_menu_p, 1, 1, 0, /*
|
0
|
953 Whether the extent has a set of commands defined by Energize.
|
20
|
954 */
|
|
955 (extent_obj))
|
0
|
956 {
|
|
957 CHECK_EXTENT (extent_obj);
|
|
958
|
|
959 if (NILP (Fconnected_to_energize_p ()))
|
|
960 return Qnil;
|
|
961 else
|
|
962 {
|
|
963 Energize_Extent_Data *ext = extent_to_data (extent_obj);
|
|
964 return (ext && ext->extentType == CEGeneric) ? Qt : Qnil;
|
|
965 }
|
|
966 }
|
|
967
|
|
968
|
|
969 /* Do what is needed so that the delayed requests will be notified by
|
|
970 ** the event loop */
|
|
971
|
|
972 extern void mark_process_as_being_ready (struct Lisp_Process* process);
|
|
973
|
|
974 static void
|
|
975 notify_delayed_requests (void)
|
|
976 {
|
|
977 if (energize_connection
|
|
978 && !NILP (energize_connection->proc)
|
|
979 && energize_connection->conn
|
|
980 && CRequestDelayedP (energize_connection->conn))
|
185
|
981 this function no longer exists.
|
0
|
982 (Replaced by mark_what_as_being_ready, with different arguments.)
|
|
983 Rewrite this.
|
|
984 mark_process_as_being_ready (XPROCESS (energize_connection->proc));
|
|
985 }
|
|
986
|
|
987
|
|
988 /******************* IMAGE storage maintenance *******************/
|
|
989
|
|
990 extern GLYPH image_instance_to_glyph (Lisp_Object);
|
|
991
|
|
992 static c_hashtable image_cache;
|
|
993
|
|
994 extern char *strdup ();
|
|
995 extern Lisp_Object Fbuffer_file_name (Lisp_Object);
|
|
996
|
|
997
|
|
998 extern Lisp_Object Fmake_face (Lisp_Object name);
|
|
999 extern Lisp_Object Fface_foreground (Lisp_Object face, Lisp_Object frame);
|
|
1000 extern Lisp_Object Fface_background (Lisp_Object face, Lisp_Object frame);
|
|
1001
|
|
1002 /* Don't let any of these get GCed, since we hold their GLYPH ids in
|
|
1003 a non-lisp hash table (image_cache) . */
|
|
1004 static Lisp_Object Vall_energize_pixmaps;
|
|
1005
|
|
1006 /* Parses an image from the image language */
|
|
1007 static GLYPH
|
|
1008 read_energize_image_data (Connection *conn, BufferInfo *binfo)
|
|
1009 {
|
|
1010 ReqLen l;
|
|
1011 char *s = CGetVstring (conn, &l);
|
|
1012 char pix_name [255];
|
|
1013 char buf [255];
|
|
1014 int attr_number, pix_len;
|
|
1015 char *file;
|
|
1016 GLYPH result = 0;
|
|
1017 /* It is bad news to pass the address of a short to gethash. */
|
|
1018 int hashed = 0;
|
|
1019
|
|
1020 if (s[0] != 'f')
|
|
1021 return 0;
|
|
1022
|
|
1023 if (gethash ((void *) s, image_cache, (void *) &hashed))
|
|
1024 /* If we have already parsed this image spec (string=) then just return
|
|
1025 the old glyph, instead of calling the lisp code, x_get_pixmap, and
|
|
1026 XtGetSubResources again. The result may be 0 if there is no pixmap
|
|
1027 file name in the resource database.
|
|
1028 */
|
|
1029 return (GLYPH) hashed;
|
|
1030
|
|
1031 if (3 != sscanf (s, "f %d p %d %s", &attr_number, &pix_len, pix_name))
|
|
1032 {
|
|
1033 sprintf (buf, "unparsable image: \"%s\"", s);
|
|
1034 error (buf);
|
|
1035 }
|
|
1036
|
|
1037 assert (pix_len == strlen (pix_name));
|
|
1038
|
|
1039 /* Read the pixmap file name for this image from the resource db */
|
|
1040 {
|
|
1041 XtResource resource [1];
|
|
1042 resource[0].resource_name = pix_name;
|
|
1043 resource[0].resource_class = XtCBitmap;
|
|
1044 resource[0].resource_type = XtRString;
|
|
1045 resource[0].resource_size = sizeof (char *);
|
|
1046 resource[0].resource_offset = 0;
|
|
1047 resource[0].default_type = XtRImmediate;
|
|
1048 resource[0].default_addr = 0;
|
|
1049 file = 0;
|
|
1050 XtGetSubresources (FRAME_X_SHELL_WIDGET (XFRAME (Fselected_frame (Qnil))),
|
|
1051 (XtPointer) &file, "image", "Image", resource, 1, NULL,
|
|
1052 0);
|
|
1053 }
|
|
1054
|
|
1055 if (! file)
|
|
1056 result = 0;
|
|
1057 else
|
|
1058 {
|
|
1059 Lisp_Object lfile = Qnil;
|
|
1060 Lisp_Object p = Qnil;
|
|
1061 struct gcpro gcpro1, gcpro2;
|
|
1062 sprintf (buf, "attribute%d", attr_number);
|
|
1063 GCPRO2 (lfile, p);
|
|
1064 lfile = build_string (file);
|
|
1065 p = Fmake_image_instance (lfile, Qnil); /* may gc */
|
|
1066 result = image_instance_to_glyph (p);
|
|
1067 Vall_energize_pixmaps = Fcons (Fcons (make_int (result), p),
|
|
1068 Vall_energize_pixmaps);
|
|
1069 if (!EQ (p, glyph_to_image_instance (result)))
|
|
1070 abort ();
|
|
1071 UNGCPRO;
|
|
1072
|
|
1073 if (XIMAGE_INSTANCE (p)->depth == 0)
|
|
1074 /* if depth is >0 then this is an XPM, and its colors are not
|
|
1075 controlled by the fg/bg of a face. So don't bother making a
|
|
1076 face for it. */
|
|
1077 {
|
|
1078 Lisp_Object face, fg, bg;
|
|
1079 struct face *c_face;
|
|
1080 /* #### review this */
|
|
1081 face = Fmake_face (intern (buf));
|
|
1082 fg = FACE_FOREGROUND (face, Qnil);
|
|
1083 bg = FACE_BACKGROUND (face, Qnil);
|
|
1084 Fcolorize_image_instance (p, fg, bg);
|
|
1085 }
|
|
1086 }
|
|
1087
|
|
1088 /* CGetVstring returns a pointer into the connection buffer; we need to
|
|
1089 copy it to use it as a hash key. */
|
|
1090 s = strdup (s);
|
|
1091
|
|
1092 hashed = result;
|
|
1093 puthash ((void *) s, (void *) hashed, image_cache);
|
|
1094 return result;
|
|
1095 }
|
|
1096
|
|
1097
|
|
1098 /* Parses Classes from the connection buffer. Defines them for
|
|
1099 * the buffer given as argument */
|
|
1100 static void
|
|
1101 read_energize_class_data (Connection *conn, unsigned int number,
|
|
1102 BufferInfo *binfo, unsigned int modify_ok)
|
|
1103 {
|
|
1104 CClass *ptr; /* pointer to class data in buffer */
|
|
1105 GDataClass *cl; /* unmodified class data */
|
|
1106 GLYPH g;
|
|
1107 int i;
|
|
1108
|
|
1109 for (i = 0; i < number; i++)
|
|
1110 {
|
|
1111 ptr = CGet (conn, CClass);
|
|
1112 g = read_energize_image_data (conn, binfo);
|
|
1113 cl = get_class (ptr->classId, binfo);
|
|
1114
|
|
1115 if (!cl)
|
|
1116 cl = alloc_GDataclass (ptr->classId, binfo);
|
|
1117 else if (!modify_ok)
|
|
1118 message("Attempt to create class with existing Id %8x", ptr->classId);
|
|
1119
|
|
1120 if (ignore_kernel) continue;
|
|
1121
|
|
1122 /* if it did exist, we just clobber it */
|
|
1123 if (cl->flags != ptr->flags)
|
|
1124 {
|
|
1125 cl->flags = ptr->flags;
|
|
1126 BUF_FACECHANGE (XBUFFER (binfo->emacs_buffer))++;
|
|
1127 }
|
|
1128 if (cl->glyph != g)
|
|
1129 {
|
|
1130 cl->glyph = g;
|
|
1131 BUF_FACECHANGE (XBUFFER (binfo->emacs_buffer))++;
|
|
1132 }
|
|
1133 }
|
|
1134 }
|
|
1135
|
|
1136 /* Parse GenericData form the connection buffer. Defines them for the buffer
|
|
1137 * given as argument */
|
|
1138 static void
|
|
1139 read_energize_generic_data (Connection *conn, unsigned int number,
|
|
1140 BufferInfo *binfo, unsigned int modify_ok)
|
|
1141 {
|
|
1142 CGeneric *ptr;
|
|
1143 GenericData *gen;
|
|
1144 GDataClass *cl;
|
|
1145 GLYPH g;
|
|
1146 int i;
|
|
1147
|
|
1148 for (i = 0; i < number; i++)
|
|
1149 {
|
|
1150 ptr = CGet (conn, CGeneric);
|
|
1151 g = read_energize_image_data (conn, binfo);
|
|
1152 gen = get_generic (ptr->genericId, binfo);
|
|
1153 cl = get_class (ptr->classId, binfo);
|
|
1154
|
|
1155 if (!gen)
|
|
1156 {
|
|
1157 /* create generic if it didn't already exist */
|
|
1158
|
|
1159 if (!cl)
|
|
1160 {
|
|
1161 message ("Attempt to create generic %8x with undefined class %8x",
|
|
1162 ptr->genericId, ptr->classId);
|
|
1163 continue;
|
|
1164 }
|
|
1165
|
|
1166 gen = alloc_GenericData (ptr->genericId, cl, binfo);
|
|
1167 gen->glyph = g;
|
|
1168 if (ptr->flags != 0xff) gen->flags = ptr->flags;
|
|
1169 gen->attribute = ptr->attribute;
|
|
1170 }
|
|
1171 else if (!modify_ok)
|
|
1172 message("Attempt to create generic with existing id %8x",
|
|
1173 ptr->genericId);
|
|
1174 else{
|
|
1175 /* modify the generic */
|
|
1176 int modified = 0;
|
|
1177 if (cl != gen->cl)
|
|
1178 {
|
|
1179 modified = 1;
|
|
1180 gen->cl = cl;
|
|
1181 }
|
|
1182 if (gen->glyph != g)
|
|
1183 {
|
|
1184 modified = 1;
|
|
1185 gen->glyph = g;
|
|
1186 }
|
|
1187 if (ptr->flags != 0xff)
|
|
1188 {
|
|
1189 modified = 1;
|
|
1190 gen->flags = ptr->flags;
|
|
1191 }
|
|
1192 if (gen->attribute != ptr->attribute)
|
|
1193 {
|
|
1194 modified = 1;
|
|
1195 gen->attribute = ptr->attribute;
|
|
1196 }
|
|
1197 if (modified)
|
|
1198 BUF_FACECHANGE (XBUFFER (binfo->emacs_buffer))++;
|
|
1199 }
|
|
1200 }
|
|
1201 }
|
|
1202
|
|
1203
|
|
1204 static void
|
|
1205 insert_one_extent (CExtent* ptr, BufferInfo* binfo, int modify_ok)
|
|
1206 {
|
|
1207 Energize_Extent_Data *ext;
|
|
1208 GenericData *gen;
|
|
1209 Bufpos extent_start;
|
|
1210 Bufpos extent_end;
|
|
1211 int set_endpoints_p = 1;
|
|
1212 int created_ext_data = 0;
|
|
1213 Lisp_Object buffer = binfo->emacs_buffer;
|
|
1214
|
|
1215 ext = get_extent_data (ptr->extentId, binfo);
|
|
1216
|
|
1217 if (!ext)
|
|
1218 {
|
|
1219 ext = (Energize_Extent_Data *) xmalloc (sizeof (Energize_Extent_Data));
|
|
1220 created_ext_data = 1;
|
|
1221 ext->seal = EXTENT_SEAL;
|
|
1222 ext->id = ptr->extentId;
|
|
1223 ext->extentType = -1;
|
|
1224 ext->extent = Qnil; /* not a normal value: set before we return */
|
|
1225 ext->start_pixmap = 0;
|
|
1226 ext->end_pixmap = 0;
|
|
1227 ext->warn_modify = 0;
|
|
1228 put_extent_data (ext->id, binfo, ext);
|
|
1229 }
|
|
1230 else if (!modify_ok)
|
|
1231 message ("Creating extent with existing id %8x", ptr->extentId);
|
|
1232
|
|
1233 ext->extentType = ptr->extentType;
|
|
1234
|
|
1235 switch (ptr->extentType)
|
|
1236 {
|
|
1237 case CEAttribute:
|
|
1238 ext->u.attr.attrValue = ptr->data;
|
|
1239 break;
|
|
1240
|
|
1241 case CEAbbreviation:
|
|
1242 ext->u.abbrev.isOpened = ptr->data;
|
|
1243 break;
|
|
1244
|
|
1245 case CEWriteProtect:
|
|
1246 break;
|
|
1247
|
|
1248 case CEGeneric:
|
|
1249 gen = get_generic (ptr->data, binfo);
|
|
1250 if (!gen)
|
|
1251 {
|
|
1252 message ("NewExtents: Nonexistent generic data %8x", ptr->data);
|
|
1253 return;
|
|
1254 }
|
|
1255 ext->u.generic.gData = gen;
|
|
1256 break;
|
|
1257
|
|
1258 default:
|
|
1259 message ("Unknown extent type %d", ptr->extentType);
|
|
1260 break;
|
|
1261 }
|
|
1262
|
|
1263 /* instruct redisplay to recompute the frame */
|
|
1264 BUF_FACECHANGE (XBUFFER (binfo->emacs_buffer))++;
|
|
1265
|
|
1266 /* ptr->startPosition == ptr->endPosition == ~0 means to not change
|
|
1267 * the extent endpoints */
|
|
1268 if (ptr->startPosition == ~0 && ptr->endPosition == ~0)
|
|
1269 {
|
|
1270 set_endpoints_p = 0;
|
|
1271 extent_start = ~0;
|
|
1272 extent_end = ~0;
|
|
1273 }
|
|
1274 else
|
|
1275 {
|
|
1276 struct buffer *b = XBUFFER (buffer);
|
|
1277 extent_start = BufposForEnergizePos (ptr->startPosition, binfo);
|
|
1278 extent_end = BufposForEnergizePos (ptr->endPosition, binfo);
|
|
1279
|
|
1280 /* We have to be careful to create the extents with endpoints
|
|
1281 which are in the buffer.
|
|
1282
|
|
1283 Under certain obscure conditions involving changes made outside
|
|
1284 of Emacs (bug 19983), the server and the editor can have different
|
|
1285 ideas about where the extents are, so these numbers can be off
|
|
1286 temporarily (during the window between read_energize_extent_data
|
|
1287 and Qenergize_auto_revert_buffer in read_energize_buffer_data
|
|
1288 from ModifyBufferRType).
|
|
1289 */
|
|
1290
|
|
1291 /* Don't allow 0-length extents, as they tend to disappear. */
|
|
1292 if (extent_start >= extent_end)
|
|
1293 extent_end = extent_start + 1;
|
|
1294
|
|
1295 /* Don't let them outside the buffer (even if we grew them). */
|
|
1296 if (extent_start >= BUF_Z (b)) extent_start = BUF_Z (b) - 1;
|
|
1297 if (extent_end >= BUF_Z (b)) extent_end = BUF_Z (b) - 1;
|
|
1298 if (extent_start < BUF_BEG (b)) extent_start = BUF_BEG (b);
|
|
1299 if (extent_end < BUF_BEG (b)) extent_end = BUF_BEG (b);
|
|
1300
|
|
1301 /* If they're 0-length again, then the extent must be at point-max.
|
|
1302 In that case, extent it backward (if possible) instead of forward.
|
|
1303 */
|
|
1304 if (extent_start >= extent_end
|
|
1305 && BUF_BEG (b) != BUF_Z (b))
|
|
1306 extent_start = extent_end - 1;
|
|
1307 }
|
|
1308
|
|
1309 /* no zero width extent */
|
|
1310 if (set_endpoints_p && extent_start == extent_end)
|
|
1311 extent_end += 1;
|
|
1312
|
|
1313 /* Now create the extent for the extent-data. There is a 1:1 mapping between
|
|
1314 these, and an extent-data points at an extent (and that extent points
|
|
1315 back) until energize tells us to delete the extent. This is the only
|
|
1316 function in which ext->extent is ever not an extent. */
|
|
1317 if (created_ext_data)
|
|
1318 {
|
|
1319 ext->extent = Fmake_extent (make_int (extent_start),
|
|
1320 make_int (extent_end), buffer);
|
|
1321 set_energize_extent_data (XEXTENT (ext->extent), ext);
|
|
1322 restore_energize_extent_state (XEXTENT (ext->extent));
|
|
1323 }
|
|
1324 else
|
|
1325 {
|
|
1326 if (!EQ (buffer, extent_buffer (XEXTENT (ext->extent))))
|
|
1327 signal_simple_error_2 ("extent not part of buffer", ext->extent,
|
|
1328 buffer);
|
|
1329
|
|
1330 if (set_endpoints_p)
|
|
1331 Fset_extent_endpoints (ext->extent, make_int (extent_start),
|
|
1332 make_int (extent_end), Qnil);
|
|
1333 restore_energize_extent_state (XEXTENT (ext->extent));
|
|
1334 }
|
|
1335
|
|
1336 if (energize_extent_data (XEXTENT (ext->extent)) != ext)
|
|
1337 abort ();
|
|
1338
|
|
1339 extent_duplicable_p (XEXTENT (ext->extent)) = 1;
|
|
1340 extent_unique_p (XEXTENT (ext->extent)) = 1;
|
|
1341 }
|
|
1342
|
|
1343
|
|
1344 /* Parse GenericData from the connection buffer. Defines them for the buffer
|
|
1345 * given as argument. Creates the Emacs extents while parsing.
|
|
1346 * Energize sends the extents ordered by increasing starting position.
|
|
1347 I don't think the following is true any more:
|
|
1348 * Emacs is __much__ faster at inserting them in decreasing starting position
|
|
1349 * also for overlaps to work correctly the outmost extents have to be
|
|
1350 * inserted first. This is what the recursive function is trying to do.
|
|
1351 */
|
|
1352 static void
|
|
1353 read_energize_extent_data (Connection *conn, unsigned int number,
|
|
1354 BufferInfo *binfo, unsigned int modify_ok,
|
|
1355 int extent_offset)
|
|
1356 {
|
|
1357 CExtent* all_extents;
|
|
1358 int i;
|
|
1359
|
|
1360 /* Gets the extents from the connection */
|
|
1361 all_extents = CGetN (conn, CExtent, number);
|
|
1362
|
|
1363 /* adjusts the endpoints with the offset */
|
|
1364 for (i = 0; i < number; i++)
|
|
1365 {
|
|
1366 if (all_extents [i].startPosition != ~0)
|
|
1367 all_extents [i].startPosition += extent_offset;
|
|
1368 if (all_extents [i].endPosition != ~0)
|
|
1369 all_extents [i].endPosition += extent_offset;
|
|
1370 }
|
|
1371
|
|
1372 /* inserts them all */
|
|
1373 for (i = number - 1; i >= 0; i--)
|
|
1374 {
|
|
1375 insert_one_extent (all_extents + i, binfo, modify_ok);
|
|
1376 }
|
|
1377 }
|
|
1378
|
|
1379 /* Parses a CBuffer in the connection stream. If (delete_from != delete_to)
|
|
1380 all characters in this range must be deleted.
|
|
1381 */
|
|
1382
|
|
1383 static int
|
|
1384 string_buffer_compare (char *string, int string_len,
|
|
1385 struct buffer *buf, Bufpos bufpos)
|
|
1386 {
|
|
1387 /* !!#### needs to be rewritten for Mule */
|
|
1388 Bufpos first_section_end = BUF_CEILING_OF (buf, bufpos);
|
|
1389
|
|
1390 /* degenerate case, which we consider to be "true" */
|
|
1391 if (string_len == 0) return 0;
|
|
1392
|
|
1393 /* string won't fit in the buffer, so comparison fails */
|
|
1394 if (BUF_Z (buf) < (bufpos + string_len)) return -1;
|
|
1395
|
|
1396 /* bad starting position, so comparison fails */
|
|
1397 if (bufpos < BUF_BEG (buf)) return -1;
|
|
1398
|
|
1399 {
|
|
1400 char *first_section_chars = (char *) BUF_BYTE_ADDRESS (buf, bufpos);
|
|
1401 int comp = strncmp (string, first_section_chars,
|
|
1402 first_section_end - bufpos);
|
185
|
1403
|
0
|
1404 if (comp) return comp;
|
|
1405 }
|
|
1406
|
|
1407 if (first_section_end < BUF_ZV (buf))
|
|
1408 /* there is a second section */
|
|
1409 {
|
|
1410 char *second_section_chars =
|
|
1411 (char *) BUF_BYTE_ADDRESS (buf, first_section_end);
|
|
1412 int comp = strncmp (string + (first_section_end - bufpos),
|
|
1413 second_section_chars,
|
|
1414 BUF_ZV (buf) - first_section_end);
|
|
1415
|
|
1416 if (comp) return comp;
|
|
1417 }
|
|
1418
|
|
1419 return 0;
|
|
1420 }
|
|
1421
|
|
1422 /* called by unwind protect, from within ParseBuffer and HandleRemoveExtents */
|
|
1423 static Lisp_Object
|
|
1424 restore_buffer_state (Lisp_Object state_cons)
|
|
1425 {
|
|
1426 BufferInfo *binfo;
|
|
1427 Lisp_Object bufferId_obj = Fcar (state_cons);
|
|
1428 unsigned int bufferId = (unsigned int) get_opaque_ptr (bufferId_obj);
|
|
1429 Lisp_Object buffer_modified_state = Fcar (Fcdr (state_cons));
|
|
1430 Lisp_Object clear_undo_list = Fcdr (Fcdr (state_cons));
|
|
1431
|
|
1432 if (bufferId != 0)
|
|
1433 {
|
|
1434 if (energize_connection
|
|
1435 && (binfo = get_buffer_info_for_id (bufferId, energize_connection))
|
|
1436 && !NILP (binfo->emacs_buffer))
|
|
1437 {
|
|
1438 /* Always ignore what Energize tells us about the buffer read-only
|
|
1439 state. For files Emacs knows better and for non-file buffers
|
|
1440 Emacs is hacking the read-only state anyway so let it be. */
|
|
1441 XBUFFER (binfo->emacs_buffer)->read_only = buffer_modified_state;
|
|
1442 if (!NILP (clear_undo_list))
|
|
1443 XBUFFER (binfo->emacs_buffer)->undo_list = Qnil;
|
|
1444 }
|
|
1445 }
|
|
1446 else
|
|
1447 /* this is just temporary */
|
|
1448 message ("Bad bufferId cons cell!");
|
|
1449 return Qnil;
|
|
1450 }
|
|
1451
|
|
1452 /* #### this shit should be using generate-new-buffer */
|
|
1453 static void
|
|
1454 rename_the_buffer (Lisp_Object new_name)
|
|
1455 {
|
|
1456 int count = 0;
|
|
1457 char number [8];
|
|
1458 struct gcpro gcpro1;
|
|
1459
|
|
1460 Lisp_Object name = new_name;
|
|
1461 GCPRO1 (name);
|
|
1462 while (!NILP (Fget_buffer (name)))
|
|
1463 {
|
|
1464 sprintf (number, "<%d>", ++count);
|
|
1465 name = concat2 (new_name, build_string (number));
|
|
1466 }
|
|
1467 Frename_buffer (name, Qnil);
|
|
1468 UNGCPRO;
|
|
1469 }
|
|
1470
|
|
1471 static int
|
|
1472 destroy_if_energize_extent (EXTENT e, void* arg)
|
|
1473 {
|
|
1474 struct Energize_Extent_Data *ext = energize_extent_data (e);
|
|
1475 if (ext)
|
|
1476 {
|
|
1477 Lisp_Object extent;
|
|
1478 Lisp_Object buffer;
|
|
1479 BufferInfo *binfo = 0;
|
|
1480 XSETEXTENT (extent, e);
|
|
1481 buffer = extent_buffer (XEXTENT (extent));
|
|
1482 Fdelete_extent (extent);
|
|
1483 if (BUFFERP (buffer))
|
|
1484 binfo = get_buffer_info_for_emacs_buffer (buffer, energize_connection);
|
|
1485 if (binfo)
|
|
1486 free_Energize_Extent_Data (ext, binfo, OFT_GC);
|
|
1487 else
|
|
1488 {
|
|
1489 /* #### partly duplicated in free_Energize_Extent_Data() */
|
|
1490 set_energize_extent_data (e, 0);
|
|
1491 ext->extent = Qnil;
|
|
1492 }
|
|
1493 }
|
|
1494 return 0;
|
|
1495 }
|
|
1496
|
|
1497 static void
|
|
1498 destroy_all_energize_extents (struct buffer *buf)
|
|
1499 {
|
|
1500 map_extents (BUF_BEG (buf), BUF_Z (buf), destroy_if_energize_extent,
|
|
1501 NULL, make_buffer (buf), 0,
|
|
1502 ME_END_CLOSED | ME_MIGHT_MODIFY_EXTENTS);
|
|
1503 }
|
|
1504
|
|
1505 static Lisp_Object
|
|
1506 restore_inside_parse_buffer (Lisp_Object val)
|
|
1507 {
|
|
1508 inside_parse_buffer = XINT (val);
|
|
1509 return (val);
|
|
1510 }
|
|
1511
|
|
1512 static void
|
|
1513 hack_window_point (Lisp_Object window,
|
|
1514 Lisp_Object old_point,
|
|
1515 Lisp_Object old_start,
|
|
1516 int keep_start_p,
|
|
1517 BufferInfo *binfo)
|
|
1518 /* If we've reverted a buffer, sometimes we want to make sure that
|
|
1519 the window-point doesn't move. */
|
|
1520 {
|
|
1521 if (NILP (window))
|
|
1522 return;
|
|
1523
|
|
1524 Fset_marker (XWINDOW (window)->pointm, old_point, binfo->emacs_buffer);
|
|
1525 if (NILP (binfo->output_mark) && keep_start_p)
|
|
1526 {
|
|
1527 Fset_marker (XWINDOW (window)->start, old_start, binfo->emacs_buffer);
|
|
1528 XWINDOW (window)->force_start = 1;
|
|
1529 }
|
|
1530 }
|
|
1531
|
|
1532 static void
|
|
1533 read_energize_buffer_data (Connection *conn, CBuffer *cbu, Editor *editor,
|
|
1534 EnergizePos delete_from, EnergizePos delete_to,
|
|
1535 Window win, int relative_p)
|
|
1536 {
|
|
1537 char *name;
|
|
1538 ReqLen name_len;
|
|
1539 char *pathname_str;
|
|
1540 ReqLen pathname_len;
|
|
1541 char *buffer_class_str;
|
|
1542 ReqLen buffer_class_len;
|
|
1543 Lisp_Object pathname = Qnil;
|
|
1544 Lisp_Object pathname_directory = Qnil;
|
|
1545 Lisp_Object buffer_name = Qnil;
|
|
1546 Lisp_Object filename = Qnil;
|
|
1547 #if 1
|
|
1548 Lisp_Object display_window = Qnil;
|
|
1549 #endif
|
|
1550 BufferInfo *binfo;
|
|
1551 int modifying_p = 0;
|
|
1552 Bufpos previous_point;
|
|
1553 Bufpos from;
|
|
1554 Bufpos to;
|
|
1555 #if 1
|
|
1556 Bufpos display_start = 1;
|
|
1557 #endif
|
|
1558 char *text;
|
|
1559 ReqLen text_len;
|
|
1560 int get_chars_from_file = 0;
|
|
1561 Lisp_Object modified_buffer_flag;
|
|
1562 int speccount = specpdl_depth ();
|
|
1563 int extent_offset;
|
|
1564 Lisp_Object restore_buffer_state_cons;
|
|
1565 int should_keep_window_start = 1;
|
|
1566 int no_text_deleted = 0;
|
|
1567
|
|
1568 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
1569
|
|
1570 /* For some reason calling the GC before parsing the buffer data
|
185
|
1571 makes a better usage of memory and emacs leaks less when
|
|
1572 creating/deleting LE browser buffers.
|
0
|
1573 However you don't want to call GC all the tiem so we only do it if the request
|
|
1574 will create more than a given number of extents. */
|
|
1575 if (cbu->nExtent > energize_extent_gc_threshold)
|
|
1576 garbage_collect_1 ();
|
|
1577
|
|
1578 record_unwind_protect (save_restriction_restore, save_restriction_save ());
|
|
1579
|
|
1580 Fwiden (Fcurrent_buffer ());
|
|
1581
|
|
1582 GCPRO4 (buffer_name, pathname, pathname_directory, filename);
|
|
1583
|
|
1584 name = CGetVstring (conn, &name_len);
|
|
1585
|
|
1586 /* read the pathname and buffer-class -- Editor Protocol > 0 */
|
|
1587 pathname_str = CGetVstring (conn, &pathname_len);
|
|
1588 buffer_class_str = CGetVstring (conn, &buffer_class_len);
|
|
1589
|
|
1590 if (name_len)
|
|
1591 buffer_name = build_string (name);
|
|
1592 if (pathname_len)
|
|
1593 pathname = build_string (pathname_str);
|
|
1594
|
|
1595 /* set up pathname_directory */
|
|
1596 if (!NILP (pathname))
|
|
1597 {
|
|
1598 if (NILP (Ffile_directory_p (pathname)))
|
|
1599 pathname_directory = Ffile_name_directory (pathname);
|
|
1600 else
|
|
1601 pathname_directory = pathname;
|
|
1602 }
|
|
1603
|
|
1604 /* make sure that pathname_directory ends with a '/', if it exists */
|
|
1605 if (!NILP (pathname_directory))
|
|
1606 {
|
14
|
1607 Bufbyte *str = XSTRING_DATA (pathname_directory);
|
|
1608 Bytecount size = XSTRING_LENGTH (pathname_directory);
|
0
|
1609 if (str[size - 1] != '/')
|
|
1610 {
|
|
1611 Lisp_Object tmp = make_string (str, size + 1);
|
|
1612 set_string_byte (XSTRING (tmp), size, '/');
|
|
1613 pathname_directory = tmp;
|
|
1614 }
|
|
1615 }
|
|
1616
|
|
1617
|
|
1618 /* get or create the BufferInfo */
|
|
1619 if (binfo = get_buffer_info_for_id (cbu->bufferId, editor))
|
|
1620 modifying_p = 1;
|
|
1621 else
|
|
1622 {
|
|
1623 if (NILP (buffer_name))
|
|
1624 {
|
|
1625 char *dummy = "*Unnamed " IDENTITY_CRISIS " Buffer*";
|
|
1626 buffer_name = build_string (dummy);
|
|
1627 }
|
|
1628 /* create new buffer */
|
|
1629 binfo = alloc_BufferInfo (cbu->bufferId, buffer_name, pathname,
|
|
1630 buffer_class_str, editor, win,
|
|
1631 cbu->nExtent + cbu->nClass + cbu->nGeneric);
|
|
1632 XBUFFER (binfo->emacs_buffer)->read_only =
|
|
1633 cbu->flags == CBReadOnly ? Qt : Qnil;
|
|
1634 }
|
|
1635
|
|
1636 /* remember where we were in which buffer before we change things */
|
|
1637 if (current_buffer != XBUFFER (binfo->emacs_buffer))
|
|
1638 {
|
|
1639 record_unwind_protect (save_excursion_restore, save_excursion_save ());
|
|
1640 Fset_buffer (binfo->emacs_buffer);
|
|
1641 }
|
|
1642
|
|
1643 /* set default-directory */
|
|
1644 if (!NILP (pathname_directory))
|
|
1645 {
|
|
1646 if (!NILP (Ffile_directory_p (pathname_directory))
|
|
1647 && !NILP (Ffile_executable_p (pathname_directory)))
|
|
1648 Fset (Qdefault_directory, pathname_directory);
|
|
1649 /* Never set this to nil, that loses badly. */
|
|
1650 /* else
|
|
1651 Fset (Qdefault_directory, Qnil); */
|
|
1652 }
|
|
1653
|
|
1654 /* set file name unless it's a directory */
|
|
1655 if (!NILP (pathname) && NILP (Ffile_directory_p (pathname)))
|
|
1656 {
|
|
1657 filename = Fexpand_file_name (pathname, Qnil);
|
|
1658 Fset (Qbuffer_file_name, filename);
|
|
1659 }
|
|
1660
|
|
1661 /* set buffer name */
|
|
1662 if (!NILP (buffer_name))
|
|
1663 {
|
|
1664 if (modifying_p
|
80
|
1665 && strcmp ((char*) XSTRING_DATA (buffer_name),
|
82
|
1666 (char*) XSTRING_DATA (XBUFFER (binfo->emacs_buffer)->name)))
|
0
|
1667 rename_the_buffer (buffer_name);
|
|
1668 }
|
|
1669
|
|
1670 if (modifying_p)
|
|
1671 {
|
|
1672 run_hook (Venergize_kernel_modification_hook);
|
|
1673 /* Make sure buffer is current after the hook */
|
|
1674 Fset_buffer (binfo->emacs_buffer);
|
|
1675 }
|
|
1676
|
|
1677 modified_buffer_flag = Fbuffer_modified_p (binfo->emacs_buffer);
|
|
1678
|
|
1679 /* enables buffer edits */
|
|
1680 restore_buffer_state_cons =
|
|
1681 Fcons (make_opaque_ptr ((void *) cbu->bufferId),
|
|
1682 Fcons (XBUFFER (binfo->emacs_buffer)->read_only, Qt));
|
|
1683 record_unwind_protect (restore_buffer_state, restore_buffer_state_cons);
|
|
1684 XBUFFER (binfo->emacs_buffer)->read_only = Qnil;
|
|
1685
|
|
1686 /* any changes here should take place "underneath" these hooks, I think */
|
|
1687 specbind (Qenergize_buffer_modified_hook, Qnil);
|
|
1688 specbind (Qfirst_change_hook, Qnil);
|
|
1689 specbind (Qbefore_change_functions, Qnil);
|
|
1690 specbind (Qbefore_change_function, Qnil); /* #### */
|
|
1691 /* As energize does not use the after-change-function it's not useful to
|
|
1692 bind it to NIL */
|
|
1693 /* specbind (Qafter_change_functions, Qnil); */
|
|
1694 /* specbind (Qafter_change_function, Qnil); #### */
|
|
1695 specbind (Qinhibit_read_only, Qt);
|
|
1696 record_unwind_protect (restore_inside_parse_buffer,
|
|
1697 make_int (inside_parse_buffer));
|
|
1698 inside_parse_buffer = 1;
|
|
1699 specbind (Qbuffer_undo_list, Qt);
|
|
1700
|
|
1701 XBUFFER (binfo->emacs_buffer)->undo_list = Qt;
|
|
1702
|
|
1703 /* BufposForEnergizePos uses the current-buffer */
|
|
1704 from = BufposForEnergizePos (delete_from, binfo);
|
|
1705 to = BufposForEnergizePos (delete_to, binfo);
|
|
1706
|
|
1707 /* See if we should get the characters from the file directly.
|
|
1708 Only protocol 0.10+ will do this.
|
|
1709 */
|
|
1710 #ifdef ENERGIZE_V2_HEADERS
|
|
1711 get_chars_from_file = 0;
|
|
1712 #else
|
|
1713 if (cbu->flags != 0xff)
|
|
1714 get_chars_from_file = cbu->flags & CBFileYourself;
|
|
1715 else
|
|
1716 get_chars_from_file = binfo->flags & CBFileYourself;
|
|
1717 #endif
|
185
|
1718
|
0
|
1719 /* Even when we get the chars from a file there is an empty text string */
|
|
1720 if (get_chars_from_file)
|
|
1721 {
|
|
1722 text = CGetVstring (conn, &text_len);
|
|
1723 text = NULL;
|
|
1724 text_len = 0;
|
|
1725 }
|
|
1726 else
|
|
1727 {
|
|
1728 text = CGetVstring (conn, &text_len);
|
|
1729 }
|
185
|
1730
|
0
|
1731 /* updates the visited file modtime */
|
|
1732 if (modifying_p && (from != to || text_len)
|
|
1733 /* but only when we do not read the file ourselves */
|
|
1734 && !get_chars_from_file)
|
|
1735 Fset_buffer_modtime (binfo->emacs_buffer, Qnil);
|
|
1736
|
|
1737 if (!modifying_p)
|
|
1738 {
|
|
1739 /* clears the buffer in case we re-use a non-energize buffer */
|
|
1740 previous_point = 1;
|
|
1741 Fset_buffer (binfo->emacs_buffer);
|
|
1742 buffer_delete_range (current_buffer, BUF_BEG (current_buffer),
|
|
1743 BUF_Z (current_buffer), 0);
|
|
1744 }
|
|
1745 else
|
|
1746 {
|
|
1747 #if 1
|
|
1748 display_window = Fget_buffer_window (binfo->emacs_buffer, Qnil, Qnil);
|
|
1749 #endif
|
|
1750 previous_point = BUF_PT (current_buffer);
|
|
1751
|
|
1752 #if 1
|
|
1753 if (!NILP (display_window))
|
|
1754 display_start =
|
|
1755 XINT (Fmarker_position (XWINDOW (display_window)->start));
|
|
1756 #endif
|
|
1757
|
|
1758 if (from != to)
|
|
1759 {
|
|
1760 struct buffer *buf = XBUFFER (binfo->emacs_buffer);
|
|
1761
|
|
1762 Fset_buffer (binfo->emacs_buffer);
|
|
1763 Fwiden (Fcurrent_buffer ());
|
|
1764 if (!NILP (binfo->output_mark)
|
|
1765 && marker_position (binfo->output_mark) >= from)
|
|
1766 Fset_marker (binfo->output_mark, make_int (from),
|
|
1767 binfo->emacs_buffer);
|
|
1768 if (((to - from) == text_len) && !get_chars_from_file &&
|
|
1769 !string_buffer_compare (text, text_len, buf, from))
|
|
1770 /* the new text is the same as the old text, don't clear
|
|
1771 the undo list*/
|
|
1772 {
|
|
1773 Fsetcdr (Fcdr (restore_buffer_state_cons), Qnil);
|
|
1774 no_text_deleted = 1;
|
|
1775 destroy_all_energize_extents (buf);
|
|
1776 }
|
|
1777 else
|
|
1778 {
|
|
1779 /* Do not keep window start if we actually delete text */
|
|
1780 should_keep_window_start = 0;
|
|
1781 Fset_buffer (binfo->emacs_buffer);
|
|
1782 destroy_all_energize_extents (buf);
|
|
1783 if (!get_chars_from_file)
|
|
1784 buffer_delete_range (current_buffer, from, to, 0);
|
|
1785 }
|
|
1786
|
|
1787 /* Do not clear the undo list if getting the chars from the file */
|
|
1788 if (get_chars_from_file)
|
|
1789 Fsetcdr (Fcdr (restore_buffer_state_cons), Qnil);
|
|
1790 }
|
|
1791 else if (!text_len && !get_chars_from_file)
|
|
1792 /* if there is no text and we didn't delete anything,
|
|
1793 don't clear the undo_list slot */
|
|
1794 Fsetcdr (Fcdr (restore_buffer_state_cons), Qnil);
|
|
1795
|
|
1796 }
|
|
1797
|
|
1798 /* buffer type */
|
|
1799 if (cbu->flags != 0xff && cbu->flags != binfo->flags)
|
|
1800 {
|
|
1801 if (!modifying_p)
|
|
1802 {
|
|
1803 if (cbu->flags == CBUserInput)
|
|
1804 {
|
|
1805 Lisp_Object buffer_local_variable_name =
|
|
1806 Qenergize_user_input_buffer_mark;
|
|
1807 binfo->output_mark = Fmake_marker ();
|
|
1808 Fset_marker (binfo->output_mark, make_int (1),
|
|
1809 binfo->emacs_buffer);
|
|
1810 /* make sure that this guy doesn't get GC'd out from under us */
|
|
1811 Fmake_local_variable (buffer_local_variable_name);
|
|
1812 Fput (buffer_local_variable_name, Qpermanent_local, Qt);
|
|
1813 Fset (buffer_local_variable_name, binfo->output_mark);
|
|
1814 /* Make sure buffer is current after the hook */
|
|
1815 Fset_buffer (binfo->emacs_buffer);
|
|
1816 }
|
|
1817 }
|
|
1818 binfo->flags = cbu->flags;
|
|
1819 }
|
|
1820
|
|
1821 if (get_chars_from_file && text_len != 0)
|
|
1822 /* I think this is always true, but let's make sure - jwz */
|
|
1823 abort ();
|
|
1824
|
|
1825 if (text_len)
|
|
1826 {
|
|
1827 if (!NILP (binfo->output_mark))
|
|
1828 {
|
|
1829 Fset_buffer (binfo->emacs_buffer);
|
|
1830 if (XMARKER (binfo->output_mark)->buffer)
|
|
1831 Fgoto_char (binfo->output_mark, Fcurrent_buffer ());
|
|
1832 else
|
|
1833 /* This should not happen */
|
|
1834 Fgoto_char (make_int (BUF_ZV (XBUFFER (binfo->emacs_buffer))),
|
|
1835 Fcurrent_buffer ());
|
|
1836
|
|
1837 if (BUF_PT (current_buffer) <= previous_point)
|
|
1838 {
|
|
1839 #if 1
|
|
1840 display_start += text_len;
|
|
1841 #endif
|
|
1842 previous_point += text_len;
|
|
1843 }
|
|
1844 buffer_insert_raw_string (current_buffer, text, text_len);
|
|
1845 Fset_marker (binfo->output_mark, make_int (BUF_PT (current_buffer)),
|
|
1846 binfo->emacs_buffer);
|
|
1847 }
|
|
1848 else if (modifying_p)
|
|
1849 {
|
|
1850 Fgoto_char (make_int (from), Fcurrent_buffer ());
|
|
1851 if (!no_text_deleted)
|
|
1852 buffer_insert_raw_string (current_buffer, text, text_len);
|
|
1853 }
|
|
1854 else
|
|
1855 buffer_insert_raw_string (current_buffer, text, text_len);
|
|
1856
|
|
1857 previous_point = XINT (Fgoto_char (make_int (previous_point)),
|
|
1858 Fcurrent_buffer ());
|
|
1859 }
|
|
1860 else if (get_chars_from_file && !modifying_p)
|
|
1861 {
|
|
1862 /* !modifying_p means the buffer is being created - read the text
|
|
1863 from the file. */
|
|
1864 Finsert_file_contents_internal (Fbuffer_file_name (binfo->emacs_buffer),
|
|
1865 /* #### coding system not correct */
|
|
1866 Qt, Qnil, Qnil, Qnil, Qnil, Qnil));
|
|
1867 }
|
|
1868
|
|
1869 if (!relative_p)
|
|
1870 extent_offset = 0;
|
|
1871 else if (!NILP (binfo->output_mark))
|
|
1872 extent_offset = EnergizePosForBufpos (XINT (Fmarker_position
|
|
1873 (binfo->output_mark)),
|
|
1874 binfo);
|
|
1875 else
|
|
1876 extent_offset = EnergizePosForBufpos (BUF_Z(XBUFFER(binfo->emacs_buffer)),
|
|
1877 binfo);
|
185
|
1878
|
0
|
1879 #if 1
|
|
1880 if (text_len || !text)
|
|
1881 hack_window_point (display_window,
|
|
1882 make_int (previous_point),
|
|
1883 make_int (display_start),
|
|
1884 should_keep_window_start,
|
|
1885 binfo);
|
|
1886 #endif
|
|
1887
|
|
1888
|
|
1889 /* Classes, generics and extents */
|
|
1890 /* make sure that we have enough room in the hash table */
|
|
1891 expand_hashtable (binfo->id_to_object,
|
|
1892 cbu->nClass + cbu->nGeneric + cbu->nExtent);
|
|
1893 read_energize_class_data (conn, cbu->nClass, binfo, modifying_p);
|
|
1894 read_energize_generic_data (conn, cbu->nGeneric, binfo, modifying_p);
|
|
1895 read_energize_extent_data (conn, cbu->nExtent, binfo, modifying_p, extent_offset);
|
|
1896
|
|
1897 /* Restore the modified bit */
|
|
1898 Fset_buffer_modified_p (modified_buffer_flag, binfo->emacs_buffer);
|
|
1899
|
|
1900 if (get_chars_from_file && modifying_p)
|
|
1901 {
|
|
1902 /* modifying_p means the buffer already exists and the extents are
|
|
1903 being re-written. It may be that the file has changed on disk,
|
|
1904 and the extents no longer correspond to the text in the buffer,
|
|
1905 which would be bad. So, check the file on disk, and if it has
|
|
1906 changed, offer to revert.
|
|
1907
|
|
1908 As this runs lisp code which may prompt the user, and consequently
|
|
1909 may accept process output, be careful to do this after we have
|
|
1910 finished reading the current request from the Energize connection.
|
|
1911 */
|
|
1912 if (NILP (Fverify_visited_file_modtime (binfo->emacs_buffer)))
|
|
1913 {
|
|
1914 call1 (Qenergize_auto_revert_buffer, binfo->emacs_buffer);
|
|
1915 hack_window_point (display_window,
|
|
1916 make_int (previous_point),
|
|
1917 make_int (display_start),
|
|
1918 1,
|
|
1919 binfo);
|
|
1920 }
|
|
1921 }
|
|
1922
|
|
1923
|
|
1924 /* restore modified hooks and globals, and return the previous buffer */
|
|
1925 UNGCPRO;
|
|
1926 unbind_to (speccount, Qnil);
|
|
1927 }
|
|
1928
|
|
1929
|
|
1930 static void
|
|
1931 cleanly_destroy_all_widgets (int count, LWLIB_ID *ids)
|
|
1932 {
|
|
1933 /* This just calls lw_destroy_all_widgets, but is careful to make sure that
|
|
1934 this doesn't cause the frames to shrink. If one deletes psheets
|
|
1935 (children of the "control" area of the MainWindow) without first
|
|
1936 unmanaging the MainWindow, the frame resizes. So first unmanage all
|
|
1937 the MainWindows of all applicable frames, then remanage them. This is
|
|
1938 nasty, but...
|
|
1939 */
|
|
1940 Lisp_Object frmcons, devcons, concons;
|
|
1941 int i, j;
|
|
1942
|
|
1943 if (count == 0)
|
|
1944 return;
|
|
1945
|
|
1946 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
1947 {
|
|
1948 Lisp_Object frame = XCAR (frmcons);
|
|
1949 struct frame *f = XFRAME (frame);
|
|
1950
|
|
1951 if (!FRAME_X_P (f))
|
|
1952 continue;
|
|
1953 /* Optimization: only unmanage the MainWindow if this frame is
|
|
1954 displaying one of the psheets in question. (Special casing
|
|
1955 the debugger panel as usual...)
|
|
1956 */
|
|
1957 for (i = 0; i < count; i++)
|
|
1958 if (ids [i] == debuggerpanel_sheet)
|
|
1959 {
|
|
1960 XtUnmanageChild (FRAME_X_CONTAINER_WIDGET (f));
|
|
1961 goto next_frame;
|
|
1962 }
|
|
1963 else
|
|
1964 for (j = 0; j < FRAME_X_CURRENT_PSHEET_COUNT (f); j++)
|
|
1965 if (ids [i] == FRAME_X_CURRENT_PSHEETS (f) [j])
|
|
1966 {
|
|
1967 XtUnmanageChild (FRAME_X_CONTAINER_WIDGET (f));
|
|
1968 goto next_frame;
|
|
1969 }
|
|
1970 next_frame: ;
|
|
1971 }
|
|
1972
|
|
1973 for (i = 0; i < count; i++)
|
|
1974 {
|
|
1975 lw_destroy_all_widgets (ids [i]);
|
|
1976 if (ids [i] == debuggerpanel_sheet)
|
|
1977 {
|
|
1978 debuggerpanel_sheet = 0;
|
|
1979 desired_debuggerpanel_exposed_p = 0;
|
|
1980 }
|
|
1981 }
|
|
1982
|
|
1983 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
1984 {
|
|
1985 Lisp_Object frame = XCAR (frmcons);
|
|
1986 struct frame *f = XFRAME (frame);
|
|
1987
|
|
1988 if (!FRAME_X_P (f))
|
|
1989 continue;
|
|
1990 XtManageChild (FRAME_X_CONTAINER_WIDGET (f));
|
|
1991 }
|
|
1992 }
|
|
1993
|
|
1994
|
|
1995 /* kill an Energize buffer */
|
|
1996 static void
|
|
1997 forget_buffer (BufferInfo *binfo)
|
|
1998 {
|
|
1999 int i;
|
|
2000 Lisp_Object buffer = binfo->emacs_buffer;
|
|
2001
|
|
2002 remove_buffer_info (binfo->id, buffer, binfo->editor);
|
|
2003 Venergize_buffers_list = Fdelq (buffer, Venergize_buffers_list);
|
|
2004
|
|
2005 /* if there was an associated frame */
|
|
2006 if (!NILP (binfo->frame))
|
|
2007 Fdelete_frame (binfo->frame, Qt);
|
|
2008
|
|
2009 if (binfo->n_p_sheets > 0)
|
|
2010 {
|
|
2011 /* Also delete the dialog boxes associated with the buffer. */
|
|
2012 cleanly_destroy_all_widgets (binfo->n_p_sheets,
|
|
2013 (LWLIB_ID *) binfo->p_sheet_ids);
|
|
2014 }
|
|
2015
|
|
2016 free_buffer_info (binfo);
|
|
2017
|
|
2018 XBUFFER (buffer)->undo_list = Qnil;
|
|
2019 /* flush the buffer SOE before flushing the extents */
|
|
2020 free_buffer_cached_stack (XBUFFER (buffer));
|
|
2021 XBUFFER (buffer)->extents = Qnil;
|
|
2022 }
|
|
2023
|
|
2024 /********************** Request-related utilities ************************/
|
|
2025
|
|
2026 /* outputs a single extent in the connection buffer */
|
|
2027 static void
|
|
2028 write_energize_extent_data (Connection *conn, Energize_Extent_Data *ext,
|
|
2029 unsigned int start, unsigned int end)
|
|
2030 {
|
|
2031 switch (ext->extentType)
|
|
2032 {
|
|
2033 case CEAttribute:
|
|
2034 CWriteExtent (conn, CEAttribute, ext->id, start, end,
|
|
2035 (EId)ext->u.attr.attrValue);
|
|
2036 break;
|
|
2037
|
|
2038 case CEAbbreviation:
|
|
2039 CWriteExtent (conn, CEAbbreviation, ext->id, start, end,
|
|
2040 (EId)ext->u.abbrev.isOpened);
|
|
2041 break;
|
|
2042
|
|
2043 case CEGeneric:
|
|
2044 CWriteExtent (conn, CEGeneric, ext->id, start, end, 0);
|
|
2045 break;
|
|
2046
|
|
2047 case CEWriteProtect:
|
|
2048 CWriteExtent (conn, CEWriteProtect, ext->id, start, end, 0);
|
|
2049 break;
|
|
2050 }
|
|
2051 }
|
|
2052
|
|
2053 /* Function called by map_extents in SaveBufferToEnergize. Outputs the
|
|
2054 extents for the extents corresponding to Energize objects, and
|
|
2055 increments the n_extents count. */
|
|
2056
|
|
2057 static int
|
|
2058 write_energize_extent_data_mapper (EXTENT extent, void *arg)
|
|
2059 {
|
|
2060 binfo_and_n_extents *bane = (binfo_and_n_extents*)arg;
|
|
2061 Lisp_Object extent_obj;
|
|
2062 Energize_Extent_Data *ext;
|
|
2063
|
|
2064 XSETEXTENT (extent_obj, extent);
|
|
2065 ext = extent_to_data (extent_obj);
|
|
2066 if (ext)
|
|
2067 {
|
|
2068 Bufpos first = XINT (Fextent_start_position (extent_obj));
|
|
2069 Bufpos last = XINT (Fextent_end_position (extent_obj));
|
|
2070 write_energize_extent_data (bane->binfo->editor->conn, ext,
|
|
2071 EnergizePosForBufpos (first, bane->binfo),
|
|
2072 EnergizePosForBufpos (last, bane->binfo));
|
|
2073 bane->n_extents += 1;
|
|
2074 }
|
|
2075 return 0;
|
|
2076 }
|
|
2077
|
|
2078 /* Sends a BufferSaved request to energize for binfo */
|
|
2079 static void
|
|
2080 write_energize_buffer_data (BufferInfo *binfo)
|
|
2081 {
|
|
2082 Connection *conn = binfo->editor->conn;
|
|
2083 EId bufferId = binfo->id;
|
|
2084 CBuffer *cbu;
|
|
2085 CEditorRequest *req;
|
|
2086 struct buffer *cur_buff = current_buffer;
|
|
2087 int speccount = specpdl_depth ();
|
|
2088 Lisp_Object file_name;
|
|
2089
|
|
2090 binfo_and_n_extents bane;
|
|
2091
|
|
2092 /* selects the buffer as current */
|
|
2093 Fset_buffer (binfo->emacs_buffer);
|
|
2094
|
|
2095 /* write header */
|
|
2096 cbu = CWriteBufferSavedHeader (conn);
|
|
2097 cbu->bufferId = bufferId;
|
|
2098 cbu->flags = 0;
|
|
2099 cbu->nClass = 0;
|
|
2100 cbu->nGeneric = 0;
|
|
2101
|
|
2102 /* file name */
|
|
2103 file_name = current_buffer->filename;
|
|
2104 if (STRINGP (file_name))
|
14
|
2105 CWriteVstring0 (conn, XSTRING_DATA (file_name));
|
0
|
2106 else
|
|
2107 CWriteVstring0 (conn, "");
|
|
2108 CWriteVstring0 (conn, ""); /* directory name */
|
|
2109 CWriteVstring0 (conn, ""); /* buffer name */
|
|
2110
|
|
2111 /* write the text */
|
|
2112 #ifndef ENERGIZE_V2_HEADERS
|
|
2113 if (binfo->flags & CBFileYourself)
|
|
2114 {
|
|
2115 /* Only the 0.10+ protocol will ask us to write the file directly. */
|
|
2116 Lisp_Object start;
|
|
2117 Lisp_Object end;
|
|
2118 XSETINT (start, BUF_BEG (current_buffer));
|
|
2119 XSETINT (end, BUF_Z (current_buffer));
|
|
2120 Fwrite_region_internal (start, end,
|
|
2121 Fbuffer_file_name (binfo->emacs_buffer),
|
|
2122 /* #### coding system not correct */
|
|
2123 Qnil, Qt, Qnil);
|
|
2124 CNeedOutputSize (conn, 9);
|
|
2125 CWriteVstringLen (conn, NULL, 0);
|
|
2126 }
|
|
2127 else
|
|
2128 #endif /* ENERGIZE_V2_HEADERS */
|
|
2129 {
|
|
2130 Lisp_Object string = make_string_from_buffer (current_buffer,
|
|
2131 BUF_BEG (current_buffer),
|
|
2132 BUF_Z (current_buffer));
|
14
|
2133 CNeedOutputSize (conn, XSTRING_LENGTH (string) + 9);
|
80
|
2134 CWriteVstringLen (conn, XSTRING_DATA (string), XSTRING_LENGTH (string));
|
0
|
2135 }
|
|
2136
|
|
2137 /* write the extents */
|
|
2138 bane.binfo = binfo;
|
|
2139 bane.n_extents = 0;
|
|
2140
|
|
2141 /* Only write the extents when not filing ourselves */
|
|
2142 #ifndef ENERGIZE_V2_HEADERS
|
|
2143 if (!(binfo->flags & CBFileYourself))
|
|
2144 #endif
|
|
2145 {
|
|
2146 map_extents (BUF_BEG (current_buffer), BUF_Z (current_buffer),
|
|
2147 write_energize_extent_data_mapper, &bane,
|
|
2148 binfo->emacs_buffer, 0, ME_END_CLOSED);
|
185
|
2149
|
0
|
2150 }
|
|
2151
|
|
2152 /* update nextent in request's header */
|
|
2153 req = (CEditorRequest *)conn->header;
|
|
2154 req->buffersaved.buffer.nExtent = bane.n_extents;
|
|
2155 CWriteLength (conn);
|
|
2156 CWriteRequestBuffer (conn);
|
|
2157
|
|
2158 /* sets the flags so that we will warn Energize about more modifications */
|
|
2159 binfo->modified_state = 0;
|
|
2160
|
|
2161 /* Mark the buffer as non editable so that we will ask Energize about it
|
|
2162 before modifying it again */
|
|
2163 binfo->editable = 0;
|
|
2164
|
|
2165 /* restores the buffer as current */
|
|
2166 set_buffer_internal (cur_buff);
|
|
2167 unbind_to (speccount, Qnil);
|
|
2168 }
|
|
2169
|
|
2170 static unsigned long
|
|
2171 energize_extent_data_id (Energize_Extent_Data *ext)
|
|
2172 {
|
|
2173 return ext ? ext->id : 0;
|
|
2174 }
|
|
2175
|
|
2176
|
|
2177 /********************** Menu ("keywords") operations **********************/
|
|
2178
|
|
2179 static int
|
|
2180 something_answered_p (void* arg)
|
|
2181 {
|
|
2182 struct reply_wait* rw = (struct reply_wait*)arg;
|
|
2183 return rw->answered_p || !energize_connection || !energize_connection->conn;
|
|
2184 }
|
|
2185
|
|
2186
|
|
2187 static void
|
|
2188 push_wait (struct reply_wait* rw)
|
|
2189 {
|
|
2190 rw->next = global_reply_wait;
|
|
2191 global_reply_wait = rw;
|
|
2192 }
|
|
2193
|
|
2194 static Lisp_Object
|
|
2195 remove_wait (Lisp_Object obj)
|
|
2196 {
|
|
2197 struct reply_wait* gw;
|
|
2198 struct reply_wait* previous;
|
|
2199 struct reply_wait* rw = (struct reply_wait *) get_opaque_ptr (obj);
|
|
2200
|
|
2201 for (previous = 0, gw = global_reply_wait;
|
|
2202 gw != rw;
|
|
2203 previous = gw, gw = gw->next);
|
|
2204 if (previous)
|
|
2205 previous->next = gw->next;
|
|
2206 else
|
|
2207 global_reply_wait = gw->next;
|
|
2208 return Qnil;
|
|
2209 }
|
|
2210
|
|
2211 static struct reply_wait*
|
|
2212 find_wait_reply (int serial)
|
|
2213 {
|
|
2214 struct reply_wait* gw;
|
|
2215 for (gw = global_reply_wait; gw && gw->serial != serial; gw = gw->next);
|
|
2216 return gw;
|
|
2217 }
|
|
2218
|
|
2219
|
|
2220 static int
|
|
2221 wait_for_reply (struct reply_wait* rw)
|
|
2222 {
|
|
2223 int speccount = specpdl_depth ();
|
|
2224 rw->answered_p = 0;
|
|
2225 push_wait (rw);
|
|
2226 record_unwind_protect (remove_wait, make_opaque_ptr (rw));
|
|
2227 wait_delaying_user_input (something_answered_p, rw);
|
|
2228 unbind_to (speccount, Qnil);
|
|
2229 return rw->answered_p;
|
|
2230 }
|
|
2231
|
|
2232 /* gets the menu for the buffer/extent pair at the head of the request buffer.
|
|
2233 returns the propose choice request if succeeds, nil otherwise (kernel
|
|
2234 connection closed, or not connected)
|
|
2235 */
|
|
2236
|
|
2237 static Lisp_Object
|
|
2238 get_energize_menu (Lisp_Object buffer, Lisp_Object extent_obj, int selection_p,
|
|
2239 Lisp_Object only_name)
|
|
2240 {
|
|
2241 Connection* conn;
|
|
2242 EId buffer_id;
|
|
2243 EId extent_id;
|
|
2244 Lisp_Object result;
|
|
2245 struct reply_wait rw;
|
|
2246 struct gcpro gcpro1, gcpro2;
|
|
2247
|
|
2248 if (!get_energize_connection_and_buffer_id (buffer,
|
|
2249 (void **) &conn,
|
|
2250 (long *) &buffer_id))
|
|
2251 return Qnil;
|
|
2252
|
|
2253 if (EXTENTP (extent_obj))
|
|
2254 extent_id = energize_extent_data_id (extent_to_data (extent_obj));
|
|
2255 else
|
|
2256 extent_id = 0;
|
|
2257
|
|
2258 CWriteQueryChoicesRequest (conn, buffer_id, extent_id);
|
|
2259 conn->header->data =
|
|
2260 selection_p ? CEChasCharSelection | CEChasObjectSelection : 0;
|
|
2261 conn->header->serial = ++request_serial_number;
|
|
2262 CWriteRequestBuffer (conn);
|
|
2263
|
|
2264 /* wait for the acknowledge */
|
|
2265 rw.serial = request_serial_number;
|
|
2266 rw.objectId = buffer_id;
|
|
2267 rw.genericId = extent_id;
|
|
2268 rw.menu_result = Qnil;
|
|
2269 rw.only_name = only_name;
|
|
2270
|
|
2271 GCPRO2 (rw.menu_result, rw.only_name);
|
|
2272 wait_for_reply (&rw);
|
|
2273 result = rw.menu_result;
|
|
2274 UNGCPRO;
|
|
2275 return result;
|
|
2276 }
|
|
2277
|
|
2278
|
|
2279 static void
|
|
2280 execute_energize_menu (Lisp_Object buffer, Energize_Extent_Data* ext,
|
|
2281 char* name, EId item_id, EId flags,
|
|
2282 Lisp_Object selection, Lisp_Object no_confirm)
|
|
2283 {
|
|
2284 Connection* conn;
|
|
2285 EId buffer_id;
|
|
2286 EId extent_id;
|
|
2287 BufferInfo* binfo;
|
|
2288 struct reply_wait rw;
|
|
2289
|
|
2290 if (!get_energize_connection_and_buffer_id (buffer, (void**)&conn,
|
|
2291 (long*)&buffer_id))
|
|
2292 return;
|
|
2293
|
|
2294 extent_id = energize_extent_data_id (ext);
|
|
2295
|
|
2296 if ((flags & CKBuffer) && !NILP (Fbuffer_modified_p (buffer)))
|
|
2297 {
|
|
2298 /* saves buffer if requested and needed */
|
|
2299 binfo = get_buffer_info_for_emacs_buffer (buffer, energize_connection);
|
|
2300 if (binfo)
|
|
2301 write_energize_buffer_data (binfo);
|
|
2302 }
|
|
2303
|
|
2304 CWriteExecuteChoicesRequest (conn, buffer_id, extent_id, item_id, 0, 0);
|
|
2305 /* send the menu name */
|
|
2306 if (energize_connection->minor >= 7)
|
|
2307 CWriteVstring0 (conn, name);
|
|
2308 conn->header->serial = ++request_serial_number;
|
|
2309 conn->header->data = 0;
|
|
2310 if (STRINGP (selection))
|
|
2311 {
|
|
2312 conn->header->data |= CEChasCharSelection;
|
14
|
2313 CWriteVstringLen (conn, XSTRING_DATA (selection),
|
|
2314 XSTRING_LENGTH (selection));
|
0
|
2315 }
|
|
2316 else if (VECTORP (selection))
|
|
2317 {
|
173
|
2318 int i, len;
|
0
|
2319 EId data;
|
|
2320 conn->header->data |= CEChasObjectSelection;
|
|
2321
|
|
2322 /* writes the length */
|
173
|
2323 data = len = XVECTOR_LENGTH (selection);
|
0
|
2324 CWrite (conn, EId, &data);
|
|
2325
|
|
2326 /* writes the elements */
|
173
|
2327 for (i = 0; i < len; i++)
|
0
|
2328 {
|
173
|
2329 if (CONSP (XVECTOR_DATA (selection) [i]))
|
|
2330 data = lisp_to_word (XVECTOR_DATA (selection) [i]);
|
0
|
2331 else
|
173
|
2332 data = XINT (XVECTOR_DATA (selection) [i]);
|
0
|
2333 CWrite (conn, EId, &data);
|
|
2334 }
|
|
2335 }
|
|
2336 else if (CONSP (selection))
|
|
2337 {
|
173
|
2338 Lisp_Object type = Fcar (selection);
|
0
|
2339 Lisp_Object value = Fcdr (selection);
|
|
2340 if (EQ (type, intern ("ENERGIZE_OBJECT"))
|
|
2341 && STRINGP (value))
|
|
2342 {
|
|
2343 conn->header->data |= CEChasObjectSelection;
|
14
|
2344 CWriteN (conn, char, XSTRING_DATA (value),
|
|
2345 XSTRING_LENGTH (value));
|
0
|
2346 }
|
|
2347 }
|
|
2348 else if (!NILP (selection))
|
|
2349 error ("unrecognized energize selection");
|
185
|
2350
|
0
|
2351 if (!NILP (no_confirm))
|
|
2352 conn->header->data |= CECnoConfirm;
|
|
2353 CWriteLength (conn);
|
|
2354 CWriteRequestBuffer (conn);
|
|
2355
|
|
2356 /* wait for the acknowledge */
|
|
2357 rw.serial = request_serial_number;
|
|
2358 rw.objectId = buffer_id;
|
|
2359 rw.genericId = extent_id;
|
|
2360 rw.itemId = item_id;
|
|
2361 rw.message = 0;
|
|
2362
|
|
2363 if (wait_for_reply (&rw) && !rw.status)
|
|
2364 {
|
|
2365 char message [128];
|
|
2366 if (energize_connection && energize_connection->conn)
|
|
2367 sprintf (message, IDENTITY_CRISIS " command failed: %.80s",
|
|
2368 (rw.message ? rw.message : "(null)"));
|
|
2369 else
|
|
2370 sprintf (message, "Connection to " IDENTITY_CRISIS " was closed.");
|
|
2371 if (rw.message)
|
|
2372 xfree (rw.message);
|
|
2373 error (message);
|
|
2374 }
|
|
2375 else
|
|
2376 {
|
|
2377 if (rw.message)
|
|
2378 xfree (rw.message);
|
|
2379 if (!energize_connection)
|
|
2380 error ("Connection to " IDENTITY_CRISIS " was closed.");
|
|
2381 }
|
|
2382 }
|
|
2383
|
|
2384 /* Returns a list of vectors representing the menu choices. Next request
|
|
2385 in connection must be a ProposeChoices. The list is
|
|
2386 (buffer extent <item1> ... <itemN>). <itemI> is (name id1 id2 flags).
|
|
2387 Idi is (high . low). We build the list in reverse order and nreverse
|
|
2388 it. If (only_name != 0), we only return the item of named only_name as
|
|
2389 a vector. */
|
|
2390
|
|
2391 static Lisp_Object
|
|
2392 list_choices (Lisp_Object buffer, Lisp_Object extent_obj,
|
|
2393 Lisp_Object only_name, CProposeChoicesRequest* creq)
|
|
2394 {
|
|
2395 Connection *conn;
|
|
2396 int i;
|
|
2397 Lisp_Object item_list;
|
|
2398 Lisp_Object item;
|
|
2399 struct Lisp_Vector *v;
|
|
2400 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2401 CChoice *choice;
|
|
2402 ReqLen name_length;
|
|
2403 char *name;
|
|
2404 char *arg_name;
|
|
2405
|
|
2406 if (energize_connection && energize_connection->conn)
|
|
2407 conn = energize_connection->conn;
|
|
2408 else
|
|
2409 return Qnil;
|
|
2410
|
|
2411 if (!creq || creq->head.reqType != ProposeChoicesRType)
|
|
2412 {
|
|
2413 CSkipRequest (conn);
|
|
2414 return Qnil;
|
|
2415 }
|
|
2416
|
|
2417 item = Qnil;
|
|
2418 item_list = Qnil;
|
|
2419
|
|
2420 GCPRO3 (only_name, item_list, item);
|
|
2421
|
|
2422 for (i = 0; i < (int)(creq->nChoices); i++)
|
|
2423 {
|
|
2424 choice = CGet (conn, CChoice);
|
|
2425 name = CGetVstring (conn, &name_length);
|
|
2426 if (!name_length)
|
|
2427 continue;
|
|
2428
|
|
2429 /* the argument, if passed, is another string after the NUL (!)
|
|
2430 * this is a quick hack to provide cheap arguments to menus entries */
|
|
2431 arg_name = strchr (name, 0240);
|
|
2432 if (arg_name)
|
|
2433 {
|
|
2434 *arg_name= 0;
|
|
2435 arg_name += 1;
|
|
2436 }
|
|
2437
|
|
2438 if (!NILP (only_name))
|
|
2439 {
|
14
|
2440 if (!strcmp ((char*) XSTRING_DATA (only_name), name))
|
0
|
2441 {
|
|
2442 if (NILP (item))
|
|
2443 {
|
|
2444 item = make_vector (5, Qnil);
|
|
2445 v = XVECTOR (item);
|
|
2446 v->contents [0] = only_name;
|
|
2447 }
|
|
2448 v->contents [1] = word_to_lisp (choice->choiceId);
|
|
2449 v->contents [2] = Qnil;
|
|
2450 v->contents [3] = make_int (choice->flags);
|
|
2451 v->contents [4] = arg_name ? build_string (arg_name) : Qnil;
|
|
2452 }
|
|
2453 }
|
|
2454 else
|
|
2455 {
|
|
2456 item = make_vector (5, Qnil);
|
|
2457 v = XVECTOR (item);
|
|
2458 v->contents [0] = build_string (name);
|
|
2459 v->contents [1] = word_to_lisp (choice->choiceId);
|
|
2460 v->contents [2] = Qnil;
|
|
2461 v->contents [3] = make_int (choice->flags);
|
|
2462 v->contents [4] = arg_name ? build_string (arg_name) : Qnil;
|
|
2463 item_list = Fcons (item, item_list); /* pushes in the list */
|
|
2464 }
|
|
2465 }
|
|
2466
|
|
2467 if (NILP (only_name))
|
|
2468 item_list = Fcons (buffer, Fcons (extent_obj, Fnreverse (item_list)));
|
|
2469 UNGCPRO;
|
|
2470
|
|
2471 return NILP (only_name) ? item_list : item;
|
|
2472 }
|
|
2473
|
20
|
2474 DEFUN ("energize-list-menu", Fenergize_list_menu, 3, 4, 0, /*
|
0
|
2475 Request the set of menu options from the Energize server that are
|
|
2476 appropriate to the buffer and the extent. Extent can be (), in which case
|
|
2477 the options are requested for the whole buffer. Selection-p tells
|
185
|
2478 if the selection is available on the dislpay emacs is using.
|
0
|
2479 Returns the options as
|
|
2480 a list that can be passed to energize-activate-menu. Items
|
|
2481 in the list can also be passed to energize-execute-menu-item.
|
|
2482 The list is (buffer extent or () <item1> ... <itemN>).
|
|
2483 where <itemI> is (name id1 id2 flags); idI is (high . low).
|
|
2484 If optional argument only-name is provided only the item with name only-name
|
|
2485 is returned, or () if no such item exists.
|
20
|
2486 */
|
|
2487 (buffer, extent_obj, selection_p, only_name))
|
0
|
2488 {
|
|
2489 Lisp_Object res;
|
|
2490 CHECK_BUFFER (buffer);
|
|
2491
|
|
2492 if (!energize_connection || !energize_connection->conn) return Qnil;
|
|
2493
|
|
2494 if (!NILP (only_name))
|
|
2495 CHECK_STRING (only_name);
|
|
2496
|
|
2497 res = get_energize_menu (buffer, extent_obj, !NILP (selection_p),
|
|
2498 only_name);
|
|
2499 notify_delayed_requests ();
|
|
2500 return res;
|
|
2501 }
|
|
2502
|
20
|
2503 DEFUN ("energize-execute-menu-item", Fenergize_execute_menu_item, 3, 5, 0, /*
|
0
|
2504 Item is a vector received by energize-list-menu. Sends a request to
|
|
2505 execute the code associated to this menu inside the Energize server.
|
|
2506 Optional fourth argument is a string or a vector to be used as the selection
|
|
2507 for entry disabled because they need the selection.
|
185
|
2508 Optional fifth argument, if non NIL, tells Energize to not request
|
0
|
2509 confirmation before executing the command.
|
20
|
2510 */
|
|
2511 (buffer, extent_obj, item, selection, no_confirm))
|
0
|
2512 {
|
|
2513 struct Lisp_Vector *v;
|
|
2514
|
|
2515 if (!energize_connection || !energize_connection->conn) return Qnil;
|
|
2516
|
|
2517 CHECK_BUFFER (buffer);
|
|
2518 CHECK_VECTOR (item);
|
|
2519 v = XVECTOR (item);
|
|
2520
|
|
2521 if (vector_length (v) != 4)
|
|
2522 error ("Bad menu item to energize-execute-menu-item");
|
|
2523
|
|
2524 /* ignore the flags for now */
|
|
2525 execute_energize_menu (buffer, extent_to_data (extent_obj),
|
80
|
2526 (char*) XSTRING_DATA (v->contents [0]),
|
0
|
2527 lisp_to_word (v->contents [1]),
|
|
2528 XINT (v->contents [3]),
|
|
2529 selection,
|
|
2530 no_confirm);
|
|
2531
|
|
2532 return Qt;
|
|
2533 }
|
|
2534
|
20
|
2535 DEFUN ("energize-execute-command-internal",
|
|
2536 Fenergize_execute_command_internal, 3, 5, 0, /*
|
0
|
2537 Command is a string naming an energize command. Sends a request to
|
|
2538 execute this command inside the Energize server.
|
|
2539 Optional fourth argument is a string or a vector to be used as the selection.
|
185
|
2540 Optional fifth argument, if non NIL, tells Energize to not request
|
0
|
2541 confirmation before executing the command.
|
|
2542
|
|
2543 See also 'energize-list-menu'.
|
20
|
2544 */
|
|
2545 (buffer, extent_obj, command, selection, no_confirm))
|
0
|
2546 {
|
|
2547 if (!energize_connection || !energize_connection->conn) return Qnil;
|
|
2548
|
|
2549 CHECK_BUFFER (buffer);
|
|
2550 CHECK_STRING (command);
|
|
2551
|
|
2552 execute_energize_menu (buffer, extent_to_data (extent_obj),
|
82
|
2553 (char*) XSTRING_DATA (command), 0, 0, selection,
|
0
|
2554 no_confirm);
|
|
2555
|
|
2556 return Qt;
|
|
2557 }
|
|
2558
|
|
2559 /********************************* kill buffer interface ****************/
|
|
2560
|
20
|
2561 DEFUN ("energize-buffer-type-internal", Fenergize_buffer_type, 1, 1, 0, /*
|
0
|
2562 Return a symbol denoting the buffer type if buffer is an Energize
|
|
2563 buffer, else it returns NIL.
|
20
|
2564 */
|
|
2565 (buffer))
|
0
|
2566 {
|
|
2567 if (!energize_connection) return Qnil;
|
|
2568
|
|
2569 CHECK_BUFFER (buffer);
|
|
2570 return get_buffer_type_for_emacs_buffer (buffer, energize_connection);
|
|
2571 }
|
|
2572
|
20
|
2573 DEFUN ("set-energize-buffer-type-internal", Fset_energize_buffer_type_internal, 2, 2, 0, /*
|
0
|
2574 Return the type symbol which is the new buffer-type, if the buffer is
|
|
2575 an Energize buffer and the type is non-NIL symbol, else it returns NIL.
|
20
|
2576 */
|
|
2577 (buffer, type))
|
0
|
2578 {
|
|
2579 BufferInfo *binfo;
|
|
2580
|
|
2581 if (!energize_connection || (NILP (type))) return Qnil;
|
|
2582
|
|
2583 CHECK_BUFFER (buffer);
|
|
2584 CHECK_SYMBOL (type);
|
|
2585
|
|
2586 if (!(binfo =
|
|
2587 get_buffer_info_for_emacs_buffer (buffer, energize_connection)))
|
|
2588 return Qnil;
|
|
2589 else
|
|
2590 return
|
|
2591 set_buffer_type_for_emacs_buffer (buffer, energize_connection, type);
|
|
2592 }
|
|
2593
|
20
|
2594 DEFUN ("energize-buffer-p", Fenergize_buffer_p, 1, 1, 0, /*
|
0
|
2595 Whether buffer is an Energize buffer.
|
20
|
2596 */
|
|
2597 (buffer))
|
0
|
2598 {
|
|
2599 BufferInfo *binfo;
|
|
2600
|
|
2601 if (!energize_connection) return Qnil;
|
|
2602
|
|
2603 CHECK_BUFFER (buffer);
|
|
2604 if (!(binfo =
|
|
2605 get_buffer_info_for_emacs_buffer (buffer, energize_connection)))
|
|
2606 return Qnil;
|
|
2607 else
|
|
2608 return Qt;
|
|
2609 }
|
|
2610
|
20
|
2611 DEFUN ("energize-buffer-id", Fenergize_buffer_id, 1, 1, 0, /*
|
0
|
2612 Return (high . low) if buffer is an Energize buffer, otherwise nil.
|
20
|
2613 */
|
|
2614 (buffer))
|
0
|
2615 {
|
|
2616 BufferInfo *binfo;
|
|
2617
|
|
2618 if (!energize_connection) return Qnil;
|
|
2619
|
|
2620 CHECK_BUFFER (buffer);
|
|
2621 if (!(binfo =
|
|
2622 get_buffer_info_for_emacs_buffer (buffer, energize_connection)))
|
|
2623 return Qnil;
|
|
2624 else
|
|
2625 return word_to_lisp (binfo->id);
|
|
2626 }
|
|
2627
|
20
|
2628 DEFUN ("energize-request-kill-buffer", Fenergize_request_kill_buffer, 1, 1, 0, /*
|
0
|
2629 Sends a request to energize for killing buffer.
|
20
|
2630 */
|
|
2631 (buffer))
|
0
|
2632 {
|
|
2633 BufferInfo *binfo;
|
|
2634
|
|
2635 if (!energize_connection) return Qnil;
|
|
2636
|
|
2637 CHECK_BUFFER (buffer);
|
|
2638 if (!(binfo = get_buffer_info_for_emacs_buffer (buffer, energize_connection)))
|
|
2639 return Qnil;
|
|
2640
|
|
2641 /* Tell Energize about it if connected */
|
|
2642 if (energize_connection->conn)
|
|
2643 {
|
|
2644 CWriteKillBufferHeader (energize_connection->conn, binfo->id);
|
|
2645 CWriteRequestBuffer (energize_connection->conn);
|
|
2646 }
|
|
2647
|
|
2648 /* Clears the internal state */
|
|
2649 forget_buffer (binfo);
|
|
2650
|
|
2651 return Qnil;
|
|
2652 }
|
|
2653
|
|
2654 /******************** Handle requests from the kernel *********************/
|
|
2655
|
|
2656 #ifdef EMACS_BTL
|
|
2657 #include "cadillac-btl-extern.h"
|
|
2658 #endif
|
|
2659
|
|
2660 /* turn logging on or off, etc. */
|
|
2661 static void
|
|
2662 handle_logging_request (Editor *editor, CLoggingRequest *creq)
|
|
2663 /* I'm a lumberjack and I'm ok... */
|
|
2664 {
|
|
2665 ReqLen name_len;
|
|
2666 char* data_filename = CGetVstring (editor->conn, &name_len);
|
|
2667
|
|
2668 #ifdef EMACS_BTL
|
|
2669 {
|
|
2670 char *execname =
|
|
2671 (STRINGP (Vinvocation_directory))?
|
14
|
2672 ((char *) XSTRING_DATA (Vinvocation_directory)):0;
|
0
|
2673
|
|
2674 switch (creq->type)
|
|
2675 {
|
|
2676 case CLRInitBTL:
|
|
2677 cadillac_terminate_logging (); /* #### rename me */
|
|
2678 cadillac_initialize_backtrace_logging /* #### rename me */
|
|
2679 (data_filename, execname, (long) creq->limit, (long) creq->interval);
|
|
2680 break;
|
|
2681
|
|
2682 case CLRInitPCL:
|
|
2683 cadillac_terminate_logging (); /* #### rename me */
|
|
2684 cadillac_initialize_pc_logging /* #### rename me */
|
|
2685 (data_filename, execname, (long) creq->limit, (long) creq->interval);
|
|
2686 break;
|
|
2687
|
|
2688 case CLRStart:
|
|
2689 cadillac_start_logging (); /* #### rename me */
|
|
2690 break;
|
|
2691
|
|
2692 case CLRStop:
|
|
2693 cadillac_stop_logging (); /* #### rename me */
|
|
2694 break;
|
|
2695
|
|
2696 case CLRTerminate:
|
|
2697 cadillac_terminate_logging (); /* #### rename me */
|
|
2698 break;
|
|
2699
|
|
2700 case CLRSetLogSignal:
|
|
2701 cadillac_set_log_signal (creq->signal); /* #### rename me */
|
|
2702 break;
|
|
2703
|
|
2704 default:
|
|
2705 error ("Bad logging request type %d", creq->type);
|
|
2706 }
|
|
2707 }
|
|
2708 #else
|
|
2709 message ("Logging request, but no such code in image.");
|
|
2710 #endif
|
|
2711 }
|
|
2712
|
|
2713
|
|
2714
|
|
2715 /* creates a new buffer */
|
|
2716 static void
|
|
2717 handle_new_buffer_request (Editor *editor, CNewBufferRequest *creq)
|
|
2718 {
|
|
2719 read_energize_buffer_data (editor->conn, &creq->buffer, editor, 0, 0,
|
|
2720 creq->transientId, 0);
|
|
2721 if (!NILP (Venergize_create_buffer_hook))
|
|
2722 {
|
|
2723 CBuffer *cbu = &creq->buffer;
|
|
2724 BufferInfo *binfo = get_buffer_info_for_id (cbu->bufferId, editor);
|
|
2725 Lisp_Object buffer;
|
|
2726 if (binfo)
|
|
2727 {
|
|
2728 Lisp_Object prev_frame;
|
|
2729 buffer = binfo->emacs_buffer;
|
|
2730 if (!NILP (binfo->frame))
|
|
2731 {
|
|
2732 prev_frame = Fselected_frame (Qnil);
|
|
2733 Fselect_frame (binfo->frame);
|
|
2734 }
|
|
2735 va_run_hook_with_args (Qenergize_create_buffer_hook, 1, buffer);
|
|
2736 if (!NILP (binfo->frame))
|
|
2737 Fselect_frame (prev_frame);
|
|
2738 }
|
|
2739 }
|
|
2740 }
|
|
2741
|
|
2742 /* Modifies the contents of a buffer */
|
|
2743 static void
|
|
2744 handle_modify_buffer_request (Editor *editor, CModifyBufferRequest *creq)
|
|
2745 {
|
|
2746 read_energize_buffer_data (editor->conn, &creq->newData, editor,
|
|
2747 creq->startPosition, creq->endPosition,
|
|
2748 0, creq->head.data);
|
|
2749 }
|
|
2750
|
|
2751 static void
|
|
2752 make_buffer_and_extent_visible (Lisp_Object list, Lisp_Object go_there)
|
|
2753 {
|
|
2754 call2 (Qenergize_make_many_buffers_visible, list, go_there);
|
|
2755 }
|
|
2756
|
|
2757 /* pops a buffer and scroll to a extent: calls to lisp */
|
|
2758 static void
|
|
2759 handle_ensure_visible_request (Editor *editor, CEnsureVisibleRequest *creq)
|
|
2760 {
|
|
2761 BufferInfo *binfo;
|
|
2762 Energize_Extent_Data *ext;
|
|
2763 Lisp_Object buffer_extent_list;
|
|
2764 struct gcpro gcpro1;
|
|
2765
|
|
2766 buffer_extent_list = Qnil;
|
|
2767 GCPRO1 (buffer_extent_list);
|
|
2768
|
|
2769 binfo = get_buffer_info_for_id (creq->bufferId, editor);
|
|
2770 if (!binfo)
|
|
2771 {
|
|
2772 message ("EnsureVisibleRequest: unknown buffer");
|
|
2773 goto finished;
|
|
2774 }
|
|
2775
|
|
2776 if (!NILP (binfo->frame))
|
|
2777 {
|
|
2778 /* ignore ensure visible for postit note buffers */
|
|
2779 goto finished;
|
|
2780 }
|
|
2781
|
|
2782 if (creq->extentId)
|
|
2783 {
|
|
2784 ext = get_extent_data (creq->extentId, binfo);
|
|
2785 if (!ext)
|
|
2786 message ("EnsureVisibleRequest: ignoring unknown extent");
|
|
2787 }
|
|
2788 else
|
|
2789 ext = 0;
|
|
2790
|
|
2791 buffer_extent_list = Fcons (ext ? data_to_extent (ext) : Qnil, Qnil);
|
|
2792 buffer_extent_list = Fcons (binfo->emacs_buffer, buffer_extent_list);
|
|
2793
|
|
2794 make_buffer_and_extent_visible (buffer_extent_list, creq->head.data ? Qt : Qnil);
|
|
2795
|
|
2796 finished:
|
|
2797 CSkipRequest (editor->conn);
|
|
2798 UNGCPRO;
|
|
2799 }
|
|
2800
|
|
2801 static void
|
|
2802 handle_ensure_many_visible_request (Editor *editor,
|
|
2803 CEnsureManyVisibleRequest *creq)
|
|
2804 {
|
|
2805 BufferInfo *binfo;
|
|
2806 Energize_Extent_Data *ext;
|
|
2807 Lisp_Object buffer_extent_list;
|
|
2808 int n;
|
|
2809 EId buffer_id;
|
|
2810 EId extent_id;
|
|
2811 struct gcpro gcpro1;
|
|
2812
|
|
2813 buffer_extent_list = Qnil;
|
|
2814 GCPRO1 (buffer_extent_list);
|
|
2815
|
|
2816 for (n = creq->head.data,
|
|
2817 buffer_id = creq->bufferId,
|
|
2818 extent_id = creq->extentId;
|
|
2819 n;
|
|
2820 n--,
|
|
2821 buffer_id = n ? *(CGet (editor->conn, EId)) : 0,
|
|
2822 extent_id = n ? *(CGet (editor->conn, EId)) : 0)
|
|
2823 {
|
|
2824 binfo = get_buffer_info_for_id (buffer_id, editor);
|
|
2825 if (!binfo)
|
|
2826 {
|
|
2827 message ("EnsureManyVisibleRequest: ignoring unknown buffer");
|
|
2828 continue;
|
|
2829 }
|
|
2830
|
|
2831 if (!NILP (binfo->frame))
|
|
2832 {
|
|
2833 /* silently ignore ensure visible for postit note buffers */
|
|
2834 continue;
|
|
2835 }
|
|
2836
|
|
2837 if (extent_id)
|
|
2838 {
|
|
2839 ext = get_extent_data (extent_id, binfo);
|
|
2840 if (!ext)
|
|
2841 message ("EnsureManyVisibleRequest: ignoring unknown extent");
|
|
2842 }
|
|
2843 else
|
|
2844 ext = 0;
|
|
2845
|
|
2846 /* cons in reverse order and reverse the list before
|
|
2847 calling make_buffer_and_extent_visible */
|
|
2848 buffer_extent_list = Fcons (binfo->emacs_buffer, buffer_extent_list);
|
|
2849 buffer_extent_list = Fcons (ext ? data_to_extent (ext) : Qnil,
|
|
2850 buffer_extent_list);
|
|
2851 }
|
|
2852 buffer_extent_list = Fnreverse (buffer_extent_list);
|
|
2853 make_buffer_and_extent_visible (buffer_extent_list, Qt);
|
|
2854
|
|
2855 UNGCPRO;
|
|
2856 }
|
|
2857
|
|
2858 /* Update the cached menus, ie update the menubar for now. */
|
|
2859 static void
|
|
2860 handle_propose_choices_request (Editor *editor, CProposeChoicesRequest *req)
|
|
2861 {
|
|
2862 BufferInfo* binfo;
|
|
2863 Lisp_Object buffer = Qnil;
|
|
2864 Lisp_Object extent = Qnil;
|
|
2865 Lisp_Object choices = Qnil;
|
|
2866 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2867 struct reply_wait* rw;
|
|
2868
|
|
2869 GCPRO3 (buffer, extent, choices);
|
|
2870
|
|
2871 /* get the buffer */
|
|
2872 binfo = get_buffer_info_for_id (req->objectId, editor);
|
|
2873 if (binfo)
|
|
2874 buffer = binfo->emacs_buffer;
|
|
2875 else
|
|
2876 buffer = Qnil;
|
|
2877
|
|
2878 /* get the extent */
|
|
2879 if (binfo && req->genericId)
|
|
2880 {
|
|
2881 Energize_Extent_Data* ext = get_extent_data (req->genericId, binfo);
|
|
2882 if (ext)
|
|
2883 extent = data_to_extent (ext);
|
|
2884 else
|
|
2885 extent = Qnil;
|
|
2886 }
|
|
2887 else
|
|
2888 extent = Qnil;
|
|
2889
|
|
2890 /* find if we were waiting for a reply */
|
|
2891 rw = find_wait_reply (req->head.serial);
|
|
2892
|
|
2893 /* handle the request */
|
|
2894 if (rw && rw->objectId == req->objectId && rw->genericId == req->genericId)
|
|
2895 {
|
|
2896 /* It's a reply for a get_energize_menu call */
|
|
2897 rw->answered_p = True;
|
|
2898 rw->status = 1;
|
|
2899 rw->menu_result = list_choices (buffer, extent, rw->only_name, req);
|
|
2900 }
|
|
2901 else
|
|
2902 {
|
|
2903 /* It's a menu update, call the hook */
|
|
2904 choices = list_choices (buffer, extent, Qnil, req);
|
|
2905 va_run_hook_with_args (Qenergize_menu_update_hook, 1, choices);
|
|
2906 }
|
|
2907 UNGCPRO;
|
|
2908 }
|
|
2909
|
|
2910 /* Kills a buffer */
|
|
2911 static void
|
|
2912 unmodify_buffer_and_kill_it (Lisp_Object buffer)
|
|
2913 {
|
|
2914 int speccount = specpdl_depth ();
|
|
2915
|
|
2916 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
|
|
2917 return;
|
|
2918
|
|
2919 Fset_buffer_modified_p (Qnil, buffer);
|
|
2920
|
|
2921 /* kill it. This will call the Energize hook to do the right thing */
|
|
2922 Fkill_buffer (buffer);
|
|
2923 }
|
|
2924
|
|
2925 static void
|
|
2926 handle_kill_buffer_request (Editor *editor, CKillBufferRequest *creq)
|
|
2927 {
|
|
2928 BufferInfo *binfo;
|
|
2929
|
|
2930 if (!(binfo = get_buffer_info_for_id (creq->bufferId, editor)))
|
|
2931 {
|
|
2932 message ("KillBufferVisibleRequest: unregistered buffer");
|
|
2933 return;
|
|
2934 }
|
|
2935
|
|
2936 unmodify_buffer_and_kill_it (binfo->emacs_buffer);
|
|
2937 }
|
|
2938
|
|
2939 static void
|
|
2940 handle_remove_extents_request (Editor *editor, CRemoveExtentsRequest *creq)
|
|
2941 {
|
|
2942 BufferInfo *binfo;
|
|
2943 int i;
|
|
2944 EId *ids;
|
|
2945 Lisp_Object restore_buffer_state_cons;
|
|
2946 int speccount = specpdl_depth ();
|
|
2947
|
|
2948 if (!(binfo = get_buffer_info_for_id (creq->bufferId, editor)))
|
|
2949 {
|
|
2950 message ("RemoveExtentsRequest: unregistered buffer");
|
|
2951 CSkipRequest (editor->conn);
|
|
2952 return;
|
|
2953 }
|
|
2954
|
|
2955 /* enable buffer edits */
|
|
2956 restore_buffer_state_cons =
|
|
2957 Fcons (make_opaque_ptr ((void *) creq->bufferId),
|
|
2958 Fcons (XBUFFER (binfo->emacs_buffer)->read_only, Qnil));
|
|
2959
|
|
2960 record_unwind_protect (restore_buffer_state, restore_buffer_state_cons);
|
|
2961
|
|
2962 XBUFFER (binfo->emacs_buffer)->read_only = Qnil;
|
|
2963
|
|
2964 /* save old hook values */
|
|
2965 specbind (Qenergize_buffer_modified_hook, Qnil);
|
|
2966
|
|
2967 ids = CGetN (editor->conn, EId, creq->nExtent);
|
|
2968 for (i = 0; i < creq->nExtent; i++)
|
|
2969 {
|
|
2970 Energize_Extent_Data *ext = get_extent_data (ids [i], binfo);
|
|
2971 if (ext)
|
|
2972 free_Energize_Extent_Data (ext, binfo, OFT_STANDALONE);
|
|
2973 }
|
|
2974
|
|
2975 /* restore modified hooks and globals */
|
|
2976 unbind_to (speccount, Qnil);
|
|
2977 }
|
|
2978
|
|
2979 #ifndef ENERGIZE_V2_HEADERS
|
|
2980 static Lisp_Object
|
|
2981 save_to_energize_unwind (Lisp_Object closure)
|
|
2982 {
|
|
2983 BITS32 buffer_id = (BITS32) cons_to_long (closure);
|
|
2984 /* If the buffer ID is not 0, then the call to save-buffer
|
|
2985 didn't complete normally - so tell Energize the save was aborted. */
|
|
2986 if (buffer_id)
|
|
2987 {
|
|
2988 Editor *editor = energize_connection;
|
|
2989 if (editor && editor->conn) /* Maybe the kernel has gone away. */
|
|
2990 {
|
|
2991 CWriteBufferSaveAbortedHeader (editor->conn, buffer_id);
|
|
2992 CWriteRequestBuffer (editor->conn);
|
|
2993 }
|
|
2994 }
|
|
2995 return Qnil;
|
|
2996 }
|
|
2997 #endif /* ENERGIZE_V2_HEADERS */
|
|
2998
|
|
2999
|
|
3000 /* handles a request to save a buffer from the kernel */
|
|
3001 static void
|
|
3002 handle_save_buffer_request (Editor *editor, CSaveBufferRequest *creq)
|
|
3003 {
|
|
3004 BufferInfo *binfo;
|
|
3005 int speccount = specpdl_depth ();
|
|
3006 struct gcpro gcpro1;
|
|
3007 Lisp_Object closure = Qnil;
|
|
3008
|
|
3009 if (!(binfo = get_buffer_info_for_id (creq->bufferId, editor)))
|
|
3010 {
|
|
3011 message ("Server attempt to save a non registered buffer");
|
|
3012 return;
|
|
3013 }
|
|
3014
|
|
3015 if (!EQ (binfo->emacs_buffer, Fcurrent_buffer ()))
|
|
3016 {
|
|
3017 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
3018 Fset_buffer (binfo->emacs_buffer);
|
|
3019 }
|
|
3020
|
|
3021 GCPRO1 (closure);
|
|
3022 if (creq->head.data == CSExecuteSave)
|
|
3023 {
|
|
3024 #ifndef ENERGIZE_V2_HEADERS
|
|
3025 Lisp_Object closure = make_opaque_ptr ((void *) creq->bufferId);
|
|
3026 record_unwind_protect (save_to_energize_unwind, closure);
|
|
3027 #endif /* ENERGIZE_V2_HEADERS */
|
|
3028 call0 (intern ("save-buffer"));
|
|
3029 #ifndef ENERGIZE_V2_HEADERS
|
|
3030 /* clear out the id to tell the unwind-protect form that the save
|
|
3031 completed normally. */
|
|
3032 set_opaque_ptr (closure, 0);
|
|
3033 #endif /* ENERGIZE_V2_HEADERS */
|
|
3034 }
|
|
3035 else
|
|
3036 write_energize_buffer_data (binfo);
|
|
3037
|
|
3038 UNGCPRO;
|
|
3039 unbind_to (speccount, Qnil);
|
|
3040 }
|
|
3041
|
|
3042 static void
|
|
3043 handle_set_modified_flag_request (Editor* editor,
|
|
3044 CSetModifiedFlagRequest* creq)
|
|
3045 {
|
|
3046 BufferInfo *binfo;
|
|
3047 int speccount = specpdl_depth ();
|
|
3048
|
|
3049 if (!(binfo = get_buffer_info_for_id (creq->bufferId, editor)))
|
|
3050 {
|
|
3051 message ("Server attempt to set modified flag of a non registered buffer");
|
|
3052 return;
|
|
3053 }
|
|
3054
|
|
3055 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
3056 specbind (Qenergize_buffer_modified_hook, Qnil);
|
|
3057
|
|
3058 /* Only set buffer modified time in older protocols
|
|
3059 as we handle the file timestamps ourselves now for
|
|
3060 CBFileYourself buffers. */
|
|
3061 #ifndef ENERGIZE_V2_HEADERS
|
|
3062 if ((energize_connection->minor < 10) && !(binfo->flags & CBFileYourself))
|
|
3063 #endif
|
|
3064 {
|
|
3065 Fset_buffer_modtime (binfo->emacs_buffer, Qnil);
|
|
3066 }
|
|
3067
|
|
3068 Fset_buffer_modified_p (creq->state ? Qt : Qnil, binfo->emacs_buffer);
|
|
3069 binfo->modified_state = creq->state;
|
|
3070 /* Mark the buffer so that we ask permission to Energize when the
|
|
3071 * user tries to modify it again */
|
|
3072 binfo->editable = 0;
|
|
3073 if (!creq->state)
|
|
3074 mark_all_extents_as_unmodified (binfo);
|
|
3075 unbind_to (speccount, Qnil);
|
|
3076 }
|
|
3077
|
|
3078
|
|
3079 /* handles requests regarding p_sheet associated to buffers */
|
|
3080 static void
|
|
3081 add_in_list_of_ids (int** ids, int* n_ids, int id)
|
|
3082 {
|
|
3083 if (*n_ids == 0)
|
|
3084 {
|
|
3085 *n_ids = 1;
|
|
3086 *ids = (int*)xmalloc (sizeof (int));
|
|
3087 }
|
|
3088 else
|
|
3089 {
|
|
3090 *n_ids += 1;
|
|
3091 *ids = (int*)xrealloc (*ids, sizeof (int) * (*n_ids));
|
|
3092 }
|
|
3093 (*ids) [(*n_ids) - 1] = id;
|
|
3094 }
|
|
3095
|
|
3096 static void
|
|
3097 remove_from_list_of_ids (int** ids, int* n_ids, int id)
|
|
3098 {
|
|
3099 int i;
|
|
3100 if (*n_ids)
|
|
3101 {
|
|
3102 /* look for id in *ids */
|
|
3103 for (i = 0; i < (*n_ids) && (*ids) [i] != id; i++);
|
|
3104 /* shift the remaining ones */
|
|
3105 for (; i < (*n_ids) - 1; i++)
|
|
3106 (*ids) [i] = (*ids) [i + 1];
|
|
3107 /* decrease the count */
|
|
3108 *n_ids -= 1;
|
|
3109 /* free array if empty */
|
|
3110 if (!*n_ids)
|
|
3111 {
|
|
3112 xfree (*ids);
|
|
3113 *ids = 0;
|
|
3114 }
|
|
3115 }
|
|
3116 }
|
|
3117
|
|
3118 extern void make_psheets_desired (struct frame *, Lisp_Object);
|
|
3119
|
|
3120 static void
|
|
3121 handle_buffer_sheet_request (Editor *editor, CSheetRequest *sreq,
|
|
3122 EId buffer_id)
|
|
3123 {
|
|
3124 BufferInfo *binfo;
|
|
3125 char *name;
|
|
3126 Connection *conn = editor->conn;
|
|
3127
|
|
3128 if (!(binfo = get_buffer_info_for_id (buffer_id, editor)))
|
|
3129 {
|
|
3130 message ("Server attempt to use p_sheet in a non registered buffer");
|
|
3131 CSkipRequest (conn);
|
|
3132 return;
|
|
3133 }
|
|
3134
|
|
3135 name = CGetVstring (conn, (ReqLen *) 0);
|
|
3136 switch ((CSheetRSubtype) sreq->head.data)
|
|
3137 {
|
|
3138 case CSCreate:
|
|
3139 lw_register_widget (name, name, sreq->sheetId, NULL, NULL,
|
|
3140 handle_sheet_control_change, NULL);
|
|
3141 add_in_list_of_ids (&binfo->p_sheet_ids, &binfo->n_p_sheets,
|
|
3142 sreq->sheetId);
|
|
3143 if (!strcmp (name, DEBUGGER_PSHEET_NAME))
|
|
3144 debuggerpanel_sheet = sreq->sheetId;
|
|
3145 break;
|
|
3146
|
|
3147 case CSDelete:
|
|
3148 remove_from_list_of_ids (&binfo->p_sheet_ids, &binfo->n_p_sheets,
|
|
3149 sreq->sheetId);
|
|
3150 cleanly_destroy_all_widgets (1, &sreq->sheetId);
|
|
3151 if (sreq->sheetId == debuggerpanel_sheet)
|
|
3152 {
|
|
3153 desired_debuggerpanel_exposed_p = 0;
|
|
3154 debuggerpanel_sheet = 0;
|
|
3155 }
|
|
3156 break;
|
|
3157
|
|
3158 case CSHide:
|
|
3159 {
|
|
3160 Lisp_Object frmcons, devcons, concons;
|
|
3161
|
|
3162 if (sreq->sheetId == debuggerpanel_sheet)
|
|
3163 desired_debuggerpanel_exposed_p = 0;
|
|
3164 else
|
|
3165 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
3166 {
|
|
3167 struct frame *frame = XFRAME (Fcar (frmcons));
|
|
3168 if (FRAME_X_P (frame))
|
|
3169 make_psheets_desired (frame, Qnil);
|
|
3170 }
|
|
3171 }
|
|
3172 break;
|
|
3173
|
|
3174 case CSShow:
|
|
3175 if (sreq->sheetId == debuggerpanel_sheet)
|
|
3176 desired_debuggerpanel_exposed_p = 1;
|
|
3177 else
|
|
3178 {
|
|
3179 Lisp_Object frmcons, devcons, concons;
|
|
3180
|
|
3181 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
3182 {
|
|
3183 struct frame *frame = XFRAME (Fcar (frmcons));
|
|
3184 if (FRAME_X_P (frame))
|
|
3185 {
|
|
3186 struct window *window =
|
|
3187 XWINDOW (FRAME_SELECTED_WINDOW (frame));
|
|
3188 if (EQ (window->buffer, binfo->emacs_buffer))
|
|
3189 make_psheets_desired (frame, binfo->emacs_buffer);
|
|
3190 }
|
|
3191 }
|
|
3192 }
|
|
3193 break;
|
|
3194 }
|
|
3195 }
|
|
3196
|
|
3197
|
|
3198
|
|
3199 /* show busy */
|
|
3200
|
|
3201 static void
|
|
3202 show_all_menubars_busy (int busy)
|
|
3203 {
|
|
3204 Lisp_Object frmcons, devcons, concons;
|
|
3205
|
|
3206 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
3207 {
|
|
3208 struct frame *f = XFRAME (XCAR (frmcons));
|
|
3209 if (FRAME_X_P (f))
|
|
3210 {
|
|
3211 if (FRAME_X_MENUBAR_WIDGET (f))
|
|
3212 lw_show_busy (FRAME_X_MENUBAR_WIDGET (f), busy);
|
|
3213 }
|
|
3214 }
|
|
3215 }
|
|
3216
|
|
3217 static void
|
|
3218 handle_show_busy_request (Editor *editor, CGenericRequest *preq)
|
|
3219 {
|
|
3220 /* call the show busy routine of the library for the menubar of
|
|
3221 * all frames */
|
|
3222 ReqLen len;
|
|
3223
|
|
3224 char* why = CGetVstring (editor->conn, &len);
|
|
3225
|
|
3226 show_all_menubars_busy (preq->head.data);
|
|
3227 Venergize_kernel_busy = preq->head.data ? Qt : Qnil;
|
|
3228 va_run_hook_with_args (Qenergize_kernel_busy_hook, 1, build_string (why));
|
|
3229 }
|
|
3230
|
|
3231 /* This request creates, destroys, raises, or lowers a psheet or dialog box.
|
|
3232 */
|
|
3233 static void
|
|
3234 handle_sheet_request (Connection* conn, CSheetRequest* sreq, Widget parent)
|
|
3235 {
|
|
3236 char* name = CGetVstring (conn, NULL);
|
|
3237
|
|
3238 switch ((CSheetRSubtype)sreq->head.data)
|
|
3239 {
|
|
3240 case CSCreate:
|
|
3241 lw_create_widget (name, name, sreq->sheetId, 0, parent,
|
|
3242 !sreq->bufferId, 0, handle_sheet_control_change, 0);
|
|
3243 break;
|
|
3244 case CSDelete:
|
|
3245 cleanly_destroy_all_widgets (1, &sreq->sheetId);
|
|
3246 break;
|
|
3247
|
|
3248 case CSShow:
|
|
3249 lw_pop_up_all_widgets (sreq->sheetId);
|
|
3250 break;
|
|
3251
|
|
3252 case CSHide:
|
|
3253 lw_pop_down_all_widgets (sreq->sheetId);
|
|
3254 break;
|
|
3255 }
|
|
3256 }
|
|
3257
|
|
3258 /* This request changes slot values in the psheets/dialog boxes. */
|
|
3259 static void
|
|
3260 handle_set_control_request (Connection* conn, CGenericRequest* creq)
|
|
3261 {
|
|
3262 CSetControlRequest* sreq = &creq->setcontrol;
|
|
3263 widget_value val;
|
|
3264 widget_value* contents;
|
|
3265
|
|
3266 unsigned long i;
|
|
3267 unsigned long n = sreq->nChoices;
|
|
3268
|
|
3269 if (n > 0)
|
|
3270 {
|
|
3271 contents = (widget_value *) xmalloc (n * sizeof (widget_value));
|
|
3272 memset (contents, 0, (n * sizeof (widget_value)));
|
|
3273 }
|
|
3274 else
|
|
3275 contents = NULL;
|
|
3276 memset (&val, 0, sizeof (val));
|
|
3277 val.name = CGetVstring (conn, NULL);
|
|
3278 val.enabled = !(sreq->flags & CKInactive);
|
|
3279 val.selected = !!(sreq->flags & CKSelected);
|
|
3280 val.change = VISIBLE_CHANGE;
|
|
3281 val.contents = contents;
|
|
3282
|
|
3283 for (i = 0; i < n; i++)
|
|
3284 {
|
|
3285 widget_value* cur = &contents [i];
|
|
3286 CChoice* choice = CGet (conn, CChoice);
|
|
3287 cur->name = CGetVstring (conn, NULL);
|
|
3288 cur->value = cur->name;
|
|
3289 cur->key = NULL;
|
|
3290 cur->enabled = !(choice->flags & CKInactive);
|
|
3291 cur->selected = !!(choice->flags & CKSelected);
|
|
3292 cur->change = VISIBLE_CHANGE;
|
|
3293 cur->contents = NULL;
|
|
3294 cur->call_data = NULL;
|
|
3295 cur->next = i == n - 1 ? NULL : &contents [i + 1];
|
|
3296 cur->toolkit_data = NULL;
|
|
3297 if ((i == 0 && n == 1) || cur->selected)
|
|
3298 {
|
|
3299 val.value = cur->name;
|
|
3300 if (!*val.value)
|
|
3301 val.value = NULL;
|
|
3302 }
|
|
3303 }
|
|
3304 lw_modify_all_widgets (sreq->sheetId, &val, True);
|
|
3305
|
|
3306 if (contents)
|
|
3307 xfree (contents);
|
|
3308 }
|
|
3309
|
|
3310 static void
|
|
3311 handle_sheet_control_change (Widget widget, EId sheet_id, void* arg)
|
|
3312 {
|
|
3313 Connection* conn;
|
|
3314 widget_value* val;
|
|
3315 widget_value* cur;
|
|
3316 widget_value* this_val = NULL;
|
|
3317 widget_value* cancel = NULL;
|
|
3318 char* this_name;
|
|
3319 int delete_window_p = (((int) arg) == -1);
|
|
3320
|
|
3321
|
|
3322 if (!energize_connection)
|
|
3323 return;
|
|
3324
|
|
3325 conn = energize_connection->conn;
|
|
3326 if (!conn)
|
|
3327 return;
|
|
3328
|
|
3329 this_name = XtName (widget);
|
|
3330 val = lw_get_all_values (sheet_id);
|
|
3331
|
|
3332 if (delete_window_p)
|
|
3333 /* Complete and utter kludge. If this dbox was dismissed with the
|
|
3334 WM close box (WM_DELETE_WINDOW, meaning the widget was destroyed)
|
|
3335 then we look for a likely "cancel" button and pretend the user
|
|
3336 clicked on that. Really the protocol should be extended for this.
|
|
3337 */
|
|
3338 for (cur = val; cur; cur = cur->next)
|
|
3339 {
|
|
3340 char *v = cur->value;
|
|
3341 if (v &&
|
|
3342 ((strlen (v) >= 6 && !strncmp (v, "cancel", 6)) ||
|
|
3343 (strlen (v) >= 5 && !strncmp (v, "abort", 5))))
|
|
3344 cancel = cur;
|
|
3345 }
|
|
3346
|
|
3347 /* first send all the edited widgets */
|
|
3348 for (cur = val; cur; cur = cur->next)
|
|
3349 {
|
|
3350 /* do not send the widget that ran the callback */
|
|
3351 if (!strcmp (cur->name, this_name))
|
|
3352 this_val = cur;
|
|
3353 else if (cur == cancel)
|
|
3354 ;
|
|
3355 /* send the edited widgets */
|
|
3356 else if (cur->edited)
|
|
3357 {
|
|
3358 char* value = cur->value;
|
|
3359 unsigned int flags = 0;
|
|
3360
|
|
3361 if (!cur->enabled)
|
|
3362 flags |= CKInactive;
|
|
3363 if (cur->selected)
|
|
3364 flags |= CKSelected;
|
|
3365
|
|
3366 /* the kernel is brain dead and expect "1" and "0" as values
|
|
3367 for the checkbox objects. So if value is NULL, make it be "0"
|
|
3368 or "1" depending on the selected state. This is until we fix
|
|
3369 the kernel. */
|
|
3370 if (!value)
|
|
3371 value = cur->selected ? "1" : "0";
|
|
3372
|
|
3373 CWriteSetControlRequest (conn, sheet_id, 0, cur->name, 1);
|
|
3374 CWriteChoice (conn, 0, flags, value, 0);
|
|
3375 CWriteLength (conn);
|
|
3376 }
|
|
3377 }
|
|
3378
|
|
3379 if (delete_window_p && !this_val)
|
|
3380 {
|
|
3381 this_val = cancel;
|
|
3382 /* if (! this_val) abort (); */
|
|
3383 }
|
|
3384
|
|
3385 /* Then send the widget that ran the callback */
|
|
3386 if (this_val)
|
|
3387 {
|
|
3388 CWriteSetControlRequest (conn, sheet_id, 0, this_val->name, 1);
|
|
3389 CWriteChoice (conn, 0, 0, this_val->value, 0);
|
|
3390 CWriteLength (conn);
|
|
3391 CWriteRequestBuffer (conn);
|
|
3392 }
|
|
3393 }
|
|
3394
|
|
3395 /******************** Low level connection stuff ************************/
|
|
3396 static void
|
|
3397 add_in_connection_input_buffer (Connection *conn, char *s, int l)
|
|
3398 {
|
|
3399 /* Should be in connection.c */
|
|
3400 if (conn->inread >= conn->infill)
|
|
3401 conn->inread = conn->infill = conn->inbuffer;
|
|
3402
|
|
3403 CNeedInputSize (conn, l);
|
|
3404 memcpy (conn->infill, s, l);
|
|
3405 conn->infill += l;
|
|
3406 }
|
|
3407
|
|
3408 static Lisp_Object
|
|
3409 process_one_energize_request (void)
|
|
3410 {
|
|
3411 Editor *editor = energize_connection;
|
|
3412 CEditorRequest *req;
|
|
3413 int res = 0;
|
|
3414
|
|
3415 if (!editor) return make_int (res);
|
|
3416
|
|
3417 if (!editor->conn)
|
|
3418 {
|
|
3419 close_energize_connection ();
|
|
3420 return make_int (res);
|
|
3421 }
|
|
3422
|
|
3423 req = CReadEditorRequest (editor->conn);
|
|
3424 if (!req)
|
|
3425 {
|
|
3426 switch (errno)
|
|
3427 {
|
|
3428 case EWOULDBLOCK:
|
|
3429 /* message ("ProcessEnergizeRequest: internal error EWOULDBLOCK"); */
|
|
3430 res = -1;
|
|
3431 break;
|
|
3432
|
|
3433 case 0:
|
|
3434 case ECONNRESET:
|
|
3435 message ("Connection to " IDENTITY_CRISIS " was closed.");
|
|
3436 close_energize_connection ();
|
|
3437 break;
|
|
3438
|
|
3439 default:
|
|
3440 message
|
|
3441 ("System error on connection to " IDENTITY_CRISIS ", closing.");
|
|
3442 close_energize_connection ();
|
|
3443 break;
|
|
3444 }
|
|
3445 }
|
|
3446 else
|
|
3447 {
|
|
3448 res = 1;
|
|
3449 switch (req->head.reqType)
|
|
3450 {
|
|
3451 case RefuseConnectionRType:
|
|
3452 message (IDENTITY_CRISIS " connection refused");
|
|
3453 close_energize_connection ();
|
|
3454 break;
|
|
3455
|
|
3456 case AcceptConnectionRType:
|
|
3457 {
|
|
3458 CProtocol* proto = CGet (editor->conn, CProtocol);
|
|
3459 editor->major = proto->major;
|
|
3460 editor->minor = proto->minor;
|
|
3461 message (IDENTITY_CRISIS " connection accepted");
|
|
3462 CSkipRequest (editor->conn);
|
|
3463 }
|
|
3464 break;
|
|
3465
|
|
3466 case NewBufferRType:
|
|
3467 handle_new_buffer_request (editor, &req->newbuffer);
|
|
3468 break;
|
|
3469
|
|
3470 case QueryBufferRType:
|
|
3471 {
|
|
3472 EId buffer_id;
|
|
3473 struct reply_wait* rw = find_wait_reply (req->head.serial);
|
|
3474 CGetVstring (editor->conn, 0); /* skip directory */
|
|
3475 CGetVstring (editor->conn, 0); /* skip file */
|
|
3476 buffer_id = *CGet (editor->conn, EId);
|
|
3477 if (rw)
|
|
3478 {
|
|
3479 rw->answered_p = 1;
|
|
3480 rw->status = req->head.data;
|
|
3481 rw->objectId = buffer_id;
|
|
3482 }
|
|
3483 }
|
|
3484 break;
|
|
3485
|
|
3486 case EnsureVisibleRType:
|
|
3487 handle_ensure_visible_request (editor, &req->ensurevisible);
|
|
3488 break;
|
|
3489
|
|
3490 case EnsureManyVisibleRType:
|
|
3491 handle_ensure_many_visible_request (editor, &req->ensuremanyvisible);
|
|
3492 break;
|
|
3493
|
|
3494 case ModifyBufferRType:
|
|
3495 handle_modify_buffer_request (editor, &req->modifybuffer);
|
|
3496 break;
|
|
3497
|
|
3498 case ProposeChoicesRType:
|
|
3499 handle_propose_choices_request (editor,
|
|
3500 &req->generic.proposechoices);
|
|
3501 break;
|
|
3502
|
|
3503 case ChoiceExecutedRType:
|
|
3504 {
|
|
3505 struct reply_wait* rw = find_wait_reply (req->head.serial);
|
|
3506 CChoiceExecutedRequest* ce = &req->generic.choiceexecuted;
|
|
3507 if (rw)
|
|
3508 {
|
|
3509 rw->answered_p = 1;
|
|
3510 rw->status = ce->head.data;
|
|
3511 rw->message = CMakeVstring (editor->conn, 0);
|
|
3512 }
|
|
3513 }
|
|
3514 break;
|
|
3515
|
|
3516 case KillBufferRType:
|
|
3517 handle_kill_buffer_request (editor, &req->killbuffer);
|
|
3518 break;
|
|
3519
|
|
3520 case ModifiedBufferRType:
|
|
3521 {
|
|
3522 struct reply_wait* rw = find_wait_reply (req->head.serial);
|
|
3523 if (rw)
|
|
3524 {
|
|
3525 rw->answered_p = 1;
|
|
3526 if (rw->objectId == req->modifiedbuffer.bufferId)
|
|
3527 rw->status = req->modifiedbuffer.state;
|
|
3528 else
|
|
3529 rw->status = CMBufferLocked;
|
|
3530 }
|
|
3531 }
|
|
3532 break;
|
|
3533
|
|
3534 case SetModifiedFlagRType:
|
|
3535 handle_set_modified_flag_request (editor, &req->setmodifiedflag);
|
|
3536 break;
|
|
3537
|
|
3538 case RemoveExtentsRType:
|
|
3539 handle_remove_extents_request (editor, &req->removeextents);
|
|
3540 break;
|
|
3541
|
|
3542 case RenumberExtentsRType:
|
|
3543 /* HandleDuplicateExtentRequest (editor, req); */
|
|
3544 break;
|
|
3545
|
|
3546 #if 0
|
|
3547 case DialogRType:
|
|
3548 /* HandleDialogRequest (editor, req, CurrentBuffer (editor)); */
|
|
3549 break;
|
|
3550 #endif
|
|
3551
|
|
3552 case SaveBufferRType:
|
|
3553 handle_save_buffer_request (editor, &req->savebuffer);
|
|
3554 break;
|
|
3555
|
|
3556 case SheetRType:{
|
|
3557 EId buffer_id = req->generic.sheet.bufferId;
|
|
3558 if (!buffer_id)
|
|
3559 buffer_id = buffer_id_of_sheet (req->generic.sheet.sheetId);
|
|
3560 if (buffer_id)
|
|
3561 handle_buffer_sheet_request (editor, &req->generic.sheet,
|
|
3562 buffer_id);
|
|
3563 else
|
|
3564 {
|
|
3565 CSheetRSubtype type = (CSheetRSubtype)req->head.data;
|
|
3566 if (type == CSDelete || type ==CSHide)
|
|
3567 /* #### ??? this does nothing. */
|
|
3568 Fselect_frame (Fselected_frame (Qnil));
|
|
3569 handle_sheet_request (editor->conn, &req->generic.sheet,
|
|
3570 FRAME_X_SHELL_WIDGET
|
|
3571 (XFRAME (Fselected_frame (Qnil))));
|
|
3572 }
|
|
3573 }
|
|
3574 break;
|
|
3575
|
|
3576 case SetControlRType:
|
|
3577 handle_set_control_request (editor->conn, (CGenericRequest*) req);
|
|
3578 break;
|
|
3579
|
|
3580 case OpenPostitRType:
|
|
3581 case KillPostitRType:
|
|
3582 message ("Don't know what to do with postit requests.");
|
|
3583 break;
|
|
3584
|
|
3585 case ShowBusyRType:
|
|
3586 handle_show_busy_request (editor, (CGenericRequest*)req);
|
|
3587 break;
|
|
3588
|
|
3589 case LoggingRType:
|
|
3590 handle_logging_request (editor, (CLoggingRequest*)req);
|
|
3591 break;
|
|
3592
|
|
3593 #ifndef ENERGIZE_V2_HEADERS
|
|
3594 case KernelEventRType:
|
|
3595 CSkipRequest (editor->conn);
|
|
3596 break;
|
|
3597 #endif
|
|
3598
|
|
3599 default:
|
|
3600 message("ProcessEnergizeRequest: can't handle request of type %d",
|
|
3601 req->head.reqType);
|
|
3602 }
|
|
3603
|
|
3604 }
|
|
3605
|
|
3606 return make_int (res);
|
|
3607 }
|
|
3608
|
|
3609 static int inside_process_energize_request_1;
|
|
3610
|
|
3611 /* this must be called ONLY by unwind_protect in process_energize_request_1 */
|
|
3612 static Lisp_Object
|
|
3613 post_handle_request (Lisp_Object ignored)
|
|
3614 {
|
|
3615 if (inside_process_energize_request_1 <= 0)
|
|
3616 abort ();
|
|
3617 inside_process_energize_request_1--;
|
|
3618 if (energize_connection && energize_connection->conn)
|
|
3619 CSkipRequest (energize_connection->conn);
|
|
3620 return Qnil;
|
|
3621 }
|
|
3622
|
|
3623 static Lisp_Object
|
|
3624 pop_conn (Lisp_Object arg)
|
|
3625 {
|
|
3626 Connection *old_conn = (Connection *) get_opaque_ptr (arg);
|
|
3627 if (! old_conn)
|
|
3628 abort ();
|
|
3629 if (! energize_connection)
|
|
3630 return Qnil;
|
|
3631 if (energize_connection->conn == old_conn)
|
|
3632 abort ();
|
|
3633
|
|
3634 if (CRequestDelayedP (energize_connection->conn))
|
|
3635 /* We don't call the CWait* functions any more so this shouldn't happen.
|
|
3636 But if it does someday, then we need to either copy the remaining
|
|
3637 bits from new_conn to old_conn, or loop processing requests until
|
|
3638 new_conn is drained.
|
|
3639 */
|
|
3640 abort ();
|
|
3641
|
|
3642 DeleteConnection (energize_connection->conn);
|
|
3643 energize_connection->conn = old_conn;
|
|
3644
|
|
3645 return Qnil;
|
|
3646 }
|
|
3647
|
|
3648 static Lisp_Object
|
|
3649 process_energize_request_1 ()
|
|
3650 {
|
|
3651 Lisp_Object result;
|
|
3652 int speccount = specpdl_depth ();
|
|
3653
|
|
3654 if (inside_process_energize_request_1)
|
|
3655 {
|
|
3656 /* When the energize process filter is called recursively, push a new
|
|
3657 connection object. The read-pointer of the connection buffer could
|
|
3658 be in the middle of a request. However, we know that the fd itself
|
|
3659 is always pointing between requests. So making a new connection is
|
|
3660 a way of skipping past the one request we were in the process of
|
|
3661 reading when we allowed process output to be handled recursively.
|
|
3662 */
|
|
3663 Connection *old_conn = energize_connection->conn;
|
|
3664 Connection *new_conn =
|
|
3665 make_energize_connection ((void *) energize_connection,
|
|
3666 old_conn->fdin, old_conn->fdout);
|
|
3667 energize_connection->conn = new_conn;
|
|
3668 record_unwind_protect (pop_conn, make_opaque_ptr (old_conn));
|
|
3669 }
|
|
3670
|
|
3671 /* this must come after pop_conn() to get the right connection object */
|
|
3672 record_unwind_protect (post_handle_request, Qnil);
|
|
3673
|
|
3674 inside_process_energize_request_1++;
|
|
3675
|
|
3676 result = process_one_energize_request ();
|
|
3677 notify_delayed_requests ();
|
|
3678
|
|
3679 /* decrements inside_process_energize_request_1 and possibly replaces
|
|
3680 energize_connection->conn with old_conn.
|
|
3681 */
|
|
3682 unbind_to (speccount, Qnil);
|
|
3683
|
|
3684 return result;
|
|
3685 }
|
|
3686
|
|
3687
|
|
3688 /******** Initialize Energize-related state and set up connection ********/
|
|
3689
|
|
3690 static void
|
|
3691 setup_connection (Editor *ed, unsigned int id1, unsigned int id2)
|
|
3692 {
|
|
3693 CEditorRequest *req = CWriteEditorRequest (ed->conn, QueryConnectionRType);
|
|
3694
|
|
3695 /* these 2 slots are ignored */
|
|
3696 req->generic.queryconnection.major = 0;
|
|
3697 req->generic.queryconnection.minor = 0;
|
|
3698
|
|
3699 req->generic.queryconnection.cadillacId1 = id1;
|
|
3700 req->generic.queryconnection.cadillacId2 = id2;
|
|
3701 req->generic.queryconnection.nProtocols = 1;
|
|
3702 /* first numerical arg is major protocol number, second is minor */
|
|
3703 CWriteProtocol (ed->conn, 0, 10, "editor");
|
|
3704 CWriteLength (ed->conn);
|
|
3705 CWriteRequestBuffer (ed->conn);
|
|
3706 }
|
|
3707
|
|
3708 /* this is used as the readMethod of the energize connection, so that
|
|
3709 the connection library won't do some buffering that messes us up.
|
|
3710 It does this buffering only if conn->readMethod == read, so using
|
|
3711 another function turns it off.
|
|
3712 */
|
|
3713 static int
|
|
3714 my_read (int fd, char *buf, int nb)
|
|
3715 {
|
|
3716 return read (fd, buf, nb);
|
|
3717 }
|
|
3718
|
|
3719 static Connection *
|
|
3720 make_energize_connection (Editor *editor, int fdin, int fdout)
|
|
3721 {
|
|
3722 Connection *conn = NewConnection ((void *)editor, fdin, fdout);
|
|
3723 if (conn)
|
|
3724 conn->readMethod = my_read;
|
|
3725 return conn;
|
|
3726 }
|
|
3727
|
20
|
3728 DEFUN ("handle-energize-request", Fhandle_energize_request, 2, 2, 0, /*
|
0
|
3729 Filter called when a request is available from Energize.
|
20
|
3730 */
|
|
3731 (proc, string))
|
0
|
3732 {
|
|
3733 if (!NILP (string))
|
|
3734 CHECK_STRING (string);
|
|
3735
|
|
3736 if (!energize_connection || !energize_connection->conn)
|
|
3737 {
|
|
3738 /* no need for a message here, Energize is dead */
|
|
3739 return make_int (0);
|
|
3740 }
|
|
3741 if (!energize_connection || (!EQ (energize_connection->proc, proc)))
|
|
3742 {
|
|
3743 message ("Got " IDENTITY_CRISIS " request but not from current connection ");
|
|
3744 return make_int (0);
|
|
3745 }
|
|
3746
|
|
3747 if (!NILP (string))
|
|
3748 add_in_connection_input_buffer (energize_connection->conn,
|
14
|
3749 (char *) XSTRING_DATA (string),
|
|
3750 XSTRING_LENGTH (string));
|
0
|
3751
|
|
3752 return process_energize_request_1 ();
|
|
3753 }
|
|
3754
|
|
3755
|
|
3756 Lisp_Object Venergize_process;
|
|
3757
|
|
3758 /* Opens a network connection to Energize.
|
|
3759 * server is a string. It can end up with :<uid> or :<username>
|
|
3760 * in which case the uid is added to the TCP port to get the connection */
|
|
3761 static void
|
|
3762 connect_to_energize (char *server_str, char *arg)
|
|
3763 {
|
|
3764 struct Lisp_Process *proc;
|
|
3765 Lisp_Object lp;
|
|
3766 Lisp_Object fil;
|
|
3767 char *host;
|
|
3768 unsigned int port;
|
|
3769 long flags;
|
|
3770 int id1;
|
|
3771 int id2;
|
|
3772
|
|
3773 if (CGetPortNumber (server_str, &host, &port))
|
|
3774 {
|
|
3775
|
|
3776 lp = Fopen_network_stream_internal (build_string ("energize"),
|
|
3777 Qnil,
|
|
3778 build_string (host),
|
|
3779 make_int (port));
|
|
3780 if (!NILP (lp))
|
|
3781 {
|
|
3782 int infd, outfd;
|
|
3783 /* Don't ask the user for confirmation when exiting Emacs */
|
|
3784 Fprocess_kill_without_query (lp, Qnil);
|
|
3785 proc = XPROCESS (lp);
|
|
3786 energize_connection = xnew (Editor);
|
|
3787 get_process_file_descriptors (proc, &infd, &outfd);
|
|
3788 energize_connection->conn =
|
|
3789 make_energize_connection (energize_connection, infd, outfd);
|
|
3790 energize_connection->proc = lp;
|
|
3791 energize_connection->binfo_hash = make_hashtable (10);
|
|
3792 energize_connection->image_table = 0;
|
|
3793 energize_connection->gc_save = Qnil;
|
|
3794 energize_connection->major = 0;
|
|
3795 energize_connection->minor = 0;
|
|
3796 peo = allocate_edit_options (10);
|
|
3797 request_serial_number = 0;
|
|
3798 global_reply_wait = 0;
|
|
3799
|
|
3800 if ((flags = fcntl (energize_connection->conn->fdin, F_GETFL, 0))
|
|
3801 == -1)
|
|
3802 abort ();
|
|
3803
|
|
3804 #ifdef O_NONBLOCK
|
|
3805 if (fcntl (energize_connection->conn->fdin, F_SETFL,
|
|
3806 flags & ~O_NONBLOCK)
|
|
3807 == -1)
|
|
3808 #else
|
|
3809 if (fcntl (energize_connection->conn->fdin, F_SETFL,
|
|
3810 flags & ~O_NDELAY)
|
|
3811 == -1)
|
|
3812 #endif
|
|
3813 abort ();
|
|
3814
|
20
|
3815 XSETSUBR (fil, &SFhandle_energize_request);
|
0
|
3816 set_process_filter (lp, fil, 1);
|
|
3817
|
|
3818 Venergize_kernel_busy = Qnil;
|
|
3819
|
|
3820 id1 = 0;
|
|
3821 id2 = 0;
|
|
3822 if (arg)
|
|
3823 sscanf (arg, "%x,%x", &id1, &id2);
|
|
3824
|
|
3825 Venergize_buffers_list = Qnil;
|
|
3826
|
|
3827 setup_connection (energize_connection, id1, id2);
|
|
3828
|
|
3829 Venergize_process = lp;
|
|
3830 }
|
|
3831 else
|
|
3832 error ("couldn't connect to " IDENTITY_CRISIS " server");
|
|
3833 }
|
|
3834 else
|
|
3835 error ("couldn't determine " IDENTITY_CRISIS " server port number");
|
|
3836
|
|
3837
|
|
3838 #ifdef ENERGIZE_V2_HEADERS
|
|
3839 if (energize_connection->minor > 9)
|
|
3840 {
|
|
3841 close_energize_connection ();
|
|
3842 error ("This Emacs doesn't understand " IDENTITY_CRISIS " version 3.");
|
|
3843 }
|
|
3844
|
|
3845 #endif /* ENERGIZE_V2_HEADERS */
|
|
3846
|
|
3847 }
|
|
3848
|
|
3849
|
|
3850 /* Close the connection to energize.
|
|
3851 * Kills all the energize related buffer */
|
|
3852 static void
|
|
3853 close_energize_connection ()
|
|
3854 {
|
|
3855 Editor *ed = energize_connection;
|
|
3856
|
|
3857 if (ed)
|
|
3858 /* make this function as paranoid as we can */
|
|
3859 {
|
|
3860 /* cleanup the busy state */
|
|
3861 show_all_menubars_busy (False);
|
|
3862 Venergize_kernel_busy = Qnil;
|
|
3863 /* destroy all pop_up boxes */
|
|
3864 lw_destroy_all_pop_ups ();
|
|
3865
|
|
3866 if (ed->conn)
|
|
3867 DeleteConnection (ed->conn);
|
|
3868 ed->conn = 0;
|
|
3869
|
|
3870 if (ed->binfo_hash)
|
|
3871 {
|
|
3872 int speccount = specpdl_depth ();
|
|
3873
|
|
3874 /* we are flushing everything, so we just ignore any change
|
|
3875 hooks and don't make an effort to delete extents since they
|
|
3876 are all going away */
|
|
3877 specbind (Qenergize_buffer_modified_hook, Qnil);
|
|
3878 specbind (Qinhibit_quit, Qt);
|
|
3879 call0 (intern ("de-energize-all-buffers"));
|
|
3880 unbind_to (speccount, Qnil);
|
|
3881
|
|
3882 free_hashtable (ed->binfo_hash);
|
|
3883 ed->binfo_hash = 0;
|
|
3884 }
|
|
3885
|
|
3886 /* Do this after de-energize-all-buffers or frame sizes thrash. */
|
|
3887 debuggerpanel_sheet = 0;
|
|
3888 desired_debuggerpanel_exposed_p = 0;
|
|
3889
|
|
3890 free_edit_options (peo);
|
|
3891
|
|
3892 if (ZEROP (ed->proc)) abort ();
|
|
3893
|
|
3894 if (!NILP (ed->proc))
|
|
3895 Fdelete_process (ed->proc);
|
|
3896 ed->proc = Qnil;
|
|
3897
|
|
3898 Venergize_buffers_list = Qnil;
|
|
3899
|
|
3900 /* now kill buffers created to satisfy requests on old connection */
|
|
3901 xfree (ed);
|
|
3902 }
|
|
3903
|
|
3904 /* mark as closed */
|
|
3905 energize_connection = 0;
|
|
3906 Venergize_process = Qnil;
|
|
3907 }
|
|
3908
|
|
3909
|
20
|
3910 DEFUN ("connect-to-energize-internal", Fconnect_to_energize_internal, 0, 2, 0, /*
|
0
|
3911 Usage: (connect-to-energize-internal <server-name> <energizearg>)
|
|
3912 Energizearg representing two 32 bit Energize ids that will be passed
|
|
3913 to the Energize server when opening the Energize connection.
|
|
3914 Only one connection can be open at a time.
|
20
|
3915 */
|
|
3916 (server_name, energize_arg))
|
0
|
3917 {
|
|
3918 unsigned char *server;
|
|
3919 unsigned char *arg;
|
|
3920
|
|
3921 if (!NILP (energize_arg))
|
|
3922 {
|
|
3923 CHECK_STRING (energize_arg);
|
14
|
3924 arg = XSTRING_DATA (energize_arg);
|
0
|
3925 }
|
|
3926 else
|
|
3927 arg = 0;
|
|
3928
|
|
3929 if (!NILP (server_name))
|
|
3930 {
|
|
3931 CHECK_STRING (server_name);
|
14
|
3932 server = XSTRING_DATA (server_name);
|
0
|
3933 }
|
|
3934 else
|
|
3935 server = 0;
|
|
3936
|
|
3937 /* since we are going ahead with this, make sure that we are
|
|
3938 really and truly disconnected first */
|
|
3939 Fclose_connection_to_energize ();
|
|
3940
|
|
3941 connect_to_energize ((char *)server, (char *)arg);
|
|
3942 return Qnil;
|
|
3943 }
|
|
3944
|
20
|
3945 DEFUN ("close-connection-to-energize", Fclose_connection_to_energize, 0, 0, 0, /*
|
0
|
3946 Close the open Energize connection, if any.
|
20
|
3947 */
|
|
3948 ())
|
0
|
3949 {
|
|
3950 if (!energize_connection) return Qnil;
|
|
3951
|
|
3952 close_energize_connection ();
|
|
3953 return Qnil;
|
|
3954 }
|
|
3955
|
|
3956
|
|
3957 /* Extents stuff; this used to be in extents.c */
|
|
3958
|
|
3959 static void
|
|
3960 set_extent_flags (EXTENT extent, Energize_Extent_Data *ext)
|
|
3961 {
|
|
3962 /* clear every flag */
|
|
3963 if (!EXTENT_LIVE_P (extent))
|
|
3964 return;
|
|
3965 extent_start_open_p (extent) = 0;
|
|
3966 extent_end_open_p (extent) = 1;
|
|
3967 extent_read_only_p (extent) = 0;
|
|
3968 set_extent_mouse_face (extent, Qnil);
|
|
3969 extent_unique_p (extent) = 0;
|
|
3970 extent_duplicable_p (extent) = 0;
|
|
3971 extent_invisible_p (extent) = 0;
|
|
3972
|
|
3973 set_extent_glyph (extent, 0, 0, GL_TEXT);
|
|
3974 set_extent_glyph (extent, 0, 1, GL_TEXT);
|
|
3975
|
|
3976 if (ext)
|
|
3977 {
|
|
3978 ext->warn_modify = 0;
|
|
3979
|
|
3980 switch (ext->extentType)
|
|
3981 {
|
|
3982 case CEAttribute:
|
|
3983 break;
|
|
3984
|
|
3985 case CEAbbreviation:
|
|
3986 break;
|
|
3987
|
|
3988 case CEWriteProtect:
|
|
3989 extent_read_only_p (extent) = 1;
|
|
3990 break;
|
|
3991
|
|
3992 case CEGeneric:
|
|
3993 {
|
|
3994 GLYPH begin_glyph = 0; /* always the class glyph */
|
|
3995 GLYPH end_glyph = 0; /* always the instance glyph */
|
|
3996
|
|
3997 /* if (ext->u.generic.gData->id)
|
|
3998 SET_EXTENT_FLAG (extent, EF_MENU);*/
|
|
3999
|
|
4000 if (ext->u.generic.gData->glyph)
|
|
4001 end_glyph = ext->u.generic.gData->glyph;
|
|
4002 if (ext->u.generic.gData->cl && ext->u.generic.gData->cl->glyph)
|
|
4003 begin_glyph = ext->u.generic.gData->cl->glyph;
|
|
4004
|
|
4005 #if 0
|
|
4006 if (begin_glyph && end_glyph)
|
|
4007 {
|
|
4008 begin_glyph = end_glyph;
|
|
4009 end_glyph = 0;
|
|
4010 }
|
|
4011 #endif
|
|
4012
|
|
4013 if (begin_glyph)
|
|
4014 set_extent_glyph (extent, begin_glyph, 0, GL_TEXT);
|
|
4015 if (end_glyph)
|
|
4016 set_extent_glyph (extent, end_glyph, 1, GL_TEXT);
|
|
4017
|
|
4018 if (ext->u.generic.gData->cl &&
|
|
4019 (ext->u.generic.gData->cl->flags & CCElectric))
|
|
4020 set_extent_mouse_face (extent, Qhighlight);
|
|
4021 if (ext->u.generic.gData->cl &&
|
|
4022 (ext->u.generic.gData->cl->flags & CCWarnModified))
|
|
4023 ext->warn_modify = 1;
|
|
4024 #if 0 /* #### some day (soon?)... */
|
|
4025 if (ext->u.generic.gData->cl &&
|
|
4026 (ext->u.generic.gData->cl->flags & CCColumn))
|
|
4027 SET_EXTENT_FLAG (extent, EF_COLUMN);
|
|
4028 #endif
|
|
4029 extent_duplicable_p (extent) = 1;
|
|
4030 extent_unique_p (extent) = 1;
|
|
4031 break;
|
|
4032 }
|
|
4033
|
|
4034 default:
|
|
4035 break;
|
|
4036 }
|
|
4037 }
|
|
4038 }
|
|
4039
|
|
4040 extern Lisp_Object Fset_extent_face (Lisp_Object extent, Lisp_Object name);
|
|
4041
|
|
4042 static void
|
|
4043 set_extent_attributes_index (EXTENT extent, Energize_Extent_Data *ext)
|
|
4044 {
|
|
4045 int graphic_attributes;
|
|
4046
|
|
4047 if (!ext)
|
|
4048 extent_face_id (extent) = -1;
|
|
4049 else
|
|
4050 {
|
|
4051 switch (ext->extentType)
|
|
4052 {
|
|
4053 case CEAttribute:
|
|
4054 graphic_attributes = ext->u.attr.attrValue;
|
|
4055 break;
|
|
4056
|
|
4057 case CEGeneric:
|
|
4058 graphic_attributes = ext->u.generic.gData->attribute;
|
|
4059 break;
|
|
4060
|
|
4061 case CEWriteProtect:
|
|
4062 /* this type has NO display attributes */
|
|
4063 extent_face_id (extent) = -1;
|
|
4064 return;
|
|
4065
|
|
4066 default:
|
|
4067 graphic_attributes = GA_NO_CHANGE;
|
|
4068 }
|
|
4069
|
|
4070 if (graphic_attributes >= GA_MAX)
|
|
4071 graphic_attributes = GA_NO_CHANGE;
|
|
4072
|
|
4073 {
|
|
4074 /* The Venergize_attributes_mapping global is an alist of the form
|
|
4075 ( (<kernel-attribute-number> . <emacs-face-name> ) ... )
|
|
4076 */
|
|
4077 Lisp_Object face = Fcdr (Fassq (make_int (graphic_attributes),
|
|
4078 Venergize_attributes_mapping));
|
|
4079 Lisp_Object e;
|
|
4080 XSETEXTENT (e, extent);
|
|
4081 if (NILP (face))
|
|
4082 message ("Unknown Energize attribute %d", graphic_attributes);
|
|
4083 else if (EQ (face, Qdefault))
|
|
4084 Fset_extent_face (e, Qnil);
|
|
4085 else
|
|
4086 Fset_extent_face (e, face);
|
|
4087 }
|
|
4088 }
|
|
4089 }
|
|
4090
|
|
4091 void
|
|
4092 restore_energize_extent_state (EXTENT extent)
|
|
4093 {
|
|
4094 Energize_Extent_Data *ext = energize_extent_data (extent);
|
|
4095 if (!ext) return;
|
|
4096 set_extent_flags (extent, ext);
|
|
4097 set_extent_attributes_index (extent, ext);
|
|
4098 }
|
|
4099
|
20
|
4100 DEFUN ("extent-to-generic-id", Fextent_to_generic_id, 1, 1, 0, /*
|
0
|
4101 Return Energize ID of buffer of EXTENT.
|
20
|
4102 */
|
|
4103 (extent_obj))
|
0
|
4104 {
|
|
4105 CHECK_EXTENT (extent_obj);
|
|
4106 return word_to_lisp (energize_extent_data_id
|
|
4107 (energize_extent_data (XEXTENT (extent_obj))));
|
|
4108 }
|
|
4109
|
|
4110
|
|
4111
|
|
4112 /* buffer modified routines */
|
|
4113 static void
|
|
4114 send_buffer_modification_state (Editor *editor, BufferInfo *binfo, int flag)
|
|
4115 {
|
|
4116 Connection *conn = editor->conn;
|
|
4117 EId bufferId = binfo->id;
|
|
4118
|
|
4119 if (conn)
|
|
4120 {
|
|
4121 int state = (flag)?(CMBufferSetModified):(CMBufferSetUnmodified);
|
|
4122 CWriteModifiedBufferHeader (conn, bufferId, state);
|
|
4123 CWriteRequestBuffer (conn);
|
|
4124 }
|
|
4125 }
|
|
4126
|
|
4127 /* returns 1 if buffer is locked (non-editable),
|
|
4128 0 if it isn't (editable), and -1 if it can't tell
|
|
4129 */
|
|
4130 static int
|
|
4131 check_buffer_lock (Editor *editor, BufferInfo *binfo)
|
|
4132 {
|
|
4133 Connection *conn = editor->conn;
|
|
4134 struct reply_wait rw;
|
|
4135
|
|
4136 /* If permision already granted by kernel dont' ask again */
|
|
4137 if (binfo->editable)
|
|
4138 return 0;
|
|
4139
|
|
4140 /* If can't ask say we do not know */
|
|
4141 if (!conn)
|
|
4142 return -1;
|
|
4143
|
|
4144 /* Ask the kernel */
|
|
4145 CWriteModifiedBufferHeader (conn, binfo->id, CMBufferQueryLock);
|
|
4146 conn->header->serial = ++request_serial_number;
|
|
4147 CWriteRequestBuffer (conn);
|
|
4148
|
|
4149 rw.serial = request_serial_number;
|
|
4150 rw.objectId = binfo->id;
|
|
4151 rw.status = -1;
|
|
4152
|
|
4153 if (!wait_for_reply (&rw))
|
|
4154 return -1;
|
|
4155
|
|
4156 if (rw.status == CMBufferLocked)
|
|
4157 {
|
|
4158 /* Buffer is locked by kernel so we cannot edit it */
|
|
4159 return 1;
|
|
4160 }
|
|
4161 else if (rw.status == CMBufferUnlocked)
|
|
4162 {
|
|
4163 /* Buffer is unlocked by kernel: edit permission granted! */
|
|
4164 binfo->editable = 1;
|
|
4165 return 0;
|
|
4166 }
|
|
4167 else
|
|
4168 {
|
|
4169 /* This should never happen */
|
|
4170 return -1;
|
|
4171 }
|
|
4172 }
|
|
4173
|
|
4174
|
|
4175 /* Ask the kernel if BUFFER is currently locked -- waits for answer */
|
|
4176 static Lisp_Object
|
|
4177 buffer_locked_p (Lisp_Object buffer)
|
|
4178 {
|
|
4179 BufferInfo *binfo;
|
|
4180
|
|
4181 if (!energize_connection)
|
|
4182 return Qnil;
|
|
4183
|
|
4184 if (NILP (buffer))
|
|
4185 XSETBUFFER (buffer, current_buffer);
|
|
4186
|
|
4187 CHECK_BUFFER (buffer);
|
|
4188
|
|
4189 binfo = get_buffer_info_for_emacs_buffer (buffer, energize_connection);
|
|
4190
|
|
4191 if (!binfo)
|
|
4192 {
|
|
4193 /* Not an Energize buffer, return Qnil: can edit buffer */
|
|
4194 return Qnil;
|
|
4195 }
|
|
4196 else
|
|
4197 {
|
|
4198 /* Energize buffer, check if editable */
|
|
4199 return check_buffer_lock (energize_connection, binfo) == 0 ? Qnil : Qt;
|
|
4200 }
|
|
4201 }
|
|
4202
|
|
4203
|
|
4204
|
|
4205 /* Called by map_extents function called by Fenergize_send_buffer_modified
|
|
4206 */
|
|
4207 static int
|
|
4208 notify_extent_modified (EXTENT extent, void *arg)
|
|
4209 {
|
|
4210 /* arg is a binfo_and_state */
|
|
4211 binfo_and_state *bans = (binfo_and_state*)arg;
|
|
4212 Energize_Extent_Data *ext;
|
|
4213 BufferInfo *binfo = bans->binfo;
|
|
4214 Connection *conn = binfo->editor->conn;
|
|
4215 EId *extent_id;
|
|
4216 Lisp_Object extent_obj;
|
|
4217
|
|
4218 XSETEXTENT (extent_obj, extent);
|
|
4219 if ((ext = extent_to_data (extent_obj))
|
|
4220 && ext->warn_modify
|
|
4221 && ext->extentType == CEGeneric
|
|
4222 && ext->u.generic.gData
|
|
4223 && ext->u.generic.gData->cl
|
|
4224 && (ext->u.generic.gData->cl->flags & CCWarnModified)
|
|
4225 && ext->u.generic.gData->modified_state != bans->state)
|
|
4226 {
|
|
4227 if (bans->tell_energize)
|
|
4228 {
|
|
4229 CWriteModifiedExtentsHeader (conn, binfo->id, bans->state, 1);
|
|
4230 extent_id = CPut (conn, EId);
|
|
4231 *extent_id = ext->id;
|
|
4232 CWriteLength (conn);
|
|
4233 CWriteRequestBuffer (conn);
|
|
4234 }
|
|
4235 ext->u.generic.gData->modified_state = bans->state;
|
|
4236 }
|
|
4237 return 0;
|
|
4238 }
|
|
4239
|
|
4240 static int
|
|
4241 ceiwme_lower_mf (EXTENT e, void *arg)
|
|
4242 {
|
|
4243 Lisp_Object extent;
|
|
4244 Energize_Extent_Data *ext;
|
|
4245 XSETEXTENT (extent, e);
|
|
4246 ext = extent_to_data (extent);
|
|
4247 if (ext && ext->warn_modify)
|
|
4248 *((EXTENT *) arg) = e;
|
|
4249 return 0;
|
|
4250 }
|
|
4251
|
|
4252 static int
|
|
4253 ceiwme_upper_mf (EXTENT e, void *arg)
|
|
4254 {
|
|
4255 Lisp_Object extent;
|
|
4256 Energize_Extent_Data *ext;
|
|
4257 XSETEXTENT (extent, e);
|
|
4258 ext = extent_to_data (extent);
|
|
4259 if (ext && ext->warn_modify)
|
|
4260 {
|
|
4261 *((EXTENT *) arg) = e;
|
|
4262 return 1;
|
|
4263 }
|
|
4264 else
|
|
4265 return 0;
|
|
4266 }
|
|
4267
|
|
4268 static void
|
|
4269 coerce_endpoints_to_be_inside_warn_on_modify_extents (Bufpos *from_ptr,
|
|
4270 Bufpos *to_ptr,
|
|
4271 struct buffer *b)
|
|
4272 {
|
|
4273 EXTENT lower_extent = 0;
|
|
4274 EXTENT upper_extent = 0;
|
|
4275 Bufpos lower_bound = *from_ptr;
|
|
4276 Bufpos upper_bound = *to_ptr;
|
|
4277 Lisp_Object tmp;
|
|
4278
|
|
4279 /* make sure that from <= to */
|
|
4280 {
|
|
4281 Bufpos tmp_int = max (lower_bound, upper_bound);
|
|
4282 *from_ptr = lower_bound = min (lower_bound, upper_bound);
|
|
4283 *to_ptr = upper_bound = tmp_int;
|
|
4284 }
|
|
4285
|
|
4286 if (!BUFFER_NOTIFY_BACKGROUND_BIT_SET_P (b))
|
|
4287 return;
|
|
4288
|
|
4289 map_extents (BUF_BEG (b), lower_bound, ceiwme_lower_mf,
|
|
4290 (void *) &lower_extent, make_buffer (b), 0, ME_END_CLOSED);
|
|
4291 if (!lower_extent)
|
|
4292 {
|
|
4293 lower_bound = BUF_BEG (b);
|
|
4294 map_extents (upper_bound, BUF_Z (b), ceiwme_upper_mf,
|
|
4295 (void *) &upper_extent, make_buffer (b), 0, ME_END_CLOSED);
|
|
4296 if (!upper_extent)
|
|
4297 upper_bound = BUF_Z (b);
|
|
4298 else
|
|
4299 {
|
|
4300 Bufpos xstart;
|
|
4301 XSETEXTENT (tmp, upper_extent);
|
|
4302 xstart = XINT (Fextent_start_position (tmp));
|
|
4303 upper_bound = max (upper_bound, xstart);
|
|
4304 }
|
|
4305 }
|
|
4306 /* I forget why, but if we found an lower bound, we don't need to find
|
|
4307 an upper bound */
|
|
4308 else
|
|
4309 {
|
|
4310 Bufpos xstart;
|
|
4311 XSETEXTENT (tmp, lower_extent);
|
|
4312 xstart = XINT (Fextent_start_position (tmp));
|
|
4313 lower_bound = min (lower_bound, xstart);
|
|
4314 }
|
|
4315
|
|
4316 *from_ptr = lower_bound;
|
|
4317 *to_ptr = upper_bound;
|
|
4318 return;
|
|
4319 }
|
|
4320
|
|
4321 static void
|
|
4322 mark_all_extents_as_unmodified (BufferInfo *binfo)
|
|
4323 {
|
|
4324 binfo_and_state bans;
|
|
4325 bans.binfo = binfo;
|
|
4326 bans.state = FALSE;
|
|
4327 bans.tell_energize = FALSE;
|
|
4328
|
|
4329 map_extents (BUF_BEG (XBUFFER (binfo->emacs_buffer)),
|
|
4330 BUF_Z (XBUFFER (binfo->emacs_buffer)),
|
|
4331 notify_extent_modified, &bans,
|
|
4332 binfo->emacs_buffer, 0, ME_END_CLOSED);
|
|
4333 }
|
|
4334
|
|
4335 /* Send the BufferModified events for the current buffer.
|
|
4336 * Handles both global buffer modified and extents modified. */
|
20
|
4337 DEFUN ("energize-send-buffer-modified", Fenergize_send_buffer_modified, 3, 3, 0, /*
|
0
|
4338 Send a BufferModified request for the current buffer.
|
20
|
4339 */
|
|
4340 (state, from, to))
|
0
|
4341 {
|
|
4342 int modifiedp = NILP (state)? 0 : 1;
|
|
4343 Lisp_Object buffer;
|
|
4344 BufferInfo *binfo;
|
|
4345 Bufpos from_int = XINT (from);
|
|
4346 Bufpos to_int = XINT (to);
|
|
4347
|
|
4348 if (!energize_connection || !energize_connection->conn) return Qnil;
|
|
4349
|
|
4350 XSETBUFFER (buffer, current_buffer);
|
|
4351
|
|
4352 Fenergize_barf_if_buffer_locked ();
|
|
4353
|
|
4354 if (binfo = get_buffer_info_for_emacs_buffer (buffer, energize_connection))
|
|
4355 {
|
|
4356 /* now make sure that from and to
|
|
4357 are inside some warn_on_modify extents somewhere */
|
|
4358 coerce_endpoints_to_be_inside_warn_on_modify_extents
|
|
4359 (&from_int, &to_int, current_buffer);
|
|
4360 XSETINT (from, from_int);
|
|
4361 XSETINT (to, to_int);
|
|
4362
|
|
4363 if (binfo->modified_state != modifiedp)
|
|
4364 {
|
|
4365 send_buffer_modification_state (energize_connection, binfo,
|
|
4366 modifiedp);
|
|
4367 binfo->modified_state = modifiedp;
|
|
4368 }
|
|
4369 #ifndef ENERGIZE_V2_HEADERS
|
|
4370 if (!(binfo->flags & CBFileYourself))
|
|
4371 #endif
|
|
4372 {
|
|
4373 if (modifiedp)
|
|
4374 {
|
|
4375 binfo_and_state bans;
|
|
4376 bans.binfo = binfo;
|
|
4377 bans.state = 1;
|
|
4378 bans.tell_energize = 1;
|
|
4379 map_extents (XINT (from), XINT (to),
|
|
4380 notify_extent_modified, &bans,
|
|
4381 binfo->emacs_buffer, 0,
|
|
4382 ME_END_CLOSED);
|
|
4383 }
|
|
4384 else
|
|
4385 mark_all_extents_as_unmodified (binfo);
|
|
4386 }
|
|
4387 }
|
|
4388 return Qnil;
|
|
4389 }
|
|
4390
|
20
|
4391 DEFUN ("energize-barf-if-buffer-locked",
|
|
4392 Fenergize_barf_if_buffer_locked, 0, 0, 0, /*
|
0
|
4393 Error if the buffer is locked.
|
20
|
4394 */
|
|
4395 ())
|
0
|
4396 {
|
|
4397 Lisp_Object buffer;
|
|
4398 XSETBUFFER (buffer, current_buffer);
|
|
4399
|
|
4400 if (!energize_connection || !energize_connection->conn)
|
|
4401 return Qnil;
|
|
4402
|
|
4403 while (!NILP (buffer_locked_p (buffer)))
|
|
4404 {
|
|
4405 notify_delayed_requests ();
|
|
4406 Fsignal (Qbuffer_locked_by_energize, (Fcons (buffer, Qnil)));
|
|
4407 }
|
|
4408 return Qnil;
|
|
4409 }
|
|
4410
|
|
4411
|
20
|
4412 DEFUN ("energize-send-region", Fenergize_send_region, 2, 2, 0, /*
|
0
|
4413 Send region as user input
|
20
|
4414 */
|
|
4415 (start, end))
|
0
|
4416 {
|
|
4417 BufferInfo *binfo;
|
|
4418 Lisp_Object b;
|
|
4419 CEditorRequest *req;
|
|
4420
|
|
4421 if (!energize_connection || !energize_connection->conn)
|
|
4422 error ("Not connected to " IDENTITY_CRISIS);
|
|
4423
|
|
4424 XSETBUFFER (b, current_buffer);
|
|
4425 if (binfo = get_buffer_info_for_emacs_buffer (b, energize_connection))
|
|
4426 {
|
|
4427 Bufpos st, en;
|
|
4428 Bufpos ceil;
|
|
4429
|
|
4430 get_buffer_range_char (current_buffer, start, end, &st, &en);
|
|
4431
|
|
4432 do
|
|
4433 {
|
|
4434 ceil = BUF_CEILING_OF (current_buffer, st);
|
|
4435
|
|
4436 req = CWriteEditorRequest (energize_connection->conn,
|
|
4437 UserTypedSomethingRType);
|
|
4438 req->usertypedsomething.bufferId = binfo->id;
|
|
4439 CWriteVstringLen
|
|
4440 (energize_connection->conn,
|
|
4441 (char *) BUF_BYTE_ADDRESS (current_buffer, st), ceil - st);
|
|
4442 CWriteLength (energize_connection->conn);
|
|
4443 CWriteRequestBuffer (energize_connection->conn);
|
|
4444 st = ceil;
|
|
4445 } while (st < en);
|
|
4446 return Qnil;
|
|
4447 }
|
|
4448 return Qnil;
|
|
4449 }
|
|
4450
|
20
|
4451 DEFUN ("connected-to-energize-p", Fconnected_to_energize_p, 0, 0, 0, /*
|
0
|
4452 Return nil if no connection to Energize.
|
20
|
4453 */
|
|
4454 ())
|
0
|
4455 {
|
|
4456 if (!energize_connection ||
|
|
4457 !energize_connection->conn ||
|
|
4458 !energize_connection->binfo_hash ||
|
|
4459 !PROCESSP (energize_connection->proc))
|
|
4460 return Qnil;
|
|
4461 else
|
|
4462 return Qt;
|
|
4463 }
|
|
4464
|
20
|
4465 DEFUN ("energize-user-input-buffer-mark",
|
|
4466 Fenergize_user_input_buffer_mark, 0, 1, 0, /*
|
0
|
4467 Return the mark associated to the given Energize buffer.
|
20
|
4468 */
|
|
4469 (buffer))
|
0
|
4470 {
|
|
4471 BufferInfo *binfo;
|
|
4472
|
|
4473 XSETBUFFER (buffer, decode_buffer (buffer, 0));
|
|
4474 if (!energize_connection) return Qnil;
|
|
4475 if ((binfo = get_buffer_info_for_emacs_buffer (buffer, energize_connection)))
|
|
4476 return binfo->output_mark;
|
|
4477 else
|
|
4478 return Qnil;
|
|
4479 }
|
|
4480
|
|
4481 Lisp_Object
|
|
4482 energize_get_buffer_process (Lisp_Object buf)
|
|
4483 {
|
|
4484 BufferInfo *binfo;
|
|
4485
|
|
4486 if (!BUFFERP (buf)) return Qnil;
|
|
4487 if (!energize_connection) return Qnil;
|
|
4488 binfo = get_buffer_info_for_emacs_buffer (buf, energize_connection);
|
|
4489 if (!binfo) return Qnil;
|
|
4490 if (! binfo->buffer_type) return Qnil;
|
|
4491 if (!strcmp (binfo->buffer_type, "energize-debugger-buffer") ||
|
|
4492 !strcmp (binfo->buffer_type, "energize-log-file-buffer"))
|
|
4493 return Venergize_process;
|
|
4494 return Qnil;
|
|
4495 }
|
|
4496
|
|
4497
|
|
4498 static int
|
|
4499 get_energize_connection_and_buffer_id (Lisp_Object buffer, void **conn_ptr,
|
|
4500 long *buffer_id_ptr)
|
|
4501 {
|
|
4502 BufferInfo *binfo;
|
|
4503
|
|
4504 if (!energize_connection || !energize_connection->conn) return 0;
|
|
4505
|
|
4506 binfo = get_buffer_info_for_emacs_buffer (buffer, energize_connection);
|
|
4507
|
|
4508 *conn_ptr = (void *) energize_connection->conn;
|
|
4509 *buffer_id_ptr = (long) binfo ? binfo->id : 0;
|
|
4510 return 1;
|
|
4511 }
|
|
4512
|
|
4513 static int
|
|
4514 get_energize_connection_and_current_buffer_id (void **conn_ptr,
|
|
4515 long *buffer_id_ptr)
|
|
4516 {
|
|
4517 Lisp_Object lisp_buffer;
|
|
4518 XSETBUFFER (lisp_buffer, current_buffer);
|
|
4519
|
|
4520 return get_energize_connection_and_buffer_id (lisp_buffer, conn_ptr,
|
|
4521 buffer_id_ptr);
|
|
4522 }
|
|
4523
|
|
4524 int *
|
|
4525 get_psheets_for_buffer (Lisp_Object buffer, int *count_ptr)
|
|
4526 {
|
|
4527 BufferInfo *binfo;
|
|
4528
|
|
4529 if (!energize_connection || !energize_connection->conn) return 0;
|
|
4530
|
|
4531 binfo = get_buffer_info_for_emacs_buffer (buffer, energize_connection);
|
|
4532 if (!binfo) return 0;
|
|
4533
|
|
4534 if (count_ptr) *count_ptr = binfo->n_p_sheets;
|
|
4535 return binfo->p_sheet_ids;
|
|
4536 }
|
|
4537
|
|
4538 void
|
|
4539 notify_energize_sheet_hidden (EId id)
|
|
4540 {
|
|
4541 EId buffer_id = buffer_id_of_sheet (id);
|
|
4542 if (!buffer_id)
|
|
4543 return;
|
|
4544
|
|
4545 if (buffer_id && energize_connection && energize_connection->conn)
|
|
4546 {
|
|
4547 CWriteSheetRequest (energize_connection->conn,
|
|
4548 CSHide, id, buffer_id, "");
|
|
4549 CWriteRequestBuffer (energize_connection->conn);
|
|
4550 }
|
|
4551 }
|
|
4552
|
20
|
4553 DEFUN ("energize-query-buffer", Fenergize_query_buffer, 1, 2, 0, /*
|
0
|
4554 Ask Energize to create a buffer containing the file filename.
|
|
4555 Returns the buffer or NIL if Energize cannot create the buffer.
|
|
4556 If second argument just-ask is T, just ask if Energize
|
|
4557 already knows about the file and returns T if yes, NIL otherwise.
|
20
|
4558 */
|
|
4559 (filename, just_ask))
|
0
|
4560 {
|
|
4561 struct Lisp_String *filename_str;
|
|
4562 CEditorRequest *creq;
|
|
4563 char *dir_sep;
|
|
4564 struct reply_wait rw;
|
|
4565
|
|
4566 if (!energize_connection || !energize_connection->conn)
|
|
4567 return Qnil;
|
|
4568
|
|
4569 filename = Fexpand_file_name (filename, Qnil);
|
|
4570 filename_str = XSTRING (filename);
|
|
4571
|
|
4572 dir_sep = (char *) strrchr ((char *) string_data (filename_str), '/');
|
|
4573
|
|
4574 creq = CWriteEditorRequest (energize_connection->conn, QueryBufferRType);
|
|
4575 creq->head.data = !NILP (just_ask);
|
|
4576 creq->head.serial = ++request_serial_number;
|
|
4577 CWriteVstringLen (energize_connection->conn, (char *) string_data (filename_str),
|
|
4578 (dir_sep)? (dir_sep - (char *) string_data (filename_str)): 0);
|
|
4579 CWriteVstringLen (energize_connection->conn,
|
|
4580 (char *) string_data (filename_str), string_length (filename_str));
|
|
4581 CWriteLength (energize_connection->conn);
|
|
4582 CWriteRequestBuffer (energize_connection->conn);
|
|
4583
|
|
4584 rw.serial = request_serial_number;
|
|
4585 rw.objectId = 0;
|
|
4586
|
|
4587 if (!wait_for_reply (&rw))
|
|
4588 return Qnil;
|
|
4589
|
|
4590 if (rw.status)
|
|
4591 {
|
|
4592 if (rw.objectId)
|
|
4593 {
|
|
4594 BufferInfo* binfo = get_buffer_info_for_id (rw.objectId,
|
|
4595 energize_connection);
|
|
4596 return binfo ? binfo->emacs_buffer : Qt;
|
|
4597 }
|
|
4598 else
|
|
4599 return Qt;
|
|
4600 }
|
|
4601 else
|
|
4602 return Qnil;
|
|
4603 }
|
|
4604
|
|
4605
|
20
|
4606 DEFUN ("energize-protocol-level", Fenergize_protocol_level, 0, 0, 0, /*
|
0
|
4607 Return the Energize protocol level.
|
20
|
4608 */
|
|
4609 ())
|
0
|
4610 {
|
|
4611 return
|
|
4612 energize_connection
|
|
4613 ? Fcons (make_int (energize_connection->major),
|
|
4614 make_int (energize_connection->minor))
|
|
4615 : Qnil;
|
|
4616 }
|
|
4617
|
|
4618
|
20
|
4619 DEFUN ("energize-psheets-visible-p", Fenergize_psheets_visible_p, 0, 1, 0, /*
|
0
|
4620 Whether the (optional) frame currently has open psheets.
|
20
|
4621 */
|
|
4622 (frame))
|
0
|
4623 {
|
|
4624 if (NILP (frame))
|
|
4625 XSETFRAME (frame, XFRAME(Fselected_frame(Qnil)));
|
|
4626 CHECK_FRAME (frame);
|
|
4627 if (FRAME_X_CURRENT_PSHEETS (XFRAME (frame)))
|
|
4628 return Qt;
|
|
4629 return Qnil;
|
|
4630 }
|
|
4631
|
20
|
4632 DEFUN ("energize-buffer-has-psheets-p", Fenergize_buffer_has_psheets_p, 0, 1, 0, /*
|
0
|
4633 Whether the buffer has psheets associated with it.
|
20
|
4634 */
|
|
4635 (buf))
|
0
|
4636 {
|
|
4637 int count;
|
|
4638 if (NILP (buf))
|
|
4639 buf = Fcurrent_buffer ();
|
|
4640 CHECK_BUFFER (buf);
|
|
4641 if (get_psheets_for_buffer (buf, &count))
|
|
4642 return Qt;
|
|
4643 return Qnil;
|
|
4644 }
|
|
4645
|
|
4646
|
|
4647 void
|
|
4648 make_psheets_desired (struct frame *f, Lisp_Object buffer)
|
|
4649 {
|
|
4650 int count;
|
|
4651 int *psheets;
|
|
4652
|
|
4653 if (NILP (buffer) || !(psheets = get_psheets_for_buffer (buffer, &count)))
|
|
4654 {
|
|
4655 FRAME_X_DESIRED_PSHEETS (f) = 0;
|
|
4656 FRAME_X_DESIRED_PSHEET_COUNT (f) = 0;
|
|
4657 FRAME_X_DESIRED_PSHEET_BUFFER (f) = Qnil;
|
|
4658 }
|
|
4659 else
|
|
4660 {
|
|
4661 /* Do not show the debugger panel in this function. The
|
|
4662 * debugger panel should never be listed in the visible psheets. */
|
|
4663 extern int debuggerpanel_sheet;
|
185
|
4664
|
0
|
4665 if (count == 1 && psheets [0] == debuggerpanel_sheet)
|
|
4666 return;
|
|
4667
|
|
4668 FRAME_X_DESIRED_PSHEETS (f) = psheets;
|
|
4669 FRAME_X_DESIRED_PSHEET_COUNT (f) = count;
|
|
4670 FRAME_X_DESIRED_PSHEET_BUFFER (f) = buffer;
|
|
4671 }
|
|
4672
|
|
4673 /* Garbage the frame so that the sheets get recomputed right away and not
|
|
4674 the next time some display change happens. Possibly redisplay should
|
|
4675 notice this on its own without the garbaged flag. But once redisplay
|
|
4676 gets smarter about such things, all garbagers should be revisited.
|
|
4677 */
|
|
4678 MARK_FRAME_CHANGED (f);
|
|
4679 }
|
|
4680
|
|
4681 Lisp_Object
|
|
4682 desired_psheet_buffer (struct frame *f)
|
|
4683 {
|
|
4684 if (FRAME_X_P (f))
|
|
4685 return FRAME_X_DESIRED_PSHEET_BUFFER (f);
|
|
4686 else
|
|
4687 return Qnil;
|
|
4688 }
|
|
4689
|
|
4690 /* This function is invoked when the user clicks on the "sheet" button.
|
|
4691 */
|
20
|
4692 DEFUN ("energize-toggle-psheet", Fenergize_toggle_psheet, 0, 0, "", /*
|
|
4693
|
|
4694 */
|
|
4695 ())
|
0
|
4696 {
|
|
4697 struct frame *frame = XFRAME(Fselected_frame(Qnil));
|
|
4698 Lisp_Object buffer = Fwindow_buffer (Fselected_window (Qnil));
|
|
4699 if (EQ (buffer, desired_psheet_buffer (frame)))
|
|
4700 make_psheets_desired (frame, Qnil);
|
|
4701 else
|
|
4702 make_psheets_desired (frame, buffer);
|
|
4703 return Qnil;
|
|
4704 }
|
|
4705
|
|
4706
|
|
4707 static void energize_show_menubar_of_buffer (Lisp_Object frame,
|
|
4708 Lisp_Object buffer,
|
|
4709 Lisp_Object psheets_too);
|
|
4710
|
|
4711 /* This is called when a buffer becomes visible in some window.
|
|
4712
|
|
4713 Show the menubar associated with this buffer, and show the psheets as
|
|
4714 well if this buffer is the last buffer whose psheets were visible in
|
|
4715 this frame.
|
|
4716 */
|
|
4717 void
|
|
4718 energize_buffer_shown_hook (struct window *window)
|
|
4719 {
|
|
4720 struct frame* frame = XFRAME (window->frame);
|
|
4721 Lisp_Object buffer = window->buffer;
|
|
4722 Lisp_Object pbuf;
|
|
4723
|
|
4724 if (! FRAME_X_P (frame)) return;
|
|
4725 pbuf = desired_psheet_buffer (frame);
|
|
4726
|
|
4727 if (!MINI_WINDOW_P (window))
|
|
4728 energize_show_menubar_of_buffer (window->frame, buffer,
|
|
4729 (EQ (buffer, pbuf) ? Qt : Qnil));
|
|
4730 }
|
|
4731
|
|
4732
|
|
4733 static int
|
|
4734 find_buffer_in_different_window (window, buffer, not_in)
|
|
4735 struct window* window;
|
|
4736 Lisp_Object buffer;
|
|
4737 struct window* not_in;
|
|
4738 {
|
|
4739 Lisp_Object child;
|
|
4740 if (!NILP (window->buffer))
|
|
4741 {
|
|
4742 /* a leaf window */
|
|
4743 return (EQ (window->buffer, buffer) && (window != not_in));
|
|
4744 }
|
|
4745 else
|
|
4746 {
|
|
4747 /* a non leaf window, visit either the hchild or the vchild */
|
|
4748 for (child = !NILP (window->vchild) ? window->vchild : window->hchild;
|
|
4749 !NILP (child);
|
|
4750 child = XWINDOW (child)->next)
|
|
4751 {
|
|
4752 if (find_buffer_in_different_window (XWINDOW (child), buffer,
|
|
4753 not_in))
|
|
4754 return 1;
|
|
4755 }
|
|
4756 return 0;
|
|
4757 }
|
|
4758 }
|
|
4759
|
|
4760 /* returns 1 if the buffer is only visible in window on frame f */
|
|
4761 static int
|
185
|
4762 buffer_only_visible_in_this_window_p (Lisp_Object buffer,
|
|
4763 struct frame* f,
|
0
|
4764 struct window* window)
|
|
4765 {
|
|
4766 return !find_buffer_in_different_window (XWINDOW (f->root_window), buffer,
|
|
4767 window);
|
|
4768 }
|
|
4769
|
|
4770 /* This is called just before a buffer which is visible becomes invisible,
|
|
4771 either because some other buffer is about to be made visible in its window,
|
|
4772 or because that window is being deleted.
|
|
4773
|
|
4774 If this buffer's psheets are visible, hide them.
|
|
4775 */
|
|
4776 void
|
|
4777 energize_buffer_hidden_hook (struct window *window)
|
|
4778 {
|
|
4779 struct frame *f = XFRAME (window->frame);
|
|
4780
|
|
4781 if (! FRAME_X_P (f)) return;
|
|
4782
|
|
4783 /* hides the p_sheet if we are changing the buffer of the
|
|
4784 * selected window of the frame and the p_sheet where displayed */
|
|
4785 if (EQ (window->buffer, desired_psheet_buffer (f))
|
|
4786 && buffer_only_visible_in_this_window_p (window->buffer, f, window))
|
|
4787 make_psheets_desired (f, Qnil);
|
|
4788 }
|
|
4789
|
|
4790
|
|
4791 /* This is called just before the selected window is no longer the selected
|
|
4792 window because some other window is being selected. The given window is
|
|
4793 not being deleted, it is merely no longer the selected one.
|
|
4794
|
|
4795 This doesn't do anything right now.
|
|
4796 */
|
|
4797 void
|
|
4798 energize_window_deselected_hook (struct window *window)
|
|
4799 {
|
|
4800 }
|
|
4801
|
|
4802
|
|
4803 /* This is called just after a window has been selected.
|
|
4804
|
|
4805 Show the menubar associated with this buffer; leave the psheets as
|
|
4806 they are.
|
|
4807 */
|
|
4808 void
|
|
4809 energize_window_selected_hook (struct window *window)
|
|
4810 {
|
|
4811 struct frame* frame = XFRAME (window->frame);
|
|
4812 Lisp_Object buffer = window->buffer;
|
|
4813
|
|
4814 if (FRAME_X_P (frame) && !MINI_WINDOW_P (window))
|
|
4815 energize_show_menubar_of_buffer (window->frame, buffer, Qnil);
|
|
4816 }
|
|
4817
|
|
4818
|
|
4819
|
|
4820 int current_debuggerpanel_exposed_p;
|
|
4821 int desired_debuggerpanel_exposed_p;
|
|
4822 int debuggerpanel_sheet;
|
|
4823
|
|
4824 static void
|
|
4825 energize_show_menubar_of_buffer (Lisp_Object frame,
|
|
4826 Lisp_Object buffer,
|
|
4827 Lisp_Object psheets_too)
|
|
4828 {
|
|
4829 struct frame *f = decode_x_frame (frame);
|
|
4830
|
|
4831 if (! NILP (psheets_too))
|
|
4832 {
|
|
4833 Lisp_Object buffer;
|
|
4834 XSETBUFFER (buffer, current_buffer);
|
|
4835 make_psheets_desired (f, buffer);
|
|
4836 }
|
|
4837 }
|
|
4838
|
|
4839
|
|
4840 /* edit-mode dialog box
|
|
4841 This stuff really sucks
|
|
4842 */
|
|
4843
|
|
4844 static struct editmode {
|
|
4845 int ok, external, view, edit, window, split;
|
|
4846 char *other;
|
|
4847 } editmode;
|
|
4848
|
|
4849 static void
|
|
4850 edit_mode_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
4851 {
|
|
4852 widget_value *data;
|
|
4853 char *name = (char *) client_data;
|
|
4854
|
|
4855 if ((int) client_data == -1) name = "cancel"; /* WM_DELETE_WINDOW */
|
|
4856
|
|
4857 if (!strcmp (XtName (widget), "otherText")) /* screw it */
|
|
4858 ;
|
|
4859 else if (!strcmp (name, "externalBox"))
|
|
4860 {
|
|
4861 /* make the text slot be active only if "other" is selected */
|
|
4862 data = malloc_widget_value ();
|
|
4863 data->name = "externalOther";
|
|
4864 if (! lw_get_some_values (id, data)) abort ();
|
|
4865 data->enabled = data->selected;
|
|
4866 data->name = "otherText";
|
|
4867 lw_modify_all_widgets (id, data, True);
|
|
4868 free_widget_value (data);
|
|
4869 }
|
|
4870 else if (!strcmp (name, "cancel"))
|
|
4871 {
|
|
4872 editmode.ok = -1;
|
|
4873 lw_destroy_all_widgets (id);
|
|
4874 }
|
|
4875 else if (!strcmp (name, "help"))
|
|
4876 {
|
|
4877 Lisp_Object v = Fmake_vector (make_int (3), Qt);
|
173
|
4878 XVECTOR_DATA (v) [0] = build_string ("ok");
|
|
4879 XVECTOR_DATA (v) [1] = list1 (Qignore);
|
0
|
4880 Fpopup_dialog_box (list2 (build_string ("dbx_editmode_help"), v));
|
|
4881 }
|
|
4882 else if (!strcmp (name, "ok"))
|
|
4883 {
|
|
4884 editmode.ok = 1;
|
|
4885 data = malloc_widget_value ();
|
|
4886 data->name = "externalEmacs";
|
|
4887 if (! lw_get_some_values (id, data)) abort ();
|
|
4888 if (data->selected) editmode.external = 0;
|
|
4889 data->name = "externalViXterm";
|
|
4890 if (! lw_get_some_values (id, data)) abort ();
|
|
4891 if (data->selected) editmode.external = 1;
|
|
4892 data->name = "externalViCmdtool";
|
|
4893 if (! lw_get_some_values (id, data)) abort ();
|
|
4894 if (data->selected) editmode.external = 2;
|
|
4895 data->name = "externalOther";
|
|
4896 if (! lw_get_some_values (id, data)) abort ();
|
|
4897 if (data->selected) editmode.external = 3;
|
|
4898 data->name = "otherText";
|
|
4899 if (! lw_get_some_values (id, data)) abort ();
|
|
4900 editmode.other = data->value;
|
|
4901
|
|
4902 data->name = "emacsView";
|
|
4903 if (! lw_get_some_values (id, data)) abort ();
|
|
4904 if (data->selected) editmode.view = 0;
|
|
4905 data->name = "viView";
|
|
4906 if (! lw_get_some_values (id, data)) abort ();
|
|
4907 if (data->selected) editmode.view = 1;
|
|
4908 data->name = "lessView";
|
|
4909 if (! lw_get_some_values (id, data)) abort ();
|
|
4910 if (data->selected) editmode.view = 2;
|
|
4911
|
|
4912 data->name = "editEmacs";
|
|
4913 if (! lw_get_some_values (id, data)) abort ();
|
|
4914 if (data->selected) editmode.edit = 0;
|
|
4915 data->name = "editVi";
|
|
4916 if (! lw_get_some_values (id, data)) abort ();
|
|
4917 if (data->selected) editmode.edit = 1;
|
|
4918
|
|
4919 data->name = "windowOne";
|
|
4920 if (! lw_get_some_values (id, data)) abort ();
|
|
4921 if (data->selected) editmode.window = 0;
|
|
4922 data->name = "windowSeveral";
|
|
4923 if (! lw_get_some_values (id, data)) abort ();
|
|
4924 if (data->selected) editmode.window = 1;
|
|
4925 data->name = "windowMany";
|
|
4926 if (! lw_get_some_values (id, data)) abort ();
|
|
4927 if (data->selected) editmode.window = 2;
|
|
4928
|
|
4929 data->name = "splitScreens";
|
|
4930 if (! lw_get_some_values (id, data)) abort ();
|
|
4931 editmode.split = !!data->selected;
|
|
4932
|
|
4933 free_widget_value (data);
|
|
4934 lw_destroy_all_widgets (id);
|
|
4935 }
|
|
4936 else
|
|
4937 {
|
|
4938 abort ();
|
|
4939 }
|
|
4940 }
|
|
4941
|
|
4942 static int
|
|
4943 editmode_done (void *arg)
|
|
4944 {
|
|
4945 return (editmode.ok != 0);
|
|
4946 }
|
|
4947
|
|
4948 extern LWLIB_ID new_lwlib_id (void);
|
|
4949
|
20
|
4950 DEFUN ("energize-edit-mode-prompt", Fenergize_edit_mode_prompt, 6, 6, 0, /*
|
|
4951
|
|
4952 */
|
|
4953 (external, edit_mode, view_mode, other_text, window, split))
|
0
|
4954 {
|
|
4955 int dbox_id;
|
|
4956 struct frame *f = selected_frame ();
|
|
4957 widget_value *data;
|
|
4958 Widget parent, dbox;
|
|
4959 Lisp_Object frame = Qnil;
|
|
4960
|
|
4961 XSETFRAME (frame, f);
|
|
4962 CHECK_X_FRAME (frame);
|
|
4963 parent = FRAME_X_SHELL_WIDGET (f);
|
|
4964
|
|
4965 CHECK_INT (external);
|
|
4966 CHECK_INT (edit_mode);
|
|
4967 CHECK_INT (view_mode);
|
|
4968 CHECK_INT (window);
|
|
4969 CHECK_INT (split);
|
|
4970 CHECK_STRING (other_text);
|
|
4971
|
|
4972 editmode.ok = 0;
|
|
4973 editmode.external = XINT (external);
|
|
4974 editmode.view = XINT (view_mode);
|
|
4975 editmode.edit = XINT (edit_mode);
|
|
4976 editmode.window = XINT (window);
|
|
4977 editmode.split = XINT (split);
|
|
4978 editmode.other = 0;
|
|
4979
|
|
4980 data = malloc_widget_value ();
|
|
4981 data->name = "editmode";
|
|
4982 data->value = "editmode";
|
|
4983 data->enabled = 1;
|
|
4984
|
|
4985 dbox_id = new_lwlib_id ();
|
|
4986 dbox = lw_create_widget ("editmode", "editmode", dbox_id, data, parent,
|
|
4987 1, 0, edit_mode_callback, 0);
|
|
4988 data->value = 0;
|
|
4989
|
|
4990 data->name = "button1"; data->call_data = data->value = "ok";
|
|
4991 lw_modify_all_widgets (dbox_id, data, True);
|
|
4992 data->name = "button2"; data->call_data = data->value = "cancel";
|
|
4993 lw_modify_all_widgets (dbox_id, data, True);
|
|
4994 data->name = "button3"; data->call_data = data->value = "help";
|
|
4995 lw_modify_all_widgets (dbox_id, data, True);
|
|
4996 data->name = data->call_data = "externalBox";
|
|
4997 lw_modify_all_widgets (dbox_id, data, True);
|
|
4998 data->name = "otherText"; data->call_data = "otherText";
|
|
4999 lw_modify_all_widgets (dbox_id, data, True);
|
|
5000 data->name = "message"; data->value = "editmode";
|
|
5001 lw_modify_all_widgets (dbox_id, data, True);
|
|
5002
|
|
5003 data->selected = 1;
|
|
5004 switch (editmode.external)
|
|
5005 {
|
|
5006 case 0: data->name = "externalEmacs"; break;
|
|
5007 case 1: data->name = "externalViXterm"; break;
|
|
5008 case 2: data->name = "externalViCmdtool"; break;
|
|
5009 case 3: data->name = "externalOther"; break;
|
|
5010 default: abort ();
|
|
5011 }
|
|
5012 lw_modify_all_widgets (dbox_id, data, True);
|
|
5013 switch (editmode.view)
|
|
5014 {
|
|
5015 case 0: data->name = "emacsView"; break;
|
|
5016 case 1: data->name = "viView"; break;
|
|
5017 case 2: data->name = "lessView"; break;
|
|
5018 default: abort ();
|
|
5019 }
|
|
5020 lw_modify_all_widgets (dbox_id, data, True);
|
|
5021 switch (editmode.edit)
|
|
5022 {
|
|
5023 case 0: data->name = "editEmacs"; break;
|
|
5024 case 1: data->name = "editVi"; break;
|
|
5025 default: abort ();
|
|
5026 }
|
|
5027 lw_modify_all_widgets (dbox_id, data, True);
|
|
5028 switch (editmode.window)
|
|
5029 {
|
|
5030 case 0: data->name = "windowOne"; break;
|
|
5031 case 1: data->name = "windowSeveral"; break;
|
|
5032 case 2: data->name = "windowMany"; break;
|
|
5033 default: abort ();
|
|
5034 }
|
|
5035 lw_modify_all_widgets (dbox_id, data, True);
|
|
5036
|
|
5037 data->name = "otherText";
|
|
5038 data->selected = 0;
|
14
|
5039 data->value = (char *) XSTRING_DATA (other_text);
|
0
|
5040 data->enabled = (editmode.external == 3);
|
|
5041 lw_modify_all_widgets (dbox_id, data, True);
|
|
5042
|
|
5043 data->name = "splitScreens";
|
|
5044 data->enabled = 1;
|
|
5045 data->selected = editmode.split;
|
|
5046 data->value = 0;
|
|
5047 lw_modify_all_widgets (dbox_id, data, True);
|
|
5048
|
|
5049 free_widget_value (data);
|
|
5050
|
|
5051 lw_pop_up_all_widgets (dbox_id);
|
|
5052
|
|
5053 wait_delaying_user_input (editmode_done, 0);
|
|
5054
|
|
5055 if (editmode.ok == -1)
|
|
5056 return Fcons (external,
|
|
5057 list5 (edit_mode, view_mode, other_text, window, split));
|
|
5058 else if (editmode.ok == 1)
|
|
5059 return Fcons (make_int (editmode.external),
|
|
5060 list5 (make_int (editmode.view),
|
|
5061 make_int (editmode.edit),
|
|
5062 build_string (editmode.other ? editmode.other : ""),
|
|
5063 make_int (editmode.window),
|
|
5064 make_int (editmode.split)));
|
|
5065 else
|
|
5066 abort ();
|
|
5067 }
|
|
5068
|
|
5069 static LWLIB_ID search_id;
|
|
5070 static int last_search_up_p;
|
|
5071
|
|
5072 static void
|
|
5073 hide_search_dialog (Widget w, LWLIB_ID id)
|
|
5074 {
|
|
5075 #if 0
|
|
5076 /* I'd like to do this, but the widget occasionally gets FUCKED */
|
|
5077 XUnmapWindow (XtDisplay (w), XtWindow (w));
|
|
5078 #else
|
|
5079 lw_destroy_all_widgets (id);
|
|
5080 #endif
|
|
5081 }
|
|
5082
|
|
5083
|
|
5084 static void
|
|
5085 search_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
5086 {
|
|
5087 Widget parent = widget;
|
|
5088 widget_value *data;
|
|
5089 char *name = (char *) client_data;
|
|
5090 Lisp_Object search, replace;
|
|
5091 Lisp_Object case_sensitive_p, regexp_p, direction, match_word_p;
|
|
5092 Lisp_Object device = Qnil;
|
|
5093
|
|
5094 if ((int) client_data == -1) name = "done"; /* WM_DELETE_WINDOW */
|
|
5095
|
|
5096 while (parent && XtClass (parent) != xmDialogShellWidgetClass)
|
|
5097 parent = XtParent (parent);
|
|
5098 if (! parent) abort ();
|
|
5099
|
|
5100 if (!strcmp (name, "done"))
|
|
5101 {
|
|
5102 hide_search_dialog (parent, id);
|
|
5103 return;
|
|
5104 }
|
|
5105 #if 0
|
|
5106 else if (!strcmp (name, "help"))
|
|
5107 {
|
|
5108 Lisp_Object v = Fmake_vector (3, Qt);
|
173
|
5109 XVECTOR_DATA (v) [0] = build_string ("ok");
|
|
5110 XVECTOR_DATA (v) [1] = list1 (Qignore);
|
0
|
5111 Fpopup_dialog_box (list2 (build_string ("dbx_search_help"), v));
|
|
5112 return;
|
|
5113 }
|
|
5114 #endif
|
|
5115
|
|
5116 {
|
|
5117 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
5118 XSETDEVICE (device, d);
|
|
5119 DEVICE_X_MOUSE_TIMESTAMP (d) = DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d);
|
|
5120 }
|
|
5121
|
|
5122 if (!strcmp (name, "gotoStart"))
|
|
5123 {
|
|
5124 signal_special_Xt_user_event (device, Qcall_interactively,
|
|
5125 Qbeginning_of_buffer);
|
|
5126 }
|
|
5127 else if (!strcmp (name, "gotoEnd"))
|
|
5128 {
|
|
5129 signal_special_Xt_user_event (device, Qcall_interactively,
|
|
5130 Qend_of_buffer);
|
|
5131 }
|
|
5132 else if (!strcmp (name, "scrollForward"))
|
|
5133 {
|
|
5134 signal_special_Xt_user_event (device, Qcall_interactively,
|
|
5135 Qscroll_up);
|
|
5136 }
|
|
5137 else if (!strcmp (name, "scrollBack"))
|
|
5138 {
|
|
5139 signal_special_Xt_user_event (device, Qcall_interactively,
|
|
5140 Qdown_up);
|
|
5141 }
|
|
5142 else
|
|
5143 {
|
|
5144 data = malloc_widget_value ();
|
|
5145 data->name = "searchText";
|
|
5146 if (! lw_get_some_values (id, data)) abort ();
|
|
5147 search = build_string (data->value);
|
|
5148 data->name = "replaceText";
|
|
5149 if (! lw_get_some_values (id, data)) abort ();
|
|
5150 replace = build_string (data->value);
|
|
5151 data->name = "regexpSearch";
|
|
5152 if (! lw_get_some_values (id, data)) abort ();
|
|
5153 regexp_p = (data->selected ? Qt : Qnil);
|
|
5154 data->name = "caseSearch";
|
|
5155 if (! lw_get_some_values (id, data)) abort ();
|
|
5156 case_sensitive_p = (data->selected ? Qt : Qnil);
|
|
5157 data->name = "matchWord";
|
|
5158 if (! lw_get_some_values (id, data)) abort ();
|
|
5159 match_word_p = (data->selected ? Qt : Qnil);
|
185
|
5160
|
0
|
5161 data->name = "directionForward";
|
|
5162 if (! lw_get_some_values (id, data)) abort ();
|
|
5163 direction = data->selected ? Qt : Qnil;
|
185
|
5164
|
0
|
5165 if (!strcmp (name, "search"))
|
|
5166 replace = Qnil;
|
|
5167 else if (!strcmp (name, "replace"))
|
|
5168 ;
|
|
5169 else if (!strcmp (name, "replace_all"))
|
|
5170 {
|
|
5171 replace = list1 (replace);
|
|
5172 /* hide_search_dialog (parent, id); */
|
|
5173 }
|
|
5174 else
|
|
5175 abort ();
|
185
|
5176
|
0
|
5177 free_widget_value (data);
|
185
|
5178
|
0
|
5179 signal_special_Xt_user_event (device,
|
|
5180 intern ("energize-search-internal"),
|
|
5181 (NILP (replace)
|
|
5182 ? list5 (case_sensitive_p, match_word_p,
|
|
5183 regexp_p, direction, search)
|
|
5184 : list6 (case_sensitive_p, match_word_p,
|
|
5185 regexp_p, direction, search,
|
|
5186 replace)));
|
|
5187 }
|
|
5188 }
|
|
5189
|
|
5190
|
20
|
5191 DEFUN ("energize-search", Fenergize_search, 0, 0, "", /*
|
0
|
5192 Pop up the search-and-replace dialog box.
|
20
|
5193 */
|
|
5194 ())
|
0
|
5195 {
|
|
5196 int dbox_id;
|
|
5197 struct frame *f = selected_frame ();
|
|
5198 widget_value *data;
|
|
5199 Widget parent, dbox;
|
|
5200 Lisp_Object frame = Qnil;
|
|
5201
|
|
5202 XSETFRAME (frame, f);
|
|
5203 CHECK_X_FRAME (frame);
|
|
5204 parent = FRAME_X_SHELL_WIDGET (f);
|
|
5205
|
|
5206 data = malloc_widget_value ();
|
|
5207
|
|
5208 dbox_id = (search_id ? search_id : new_lwlib_id());
|
|
5209 dbox = lw_create_widget ("search", "search", dbox_id, NULL, parent,
|
|
5210 1, 0, search_callback, 0);
|
|
5211 data->enabled = 1;
|
|
5212 data->value = 0;
|
|
5213
|
|
5214 data->name = "button1"; data->value = data->call_data = "search";
|
|
5215 lw_modify_all_widgets (dbox_id, data, True);
|
|
5216 data->name = "button2"; data->value = data->call_data = "replace";
|
|
5217 lw_modify_all_widgets (dbox_id, data, True);
|
|
5218 data->name = "button3"; data->value = data->call_data = "replace_all";
|
|
5219 lw_modify_all_widgets (dbox_id, data, True);
|
|
5220 data->name = "button4"; data->value = data->call_data = "done";
|
|
5221 lw_modify_all_widgets (dbox_id, data, True);
|
|
5222
|
|
5223 data->value = 0;
|
|
5224 data->name = data->call_data = "gotoStart";
|
|
5225 lw_modify_all_widgets (dbox_id, data, True);
|
|
5226 data->name = data->call_data = "gotoEnd";
|
|
5227 lw_modify_all_widgets (dbox_id, data, True);
|
|
5228 data->name = data->call_data = "scrollBack";
|
|
5229 lw_modify_all_widgets (dbox_id, data, True);
|
|
5230 data->name = data->call_data = "scrollForward";
|
|
5231 lw_modify_all_widgets (dbox_id, data, True);
|
|
5232
|
|
5233 data->value = 0;
|
|
5234 data->name = data->call_data = "caseSearch";
|
|
5235 data->selected = NILP (current_buffer->case_fold_search);
|
|
5236 lw_modify_all_widgets (dbox_id, data, True);
|
|
5237
|
|
5238 data->name = data->call_data = "directionForward";
|
|
5239 data->selected = 1;
|
|
5240 lw_modify_all_widgets (dbox_id, data, True);
|
|
5241 data->name = data->call_data = "directionBackward";
|
|
5242 data->selected = 0;
|
|
5243 lw_modify_all_widgets (dbox_id, data, True);
|
|
5244
|
|
5245 free_widget_value (data);
|
|
5246
|
|
5247 lw_pop_up_all_widgets (dbox_id);
|
|
5248 last_search_up_p = 0;
|
|
5249 if (search_id)
|
|
5250 {
|
|
5251 Widget w = lw_get_widget (dbox_id, parent, True);
|
|
5252 if (! w) abort ();
|
|
5253 XMapRaised (XtDisplay (w), XtWindow (w));
|
|
5254 }
|
|
5255 else
|
|
5256 {
|
|
5257 search_id = dbox_id;
|
|
5258 }
|
|
5259
|
|
5260 return Qnil;
|
|
5261 }
|
|
5262
|
|
5263
|
|
5264
|
|
5265 /*************** Definition of Emacs Lisp-callable functions ***************/
|
|
5266
|
|
5267 void
|
|
5268 syms_of_energize (void)
|
|
5269 {
|
20
|
5270 DEFSUBR (Fenergize_send_buffer_modified);
|
|
5271 DEFSUBR (Fenergize_list_menu);
|
|
5272 DEFSUBR (Fenergize_execute_menu_item);
|
|
5273 DEFSUBR (Fenergize_execute_command_internal);
|
|
5274 DEFSUBR (Fconnect_to_energize_internal);
|
|
5275 DEFSUBR (Fconnected_to_energize_p);
|
|
5276 DEFSUBR (Fclose_connection_to_energize);
|
|
5277 DEFSUBR (Fhandle_energize_request);
|
|
5278 DEFSUBR (Fenergize_buffer_p);
|
|
5279 DEFSUBR (Fenergize_buffer_type);
|
|
5280 DEFSUBR (Fset_energize_buffer_type_internal);
|
|
5281 DEFSUBR (Fenergize_buffer_id);
|
|
5282 DEFSUBR (Fenergize_request_kill_buffer);
|
|
5283 DEFSUBR (Fenergize_send_region);
|
|
5284 DEFSUBR (Fenergize_user_input_buffer_mark);
|
|
5285 DEFSUBR (Fenergize_update_menubar);
|
|
5286 DEFSUBR (Fenergize_extent_menu_p);
|
|
5287 DEFSUBR (Fenergize_query_buffer);
|
|
5288 DEFSUBR (Fenergize_barf_if_buffer_locked);
|
|
5289 DEFSUBR (Fenergize_psheets_visible_p);
|
|
5290 DEFSUBR (Fenergize_buffer_has_psheets_p);
|
|
5291 DEFSUBR (Fenergize_toggle_psheet);
|
|
5292 DEFSUBR (Fenergize_protocol_level);
|
|
5293 DEFSUBR (Fenergize_edit_mode_prompt);
|
|
5294 DEFSUBR (Fenergize_search);
|
|
5295 DEFSUBR (Fextent_to_generic_id);
|
0
|
5296
|
|
5297 defsymbol (&Qenergize_create_buffer_hook, "energize-create-buffer-hook");
|
|
5298 defsymbol (&Qenergize_buffer_modified_hook, "energize-buffer-modified-hook");
|
|
5299
|
|
5300 defsymbol (&Qenergize_kernel_busy, "energize-kernel-busy");
|
|
5301
|
|
5302 defsymbol (&Qenergize_kernel_busy_hook, "energize-kernel-busy-hook");
|
|
5303 defsymbol (&Qenergize_menu_update_hook, "energize-menu-update-hook");
|
|
5304 defsymbol (&Qbuffer_locked_by_energize, "buffer-locked-by-energize");
|
|
5305 defsymbol (&Qenergize_user_input_buffer_mark,
|
|
5306 "energize-user-input-buffer-mark");
|
|
5307 defsymbol (&Qenergize_make_many_buffers_visible,
|
|
5308 "energize-make-many-buffers-visible");
|
|
5309 defsymbol (&Qenergize, "energize");
|
|
5310 defsymbol (&Qenergize_auto_revert_buffer, "energize-auto-revert-buffer");
|
|
5311 }
|
|
5312
|
|
5313 void
|
|
5314 vars_of_energize (void)
|
|
5315 {
|
|
5316 energize_connection = 0;
|
|
5317 inside_process_energize_request_1 = 0;
|
|
5318
|
|
5319 staticpro (&Venergize_buffers_list);
|
|
5320 Venergize_buffers_list = Qnil;
|
|
5321
|
|
5322 staticpro (&Vall_energize_pixmaps);
|
|
5323 Vall_energize_pixmaps = Qnil;
|
|
5324
|
|
5325 Fprovide (intern ("energize"));
|
|
5326
|
|
5327 search_id = 0;
|
|
5328
|
|
5329 DEFVAR_LISP ("energize-process", &Venergize_process /*
|
|
5330 The Lisp object representing the Energize connection, or nil
|
|
5331 */ );
|
|
5332 Venergize_process = Qnil;
|
|
5333
|
|
5334 DEFVAR_LISP ("energize-create-buffer-hook", &Venergize_create_buffer_hook /*
|
185
|
5335 Hook called when buffer is created by energize; takes
|
0
|
5336 BUFFER as its only argument.
|
|
5337 */ );
|
|
5338 Venergize_create_buffer_hook = Qnil;
|
|
5339
|
|
5340
|
|
5341 DEFVAR_LISP ("energize-kernel-modification-hook",
|
|
5342 &Venergize_kernel_modification_hook /*
|
|
5343 Hook called when a buffer is being modified by energize;
|
|
5344 takes no arguments.
|
|
5345 */ );
|
|
5346 Venergize_kernel_modification_hook = Qnil;
|
|
5347
|
|
5348 DEFVAR_BOOL ("ignore-kernel",
|
|
5349 &ignore_kernel /*
|
|
5350 Set when the kernel should be ignored -- for debugging.
|
|
5351 */ );
|
|
5352 ignore_kernel = 0;
|
|
5353
|
|
5354 DEFVAR_LISP ("energize-kernel-busy", &Venergize_kernel_busy /*
|
|
5355 True if the Energize kernel is busy.
|
|
5356 */ );
|
|
5357 Venergize_kernel_busy = Qnil;
|
|
5358 DEFVAR_LISP ("energize-kernel-busy-hook", &Venergize_kernel_busy_hook /*
|
|
5359 Hook called when the Energize kernel becomes busy or non busy.
|
|
5360 */ );
|
|
5361 Venergize_kernel_busy_hook = Qnil;
|
|
5362
|
|
5363 DEFVAR_LISP ("energize-menu-update-hook", &Venergize_menu_update_hook /*
|
|
5364 Hook called when the Energize kernel updates the menubar.
|
|
5365 */ );
|
|
5366 Venergize_menu_update_hook = Qnil;
|
|
5367
|
|
5368 DEFVAR_LISP ("energize-attributes-mapping", &Venergize_attributes_mapping /*
|
|
5369 A-list to map kernel attributes indexes to Emacs attributes
|
|
5370 */ );
|
|
5371 Venergize_attributes_mapping = Qnil;
|
|
5372
|
|
5373 DEFVAR_INT ("energize-extent-gc-threshold", &energize_extent_gc_threshold /*
|
|
5374 Number of extents in a ModifyBuffer request above which to do a GC
|
|
5375 */ );
|
|
5376 energize_extent_gc_threshold = 20;
|
185
|
5377
|
0
|
5378 pure_put (Qbuffer_locked_by_energize, Qerror_conditions,
|
|
5379 list2 (Qbuffer_locked_by_energize, Qerror));
|
|
5380 pure_put (Qbuffer_locked_by_energize, Qerror_message,
|
|
5381 build_string ("Buffer is currently locked by kernel"));
|
|
5382 }
|
|
5383
|
|
5384 void
|
|
5385 complex_vars_of_energize (void)
|
|
5386 {
|
|
5387 image_cache = make_strings_hashtable (50);
|
|
5388 }
|
|
5389
|
|
5390 #endif /* ENERGIZE */
|