comparison src/buffer.c @ 87218:409f76c92cb2

(reset_buffer_local_variables): If permanent_too is 0, also preserve non-built-in buffer-local variables. (Fkill_all_local_variables): Don't re-create&re-set permanent buffer-local variables.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 10 Dec 2007 03:47:46 +0000
parents 7d40f609f780
children 40dcde0eb331
comparison
equal deleted inserted replaced
87217:b158ddb21552 87218:409f76c92cb2
105 105
106 /* Number of per-buffer variables used. */ 106 /* Number of per-buffer variables used. */
107 107
108 int last_per_buffer_idx; 108 int last_per_buffer_idx;
109 109
110 Lisp_Object Fset_buffer (); 110 EXFUN (Fset_buffer, 1);
111 void set_buffer_internal (); 111 void set_buffer_internal P_ ((struct buffer *b));
112 void set_buffer_internal_1 (); 112 void set_buffer_internal_1 P_ ((struct buffer *b));
113 static void call_overlay_mod_hooks (); 113 static void call_overlay_mod_hooks P_ ((Lisp_Object list, Lisp_Object overlay,
114 static void swap_out_buffer_local_variables (); 114 int after, Lisp_Object arg1,
115 static void reset_buffer_local_variables (); 115 Lisp_Object arg2, Lisp_Object arg3));
116 static void swap_out_buffer_local_variables P_ ((struct buffer *b));
117 static void reset_buffer_local_variables P_ ((struct buffer *b, int permanent_too));
116 118
117 /* Alist of all buffer names vs the buffers. */ 119 /* Alist of all buffer names vs the buffers. */
118 /* This used to be a variable, but is no longer, 120 /* This used to be a variable, but is no longer,
119 to prevent lossage due to user rplac'ing this alist or its elements. */ 121 to prevent lossage due to user rplac'ing this alist or its elements. */
120 Lisp_Object Vbuffer_alist; 122 Lisp_Object Vbuffer_alist;
714 /* Reset buffer B's local variables info. 716 /* Reset buffer B's local variables info.
715 Don't use this on a buffer that has already been in use; 717 Don't use this on a buffer that has already been in use;
716 it does not treat permanent locals consistently. 718 it does not treat permanent locals consistently.
717 Instead, use Fkill_all_local_variables. 719 Instead, use Fkill_all_local_variables.
718 720
719 If PERMANENT_TOO is 1, then we reset permanent built-in 721 If PERMANENT_TOO is 1, then we reset permanent
720 buffer-local variables. If PERMANENT_TOO is 0, 722 buffer-local variables. If PERMANENT_TOO is 0,
721 we preserve those. */ 723 we preserve those. */
722 724
723 static void 725 static void
724 reset_buffer_local_variables (b, permanent_too) 726 reset_buffer_local_variables (b, permanent_too)
752 #ifndef DOS_NT 754 #ifndef DOS_NT
753 b->buffer_file_type = Qnil; 755 b->buffer_file_type = Qnil;
754 #endif 756 #endif
755 757
756 /* Reset all (or most) per-buffer variables to their defaults. */ 758 /* Reset all (or most) per-buffer variables to their defaults. */
757 b->local_var_alist = Qnil; 759 if (permanent_too)
760 b->local_var_alist = Qnil;
761 else
762 {
763 Lisp_Object tmp, last = Qnil;
764 for (tmp = b->local_var_alist; CONSP (tmp); tmp = XCDR (tmp))
765 if (CONSP (XCAR (tmp))
766 && SYMBOLP (XCAR (XCAR (tmp)))
767 && !NILP (Fget (XCAR (XCAR (tmp)), Qpermanent_local)))
768 /* If permanent-local, keep it. */
769 last = tmp;
770 else if (NILP (last))
771 b->local_var_alist = XCDR (tmp);
772 else
773 XSETCDR (last, XCDR (tmp));
774 }
775
758 for (i = 0; i < last_per_buffer_idx; ++i) 776 for (i = 0; i < last_per_buffer_idx; ++i)
759 if (permanent_too || buffer_permanent_local_flags[i] == 0) 777 if (permanent_too || buffer_permanent_local_flags[i] == 0)
760 SET_PER_BUFFER_VALUE_P (b, i, 0); 778 SET_PER_BUFFER_VALUE_P (b, i, 0);
761 779
762 /* For each slot that has a default value, 780 /* For each slot that has a default value,
2450 2468
2451 The first thing this function does is run 2469 The first thing this function does is run
2452 the normal hook `change-major-mode-hook'. */) 2470 the normal hook `change-major-mode-hook'. */)
2453 () 2471 ()
2454 { 2472 {
2455 register Lisp_Object alist, sym, tem;
2456 Lisp_Object oalist;
2457
2458 if (!NILP (Vrun_hooks)) 2473 if (!NILP (Vrun_hooks))
2459 call1 (Vrun_hooks, Qchange_major_mode_hook); 2474 call1 (Vrun_hooks, Qchange_major_mode_hook);
2460 oalist = current_buffer->local_var_alist; 2475
2461 2476 /* Make sure none of the bindings in local_var_alist
2462 /* Make sure none of the bindings in oalist
2463 remain swapped in, in their symbols. */ 2477 remain swapped in, in their symbols. */
2464 2478
2465 swap_out_buffer_local_variables (current_buffer); 2479 swap_out_buffer_local_variables (current_buffer);
2466 2480
2467 /* Actually eliminate all local bindings of this buffer. */ 2481 /* Actually eliminate all local bindings of this buffer. */
2468 2482
2469 reset_buffer_local_variables (current_buffer, 0); 2483 reset_buffer_local_variables (current_buffer, 0);
2470
2471 /* Any which are supposed to be permanent,
2472 make local again, with the same values they had. */
2473
2474 for (alist = oalist; CONSP (alist); alist = XCDR (alist))
2475 {
2476 sym = XCAR (XCAR (alist));
2477 tem = Fget (sym, Qpermanent_local);
2478 if (! NILP (tem))
2479 {
2480 Fmake_local_variable (sym);
2481 Fset (sym, XCDR (XCAR (alist)));
2482 }
2483 }
2484 2484
2485 /* Force mode-line redisplay. Useful here because all major mode 2485 /* Force mode-line redisplay. Useful here because all major mode
2486 commands call this function. */ 2486 commands call this function. */
2487 update_mode_lines++; 2487 update_mode_lines++;
2488 2488