Mercurial > emacs
comparison src/editfns.c @ 13767:862fff660446
(Fset_time_zone_rule): Move static var environbuf
to top level.
(syms_of_editfns): Initialize environbuf explicitly.
(Vbuffer_access_fontified_property): New variable.
(syms_of_editfns): Set up Lisp var.
(make_buffer_string): Don't call the Vbuffer_access_fontify_functions
if the text is already fontified.
(Fbuffer_string): Pas 1 for PROPS arg.
(update_buffer_properties): New subroutine.
(Finsert_buffer_substring): Use update_buffer_properties.
(make_buffer_string): New arg PROPS.
(Fbuffer_string, Fbuffer_substring): Pass new arg.
(Fbuffer_substring_no_properties): New function.
(syms_of_editfns): defsubr it.
(Vbuffer_access_fontify_functions): New variable.
(Qbuffer_access_fontify_functions): New variable.
(syms_of_editfns): Set up Lisp variable, initialize them.
(make_buffer_string): Run this new hook.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 21 Dec 1995 16:58:55 +0000 |
parents | 5fe951036f57 |
children | 2a71500dfb93 |
comparison
equal
deleted
inserted
replaced
13766:adaa14fd574e | 13767:862fff660446 |
---|---|
41 extern char **environ; | 41 extern char **environ; |
42 extern Lisp_Object make_time (); | 42 extern Lisp_Object make_time (); |
43 extern void insert_from_buffer (); | 43 extern void insert_from_buffer (); |
44 static long difftm (); | 44 static long difftm (); |
45 static void set_time_zone_rule (); | 45 static void set_time_zone_rule (); |
46 static void update_buffer_properties (); | |
47 | |
48 Lisp_Object Vbuffer_access_fontify_functions; | |
49 Lisp_Object Qbuffer_access_fontify_functions; | |
50 Lisp_Object Vbuffer_access_fontified_property; | |
46 | 51 |
47 /* Some static data, and a function to initialize it for each run */ | 52 /* Some static data, and a function to initialize it for each run */ |
48 | 53 |
49 Lisp_Object Vsystem_name; | 54 Lisp_Object Vsystem_name; |
50 Lisp_Object Vuser_real_login_name; /* login name of current user ID */ | 55 Lisp_Object Vuser_real_login_name; /* login name of current user ID */ |
877 } | 882 } |
878 else | 883 else |
879 return Fmake_list (2, Qnil); | 884 return Fmake_list (2, Qnil); |
880 } | 885 } |
881 | 886 |
887 /* This holds the value of `environ' produced by the previous | |
888 call to Fset_time_zone_rule, or 0 if Fset_time_zone_rule | |
889 has never been called. */ | |
890 static char **environbuf; | |
891 | |
882 DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0, | 892 DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0, |
883 "Set the local time zone using TZ, a string specifying a time zone rule.\n\ | 893 "Set the local time zone using TZ, a string specifying a time zone rule.\n\ |
884 If TZ is nil, use implementation-defined default time zone information.") | 894 If TZ is nil, use implementation-defined default time zone information.") |
885 (tz) | 895 (tz) |
886 Lisp_Object tz; | 896 Lisp_Object tz; |
887 { | 897 { |
888 static char **environbuf; | |
889 char *tzstring; | 898 char *tzstring; |
890 | 899 |
891 if (NILP (tz)) | 900 if (NILP (tz)) |
892 tzstring = 0; | 901 tzstring = 0; |
893 else | 902 else |
1140 /* Making strings from buffer contents. */ | 1149 /* Making strings from buffer contents. */ |
1141 | 1150 |
1142 /* Return a Lisp_String containing the text of the current buffer from | 1151 /* Return a Lisp_String containing the text of the current buffer from |
1143 START to END. If text properties are in use and the current buffer | 1152 START to END. If text properties are in use and the current buffer |
1144 has properties in the range specified, the resulting string will also | 1153 has properties in the range specified, the resulting string will also |
1145 have them. | 1154 have them, if PROPS is nonzero. |
1146 | 1155 |
1147 We don't want to use plain old make_string here, because it calls | 1156 We don't want to use plain old make_string here, because it calls |
1148 make_uninit_string, which can cause the buffer arena to be | 1157 make_uninit_string, which can cause the buffer arena to be |
1149 compacted. make_string has no way of knowing that the data has | 1158 compacted. make_string has no way of knowing that the data has |
1150 been moved, and thus copies the wrong data into the string. This | 1159 been moved, and thus copies the wrong data into the string. This |
1151 doesn't effect most of the other users of make_string, so it should | 1160 doesn't effect most of the other users of make_string, so it should |
1152 be left as is. But we should use this function when conjuring | 1161 be left as is. But we should use this function when conjuring |
1153 buffer substrings. */ | 1162 buffer substrings. */ |
1154 | 1163 |
1155 Lisp_Object | 1164 Lisp_Object |
1156 make_buffer_string (start, end) | 1165 make_buffer_string (start, end, props) |
1157 int start, end; | 1166 int start, end; |
1167 int props; | |
1158 { | 1168 { |
1159 Lisp_Object result, tem, tem1; | 1169 Lisp_Object result, tem, tem1; |
1160 | 1170 |
1161 if (start < GPT && GPT < end) | 1171 if (start < GPT && GPT < end) |
1162 move_gap (start); | 1172 move_gap (start); |
1163 | 1173 |
1164 result = make_uninit_string (end - start); | 1174 result = make_uninit_string (end - start); |
1165 bcopy (&FETCH_CHAR (start), XSTRING (result)->data, end - start); | 1175 bcopy (&FETCH_CHAR (start), XSTRING (result)->data, end - start); |
1166 | 1176 |
1167 tem = Fnext_property_change (make_number (start), Qnil, make_number (end)); | 1177 /* If desired, update and copy the text properties. */ |
1168 tem1 = Ftext_properties_at (make_number (start), Qnil); | |
1169 | |
1170 #ifdef USE_TEXT_PROPERTIES | 1178 #ifdef USE_TEXT_PROPERTIES |
1171 if (XINT (tem) != end || !NILP (tem1)) | 1179 if (props) |
1172 copy_intervals_to_string (result, current_buffer, start, end - start); | 1180 { |
1181 update_buffer_properties (start, end); | |
1182 | |
1183 tem = Fnext_property_change (make_number (start), Qnil, make_number (end)); | |
1184 tem1 = Ftext_properties_at (make_number (start), Qnil); | |
1185 | |
1186 if (XINT (tem) != end || !NILP (tem1)) | |
1187 copy_intervals_to_string (result, current_buffer, start, end - start); | |
1188 } | |
1173 #endif | 1189 #endif |
1174 | 1190 |
1175 return result; | 1191 return result; |
1192 } | |
1193 | |
1194 /* Call Vbuffer_access_fontify_functions for the range START ... END | |
1195 in the current buffer, if necessary. */ | |
1196 | |
1197 static void | |
1198 update_buffer_properties (start, end) | |
1199 int start, end; | |
1200 { | |
1201 #ifdef USE_TEXT_PROPERTIES | |
1202 /* If this buffer has some access functions, | |
1203 call them, specifying the range of the buffer being accessed. */ | |
1204 if (!NILP (Vbuffer_access_fontify_functions)) | |
1205 { | |
1206 Lisp_Object args[3]; | |
1207 Lisp_Object tem; | |
1208 | |
1209 args[0] = Qbuffer_access_fontify_functions; | |
1210 XSETINT (args[1], start); | |
1211 XSETINT (args[2], end); | |
1212 | |
1213 /* But don't call them if we can tell that the work | |
1214 has already been done. */ | |
1215 if (!NILP (Vbuffer_access_fontified_property)) | |
1216 { | |
1217 tem = Ftext_property_any (args[1], args[2], | |
1218 Vbuffer_access_fontified_property, | |
1219 Qnil, Qnil); | |
1220 if (! NILP (tem)) | |
1221 Frun_hook_with_args (3, &args); | |
1222 } | |
1223 else | |
1224 Frun_hook_with_args (3, &args); | |
1225 } | |
1226 #endif | |
1176 } | 1227 } |
1177 | 1228 |
1178 DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0, | 1229 DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0, |
1179 "Return the contents of part of the current buffer as a string.\n\ | 1230 "Return the contents of part of the current buffer as a string.\n\ |
1180 The two arguments START and END are character positions;\n\ | 1231 The two arguments START and END are character positions;\n\ |
1186 | 1237 |
1187 validate_region (&b, &e); | 1238 validate_region (&b, &e); |
1188 beg = XINT (b); | 1239 beg = XINT (b); |
1189 end = XINT (e); | 1240 end = XINT (e); |
1190 | 1241 |
1191 return make_buffer_string (beg, end); | 1242 return make_buffer_string (beg, end, 1); |
1243 } | |
1244 | |
1245 DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties, | |
1246 Sbuffer_substring_no_properties, 2, 2, 0, | |
1247 "Return the characters of part of the buffer, without the text properties.\n\ | |
1248 The two arguments START and END are character positions;\n\ | |
1249 they can be in either order.") | |
1250 (b, e) | |
1251 Lisp_Object b, e; | |
1252 { | |
1253 register int beg, end; | |
1254 | |
1255 validate_region (&b, &e); | |
1256 beg = XINT (b); | |
1257 end = XINT (e); | |
1258 | |
1259 return make_buffer_string (beg, end, 0); | |
1192 } | 1260 } |
1193 | 1261 |
1194 DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0, | 1262 DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0, |
1195 "Return the contents of the current buffer as a string.\n\ | 1263 "Return the contents of the current buffer as a string.\n\ |
1196 If narrowing is in effect, this function returns only the visible part\n\ | 1264 If narrowing is in effect, this function returns only the visible part\n\ |
1197 of the buffer.") | 1265 of the buffer.") |
1198 () | 1266 () |
1199 { | 1267 { |
1200 return make_buffer_string (BEGV, ZV); | 1268 return make_buffer_string (BEGV, ZV, 1); |
1201 } | 1269 } |
1202 | 1270 |
1203 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring, | 1271 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring, |
1204 1, 3, 0, | 1272 1, 3, 0, |
1205 "Insert before point a substring of the contents of buffer BUFFER.\n\ | 1273 "Insert before point a substring of the contents of buffer BUFFER.\n\ |
1208 They default to the beginning and the end of BUFFER.") | 1276 They default to the beginning and the end of BUFFER.") |
1209 (buf, b, e) | 1277 (buf, b, e) |
1210 Lisp_Object buf, b, e; | 1278 Lisp_Object buf, b, e; |
1211 { | 1279 { |
1212 register int beg, end, temp; | 1280 register int beg, end, temp; |
1213 register struct buffer *bp; | 1281 register struct buffer *bp, *obuf; |
1214 Lisp_Object buffer; | 1282 Lisp_Object buffer; |
1215 | 1283 |
1216 buffer = Fget_buffer (buf); | 1284 buffer = Fget_buffer (buf); |
1217 if (NILP (buffer)) | 1285 if (NILP (buffer)) |
1218 nsberror (buf); | 1286 nsberror (buf); |
1236 if (beg > end) | 1304 if (beg > end) |
1237 temp = beg, beg = end, end = temp; | 1305 temp = beg, beg = end, end = temp; |
1238 | 1306 |
1239 if (!(BUF_BEGV (bp) <= beg && end <= BUF_ZV (bp))) | 1307 if (!(BUF_BEGV (bp) <= beg && end <= BUF_ZV (bp))) |
1240 args_out_of_range (b, e); | 1308 args_out_of_range (b, e); |
1309 | |
1310 obuf = current_buffer; | |
1311 set_buffer_internal_1 (bp); | |
1312 update_buffer_properties (beg, end); | |
1313 set_buffer_internal_1 (obuf); | |
1241 | 1314 |
1242 insert_from_buffer (bp, beg, end - beg, 0); | 1315 insert_from_buffer (bp, beg, end - beg, 0); |
1243 return Qnil; | 1316 return Qnil; |
1244 } | 1317 } |
1245 | 1318 |
2303 | 2376 |
2304 | 2377 |
2305 void | 2378 void |
2306 syms_of_editfns () | 2379 syms_of_editfns () |
2307 { | 2380 { |
2381 environbuf = 0; | |
2382 | |
2383 Qbuffer_access_fontify_functions | |
2384 = intern ("buffer-access-fontify-functions"); | |
2385 staticpro (&Qbuffer_access_fontify_functions); | |
2386 | |
2387 DEFVAR_LISP ("buffer-access-fontify-functions", | |
2388 &Vbuffer_access_fontify_functions, | |
2389 "List of functions called by `buffer-substring' to fontify if necessary.\n\ | |
2390 Each function is called with two arguments which specify the range\n\ | |
2391 of the buffer being accessed."); | |
2392 Vbuffer_access_fontify_functions = Qnil; | |
2393 | |
2394 DEFVAR_LISP ("buffer_access_fontified_property", | |
2395 &Vbuffer_access_fontified_property, | |
2396 "Property which (if non-nil) indicates text has been fontified.\n\ | |
2397 `buffer-substring' need not call the `buffer-access-fontify-functions'\n\ | |
2398 functions if all the text being accessed has this property."); | |
2399 Vbuffer_access_fontified_property = Qnil; | |
2400 | |
2308 DEFVAR_LISP ("system-name", &Vsystem_name, | 2401 DEFVAR_LISP ("system-name", &Vsystem_name, |
2309 "The name of the machine Emacs is running on."); | 2402 "The name of the machine Emacs is running on."); |
2310 | 2403 |
2311 DEFVAR_LISP ("user-full-name", &Vuser_full_name, | 2404 DEFVAR_LISP ("user-full-name", &Vuser_full_name, |
2312 "The full name of the user logged in."); | 2405 "The full name of the user logged in."); |
2320 defsubr (&Schar_equal); | 2413 defsubr (&Schar_equal); |
2321 defsubr (&Sgoto_char); | 2414 defsubr (&Sgoto_char); |
2322 defsubr (&Sstring_to_char); | 2415 defsubr (&Sstring_to_char); |
2323 defsubr (&Schar_to_string); | 2416 defsubr (&Schar_to_string); |
2324 defsubr (&Sbuffer_substring); | 2417 defsubr (&Sbuffer_substring); |
2418 defsubr (&Sbuffer_substring_no_properties); | |
2325 defsubr (&Sbuffer_string); | 2419 defsubr (&Sbuffer_string); |
2326 | 2420 |
2327 defsubr (&Spoint_marker); | 2421 defsubr (&Spoint_marker); |
2328 defsubr (&Smark_marker); | 2422 defsubr (&Smark_marker); |
2329 defsubr (&Spoint); | 2423 defsubr (&Spoint); |