Mercurial > emacs
comparison src/buffer.c @ 11214:b880572ce431
(Fkill_buffer): Call reset_buffer_local_variables
and swap_out_buffer_local_variables.
(swap_out_buffer_local_variables): New subroutine.
(Fkill_all_local_variables): Use that subroutine.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 06 Apr 1995 06:58:50 +0000 |
parents | 20ff2eaa8bf8 |
children | f3b11dc9014e |
comparison
equal
deleted
inserted
replaced
11213:d0811ba886f8 | 11214:b880572ce431 |
---|---|
99 struct buffer buffer_local_types; | 99 struct buffer buffer_local_types; |
100 | 100 |
101 Lisp_Object Fset_buffer (); | 101 Lisp_Object Fset_buffer (); |
102 void set_buffer_internal (); | 102 void set_buffer_internal (); |
103 static void call_overlay_mod_hooks (); | 103 static void call_overlay_mod_hooks (); |
104 static void swap_out_buffer_local_variables (); | |
104 | 105 |
105 /* Alist of all buffer names vs the buffers. */ | 106 /* Alist of all buffer names vs the buffers. */ |
106 /* This used to be a variable, but is no longer, | 107 /* This used to be a variable, but is no longer, |
107 to prevent lossage due to user rplac'ing this alist or its elements. */ | 108 to prevent lossage due to user rplac'ing this alist or its elements. */ |
108 Lisp_Object Vbuffer_alist; | 109 Lisp_Object Vbuffer_alist; |
1007 BUF_INTERVALS (b) = NULL_INTERVAL; | 1008 BUF_INTERVALS (b) = NULL_INTERVAL; |
1008 #endif | 1009 #endif |
1009 | 1010 |
1010 /* Perhaps we should explicitly free the interval tree here... */ | 1011 /* Perhaps we should explicitly free the interval tree here... */ |
1011 } | 1012 } |
1013 | |
1014 /* Reset the local variables, so that this buffer's local values | |
1015 won't be protected from GC. They would be protected | |
1016 if they happened to remain encached in their symbols. | |
1017 This gets rid of them for certain. */ | |
1018 swap_out_buffer_local_variables (b); | |
1019 reset_buffer_local_variables (b); | |
1012 | 1020 |
1013 b->name = Qnil; | 1021 b->name = Qnil; |
1014 | 1022 |
1015 BLOCK_INPUT; | 1023 BLOCK_INPUT; |
1016 if (! b->base_buffer) | 1024 if (! b->base_buffer) |
1443 | 1451 |
1444 if (!NILP (Vrun_hooks)) | 1452 if (!NILP (Vrun_hooks)) |
1445 call1 (Vrun_hooks, intern ("change-major-mode-hook")); | 1453 call1 (Vrun_hooks, intern ("change-major-mode-hook")); |
1446 oalist = current_buffer->local_var_alist; | 1454 oalist = current_buffer->local_var_alist; |
1447 | 1455 |
1448 /* Make sure no local variables remain set up with this buffer | 1456 /* Make sure none of the bindings in oalist |
1449 for their current values. */ | 1457 remain swapped in, in their symbols. */ |
1450 | 1458 |
1451 for (alist = oalist; !NILP (alist); alist = XCONS (alist)->cdr) | 1459 swap_out_buffer_local_variables (current_buffer); |
1452 { | |
1453 sym = XCONS (XCONS (alist)->car)->car; | |
1454 | |
1455 /* Need not do anything if some other buffer's binding is now encached. */ | |
1456 tem = XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->car; | |
1457 if (XBUFFER (tem) == current_buffer) | |
1458 { | |
1459 /* Symbol is set up for this buffer's old local value. | |
1460 Set it up for the current buffer with the default value. */ | |
1461 | |
1462 tem = XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->cdr; | |
1463 /* Store the symbol's current value into the alist entry | |
1464 it is currently set up for. This is so that, if the | |
1465 local is marked permanent, and we make it local again below, | |
1466 we don't lose the value. */ | |
1467 XCONS (XCONS (tem)->car)->cdr | |
1468 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car); | |
1469 /* Switch to the symbol's default-value alist entry. */ | |
1470 XCONS (tem)->car = tem; | |
1471 /* Mark it as current for the current buffer. */ | |
1472 XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->car | |
1473 = Fcurrent_buffer (); | |
1474 /* Store the current value into any forwarding in the symbol. */ | |
1475 store_symval_forwarding (sym, XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car, | |
1476 XCONS (tem)->cdr); | |
1477 } | |
1478 } | |
1479 | 1460 |
1480 /* Actually eliminate all local bindings of this buffer. */ | 1461 /* Actually eliminate all local bindings of this buffer. */ |
1481 | 1462 |
1482 reset_buffer_local_variables (current_buffer); | 1463 reset_buffer_local_variables (current_buffer); |
1483 | 1464 |
1502 /* Force mode-line redisplay. Useful here because all major mode | 1483 /* Force mode-line redisplay. Useful here because all major mode |
1503 commands call this function. */ | 1484 commands call this function. */ |
1504 update_mode_lines++; | 1485 update_mode_lines++; |
1505 | 1486 |
1506 return Qnil; | 1487 return Qnil; |
1488 } | |
1489 | |
1490 /* Make sure no local variables remain set up with buffer B | |
1491 for their current values. */ | |
1492 | |
1493 static void | |
1494 swap_out_buffer_local_variables (b) | |
1495 struct buffer *b; | |
1496 { | |
1497 Lisp_Object oalist, alist, sym, tem, buffer; | |
1498 | |
1499 XSETBUFFER (buffer, b); | |
1500 oalist = b->local_var_alist; | |
1501 | |
1502 for (alist = oalist; !NILP (alist); alist = XCONS (alist)->cdr) | |
1503 { | |
1504 sym = XCONS (XCONS (alist)->car)->car; | |
1505 | |
1506 /* Need not do anything if some other buffer's binding is now encached. */ | |
1507 tem = XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->car; | |
1508 if (XBUFFER (tem) == current_buffer) | |
1509 { | |
1510 /* Symbol is set up for this buffer's old local value. | |
1511 Set it up for the current buffer with the default value. */ | |
1512 | |
1513 tem = XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->cdr; | |
1514 /* Store the symbol's current value into the alist entry | |
1515 it is currently set up for. This is so that, if the | |
1516 local is marked permanent, and we make it local again | |
1517 later in Fkill_all_local_variables, we don't lose the value. */ | |
1518 XCONS (XCONS (tem)->car)->cdr | |
1519 = do_symval_forwarding (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car); | |
1520 /* Switch to the symbol's default-value alist entry. */ | |
1521 XCONS (tem)->car = tem; | |
1522 /* Mark it as current for buffer B. */ | |
1523 XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->car | |
1524 = buffer; | |
1525 /* Store the current value into any forwarding in the symbol. */ | |
1526 store_symval_forwarding (sym, XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car, | |
1527 XCONS (tem)->cdr); | |
1528 } | |
1529 } | |
1507 } | 1530 } |
1508 | 1531 |
1509 /* Find all the overlays in the current buffer that contain position POS. | 1532 /* Find all the overlays in the current buffer that contain position POS. |
1510 Return the number found, and store them in a vector in *VEC_PTR. | 1533 Return the number found, and store them in a vector in *VEC_PTR. |
1511 Store in *LEN_PTR the size allocated for the vector. | 1534 Store in *LEN_PTR the size allocated for the vector. |