Mercurial > hg > xemacs-beta
comparison src/symbols.c @ 82:6a378aca36af r20-0b91
Import from CVS: tag r20-0b91
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:07:36 +0200 |
parents | 1ce6082ce73f |
children | 4be1180a9e89 |
comparison
equal
deleted
inserted
replaced
81:ebca3d831cea | 82:6a378aca36af |
---|---|
434 | 434 |
435 /* Extract and set components of symbols */ | 435 /* Extract and set components of symbols */ |
436 | 436 |
437 static void set_up_buffer_local_cache (Lisp_Object sym, | 437 static void set_up_buffer_local_cache (Lisp_Object sym, |
438 struct symbol_value_buffer_local *bfwd, | 438 struct symbol_value_buffer_local *bfwd, |
439 struct buffer *buf); | 439 struct buffer *buf, |
440 Lisp_Object new_alist_el, | |
441 int set_it_p); | |
440 | 442 |
441 DEFUN ("boundp", Fboundp, 1, 1, 0, /* | 443 DEFUN ("boundp", Fboundp, 1, 1, 0, /* |
442 T if SYMBOL's value is not void. | 444 T if SYMBOL's value is not void. |
443 */ | 445 */ |
444 (sym)) | 446 (sym)) |
1273 */ | 1275 */ |
1274 | 1276 |
1275 static void | 1277 static void |
1276 set_up_buffer_local_cache (Lisp_Object sym, | 1278 set_up_buffer_local_cache (Lisp_Object sym, |
1277 struct symbol_value_buffer_local *bfwd, | 1279 struct symbol_value_buffer_local *bfwd, |
1278 struct buffer *buf) | 1280 struct buffer *buf, |
1279 { | 1281 Lisp_Object new_alist_el, |
1280 Lisp_Object new_alist_el, new_val; | 1282 int set_it_p) |
1283 { | |
1284 Lisp_Object new_val; | |
1281 | 1285 |
1282 if (!NILP (bfwd->current_buffer) | 1286 if (!NILP (bfwd->current_buffer) |
1283 && buf == XBUFFER (bfwd->current_buffer)) | 1287 && buf == XBUFFER (bfwd->current_buffer)) |
1284 /* Cache is already set up. */ | 1288 /* Cache is already set up. */ |
1285 return; | 1289 return; |
1286 | 1290 |
1287 /* Flush out the old cache. */ | 1291 /* Flush out the old cache. */ |
1288 write_out_buffer_local_cache (sym, bfwd); | 1292 write_out_buffer_local_cache (sym, bfwd); |
1289 | 1293 |
1290 /* Retrieve the new alist element and new value. */ | 1294 /* Retrieve the new alist element and new value. */ |
1295 if (NILP (new_alist_el) | |
1296 && set_it_p) | |
1291 new_alist_el = buffer_local_alist_element (buf, sym, bfwd); | 1297 new_alist_el = buffer_local_alist_element (buf, sym, bfwd); |
1298 | |
1292 if (NILP (new_alist_el)) | 1299 if (NILP (new_alist_el)) |
1293 new_val = bfwd->default_value; | 1300 new_val = bfwd->default_value; |
1294 else | 1301 else |
1295 new_val = Fcdr (new_alist_el); | 1302 new_val = Fcdr (new_alist_el); |
1296 | 1303 |
1358 variable forwards to a C variable, we need to change the | 1365 variable forwards to a C variable, we need to change the |
1359 value of the C variable. set_up_buffer_local_cache() | 1366 value of the C variable. set_up_buffer_local_cache() |
1360 will do this. It doesn't hurt to do it whenever | 1367 will do this. It doesn't hurt to do it whenever |
1361 BUF == current_buffer, so just go ahead and do that. */ | 1368 BUF == current_buffer, so just go ahead and do that. */ |
1362 if (buf == current_buffer) | 1369 if (buf == current_buffer) |
1363 set_up_buffer_local_cache (sym, bfwd, buf); | 1370 set_up_buffer_local_cache (sym, bfwd, buf, Qnil, 0); |
1364 } | 1371 } |
1365 } | 1372 } |
1366 } | 1373 } |
1367 | 1374 |
1368 static Lisp_Object | 1375 static Lisp_Object |
1369 find_symbol_value_1 (Lisp_Object sym, struct buffer *buf, | 1376 find_symbol_value_1 (Lisp_Object sym, struct buffer *buf, |
1370 struct console *con, int swap_it_in) | 1377 struct console *con, int swap_it_in, |
1378 Lisp_Object symcons, int set_it_p) | |
1371 { | 1379 { |
1372 Lisp_Object valcontents; | 1380 Lisp_Object valcontents; |
1373 | 1381 |
1374 retry: | 1382 retry: |
1375 valcontents = XSYMBOL (sym)->value; | 1383 valcontents = XSYMBOL (sym)->value; |
1386 /* semi-change-o */ | 1394 /* semi-change-o */ |
1387 goto retry_2; | 1395 goto retry_2; |
1388 | 1396 |
1389 case SYMVAL_VARALIAS: | 1397 case SYMVAL_VARALIAS: |
1390 sym = follow_varalias_pointers (sym, Qt /* #### kludge */); | 1398 sym = follow_varalias_pointers (sym, Qt /* #### kludge */); |
1399 symcons = Qnil; | |
1391 /* presto change-o! */ | 1400 /* presto change-o! */ |
1392 goto retry; | 1401 goto retry; |
1393 | 1402 |
1394 case SYMVAL_BUFFER_LOCAL: | 1403 case SYMVAL_BUFFER_LOCAL: |
1395 case SYMVAL_SOME_BUFFER_LOCAL: | 1404 case SYMVAL_SOME_BUFFER_LOCAL: |
1397 struct symbol_value_buffer_local *bfwd | 1406 struct symbol_value_buffer_local *bfwd |
1398 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); | 1407 = XSYMBOL_VALUE_BUFFER_LOCAL (valcontents); |
1399 | 1408 |
1400 if (swap_it_in) | 1409 if (swap_it_in) |
1401 { | 1410 { |
1402 set_up_buffer_local_cache (sym, bfwd, buf); | 1411 set_up_buffer_local_cache (sym, bfwd, buf, symcons, set_it_p); |
1403 valcontents = bfwd->current_value; | 1412 valcontents = bfwd->current_value; |
1404 } | 1413 } |
1405 else | 1414 else |
1406 { | 1415 { |
1407 if (!NILP (bfwd->current_buffer) && | 1416 if (!NILP (bfwd->current_buffer) && |
1408 buf == XBUFFER (bfwd->current_buffer)) | 1417 buf == XBUFFER (bfwd->current_buffer)) |
1409 valcontents = bfwd->current_value; | 1418 valcontents = bfwd->current_value; |
1410 else | 1419 else if (NILP (symcons)) |
1411 { | 1420 { |
1421 if (set_it_p) | |
1412 valcontents = assq_no_quit (sym, buf->local_var_alist); | 1422 valcontents = assq_no_quit (sym, buf->local_var_alist); |
1413 if (NILP (valcontents)) | 1423 if (NILP (valcontents)) |
1414 valcontents = bfwd->default_value; | 1424 valcontents = bfwd->default_value; |
1415 else | 1425 else |
1416 valcontents = Fcdr (valcontents); | 1426 valcontents = XCDR (valcontents); |
1417 } | 1427 } |
1428 else | |
1429 valcontents = XCDR (symcons); | |
1418 } | 1430 } |
1419 break; | 1431 break; |
1420 } | 1432 } |
1421 | 1433 |
1422 default: | 1434 default: |
1447 | 1459 |
1448 return find_symbol_value_1 (sym, buf, | 1460 return find_symbol_value_1 (sym, buf, |
1449 /* If it bombs out at startup due to a | 1461 /* If it bombs out at startup due to a |
1450 Lisp error, this may be nil. */ | 1462 Lisp error, this may be nil. */ |
1451 CONSOLEP (Vselected_console) | 1463 CONSOLEP (Vselected_console) |
1452 ? XCONSOLE (Vselected_console) : 0, 0); | 1464 ? XCONSOLE (Vselected_console) : 0, 0, Qnil, 1); |
1453 } | 1465 } |
1454 | 1466 |
1455 static Lisp_Object | 1467 static Lisp_Object |
1456 symbol_value_in_console (Lisp_Object sym, Lisp_Object console) | 1468 symbol_value_in_console (Lisp_Object sym, Lisp_Object console) |
1457 { | 1469 { |
1460 if (!NILP (console)) | 1472 if (!NILP (console)) |
1461 CHECK_CONSOLE (console); | 1473 CHECK_CONSOLE (console); |
1462 else | 1474 else |
1463 console = Vselected_console; | 1475 console = Vselected_console; |
1464 | 1476 |
1465 return find_symbol_value_1 (sym, current_buffer, XCONSOLE (console), 0); | 1477 return find_symbol_value_1 (sym, current_buffer, XCONSOLE (console), 0, |
1478 Qnil, 1); | |
1466 } | 1479 } |
1467 | 1480 |
1468 /* Return the current value of SYM. The difference between this function | 1481 /* Return the current value of SYM. The difference between this function |
1469 and calling symbol_value_in_buffer with a BUFFER of Qnil is that | 1482 and calling symbol_value_in_buffer with a BUFFER of Qnil is that |
1470 this updates the CURRENT_VALUE slot of buffer-local variables to | 1483 this updates the CURRENT_VALUE slot of buffer-local variables to |
1487 actually fix things so we can't get here in that case? */ | 1500 actually fix things so we can't get here in that case? */ |
1488 assert (!initialized || preparing_for_armageddon); | 1501 assert (!initialized || preparing_for_armageddon); |
1489 dev = 0; | 1502 dev = 0; |
1490 } | 1503 } |
1491 | 1504 |
1492 return find_symbol_value_1 (sym, current_buffer, dev, 1); | 1505 return find_symbol_value_1 (sym, current_buffer, dev, 1, Qnil, 1); |
1506 } | |
1507 | |
1508 /* This is an optimized function for quick lookup of buffer local symbols | |
1509 by avoiding O(n) search. This will work when either: | |
1510 a) We have already found the symbol e.g. by traversing local_var_alist. | |
1511 or | |
1512 b) We know that the symbol will not be found in the current buffer's | |
1513 list of local variables. | |
1514 In the former case, find_it_p is 1 and symbol_cons is the element from | |
1515 local_var_alist. In the latter case, find_it_p is 0 and symbol_cons | |
1516 is the symbol. | |
1517 | |
1518 This function is called from set_buffer_internal which does both of these | |
1519 things. */ | |
1520 | |
1521 Lisp_Object | |
1522 find_symbol_value_quickly (Lisp_Object symbol_cons, int find_it_p) | |
1523 { | |
1524 /* WARNING: This function can be called when current_buffer is 0 | |
1525 and Vselected_console is Qnil, early in initialization. */ | |
1526 struct console *dev; | |
1527 Lisp_Object sym = find_it_p ? XCAR (symbol_cons) : symbol_cons; | |
1528 | |
1529 CHECK_SYMBOL (sym); | |
1530 if (CONSOLEP (Vselected_console)) | |
1531 dev = XCONSOLE (Vselected_console); | |
1532 else | |
1533 { | |
1534 /* This can also get called while we're preparing to shutdown. | |
1535 #### What should really happen in that case? Should we | |
1536 actually fix things so we can't get here in that case? */ | |
1537 assert (!initialized || preparing_for_armageddon); | |
1538 dev = 0; | |
1539 } | |
1540 | |
1541 return find_symbol_value_1 (sym, current_buffer, dev, 1, | |
1542 find_it_p ? symbol_cons : Qnil, | |
1543 find_it_p); | |
1493 } | 1544 } |
1494 | 1545 |
1495 DEFUN ("symbol-value", Fsymbol_value, 1, 1, 0, /* | 1546 DEFUN ("symbol-value", Fsymbol_value, 1, 1, 0, /* |
1496 Return SYMBOL's value. Error if that is void. | 1547 Return SYMBOL's value. Error if that is void. |
1497 */ | 1548 */ |
2117 { | 2168 { |
2118 case SYMVAL_FIXNUM_FORWARD: | 2169 case SYMVAL_FIXNUM_FORWARD: |
2119 case SYMVAL_BOOLEAN_FORWARD: | 2170 case SYMVAL_BOOLEAN_FORWARD: |
2120 case SYMVAL_OBJECT_FORWARD: | 2171 case SYMVAL_OBJECT_FORWARD: |
2121 case SYMVAL_DEFAULT_BUFFER_FORWARD: | 2172 case SYMVAL_DEFAULT_BUFFER_FORWARD: |
2122 set_up_buffer_local_cache (variable, bfwd, current_buffer); | 2173 set_up_buffer_local_cache (variable, bfwd, current_buffer, Qnil, 1); |
2123 break; | 2174 break; |
2124 | 2175 |
2125 case SYMVAL_UNBOUND_MARKER: | 2176 case SYMVAL_UNBOUND_MARKER: |
2126 case SYMVAL_CURRENT_BUFFER_FORWARD: | 2177 case SYMVAL_CURRENT_BUFFER_FORWARD: |
2127 break; | 2178 break; |
2213 /* We just changed the value in the current_buffer. If this | 2264 /* We just changed the value in the current_buffer. If this |
2214 variable forwards to a C variable, we need to change the | 2265 variable forwards to a C variable, we need to change the |
2215 value of the C variable. set_up_buffer_local_cache() | 2266 value of the C variable. set_up_buffer_local_cache() |
2216 will do this. It doesn't hurt to do it always, | 2267 will do this. It doesn't hurt to do it always, |
2217 so just go ahead and do that. */ | 2268 so just go ahead and do that. */ |
2218 set_up_buffer_local_cache (variable, bfwd, current_buffer); | 2269 set_up_buffer_local_cache (variable, bfwd, current_buffer, Qnil, 1); |
2219 } | 2270 } |
2220 return (variable); | 2271 return (variable); |
2221 | 2272 |
2222 default: | 2273 default: |
2223 return (variable); | 2274 return (variable); |