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