Mercurial > hg > xemacs-beta
comparison src/extents.c @ 185:3d6bfa290dbd r20-3b19
Import from CVS: tag r20-3b19
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:55:28 +0200 |
parents | e121b013d1f0 |
children | 489f57a838ef |
comparison
equal
deleted
inserted
replaced
184:bcd2674570bf | 185:3d6bfa290dbd |
---|---|
419 int mouse_highlight_priority; | 419 int mouse_highlight_priority; |
420 | 420 |
421 Lisp_Object Qextentp; | 421 Lisp_Object Qextentp; |
422 Lisp_Object Qextent_live_p; | 422 Lisp_Object Qextent_live_p; |
423 | 423 |
424 Lisp_Object Qend_closed; | |
425 Lisp_Object Qstart_open; | |
426 Lisp_Object Qall_extents_closed; | 424 Lisp_Object Qall_extents_closed; |
427 Lisp_Object Qall_extents_open; | 425 Lisp_Object Qall_extents_open; |
428 Lisp_Object Qall_extents_closed_open; | 426 Lisp_Object Qall_extents_closed_open; |
429 Lisp_Object Qall_extents_open_closed; | 427 Lisp_Object Qall_extents_open_closed; |
430 Lisp_Object Qstart_in_region; | 428 Lisp_Object Qstart_in_region; |
544 | 542 |
545 /* If we have to get more space, get enough to last a while. We use | 543 /* If we have to get more space, get enough to last a while. We use |
546 a geometric progession that saves on realloc space. */ | 544 a geometric progession that saves on realloc space. */ |
547 increment += 100 + ga->numels / 8; | 545 increment += 100 + ga->numels / 8; |
548 | 546 |
549 ptr = xrealloc (ptr, | 547 ptr = (char *) xrealloc (ptr, |
550 (ga->numels + ga->gapsize + increment)*ga->elsize); | 548 (ga->numels + ga->gapsize + increment)*ga->elsize); |
551 if (ptr == 0) | 549 if (ptr == 0) |
552 memory_full (); | 550 memory_full (); |
553 ga->array = ptr; | 551 ga->array = ptr; |
554 | 552 |
555 real_gap_loc = ga->gap; | 553 real_gap_loc = ga->gap; |
635 { | 633 { |
636 m = gap_array_marker_freelist; | 634 m = gap_array_marker_freelist; |
637 gap_array_marker_freelist = gap_array_marker_freelist->next; | 635 gap_array_marker_freelist = gap_array_marker_freelist->next; |
638 } | 636 } |
639 else | 637 else |
640 m = (Gap_Array_Marker *) xmalloc (sizeof (*m)); | 638 m = xnew (Gap_Array_Marker); |
641 | 639 |
642 m->pos = GAP_ARRAY_ARRAY_TO_MEMORY_POS (ga, pos); | 640 m->pos = GAP_ARRAY_ARRAY_TO_MEMORY_POS (ga, pos); |
643 m->next = ga->markers; | 641 m->next = ga->markers; |
644 ga->markers = m; | 642 ga->markers = m; |
645 return m; | 643 return m; |
687 GAP_ARRAY_MEMORY_TO_ARRAY_POS (ga, (m)->pos) | 685 GAP_ARRAY_MEMORY_TO_ARRAY_POS (ga, (m)->pos) |
688 | 686 |
689 static Gap_Array * | 687 static Gap_Array * |
690 make_gap_array (int elsize) | 688 make_gap_array (int elsize) |
691 { | 689 { |
692 Gap_Array *ga = (Gap_Array *) xmalloc (sizeof(*ga)); | 690 Gap_Array *ga = xnew_and_zero (Gap_Array); |
693 memset (ga, 0, sizeof(*ga)); | |
694 ga->elsize = elsize; | 691 ga->elsize = elsize; |
695 return ga; | 692 return ga; |
696 } | 693 } |
697 | 694 |
698 static void | 695 static void |
862 { | 859 { |
863 m = extent_list_marker_freelist; | 860 m = extent_list_marker_freelist; |
864 extent_list_marker_freelist = extent_list_marker_freelist->next; | 861 extent_list_marker_freelist = extent_list_marker_freelist->next; |
865 } | 862 } |
866 else | 863 else |
867 m = (Extent_List_Marker *) xmalloc (sizeof (*m)); | 864 m = xnew (Extent_List_Marker); |
868 | 865 |
869 m->m = gap_array_make_marker (endp ? el->end : el->start, pos); | 866 m->m = gap_array_make_marker (endp ? el->end : el->start, pos); |
870 m->endp = endp; | 867 m->endp = endp; |
871 m->next = el->markers; | 868 m->next = el->markers; |
872 el->markers = m; | 869 el->markers = m; |
897 gap_array_marker_pos ((mkr)->endp ? (el)->end : (el)->start, (mkr)->m) | 894 gap_array_marker_pos ((mkr)->endp ? (el)->end : (el)->start, (mkr)->m) |
898 | 895 |
899 static Extent_List * | 896 static Extent_List * |
900 allocate_extent_list (void) | 897 allocate_extent_list (void) |
901 { | 898 { |
902 Extent_List *el = (Extent_List *) xmalloc (sizeof(*el)); | 899 Extent_List *el = xnew (Extent_List); |
903 el->start = make_gap_array (sizeof(EXTENT)); | 900 el->start = make_gap_array (sizeof(EXTENT)); |
904 el->end = make_gap_array (sizeof(EXTENT)); | 901 el->end = make_gap_array (sizeof(EXTENT)); |
905 el->markers = 0; | 902 el->markers = 0; |
906 return el; | 903 return el; |
907 } | 904 } |
926 0, 0, 0, struct extent_auxiliary); | 923 0, 0, 0, struct extent_auxiliary); |
927 | 924 |
928 static Lisp_Object | 925 static Lisp_Object |
929 mark_extent_auxiliary (Lisp_Object obj, void (*markobj) (Lisp_Object)) | 926 mark_extent_auxiliary (Lisp_Object obj, void (*markobj) (Lisp_Object)) |
930 { | 927 { |
931 struct extent_auxiliary *data = | 928 struct extent_auxiliary *data = XEXTENT_AUXILIARY (obj); |
932 (struct extent_auxiliary *) XEXTENT_AUXILIARY (obj); | |
933 ((markobj) (data->begin_glyph)); | 929 ((markobj) (data->begin_glyph)); |
934 ((markobj) (data->end_glyph)); | 930 ((markobj) (data->end_glyph)); |
935 ((markobj) (data->invisible)); | 931 ((markobj) (data->invisible)); |
936 ((markobj) (data->children)); | 932 ((markobj) (data->children)); |
937 ((markobj) (data->read_only)); | 933 ((markobj) (data->read_only)); |
942 void | 938 void |
943 allocate_extent_auxiliary (EXTENT ext) | 939 allocate_extent_auxiliary (EXTENT ext) |
944 { | 940 { |
945 Lisp_Object extent_aux = Qnil; | 941 Lisp_Object extent_aux = Qnil; |
946 struct extent_auxiliary *data = | 942 struct extent_auxiliary *data = |
947 alloc_lcrecord (sizeof (struct extent_auxiliary), | 943 alloc_lcrecord_type (struct extent_auxiliary, lrecord_extent_auxiliary); |
948 lrecord_extent_auxiliary); | |
949 | 944 |
950 copy_lcrecord (data, &extent_auxiliary_defaults); | 945 copy_lcrecord (data, &extent_auxiliary_defaults); |
951 XSETEXTENT_AUXILIARY (extent_aux, data); | 946 XSETEXTENT_AUXILIARY (extent_aux, data); |
952 ext->plist = Fcons (extent_aux, ext->plist); | 947 ext->plist = Fcons (extent_aux, ext->plist); |
953 ext->flags.has_aux = 1; | 948 ext->flags.has_aux = 1; |
1047 static Lisp_Object | 1042 static Lisp_Object |
1048 allocate_extent_info (void) | 1043 allocate_extent_info (void) |
1049 { | 1044 { |
1050 Lisp_Object extent_info = Qnil; | 1045 Lisp_Object extent_info = Qnil; |
1051 struct extent_info *data = | 1046 struct extent_info *data = |
1052 alloc_lcrecord (sizeof (struct extent_info), | 1047 alloc_lcrecord_type (struct extent_info, lrecord_extent_info); |
1053 lrecord_extent_info); | |
1054 | 1048 |
1055 XSETEXTENT_INFO (extent_info, data); | 1049 XSETEXTENT_INFO (extent_info, data); |
1056 data->extents = allocate_extent_list (); | 1050 data->extents = allocate_extent_list (); |
1057 data->soe = 0; | 1051 data->soe = 0; |
1058 return extent_info; | 1052 return extent_info; |
1522 } | 1516 } |
1523 | 1517 |
1524 static struct stack_of_extents * | 1518 static struct stack_of_extents * |
1525 allocate_soe (void) | 1519 allocate_soe (void) |
1526 { | 1520 { |
1527 struct stack_of_extents *soe = | 1521 struct stack_of_extents *soe = xnew_and_zero (struct stack_of_extents); |
1528 malloc_type_and_zero (struct stack_of_extents); | |
1529 soe->extents = allocate_extent_list (); | 1522 soe->extents = allocate_extent_list (); |
1530 soe->pos = -1; | 1523 soe->pos = -1; |
1531 return soe; | 1524 return soe; |
1532 } | 1525 } |
1533 | 1526 |
2362 /* adjust_extents_for_deletion() */ | 2355 /* adjust_extents_for_deletion() */ |
2363 /* ------------------------------- */ | 2356 /* ------------------------------- */ |
2364 | 2357 |
2365 struct adjust_extents_for_deletion_arg | 2358 struct adjust_extents_for_deletion_arg |
2366 { | 2359 { |
2367 extent_dynarr *list; | 2360 EXTENT_dynarr *list; |
2368 }; | 2361 }; |
2369 | 2362 |
2370 static int | 2363 static int |
2371 adjust_extents_for_deletion_mapper (EXTENT extent, void *arg) | 2364 adjust_extents_for_deletion_mapper (EXTENT extent, void *arg) |
2372 { | 2365 { |
2402 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents (object); | 2395 Stack_Of_Extents *soe = buffer_or_string_stack_of_extents (object); |
2403 | 2396 |
2404 #ifdef ERROR_CHECK_EXTENTS | 2397 #ifdef ERROR_CHECK_EXTENTS |
2405 sledgehammer_extent_check (object); | 2398 sledgehammer_extent_check (object); |
2406 #endif | 2399 #endif |
2407 closure.list = (extent_dynarr *) Dynarr_new (EXTENT); | 2400 closure.list = Dynarr_new (EXTENT); |
2408 | 2401 |
2409 /* We're going to be playing weird games below with extents and the SOE | 2402 /* We're going to be playing weird games below with extents and the SOE |
2410 and such, so compute the list now of all the extents that we're going | 2403 and such, so compute the list now of all the extents that we're going |
2411 to muck with. If we do the mapping and adjusting together, things can | 2404 to muck with. If we do the mapping and adjusting together, things can |
2412 get all screwed up. */ | 2405 get all screwed up. */ |
2598 } | 2591 } |
2599 | 2592 |
2600 struct extent_fragment * | 2593 struct extent_fragment * |
2601 extent_fragment_new (Lisp_Object buffer_or_string, struct frame *frm) | 2594 extent_fragment_new (Lisp_Object buffer_or_string, struct frame *frm) |
2602 { | 2595 { |
2603 struct extent_fragment *ef = (struct extent_fragment *) | 2596 struct extent_fragment *ef = xnew_and_zero (struct extent_fragment); |
2604 xmalloc (sizeof (struct extent_fragment)); | 2597 |
2605 | |
2606 memset (ef, 0, sizeof (*ef)); | |
2607 ef->object = buffer_or_string; | 2598 ef->object = buffer_or_string; |
2608 ef->frm = frm; | 2599 ef->frm = frm; |
2609 ef->extents = Dynarr_new (EXTENT); | 2600 ef->extents = Dynarr_new (EXTENT); |
2610 ef->begin_glyphs = Dynarr_new (struct glyph_block); | 2601 ef->begin_glyphs = Dynarr_new (glyph_block); |
2611 ef->end_glyphs = Dynarr_new (struct glyph_block); | 2602 ef->end_glyphs = Dynarr_new (glyph_block); |
2612 | 2603 |
2613 return ef; | 2604 return ef; |
2614 } | 2605 } |
2615 | 2606 |
2616 void | 2607 void |
2631 return -1; | 2622 return -1; |
2632 return extent_priority (foo) > extent_priority (bar); | 2623 return extent_priority (foo) > extent_priority (bar); |
2633 } | 2624 } |
2634 | 2625 |
2635 static void | 2626 static void |
2636 extent_fragment_sort_by_priority (extent_dynarr *extarr) | 2627 extent_fragment_sort_by_priority (EXTENT_dynarr *extarr) |
2637 { | 2628 { |
2638 int i; | 2629 int i; |
2639 | 2630 |
2640 /* Sort our copy of the stack by extent_priority. We use a bubble | 2631 /* Sort our copy of the stack by extent_priority. We use a bubble |
2641 sort here because it's going to be faster than qsort() for small | 2632 sort here because it's going to be faster than qsort() for small |
3035 if (print_readably) | 3026 if (print_readably) |
3036 { | 3027 { |
3037 if (!EXTENT_LIVE_P (XEXTENT (obj))) | 3028 if (!EXTENT_LIVE_P (XEXTENT (obj))) |
3038 error ("printing unreadable object #<destroyed extent>"); | 3029 error ("printing unreadable object #<destroyed extent>"); |
3039 else | 3030 else |
3040 error ("printing unreadable object #<extent 0x%lx>", | 3031 error ("printing unreadable object #<extent 0x%p>", |
3041 (long)XEXTENT (obj)); | 3032 XEXTENT (obj)); |
3042 } | 3033 } |
3043 | 3034 |
3044 if (!EXTENT_LIVE_P (XEXTENT (obj))) | 3035 if (!EXTENT_LIVE_P (XEXTENT (obj))) |
3045 write_c_string ("#<destroyed extent", printcharfun); | 3036 write_c_string ("#<destroyed extent", printcharfun); |
3046 else | 3037 else |
3047 { | 3038 { |
3048 char *buf = alloca (strlen (title) + strlen (name) | 3039 char *buf = (char *) |
3049 + strlen (posttitle)); | 3040 alloca (strlen (title) + strlen (name) + strlen (posttitle) + 1); |
3050 write_c_string ("#<extent ", printcharfun); | 3041 write_c_string ("#<extent ", printcharfun); |
3051 print_extent_1 (obj, printcharfun, escapeflag); | 3042 print_extent_1 (obj, printcharfun, escapeflag); |
3052 write_c_string (extent_detached_p (XEXTENT (obj)) | 3043 write_c_string (extent_detached_p (XEXTENT (obj)) |
3053 ? " from " : " in ", printcharfun); | 3044 ? " from " : " in ", printcharfun); |
3054 sprintf (buf, "%s%s%s", title, name, posttitle); | 3045 sprintf (buf, "%s%s%s", title, name, posttitle); |
3291 | 3282 |
3292 DEFUN ("next-extent", Fnext_extent, 1, 1, 0, /* | 3283 DEFUN ("next-extent", Fnext_extent, 1, 1, 0, /* |
3293 Find next extent after EXTENT. | 3284 Find next extent after EXTENT. |
3294 If EXTENT is a buffer return the first extent in the buffer; likewise | 3285 If EXTENT is a buffer return the first extent in the buffer; likewise |
3295 for strings. | 3286 for strings. |
3296 Extents in a buffer are ordered in what is called the \"display\" | 3287 Extents in a buffer are ordered in what is called the "display" |
3297 order, which sorts by increasing start positions and then by *decreasing* | 3288 order, which sorts by increasing start positions and then by *decreasing* |
3298 end positions. | 3289 end positions. |
3299 If you want to perform an operation on a series of extents, use | 3290 If you want to perform an operation on a series of extents, use |
3300 `map-extents' instead of this function; it is much more efficient. | 3291 `map-extents' instead of this function; it is much more efficient. |
3301 The primary use of this function should be to enumerate all the | 3292 The primary use of this function should be to enumerate all the |
3342 } | 3333 } |
3343 | 3334 |
3344 #ifdef DEBUG_XEMACS | 3335 #ifdef DEBUG_XEMACS |
3345 | 3336 |
3346 DEFUN ("next-e-extent", Fnext_e_extent, 1, 1, 0, /* | 3337 DEFUN ("next-e-extent", Fnext_e_extent, 1, 1, 0, /* |
3347 Find next extent after EXTENT using the \"e\" order. | 3338 Find next extent after EXTENT using the "e" order. |
3348 If EXTENT is a buffer return the first extent in the buffer; likewise | 3339 If EXTENT is a buffer return the first extent in the buffer; likewise |
3349 for strings. | 3340 for strings. |
3350 */ | 3341 */ |
3351 (extent)) | 3342 (extent)) |
3352 { | 3343 { |
3363 XSETEXTENT (val, next); | 3354 XSETEXTENT (val, next); |
3364 return val; | 3355 return val; |
3365 } | 3356 } |
3366 | 3357 |
3367 DEFUN ("previous-e-extent", Fprevious_e_extent, 1, 1, 0, /* | 3358 DEFUN ("previous-e-extent", Fprevious_e_extent, 1, 1, 0, /* |
3368 Find last extent before EXTENT using the \"e\" order. | 3359 Find last extent before EXTENT using the "e" order. |
3369 If EXTENT is a buffer return the last extent in the buffer; likewise | 3360 If EXTENT is a buffer return the last extent in the buffer; likewise |
3370 for strings. | 3361 for strings. |
3371 This function is analogous to `next-e-extent'. | 3362 This function is analogous to `next-e-extent'. |
3372 */ | 3363 */ |
3373 (extent)) | 3364 (extent)) |
3426 /************************************************************************/ | 3417 /************************************************************************/ |
3427 | 3418 |
3428 DEFUN ("extent-parent", Fextent_parent, 1, 1, 0, /* | 3419 DEFUN ("extent-parent", Fextent_parent, 1, 1, 0, /* |
3429 Return the parent (if any) of EXTENT. | 3420 Return the parent (if any) of EXTENT. |
3430 If an extent has a parent, it derives all its properties from that extent | 3421 If an extent has a parent, it derives all its properties from that extent |
3431 and has no properties of its own. (The only \"properties\" that the | 3422 and has no properties of its own. (The only "properties" that the |
3432 extent keeps are the buffer/string it refers to and the start and end | 3423 extent keeps are the buffer/string it refers to and the start and end |
3433 points.) It is possible for an extent's parent to itself have a parent. | 3424 points.) It is possible for an extent's parent to itself have a parent. |
3434 */ | 3425 */ |
3435 (extent)) | 3426 (extent)) |
3436 /* do I win the prize for the strangest split infinitive? */ | 3427 /* do I win the prize for the strangest split infinitive? */ |
3639 { | 3630 { |
3640 /* also need to copy the aux struct. It won't work for | 3631 /* also need to copy the aux struct. It won't work for |
3641 this extent to share the same aux struct as the original | 3632 this extent to share the same aux struct as the original |
3642 one. */ | 3633 one. */ |
3643 struct extent_auxiliary *data = | 3634 struct extent_auxiliary *data = |
3644 alloc_lcrecord (sizeof (struct extent_auxiliary), | 3635 alloc_lcrecord_type (struct extent_auxiliary, |
3645 lrecord_extent_auxiliary); | 3636 lrecord_extent_auxiliary); |
3646 | 3637 |
3647 copy_lcrecord (data, XEXTENT_AUXILIARY (XCAR (original->plist))); | 3638 copy_lcrecord (data, XEXTENT_AUXILIARY (XCAR (original->plist))); |
3648 XSETEXTENT_AUXILIARY (XCAR (e->plist), data); | 3639 XSETEXTENT_AUXILIARY (XCAR (e->plist), data); |
3649 } | 3640 } |
3650 | 3641 |
4345 XSETEXTENT (extent_obj, closure.best_match); | 4336 XSETEXTENT (extent_obj, closure.best_match); |
4346 return extent_obj; | 4337 return extent_obj; |
4347 } | 4338 } |
4348 | 4339 |
4349 DEFUN ("extent-at", Fextent_at, 1, 5, 0, /* | 4340 DEFUN ("extent-at", Fextent_at, 1, 5, 0, /* |
4350 Find \"smallest\" extent at POS in OBJECT having PROPERTY set. | 4341 Find "smallest" extent at POS in OBJECT having PROPERTY set. |
4351 Normally, an extent is \"at\" POS if it overlaps the region (POS, POS+1); | 4342 Normally, an extent is "at" POS if it overlaps the region (POS, POS+1); |
4352 i.e. if it covers the character after POS. (However, see the definition | 4343 i.e. if it covers the character after POS. (However, see the definition |
4353 of AT-FLAG.) \"Smallest\" means the extent that comes last in the display | 4344 of AT-FLAG.) "Smallest" means the extent that comes last in the display |
4354 order; this normally means the extent whose start position is closest to | 4345 order; this normally means the extent whose start position is closest to |
4355 POS. See `next-extent' for more information. | 4346 POS. See `next-extent' for more information. |
4356 OBJECT specifies a buffer or string and defaults to the current buffer. | 4347 OBJECT specifies a buffer or string and defaults to the current buffer. |
4357 PROPERTY defaults to nil, meaning that any extent will do. | 4348 PROPERTY defaults to nil, meaning that any extent will do. |
4358 Properties are attached to extents with `set-extent-property', which see. | 4349 Properties are attached to extents with `set-extent-property', which see. |
5871 | 5862 |
5872 DEFUN ("get-text-property", Fget_text_property, 2, 4, 0, /* | 5863 DEFUN ("get-text-property", Fget_text_property, 2, 4, 0, /* |
5873 Returns the value of the PROP property at the given position. | 5864 Returns the value of the PROP property at the given position. |
5874 Optional arg OBJECT specifies the buffer or string to look in, and | 5865 Optional arg OBJECT specifies the buffer or string to look in, and |
5875 defaults to the current buffer. | 5866 defaults to the current buffer. |
5876 Optional arg AT-FLAG controls what it means for a property to be \"at\" | 5867 Optional arg AT-FLAG controls what it means for a property to be "at" |
5877 a position, and has the same meaning as in `extent-at'. | 5868 a position, and has the same meaning as in `extent-at'. |
5878 This examines only those properties added with `put-text-property'. | 5869 This examines only those properties added with `put-text-property'. |
5879 See also `get-char-property'. | 5870 See also `get-char-property'. |
5880 */ | 5871 */ |
5881 (pos, prop, object, at_flag)) | 5872 (pos, prop, object, at_flag)) |
5885 | 5876 |
5886 DEFUN ("get-char-property", Fget_char_property, 2, 4, 0, /* | 5877 DEFUN ("get-char-property", Fget_char_property, 2, 4, 0, /* |
5887 Returns the value of the PROP property at the given position. | 5878 Returns the value of the PROP property at the given position. |
5888 Optional arg OBJECT specifies the buffer or string to look in, and | 5879 Optional arg OBJECT specifies the buffer or string to look in, and |
5889 defaults to the current buffer. | 5880 defaults to the current buffer. |
5890 Optional arg AT-FLAG controls what it means for a property to be \"at\" | 5881 Optional arg AT-FLAG controls what it means for a property to be "at" |
5891 a position, and has the same meaning as in `extent-at'. | 5882 a position, and has the same meaning as in `extent-at'. |
5892 This examines properties on all extents. | 5883 This examines properties on all extents. |
5893 See also `get-text-property'. | 5884 See also `get-text-property'. |
5894 */ | 5885 */ |
5895 (pos, prop, object, at_flag)) | 5886 (pos, prop, object, at_flag)) |