comparison src/editfns.c @ 10480:fbb254882b9f

(subst_char_in_region_unwind): New function. (Fsubst_char_in_region): Use it to make undo_list t temporarily.
author Richard M. Stallman <rms@gnu.org>
date Thu, 19 Jan 1995 18:56:10 +0000
parents a7fe0fb11314
children 9ab21ef32537
comparison
equal deleted inserted replaced
10479:f2f290b13413 10480:fbb254882b9f
1264 1264
1265 /* Same length too => they are equal. */ 1265 /* Same length too => they are equal. */
1266 return make_number (0); 1266 return make_number (0);
1267 } 1267 }
1268 1268
1269 static Lisp_Object
1270 subst_char_in_region_unwind (arg)
1271 Lisp_Object arg;
1272 {
1273 return current_buffer->undo_list = arg;
1274 }
1275
1269 DEFUN ("subst-char-in-region", Fsubst_char_in_region, 1276 DEFUN ("subst-char-in-region", Fsubst_char_in_region,
1270 Ssubst_char_in_region, 4, 5, 0, 1277 Ssubst_char_in_region, 4, 5, 0,
1271 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\ 1278 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\
1272 If optional arg NOUNDO is non-nil, don't record this change for undo\n\ 1279 If optional arg NOUNDO is non-nil, don't record this change for undo\n\
1273 and don't mark the buffer as really changed.") 1280 and don't mark the buffer as really changed.")
1274 (start, end, fromchar, tochar, noundo) 1281 (start, end, fromchar, tochar, noundo)
1275 Lisp_Object start, end, fromchar, tochar, noundo; 1282 Lisp_Object start, end, fromchar, tochar, noundo;
1276 { 1283 {
1277 register int pos, stop, look; 1284 register int pos, stop, look;
1278 int changed = 0; 1285 int changed = 0;
1286 int count = specpdl_ptr - specpdl;
1279 1287
1280 validate_region (&start, &end); 1288 validate_region (&start, &end);
1281 CHECK_NUMBER (fromchar, 2); 1289 CHECK_NUMBER (fromchar, 2);
1282 CHECK_NUMBER (tochar, 3); 1290 CHECK_NUMBER (tochar, 3);
1283 1291
1284 pos = XINT (start); 1292 pos = XINT (start);
1285 stop = XINT (end); 1293 stop = XINT (end);
1286 look = XINT (fromchar); 1294 look = XINT (fromchar);
1295
1296 /* If we don't want undo, turn off putting stuff on the list.
1297 That's faster than getting rid of things,
1298 and it prevents even the entry for a first change. */
1299 if (!NILP (noundo))
1300 {
1301 record_unwind_protect (subst_char_in_region_unwind,
1302 current_buffer->undo_list);
1303 current_buffer->undo_list = Qt;
1304 }
1287 1305
1288 while (pos < stop) 1306 while (pos < stop)
1289 { 1307 {
1290 if (FETCH_CHAR (pos) == look) 1308 if (FETCH_CHAR (pos) == look)
1291 { 1309 {
1313 1331
1314 if (changed) 1332 if (changed)
1315 signal_after_change (XINT (start), 1333 signal_after_change (XINT (start),
1316 stop - XINT (start), stop - XINT (start)); 1334 stop - XINT (start), stop - XINT (start));
1317 1335
1336 unbind_to (count, Qnil);
1318 return Qnil; 1337 return Qnil;
1319 } 1338 }
1320 1339
1321 DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0, 1340 DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0,
1322 "From START to END, translate characters according to TABLE.\n\ 1341 "From START to END, translate characters according to TABLE.\n\