Mercurial > hg > xemacs-beta
comparison src/marker.c @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | 8efd647ea9ca |
children | 6240c7796c7a |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
32 | 32 |
33 #include <config.h> | 33 #include <config.h> |
34 #include "lisp.h" | 34 #include "lisp.h" |
35 | 35 |
36 #include "buffer.h" | 36 #include "buffer.h" |
37 | |
38 static Lisp_Object mark_marker (Lisp_Object, void (*) (Lisp_Object)); | |
39 static void print_marker (Lisp_Object, Lisp_Object, int); | |
40 static int marker_equal (Lisp_Object, Lisp_Object, int); | |
41 static unsigned long marker_hash (Lisp_Object obj, int depth); | |
42 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("marker", marker, | |
43 mark_marker, print_marker, 0, | |
44 marker_equal, marker_hash, | |
45 struct Lisp_Marker); | |
46 | 37 |
47 static Lisp_Object | 38 static Lisp_Object |
48 mark_marker (Lisp_Object obj, void (*markobj) (Lisp_Object)) | 39 mark_marker (Lisp_Object obj, void (*markobj) (Lisp_Object)) |
49 { | 40 { |
50 struct Lisp_Marker *marker = XMARKER (obj); | 41 struct Lisp_Marker *marker = XMARKER (obj); |
66 { | 57 { |
67 struct Lisp_Marker *marker = XMARKER (obj); | 58 struct Lisp_Marker *marker = XMARKER (obj); |
68 char buf[200]; | 59 char buf[200]; |
69 | 60 |
70 if (print_readably) | 61 if (print_readably) |
71 error ("printing unreadable object #<marker 0x%x>", marker); | 62 error ("printing unreadable object #<marker 0x%lx>", (long) marker); |
72 | 63 |
73 write_c_string (GETTEXT ("#<marker "), printcharfun); | 64 write_c_string (GETTEXT ("#<marker "), printcharfun); |
74 if (!marker->buffer) | 65 if (!marker->buffer) |
75 write_c_string (GETTEXT ("in no buffer"), printcharfun); | 66 write_c_string (GETTEXT ("in no buffer"), printcharfun); |
76 else | 67 else |
77 { | 68 { |
78 sprintf (buf, "at %d in ", marker_position (obj)); | 69 sprintf (buf, "at %d in ", marker_position (obj)); |
79 write_c_string (buf, printcharfun); | 70 write_c_string (buf, printcharfun); |
80 print_internal (marker->buffer->name, printcharfun, 0); | 71 print_internal (marker->buffer->name, printcharfun, 0); |
81 } | 72 } |
82 sprintf (buf, " 0x%x>", marker); | 73 sprintf (buf, " 0x%lx>", (long) marker); |
83 write_c_string (buf, printcharfun); | 74 write_c_string (buf, printcharfun); |
84 } | 75 } |
85 | 76 |
86 static int | 77 static int |
87 marker_equal (Lisp_Object o1, Lisp_Object o2, int depth) | 78 marker_equal (Lisp_Object o1, Lisp_Object o2, int depth) |
103 if (hash) | 94 if (hash) |
104 hash = HASH2 (hash, XMARKER (obj)->memind); | 95 hash = HASH2 (hash, XMARKER (obj)->memind); |
105 return hash; | 96 return hash; |
106 } | 97 } |
107 | 98 |
99 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("marker", marker, | |
100 mark_marker, print_marker, 0, | |
101 marker_equal, marker_hash, | |
102 struct Lisp_Marker); | |
108 | 103 |
109 /* Operations on markers. */ | 104 /* Operations on markers. */ |
110 | 105 |
111 DEFUN ("marker-buffer", Fmarker_buffer, 1, 1, 0, /* | 106 DEFUN ("marker-buffer", Fmarker_buffer, 1, 1, 0, /* |
112 Return the buffer that MARKER points into, or nil if none. | 107 Return the buffer that MARKER points into, or nil if none. |
113 Returns nil if MARKER points into a dead buffer. | 108 Return nil if MARKER points into a dead buffer or doesn't point anywhere. |
114 */ | 109 */ |
115 (marker)) | 110 (marker)) |
116 { | 111 { |
117 Lisp_Object buf; | 112 struct buffer *buf; |
118 CHECK_MARKER (marker); | 113 CHECK_MARKER (marker); |
119 if (XMARKER (marker)->buffer) | 114 /* Return marker's buffer only if it is not dead. */ |
120 { | 115 if ((buf = XMARKER (marker)->buffer) && BUFFER_LIVE_P (buf)) |
121 XSETBUFFER (buf, XMARKER (marker)->buffer); | 116 { |
122 /* Return marker's buffer only if it is not dead. */ | 117 Lisp_Object buffer; |
123 if (BUFFER_LIVE_P (XBUFFER (buf))) | 118 XSETBUFFER (buffer, buf); |
124 return buf; | 119 return buffer; |
125 } | 120 } |
126 return Qnil; | 121 return Qnil; |
127 } | 122 } |
128 | 123 |
129 DEFUN ("marker-position", Fmarker_position, 1, 1, 0, /* | 124 DEFUN ("marker-position", Fmarker_position, 1, 1, 0, /* |
130 Return the position MARKER points at, as a character number. | 125 Return the position MARKER points at, as a character number. |
131 Returns `nil' if marker doesn't point anywhere. | 126 Return `nil' if marker doesn't point anywhere. |
132 */ | 127 */ |
133 (marker)) | 128 (marker)) |
134 { | 129 { |
135 CHECK_MARKER (marker); | 130 CHECK_MARKER (marker); |
136 if (XMARKER (marker)->buffer) | 131 return XMARKER (marker)->buffer ? make_int (marker_position (marker)) : Qnil; |
137 { | |
138 return (make_int (marker_position (marker))); | |
139 } | |
140 return Qnil; | |
141 } | 132 } |
142 | 133 |
143 #if 0 /* useful debugging function */ | 134 #if 0 /* useful debugging function */ |
144 | 135 |
145 static void | 136 static void |
276 } | 267 } |
277 | 268 |
278 | 269 |
279 /* This version of Fset_marker won't let the position | 270 /* This version of Fset_marker won't let the position |
280 be outside the visible part. */ | 271 be outside the visible part. */ |
281 Lisp_Object | 272 Lisp_Object |
282 set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer) | 273 set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer) |
283 { | 274 { |
284 return set_marker_internal (marker, pos, buffer, 1); | 275 return set_marker_internal (marker, pos, buffer, 1); |
285 } | 276 } |
286 | 277 |
521 #if 0 /* FSFmacs crock */ | 512 #if 0 /* FSFmacs crock */ |
522 DEFSUBR (Fbuffer_has_markers_at); | 513 DEFSUBR (Fbuffer_has_markers_at); |
523 #endif | 514 #endif |
524 } | 515 } |
525 | 516 |
526 void init_buffer_markers (struct buffer *b); | |
527 void | 517 void |
528 init_buffer_markers (struct buffer *b) | 518 init_buffer_markers (struct buffer *b) |
529 { | 519 { |
530 Lisp_Object buf = Qnil; | 520 Lisp_Object buf; |
531 | 521 |
532 XSETBUFFER (buf, b); | 522 XSETBUFFER (buf, b); |
533 b->mark = Fmake_marker (); | 523 b->mark = Fmake_marker (); |
534 BUF_MARKERS (b) = 0; | 524 BUF_MARKERS (b) = 0; |
535 b->point_marker = Fmake_marker (); | 525 b->point_marker = Fmake_marker (); |
536 Fset_marker (b->point_marker, make_int (1), buf); | 526 Fset_marker (b->point_marker, make_int (1), buf); |
537 } | 527 } |
538 | 528 |
539 void uninit_buffer_markers (struct buffer *b); | |
540 void | 529 void |
541 uninit_buffer_markers (struct buffer *b) | 530 uninit_buffer_markers (struct buffer *b) |
542 { | 531 { |
543 /* Unchain all markers of this buffer | 532 /* Unchain all markers of this buffer |
544 and leave them pointing nowhere. */ | 533 and leave them pointing nowhere. */ |